Skip to content

Commit

Permalink
[IMP] sale_order_qty_change_no_recompute: Prevent recalculation of pr…
Browse files Browse the repository at this point in the history
…ice when quantity is changed on sales order line
  • Loading branch information
Yadier-Tecnativa committed Apr 11, 2023
1 parent 8618ebc commit 97cb12c
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions sale_order_qty_change_no_recompute/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,34 @@
# Copyright 2021 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models
from odoo.tools import config
from odoo import api, models


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

def _onchange_eval(self, field_name, onchange, result):
"""Remove the trigger for the undesired onchange method with this field.
We have to act at this place, as `_onchange_methods` is defined as a
property, and thus it can't be inherited due to the conflict of
inheritance between Python and Odoo ORM, so we can consider this as a HACK.
"""
ctx = self.env.context
if field_name in {"product_uom_qty", "product_uom"} and (
not config["test_enable"]
or (config["test_enable"] and ctx.get("prevent_onchange_quantity", False))
):
cls = type(self)
for method in self._onchange_methods.get(field_name, ()):
if method == cls.product_uom_change:
self._onchange_methods[field_name].remove(method)
break
return super()._onchange_eval(field_name, onchange, result)
@api.depends("product_id", "product_uom", "product_uom_qty")
def _compute_price_unit(self):
for line in self:
if line.qty_invoiced > 0:
continue
if (
not line.product_uom
or not line.product_id
or not line.order_id.pricelist_id
):
line.price_unit = 0.0
else:
price = line.with_company(line.company_id)._get_display_price()
# if the price was set manually, it remains unchanged
if price != line.price_unit and line.price_unit > 0:
price = line.price_unit
line.price_unit = line.product_id._get_tax_included_unit_price(
line.company_id,
line.order_id.currency_id,
line.order_id.date_order,
"sale",
fiscal_position=line.order_id.fiscal_position_id,
product_price_unit=price,
product_currency=line.currency_id,
)

0 comments on commit 97cb12c

Please sign in to comment.