Skip to content

Commit

Permalink
[FIX] purchase_order_secondary_unit: precompute for some fields
Browse files Browse the repository at this point in the history
  • Loading branch information
acsonefho authored and dalonsod committed Mar 27, 2024
1 parent 9b93a2e commit 4325613
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions purchase_order_secondary_unit/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class PurchaseOrderLine(models.Model):
}
_product_uom_field = "uom_po_id"

product_qty = fields.Float(
store=True, readonly=False, compute="_compute_product_qty", copy=True
)
product_qty = fields.Float(precompute=True)
product_packaging_qty = fields.Float(precompute=True)
product_packaging_id = fields.Many2one(precompute=True)

@api.depends("secondary_uom_qty", "secondary_uom_id")
def _compute_product_qty(self):
Expand All @@ -35,8 +35,12 @@ def onchange_product_id(self):
res = super().onchange_product_id()
# Check to avoid executing onchange unnecessarily,
# which can sometimes cause tests of other modules to fail
if self.secondary_uom_id != self.product_id.purchase_secondary_uom_id:
self.secondary_uom_id = self.product_id.purchase_secondary_uom_id
product_sec_uom = (
self.product_id.purchase_secondary_uom_id
or self.product_id.product_tmpl_id.purchase_secondary_uom_id
)
if self.secondary_uom_id != product_sec_uom:
self.secondary_uom_id = product_sec_uom
if self.secondary_uom_id:
self.secondary_uom_qty = 1.0
return res

0 comments on commit 4325613

Please sign in to comment.