diff --git a/addons/mrp_account/models/mrp_production.py b/addons/mrp_account/models/mrp_production.py index 01d5c496107..2b42f62318e 100644 --- a/addons/mrp_account/models/mrp_production.py +++ b/addons/mrp_account/models/mrp_production.py @@ -14,6 +14,8 @@ class MrpProductionWorkcenterLineTime(models.Model): class MrpProduction(models.Model): _inherit = 'mrp.production' + extra_cost = fields.Float(copy=False, help='Extra cost per produced unit') + def _cal_price(self, consumed_moves): """Set a price unit on the finished move according to `consumed_moves`. """ @@ -29,8 +31,9 @@ class MrpProduction(models.Model): work_center_cost += (duration / 60.0) * work_order.workcenter_id.costs_hour if finished_move.product_id.cost_method in ('fifo', 'average'): qty_done = finished_move.product_uom._compute_quantity(finished_move.quantity_done, finished_move.product_id.uom_id) - finished_move.price_unit = (sum([-m.value for m in consumed_moves]) + work_center_cost) / qty_done - finished_move.value = sum([-m.value for m in consumed_moves]) + work_center_cost + extra_cost = self.extra_cost * qty_done + finished_move.price_unit = (sum([-m.value for m in consumed_moves]) + work_center_cost + extra_cost) / qty_done + finished_move.value = sum([-m.value for m in consumed_moves]) + work_center_cost + extra_cost return True def _prepare_wc_analytic_line(self, wc_line): diff --git a/addons/mrp_account/tests/test_mrp_account.py b/addons/mrp_account/tests/test_mrp_account.py index 9f3e75e43c2..64bba25019b 100644 --- a/addons/mrp_account/tests/test_mrp_account.py +++ b/addons/mrp_account/tests/test_mrp_account.py @@ -73,6 +73,7 @@ class TestMrpAccount(common.TransactionCase): production_table_form.product_qty = 5.0 production_table = production_table_form.save() + production_table.extra_cost = 20 production_table.action_confirm() produce_form = Form(self.env['mrp.product.produce'].with_context({ @@ -85,8 +86,8 @@ class TestMrpAccount(common.TransactionCase): production_table.post_inventory() move_value = production_table.move_finished_ids.filtered(lambda x: x.state == "done").value - # 1 table head at 20 + 4 table leg at 15 + 4 bolt at 10 + 10 screw at 10 - self.assertEqual(move_value, 121, 'Thing should have the correct price') + # 1 table head at 20 + 4 table leg at 15 + 4 bolt at 10 + 10 screw at 10 + 1*20 (extra cost) + self.assertEqual(move_value, 141, 'Thing should have the correct price') # produce_wizard = self.env['mrp.product.produce'].with_context({ # 'active_id': production_table.id,