From beb7159980f7ed29323d99fd4b72de3fa187f455 Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Mon, 8 Feb 2021 10:20:49 +0000 Subject: [FIX] mrp_subcontracting_account: update inventory valuation When buying a subcontracted product, if the inventory valuation of the product category is automated, the product delivery does not create a new journal entry, i.e. the automated inventory valuation is not done. To reproduce the error: (Need account_accountant,purchase) 1. In Settings, enable "Subcontracting" 2. Create a product category PC - Parent: All - Inventory Valuation: Automated 3. Create a product P - Must be storable - In category PC - Set a positive cost 4. Add a BoM to P - Type: Subcontracting 5. Create a RfQ - Vendor: BoM's subcontractor - Product: P 6. Confirm & Receive Products 7. Go to Accounting > Accounting > Miscellaneous > Journal Entries Error: There isn't any journal entry about the new product. This is an error because the inventory valuation for this product is automated, so there should be a line with the P-product and the cost set on step 3. When validating the delivery, the server checks the stock move lines considered as incoming: https://github.com/odoo/odoo/blob/5098cb25accce91347760cbd2f6427c07265fa00/addons/stock_account/models/stock_move.py#L61-L65 Problem is that `_should_be_valued` for subcontractor's location returns `True`, therefore the stock move line will not be added. => The `mrp_subcontracting` module needs to add a condition: A location can be valued if it is not subcontractor's location. OPW-2446298 closes odoo/odoo#65919 X-original-commit: cfd68df91d25682507cbfe88c67ab69ec5d3997d Signed-off-by: Adrien Widart --- addons/mrp_subcontracting_account/models/__init__.py | 1 + .../mrp_subcontracting_account/models/stock_location.py | 15 +++++++++++++++ .../tests/test_subcontracting_account.py | 6 ++++-- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 addons/mrp_subcontracting_account/models/stock_location.py diff --git a/addons/mrp_subcontracting_account/models/__init__.py b/addons/mrp_subcontracting_account/models/__init__.py index ac9517445ae..36be4423668 100644 --- a/addons/mrp_subcontracting_account/models/__init__.py +++ b/addons/mrp_subcontracting_account/models/__init__.py @@ -2,3 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import stock_picking +from . import stock_location diff --git a/addons/mrp_subcontracting_account/models/stock_location.py b/addons/mrp_subcontracting_account/models/stock_location.py new file mode 100644 index 00000000000..33bed7e6995 --- /dev/null +++ b/addons/mrp_subcontracting_account/models/stock_location.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + + +from odoo import models + + +class StockLocation(models.Model): + _inherit = "stock.location" + + def _should_be_valued(self): + res = super()._should_be_valued() + if self.company_id.subcontracting_location_id: + res &= self != self.company_id.subcontracting_location_id + return res diff --git a/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py b/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py index fb27445d0f7..fe5b6b8011c 100644 --- a/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py +++ b/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py @@ -54,5 +54,7 @@ class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon): picking_receipt._action_done() mo = picking_receipt._get_subcontracted_productions() - self.assertEqual(mo.move_finished_ids.stock_valuation_layer_ids.value, 60) - self.assertEqual(mo.move_finished_ids.product_id.value_svl, 60) + self.assertEqual(mo.move_finished_ids.stock_valuation_layer_ids.value, 0) + self.assertEqual(mo.move_finished_ids.product_id.value_svl, 30) + self.assertEqual(picking_receipt.move_lines.stock_valuation_layer_ids.value, 30) + self.assertEqual(picking_receipt.move_lines.product_id.value_svl, 30) -- cgit v1.2.3