From ba4e24b9326a0e906de7ec58a25feb1358ee13ca Mon Sep 17 00:00:00 2001 From: yhu-odoo Date: Wed, 2 Nov 2022 10:25:30 +0000 Subject: [PATCH] [FIX] mrp_account: missing employee cost when calculate bom cost Adapt community to make it possible to add employee cost when calculate bom cost. closes odoo/odoo#105645 X-original-commit: a239802249b2af2cc3fc2b3bb9fdfd0a408d887a Related: odoo/enterprise#33898 Signed-off-by: William Henrotin (whe) Signed-off-by: Yuchen Huang (yhu) --- addons/mrp_account/models/__init__.py | 1 + addons/mrp_account/models/mrp_routing.py | 12 ++++++++++++ addons/mrp_account/models/product.py | 2 +- addons/mrp_account/tests/test_bom_price.py | 4 +++- .../tests/test_subcontracting_account.py | 4 ++-- 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 addons/mrp_account/models/mrp_routing.py diff --git a/addons/mrp_account/models/__init__.py b/addons/mrp_account/models/__init__.py index 33ff5e20d93..90c1c962e22 100644 --- a/addons/mrp_account/models/__init__.py +++ b/addons/mrp_account/models/__init__.py @@ -5,6 +5,7 @@ from . import mrp_bom from . import mrp_workcenter from . import mrp_workorder from . import mrp_production +from . import mrp_routing from . import product from . import stock_move from . import stock_rule diff --git a/addons/mrp_account/models/mrp_routing.py b/addons/mrp_account/models/mrp_routing.py new file mode 100644 index 00000000000..f36d70eac02 --- /dev/null +++ b/addons/mrp_account/models/mrp_routing.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class MrpRoutingWorkcenter(models.Model): + _inherit = 'mrp.routing.workcenter' + + def _total_cost_per_hour(self): + self.ensure_one() + return self.workcenter_id.costs_hour diff --git a/addons/mrp_account/models/product.py b/addons/mrp_account/models/product.py index 06471524d8c..e10272b02c9 100644 --- a/addons/mrp_account/models/product.py +++ b/addons/mrp_account/models/product.py @@ -80,7 +80,7 @@ class ProductProduct(models.Model): opt.workcenter_id.time_start + opt.workcenter_id.time_stop + opt.time_cycle * 100 / opt.workcenter_id.time_efficiency) - total += (duration_expected / 60) * opt.workcenter_id.costs_hour + total += (duration_expected / 60) * opt._total_cost_per_hour() for line in bom.bom_line_ids: if line._skip_bom_line(self): diff --git a/addons/mrp_account/tests/test_bom_price.py b/addons/mrp_account/tests/test_bom_price.py index 8ea43a4ac4a..5d407b0d635 100644 --- a/addons/mrp_account/tests/test_bom_price.py +++ b/addons/mrp_account/tests/test_bom_price.py @@ -6,7 +6,7 @@ from odoo.tests import common, Form from odoo.tools.float_utils import float_round, float_compare -class TestBomPrice(common.TransactionCase): +class TestBomPriceCommon(common.TransactionCase): @classmethod def _create_product(cls, name, price): @@ -101,6 +101,8 @@ class TestBomPrice(common.TransactionCase): line.product_qty = 57 cls.bom_2 = bom_form2.save() + +class TestBomPrice(TestBomPriceCommon): def test_00_compute_price(self): """Test multi-level BoM cost""" self.assertEqual(self.dining_table.standard_price, 1000, "Initial price of the Product should be 1000") diff --git a/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py b/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py index cf7955b474c..7e62091595e 100644 --- a/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py +++ b/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py @@ -6,7 +6,7 @@ from odoo.tests.common import Form from odoo.tools.float_utils import float_round, float_compare from odoo.addons.mrp_subcontracting.tests.common import TestMrpSubcontractingCommon -from odoo.addons.mrp_account.tests.test_bom_price import TestBomPrice +from odoo.addons.mrp_account.tests.test_bom_price import TestBomPriceCommon class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon): def test_subcontracting_account_flow_1(self): @@ -212,7 +212,7 @@ class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon): ]) -class TestBomPriceSubcontracting(TestBomPrice): +class TestBomPriceSubcontracting(TestBomPriceCommon): def test_01_compute_price_subcontracting_cost(self): """Test calculation of bom cost with subcontracting."""