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

[FIX] mrp: fix negative values in subcontracting BoM Overview #144702

Closed

Conversation

pfertyk
Copy link
Contributor

@pfertyk pfertyk commented Dec 4, 2023

Task: 3607854

Description of the issue/feature this PR addresses:

Current behavior before PR:

Desired behavior after PR is merged:


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Dec 4, 2023

Pull request status dashboard.

@C3POdoo C3POdoo added the RD research & development, internal work label Dec 4, 2023
@pfertyk pfertyk force-pushed the 17.0-subcontracting-negative-values-pafe branch 3 times, most recently from ff2df2f to dd0bee0 Compare December 7, 2023 14:06
@pfertyk pfertyk force-pushed the 17.0-subcontracting-negative-values-pafe branch 3 times, most recently from 9a7bc61 to e5ce20f Compare December 18, 2023 08:11
@pfertyk pfertyk force-pushed the 17.0-subcontracting-negative-values-pafe branch from e5ce20f to 82c64c5 Compare December 26, 2023 10:33
@pfertyk pfertyk force-pushed the 17.0-subcontracting-negative-values-pafe branch 4 times, most recently from 1645389 to fcd2c87 Compare January 15, 2024 16:26
@pfertyk pfertyk marked this pull request as ready for review January 23, 2024 09:06
@C3POdoo C3POdoo requested a review from a team January 23, 2024 09:08
@pfertyk pfertyk force-pushed the 17.0-subcontracting-negative-values-pafe branch from fcd2c87 to 3e1996d Compare January 23, 2024 10:15
@pfertyk pfertyk force-pushed the 17.0-subcontracting-negative-values-pafe branch 3 times, most recently from 19bfe04 to 29b9edd Compare January 30, 2024 09:56
@@ -116,7 +116,8 @@ def _get_resupply_availability(self, route_info, components):
vendor_lead_time = route_info['supplier'].delay
manufacture_lead_time = route_info['bom'].produce_delay
subcontract_delay = resupply_delay if resupply_delay else 0
subcontract_delay += max(vendor_lead_time, manufacture_lead_time + max_component_delay)
subcontract_delay += max(vendor_lead_time, manufacture_lead_time) + max_component_delay
Copy link
Contributor

Choose a reason for hiding this comment

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

Changeing this is wrong to me because of the formula introduced here 78e44dc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid that the original formula might be wrong 😅 I think that, in this case, the max_component_delay value represents either the availability from stock or from resupply. So, the final value is a max of vendor lead time and manufacture lead time (i.e. what the vendor declares vs the actual time it takes to manufacture a product) and then we add the delay of components (e.g. 0 if they are available or resupply time if they are not). We cannot start the manufacturing process until we get the components, so the component delay was moved out of the max calculation.

But I agree that this is all very complicated, and the names of variables don't always reflect on the actual information they hold :( Perhaps we can discuss this further, or involve one of our MGM in this conversation?

self.env['stock.quant']._update_available_quantity(self.comp1, self.warehouse.lot_stock_id, 100)
self.env['stock.quant']._update_available_quantity(self.comp2, self.warehouse.lot_stock_id, 100)
self.env['stock.quant']._update_available_quantity(self.comp1, self.env.company.subcontracting_location_id, 100)
self.env['stock.quant']._update_available_quantity(self.comp2, self.env.company.subcontracting_location_id, 100)
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer you duplicate the test and change the update quantity in yours

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid that the test was failing without this change :( I think that the old code was not working correctly, i.e. it was checking the wrong location or not checking it at all ... I implemented this a while ago, I will have to review my notes. But do you think that, in this case, warehouse.lot_stock_id is the correct place for subcontracting components? Doesn't it make more sense to store them in subcontracting_location_id ?

@@ -535,7 +537,7 @@ def test_subcontracting_lead_days_on_overview(self):
bom_data = self.env['report.mrp.report_bom_structure']._get_bom_data(self.bom, self.warehouse, self.finished)
self.assertEqual(bom_data['lead_time'], 15 + 5 + 5 + 0,
"Lead time = Purchase lead time(finished) + Days to Purchase + Purchase security lead time + DTPMO on BOM")
self.assertEqual(bom_data['resupply_avail_delay'], 10 + 5 + 5 + 20,
self.assertEqual(bom_data['resupply_avail_delay'], 15 + 5 + 5 + 20,
Copy link
Contributor

Choose a reason for hiding this comment

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

why ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I think I figured this out 🙂

Normally:

resupply avail delay = 
resupply delay +
max(vendor lead time, manufacture lead time) +
max component delay

In Purchase, we also need to add to that "Purchase security lead days" and "Days to Purchase".

In this case:

  • resupply delay = 0 (False in _get_resupply_availability in MRP, because route type is not "manufacture")
  • vendor lead time = 15 (delay of the final product)
  • manufacture lead time = 10 (produce_delay of the BoM)
  • Purchase security lead days = 5 (po_lead)
  • Days to Purchase = 5 (days_to_purchase)
  • max component delay = 20

The only surprise for me is the last part, which I would expect to be 10 (we have 2 components, with delays 10 and 6). But then I realized that in Purchase, we also add po_lead and days_to_purchase to component delay 😉 So it's 10 + 5 + 5 = 20.

The final value is 0 + max(15, 10) + 5 + 5 + 20 = 15 + 5 + 5 + 20, which is what the test checks after my changes 😄 I will update the assertion below, so we don't have to investigate this again 😉

@pfertyk pfertyk force-pushed the 17.0-subcontracting-negative-values-pafe branch from 29b9edd to 53db399 Compare February 27, 2024 08:38
@pfertyk pfertyk force-pushed the 17.0-subcontracting-negative-values-pafe branch from 53db399 to a180b94 Compare March 5, 2024 22:54
A subcontracting BoM sometimes shows negative values in Overview, if
components are available in subcontractor's location.

Task: 3607854
@pfertyk pfertyk force-pushed the 17.0-subcontracting-negative-values-pafe branch from a180b94 to 24a2dc2 Compare March 13, 2024 08:03
@Whenrow
Copy link
Contributor

Whenrow commented Mar 13, 2024

robodoo r+

@fw-bot fw-bot deleted the 17.0-subcontracting-negative-values-pafe branch March 27, 2024 11:46
synercatalyst pushed a commit to synercatalyst/odoo that referenced this pull request May 1, 2024
A subcontracting BoM sometimes shows negative values in Overview, if
components are available in subcontractor's location.

closes odoo#144702

Task: 3607854
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants