Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0'][ADD] Add purchase_propagate_qty_mrp #2449

Open
wants to merge 3 commits into
base: 14.0
Choose a base branch
from

Conversation

TDu
Copy link
Member

@TDu TDu commented Nov 4, 2024

No description provided.

@TDu TDu force-pushed the 14-purchase-propagate-qty-mrp branch 2 times, most recently from b3ea1b0 to 98973f7 Compare November 5, 2024 11:01

def _propagate_qty_to_moves_mrp(self):
self.ensure_one()
bom = self.env["mrp.bom"].sudo()._bom_find(product=self.product_id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes _bom_find should be used but at first the moves should be checked.
If there is no move with a bom line which linked to a bom for the purchased product than _bom_find should be used.
This is the case for a kits in kit scenario then there is no bom for the main product.

Suggested change
bom = self.env["mrp.bom"].sudo()._bom_find(product=self.product_id)
boms = self.move_ids.bom_line_id.bom_id
relevant_bom = False
for bom in boms:
if bom.type == "phantom" and (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:
relevant_bom = self.env["mrp.bom"].sudo()._bom_find(product=self.product_id, bom_type="phantom")
bom = relevant_bom

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review. Using the bom_line_id on stock.move to find the related bom sounds much better.

Do you think using _bom_find is still necessary, because anyway no matching will be possible between the stock.move and the bom.line from the explode.

I will not include it yet.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is still necessary for a kit in kit scenario.
For example:
P-Kit-1 -> includes P1 and P2
P-Kit-2 -> includes P3 and P4
P-Kit-3 -> includes P-Kit-1 and P-Kit-2

The you will end update with moves for P1, P2, P3 and P4 no move will be link to the bom of P-Kit-3, the will be linked to P-Kit-1 bomlines and P-Kit-2. You will never find a bom for P-Kit-3.

bom_line_data["qty"], quant_uom
)
moves = self.move_ids.filtered(
lambda move: move.product_id == bom_line.product_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lambda move: move.product_id == bom_line.product_id
lambda move: move.bom_line_id == bom_line

@TDu TDu force-pushed the 14-purchase-propagate-qty-mrp branch from 98973f7 to d8e06d3 Compare November 5, 2024 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants