Skip to content

Commit 470a1f1

Browse files
[FIX] mrp: avoid crash when printing BOM with 0-quantity byproducts
Issue: Printing the BOM crashes when one of the byproduct quantity is set to 0 Steps to reproduce: - Open the manufactoring app - Go to settings and activate by-product settings - Go to Products > Bills of Materials - Open a BOM - Put the quantity of one the by-product by 0 - Click on overview - Click on the print button Cause: In the `mrp_report_bom_structure.xml` template, there is this division: - `<td class="text-end" t-esc="byproduct['bom_cost'] / byproduct['quantity']" t-options='{"widget": "monetary", "display_currency": currency}'/>` without checking if `byproduct['quantity']` is different than 0. Solution: Added the check on `byproduct['quantity']` in the foreach Additional notes: Since it makes no real sense to have a non-zero BoM cost associated with a byproduct whose quantity is zero, the cost is set to 0 when the quantity is 0. opw-4853525 closes odoo#217819 X-original-commit: 1ef366f Signed-off-by: Tiffany Chang (tic) <tic@odoo.com> Signed-off-by: Maxime Noirhomme (noma) <noma@odoo.com>
1 parent 188a3fe commit 470a1f1

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

addons/mrp/report/mrp_report_bom_structure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def _get_byproducts_lines(self, product, bom, bom_quantity, level, total, index)
418418
if byproduct._skip_byproduct_line(product):
419419
continue
420420
line_quantity = (bom_quantity / (bom.product_qty or 1.0)) * byproduct.product_qty
421-
cost_share = byproduct.cost_share / 100
421+
cost_share = byproduct.cost_share / 100 if byproduct.product_qty > 0 else 0
422422
byproduct_cost_portion += cost_share
423423
price = byproduct.product_id.uom_id._compute_price(byproduct.product_id.with_company(company).standard_price, byproduct.product_uom_id) * line_quantity
424424
byproducts.append({

addons/mrp/report/mrp_report_bom_structure.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<td class="text-end" t-esc="data['prod_cost']/data['quantity']" t-options='{"widget": "monetary", "display_currency": currency}'/>
7272
</tr>
7373
<t t-if="data['show_costs'] and data['byproducts']" t-foreach="data['byproducts']" t-as="byproduct">
74-
<tr>
74+
<tr t-if="byproduct['quantity'] &gt; 0">
7575
<td name="td_mrp_bom_byproducts_f" class="text-end" t-esc="byproduct['name']"/>
7676
<td class="text-end"><strong>Unit Cost</strong></td>
7777
<td class="text-start" groups="uom.group_uom" t-esc="byproduct['uom_name']"/>

0 commit comments

Comments
 (0)