From 2b2a7712e1e0d9317dbf9dcb708ef335bdfa7e50 Mon Sep 17 00:00:00 2001 From: clesgow Date: Fri, 5 Aug 2022 16:10:52 +0000 Subject: [PATCH] [IMP] mrp: Add automatic Days to Prepare MO Since the new Overview report can compute the lead days and availability delays from a BoM and all of its components and/or subassemblies, we can use this data to compute the days that would be required to resupply all components from a BoM. So we add a button to compute it directly on the product form. Task-2628323 Part-of: odoo/odoo#93194 --- addons/mrp/models/product.py | 13 +++++++++++++ addons/mrp/views/product_views.xml | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/addons/mrp/models/product.py b/addons/mrp/models/product.py index 663e6da0aef..18f93a6050f 100644 --- a/addons/mrp/models/product.py +++ b/addons/mrp/models/product.py @@ -87,6 +87,10 @@ class ProductTemplate(models.Model): } return action + def action_compute_bom_days(self): + templates = self.filtered(lambda t: t.bom_count > 0) + if templates: + return templates.mapped('product_variant_id').action_compute_bom_days() class ProductProduct(models.Model): _inherit = "product.product" @@ -281,6 +285,15 @@ class ProductProduct(models.Model): res['context'].pop('default_product_tmpl_id', None) return res + def action_compute_bom_days(self): + bom_by_products = self.env['mrp.bom']._bom_find(self) + company_id = self.env.context.get('default_company_id', self.env.company.id) + warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_id)], limit=1) + for product in self: + bom_data = self.env['report.mrp.report_bom_structure'].with_context(minimized=True)._get_bom_data(bom_by_products[product], warehouse, product, ignore_stock=True) + availability_delay = bom_data.get('resupply_avail_delay') + product.days_to_prepare_mo = availability_delay - bom_data.get('lead_time', 0) if availability_delay else 0 + def _match_all_variant_values(self, product_template_attribute_value_ids): """ It currently checks that all variant values (`product_template_attribute_value_ids`) are in the product (`self`). diff --git a/addons/mrp/views/product_views.xml b/addons/mrp/views/product_views.xml index 5ea072a561e..38b86b1623c 100644 --- a/addons/mrp/views/product_views.xml +++ b/addons/mrp/views/product_views.xml @@ -8,6 +8,7 @@ +