Skip to content

Commit

Permalink
[IMP] sale_order_qty_change_no_recompute: Add context in test to prev…
Browse files Browse the repository at this point in the history
…ent onchange quantity and some possible related error in another addons.
  • Loading branch information
victoralmau authored and pedrobaeza committed May 1, 2023
1 parent 127e21e commit 6220365
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sale_order_qty_change_no_recompute/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Sale Order Qty change no recompute",
"summary": "Prevent recompute if only quantity has changed in sale order line",
"version": "14.0.1.0.0",
"version": "14.0.1.0.1",
"category": "Sale Workflow",
"website": "https://github.com/OCA/sale-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
Expand Down
7 changes: 6 additions & 1 deletion sale_order_qty_change_no_recompute/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models
from odoo.tools import config


class SaleOrderLine(models.Model):
Expand All @@ -15,7 +16,11 @@ def _onchange_eval(self, field_name, onchange, result):
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.
"""
if field_name == "product_uom_qty":
ctx = self.env.context
if field_name == "product_uom_qty" 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def setUpClass(cls):
{"name": "Test Product 2", "list_price": 30.00, "taxes_id": False}
)
pricelist = cls.env["product.pricelist"].create({"name": "Test pricelist"})
sale_form = Form(cls.env["sale.order"])
sale_form = Form(
cls.env["sale.order"].with_context(prevent_onchange_quantity=True)
)
sale_form.partner_id = cls.env.ref("base.res_partner_12")
sale_form.pricelist_id = pricelist
with sale_form.order_line.new() as cls.line_form:
Expand Down

0 comments on commit 6220365

Please sign in to comment.