diff --git a/addons/mrp_subcontracting_account/models/__init__.py b/addons/mrp_subcontracting_account/models/__init__.py index aee2f0054db..c65666fb491 100644 --- a/addons/mrp_subcontracting_account/models/__init__.py +++ b/addons/mrp_subcontracting_account/models/__init__.py @@ -3,3 +3,4 @@ from . import stock_picking from . import product_product +from . import stock_move diff --git a/addons/mrp_subcontracting_account/models/stock_move.py b/addons/mrp_subcontracting_account/models/stock_move.py new file mode 100644 index 00000000000..d57c2c94df8 --- /dev/null +++ b/addons/mrp_subcontracting_account/models/stock_move.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 StockMove(models.Model): + _inherit = 'stock.move' + + def _should_force_price_unit(self): + self.ensure_one() + return self.is_subcontract or super()._should_force_price_unit() diff --git a/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py b/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py index 7a1b38ec87f..60a1da5d0c7 100644 --- a/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py +++ b/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py @@ -68,6 +68,26 @@ class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon): self.assertEqual(picking_receipt.move_ids.stock_valuation_layer_ids.value, 0) self.assertEqual(picking_receipt.move_ids.product_id.value_svl, 60) + # Do the same without any additionnal cost + picking_form = Form(self.env['stock.picking']) + picking_form.picking_type_id = self.env.ref('stock.picking_type_in') + picking_form.partner_id = self.subcontractor_partner1 + with picking_form.move_ids_without_package.new() as move: + move.product_id = self.finished + move.product_uom_qty = 1 + picking_receipt = picking_form.save() + picking_receipt.move_ids.price_unit = 0 + + picking_receipt.action_confirm() + picking_receipt.move_ids.quantity_done = 1.0 + picking_receipt._action_done() + + mo = picking_receipt._get_subcontract_production() + # In this case, since there isn't any additionnal cost, the total cost of the subcontracting + # is the sum of the components' costs: 10 + 20 = 30 + self.assertEqual(mo.move_finished_ids.stock_valuation_layer_ids.value, 30) + self.assertEqual(picking_receipt.move_ids.product_id.value_svl, 90) + def test_subcontracting_account_backorder(self): """ This test uses tracked (serial and lot) component and tracked (serial) finished product The original subcontracting production order will be split into 4 backorders. This test diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py index 82eec648948..7ba1144f46c 100644 --- a/addons/stock_account/models/stock_move.py +++ b/addons/stock_account/models/stock_move.py @@ -34,6 +34,10 @@ class StockMove(models.Model): self.analytic_account_line_id.unlink() return super()._action_cancel() + def _should_force_price_unit(self): + self.ensure_one() + return False + def _get_price_unit(self): """ Returns the unit price to value this stock move """ self.ensure_one() @@ -42,7 +46,7 @@ class StockMove(models.Model): # If the move is a return, use the original move's price unit. if self.origin_returned_move_id and self.origin_returned_move_id.sudo().stock_valuation_layer_ids: price_unit = self.origin_returned_move_id.sudo().stock_valuation_layer_ids[-1].unit_cost - return not float_is_zero(price_unit, precision) and price_unit or self.product_id.standard_price + return price_unit if not float_is_zero(price_unit, precision) or self._should_force_price_unit() else self.product_id.standard_price @api.model def _get_valued_types(self):