Skip to content

Commit

Permalink
fixup! Add purchase_propagate_qty_mrp
Browse files Browse the repository at this point in the history
  • Loading branch information
TDu committed Nov 5, 2024
1 parent d8e06d3 commit 1a48169
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions purchase_propagate_qty_mrp/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,29 @@ def _propagage_qty_to_moves(self):

def _propagate_qty_to_moves_mrp(self):
self.ensure_one()
bom = self.env["mrp.bom"].sudo()._bom_find(product=self.product_id)
if not bom or bom.type != "phantom":
relevant_bom = False
for bom in self.move_ids.bom_line_id.bom_id:
if bom.type != "phantom":
continue

Check warning on line 27 in purchase_propagate_qty_mrp/models/purchase_order_line.py

View check run for this annotation

Codecov / codecov/patch

purchase_propagate_qty_mrp/models/purchase_order_line.py#L27

Added line #L27 was not covered by tests
if (
bom.product_id == self.product_id
or bom.product_tmpl_id == self.product_id.product_tmpl_id
and not bom.product_id
):
relevant_bom = bom
break
if not relevant_bom:
return None

Check warning on line 36 in purchase_propagate_qty_mrp/models/purchase_order_line.py

View check run for this annotation

Codecov / codecov/patch

purchase_propagate_qty_mrp/models/purchase_order_line.py#L36

Added line #L36 was not covered by tests
new_kit_quantity = self.product_uom_qty
boms, bom_sub_lines = bom.explode(self.product_id, new_kit_quantity)
boms, bom_sub_lines = relevant_bom.explode(self.product_id, new_kit_quantity)
for bom_line, bom_line_data in bom_sub_lines:
bom_line_uom = bom_line.product_uom_id
quant_uom = bom_line.product_id.uom_id
new_component_qty, procurement_uom = bom_line_uom._adjust_uom_quantities(
bom_line_data["qty"], quant_uom
)
moves = self.move_ids.filtered(
lambda move: move.product_id == bom_line.product_id
and move.state != "cancel"
lambda move: move.bom_line_id == bom_line and move.state != "cancel"
)
previous_component_qty = sum(moves.mapped("product_uom_qty"))
removable_qty = moves._get_removable_qty()
Expand Down

0 comments on commit 1a48169

Please sign in to comment.