[FIX] mrp: BoM overview kit fix
When overviewing a BoM with a "kit" type and with no route, the availability was always unavailable, wich is wrong if all the parts are in stock or can be replenished. Task-3184663 closes odoo/odoo#121783 X-original-commit: f13b4d1ae8c12a1668222e6994dea26a27c6f5d4 Related: odoo/enterprise#41248 Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -237,7 +237,7 @@ class ReportBomStructure(models.AbstractModel):
|
||||
bom_report_line['byproducts_total'] = sum(byproduct['quantity'] for byproduct in byproducts)
|
||||
bom_report_line['bom_cost'] *= bom_report_line['cost_share']
|
||||
|
||||
availabilities = self._get_availabilities(product, current_quantity, product_info, bom_key, quantities_info, level, ignore_stock, components)
|
||||
availabilities = self._get_availabilities(product, current_quantity, product_info, bom_key, quantities_info, level, ignore_stock, components, bom_report_line)
|
||||
bom_report_line.update(availabilities)
|
||||
|
||||
if level == 0:
|
||||
@@ -514,7 +514,7 @@ class ReportBomStructure(models.AbstractModel):
|
||||
return {}
|
||||
|
||||
@api.model
|
||||
def _get_availabilities(self, product, quantity, product_info, bom_key, quantities_info, level, ignore_stock=False, components=False):
|
||||
def _get_availabilities(self, product, quantity, product_info, bom_key, quantities_info, level, ignore_stock=False, components=False, report_line=False):
|
||||
# Get availabilities according to stock (today & forecasted).
|
||||
stock_state, stock_delay = ('unavailable', False)
|
||||
if not ignore_stock:
|
||||
@@ -529,6 +529,10 @@ class ReportBomStructure(models.AbstractModel):
|
||||
elif route_info:
|
||||
resupply_state, resupply_delay = self._get_resupply_availability(route_info, components)
|
||||
|
||||
if resupply_state == "unavailable" and route_info == {} and components and report_line:
|
||||
val = self._get_last_availability(report_line)
|
||||
return val
|
||||
|
||||
base = {
|
||||
'resupply_avail_delay': resupply_delay,
|
||||
'stock_avail_state': stock_state,
|
||||
@@ -608,7 +612,6 @@ class ReportBomStructure(models.AbstractModel):
|
||||
def _has_attachments(self, data):
|
||||
return data['attachment_ids'] or any(self._has_attachments(component) for component in data.get('components', []))
|
||||
|
||||
@api.model
|
||||
def _merge_components(self, component_1, component_2):
|
||||
qty = component_2['quantity']
|
||||
component_1["quantity"] = component_1["quantity"] + qty
|
||||
@@ -619,3 +622,19 @@ class ReportBomStructure(models.AbstractModel):
|
||||
return
|
||||
for index in range(len(component_1.get("components"))):
|
||||
self._merge_components(component_1["components"][index], component_2["components"][index])
|
||||
|
||||
def _get_last_availability(self, report_line):
|
||||
delay = 0
|
||||
component_max_delay = False
|
||||
for component in report_line["components"]:
|
||||
if component["availability_delay"] is False:
|
||||
component_max_delay = component
|
||||
break
|
||||
elif component["availability_delay"] >= delay:
|
||||
component_max_delay = component
|
||||
delay = component["availability_delay"]
|
||||
return {'resupply_avail_delay': component_max_delay['resupply_avail_delay'],
|
||||
'stock_avail_state': component_max_delay['stock_avail_state'],
|
||||
'availability_display': component_max_delay['availability_display'],
|
||||
'availability_state': component_max_delay['availability_state'],
|
||||
'availability_delay': component_max_delay['availability_delay']}
|
||||
|
||||
+2
-2
@@ -19,13 +19,13 @@
|
||||
<div class="d-flex flex-column gap-1">
|
||||
<form class="d-flex w-100 gap-2">
|
||||
<label class="visually-hidden" for="bom_quantity">Quantity</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group col-xl-4">
|
||||
<div class="input-group-text">Quantity</div>
|
||||
<input id="bom_quantity" type="number" step="any" t-on-change="ev => this.updateQuantity(ev)" t-on-keypress="ev => this.onKeyPress(ev)" t-att-value="props.bomQuantity" min="1" class="o_input form-control text-end"/>
|
||||
<div t-if="props.showOptions.uom" t-esc="props.uomName" class="input-group-text">Quantity</div>
|
||||
</div>
|
||||
<t t-if="props.showVariants" >
|
||||
<label class="col-xl-2 col-lg-3 col-sm-4">Variant:</label>
|
||||
<div class="input-group-text">Variant:</div>
|
||||
<div class="col-xl-10 col-lg-9 col-sm-8">
|
||||
<Many2XAutocomplete
|
||||
value="props.data.name"
|
||||
|
||||
Reference in New Issue
Block a user