[REF] mrp_account: add an extra_cost notion on the manufacturing order

This is a preliminary work to handle the price of subcontracting. We put
this field in the generic `mrp_account` module because we also want to
support adding an extra cost on a finished move without having to work
with the wokorders, on a future task.

task 1831382
This commit is contained in:
Simon Lejeune
2019-04-03 13:51:05 +00:00
parent 1019ceee6e
commit e972d25400
2 changed files with 8 additions and 4 deletions
+5 -2
View File
@@ -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):
+3 -2
View File
@@ -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,