From 0ff1e5fab5f394dbd1221fcf09dc1e280930c566 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Thu, 18 Oct 2018 14:58:08 +0200 Subject: [PATCH] [FIX] mrp_bom_cost: bom cost / bom quantity Use case to reproduce: - create a BoM of 50 finished products: - Add a routing with an operation time of 1h - Set a 1$/h cost on workcenter - Set unit price from BoM It will be 1$ for one product. It should be 0.02$ since it will take 1h for 50 products, so the price should be 1/50 It happens because the system add the operation time by unit instead of adding it only once. related to commit 17b625695521b9a1af75e0c10337d0d3076c8fce opw-1890005 --- addons/mrp_bom_cost/models/product.py | 3 +-- addons/mrp_bom_cost/tests/test_bom_price.py | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/addons/mrp_bom_cost/models/product.py b/addons/mrp_bom_cost/models/product.py index c1a276918ae..cbb955c2d6d 100644 --- a/addons/mrp_bom_cost/models/product.py +++ b/addons/mrp_bom_cost/models/product.py @@ -52,12 +52,11 @@ class ProductProduct(models.Model): if not boms_to_recompute: boms_to_recompute = [] total = 0 - quant_quantity = bom.product_uom_id._compute_quantity(bom.product_qty, bom.product_tmpl_id.uom_id) for opt in bom.routing_id.operation_ids: duration_expected = ( opt.workcenter_id.time_start + opt.workcenter_id.time_stop + - quant_quantity * opt.time_cycle) + opt.time_cycle) total += (duration_expected / 60) * opt.workcenter_id.costs_hour for line in bom.bom_line_ids: if line._skip_bom_line(self): diff --git a/addons/mrp_bom_cost/tests/test_bom_price.py b/addons/mrp_bom_cost/tests/test_bom_price.py index a347a497e37..c91f6203bca 100644 --- a/addons/mrp_bom_cost/tests/test_bom_price.py +++ b/addons/mrp_bom_cost/tests/test_bom_price.py @@ -3,7 +3,7 @@ from odoo.exceptions import UserError from odoo.tests import common, Form -from odoo.tools.float_utils import float_round +from odoo.tools.float_utils import float_round, float_compare class TestBom(common.TransactionCase): @@ -166,11 +166,11 @@ class TestBom(common.TransactionCase): # Table Head Operation Cost (1 Dozen) # -------------------------------------------------------------------------- # Operation cost calculate for 1 dozens - # Cutting (20 * 12 / 60) * 100 = 400 - # Drilling (25 * 12 / 60) * 100 = 500 - # Fitting (30 * 12 / 60) * 100 = 600 + # Cutting (20 * 1 / 60) * 100 = 33,33 + # Drilling (25 * 1 / 60) * 100 = 41,67 + # Fitting (30 * 1 / 60) * 100 = 50 # ---------------------------------------- - # Operation Cost 1 dozen (1500 per dozen) and 125 for 1 Unit + # Operation Cost 1 dozen (125 per dozen) and 10.42 for 1 Unit # -------------------------------------------------------------------------- self.bom_2.routing_id = routing_1.id @@ -180,8 +180,8 @@ class TestBom(common.TransactionCase): # Total cost of Dining Table = (550) + Total cost of operations (125) = 675.0 self.assertEquals(float_round(self.dining_table.standard_price, precision_digits=2), 675.0, "After computing price from BoM price should be 612.5") self.Product.browse([self.dining_table.id, self.table_head.id]).action_bom_cost() - # Total cost of Dining Table = (718.75) + Total cost of all operations (125 + 125) = 968.75 - self.assertEquals(float_round(self.dining_table.standard_price, precision_digits=2), 968.75, "After computing price from BoM price should be 786.46") + # Total cost of Dining Table = (718.75) + Total cost of all operations (125 + 10.42) = 854.17 + self.assertEquals(float_compare(self.dining_table.standard_price, 854.17, precision_digits=2), 0, "After computing price from BoM price should be 786.46") def test_01_compute_price_inventory_valuation(self): """Test update cost from bom in list view when inventory valuation is real time."""