Skip to content

Commit

Permalink
[MIG] purchase_order_qty_change_no_recompute: Migration to 16.0
Browse files Browse the repository at this point in the history
TT46595
  • Loading branch information
victoralmau committed Mar 1, 2024
1 parent f4cceba commit 3f5d9f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion purchase_order_qty_change_no_recompute/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["purchase", "purchase_discount"],
"depends": ["purchase_discount"],
"maintainers": ["victoralmau"],
}
9 changes: 8 additions & 1 deletion purchase_order_qty_change_no_recompute/monkeypatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@


def get_depends(self, model):
"""Override of the Python method to remove the dependency of the unit fields."""
"""Override of the Python method to remove the dependency of the unit fields.
We also need to add the name and date_planned fields because they use the same
compute method as the price_unit field."""
depends, depends_context = get_depends_original(self, model)
if model._name == "purchase.order.line" and self.name in {
"name",
"date_planned",
"price_unit",
"discount",
}:
if "product_qty" in depends:
depends.remove("product_qty")
if "product_uom" in depends:
depends.remove("product_uom")
# We need to add a field to the depends to be defined.
if self.name == "date_planned":
depends.append("product_id")
return depends, depends_context


Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import Form, TransactionCase
from odoo.tests.common import Form

from odoo.addons.base.tests.common import BaseCommon

class TestPurchaseOrderQtyChange(TransactionCase):

class TestPurchaseOrderQtyChange(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Remove this variable in v16 and put instead:
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
DISABLED_MAIL_CONTEXT = {
"tracking_disable": True,
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.partner = cls.env["res.partner"].create({"name": "Test supplier"})
cls.product_1 = cls.env["product.product"].create(
{
Expand Down Expand Up @@ -44,9 +36,7 @@ def setUpClass(cls):
],
}
)
purchase_order_form = Form(
cls.env["purchase.order"].with_context(prevent_onchange_quantity=True)
)
purchase_order_form = Form(cls.env["purchase.order"])
purchase_order_form.partner_id = cls.partner
with purchase_order_form.order_line.new() as cls.line_form:
cls.line_form.product_id = cls.product_1
Expand Down

0 comments on commit 3f5d9f9

Please sign in to comment.