[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
This commit is contained in:
clesgow
2022-08-26 17:16:42 +02:00
parent a974290237
commit 2b2a7712e1
2 changed files with 17 additions and 0 deletions
+13
View File
@@ -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`).
+4
View File
@@ -8,6 +8,7 @@
<field name="inherit_id" ref="stock.view_template_property_form"/>
<field name="arch" type="xml">
<xpath expr="//label[@for='sale_delay']" position="before">
<field name="bom_count" string="Bill of Materials" invisible="1"/>
<label for="produce_delay" string="Manuf. Lead Time" attrs="{'invisible':[('type','=','service')]}"/>
<div attrs="{'invisible':[('type','=','service')]}">
<field name="produce_delay" class="oe_inline"/> days
@@ -15,6 +16,9 @@
<label for="days_to_prepare_mo" attrs="{'invisible':[('type','=','service')]}"/>
<div attrs="{'invisible':[('type','=','service')]}">
<field name="days_to_prepare_mo" class="oe_inline"/> days
<button name="action_compute_bom_days" string="Compute from BoM" type="object" attrs="{'invisible':['|', ('type', '=', 'service'), ('bom_count', '=', 0)]}"
help="Compute the days required to resupply all components from BoM, by either buying or manufacturing the components and/or subassemblies."
class="oe_link oe_read_only pt-0"/>
</div>
</xpath>
<xpath expr="//field[@name='product_variant_count']" position="after">