Skip to content

Commit

Permalink
[IMP] purchase_only_by_packaging: Improve _compute_product_qty() to b…
Browse files Browse the repository at this point in the history
…e compatible with purchase_blanket_order
  • Loading branch information
victoralmau committed Mar 1, 2024
1 parent 6198511 commit 02449f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions purchase_only_by_packaging/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ def _force_qty_with_package(self):
@api.onchange("product_qty")
def _onchange_product_qty(self):
self._force_qty_with_package()

@api.depends("product_packaging_id")
def _compute_product_qty(self):
res = super()._compute_product_qty()
for item in self.filtered(lambda x: x.product_packaging_id):
old_qty = item.product_qty
item.product_qty = item.product_id._convert_packaging_qty(
old_qty, item.product_uom, packaging=item.product_packaging_id
)
return res
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def test_convert_packaging_qty(self):
"""
self.product.purchase_only_by_packaging = True
packaging = self.packaging_tu
self.order_line.product_packaging_id = packaging
# For this step, the qty is not forced on the packaging
# But the warning will be raise because the value of packaging qty is
# not integer package
with self.assertRaises(ValidationError):
self.order_line.product_packaging_id = packaging
self.order_line.product_packaging_qty = 0.6
self.assertAlmostEqual(
self.order_line.product_qty, 12, places=self.precision
Expand Down

0 comments on commit 02449f4

Please sign in to comment.