From 064ce8dcfe88373649cd2774f90f618af3a0f55f Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Mon, 23 May 2022 11:26:26 +0000 Subject: [PATCH] [FIX] stock_account: create AML for SML owned by company If a picking is owned by the company and if the user receives a FIFO product, a SVL will be created without any journal entry To reproduce the issue: (Need account_accountant) 1. In Settings, enable "Consignment" 2. Create a product category PC: - Costing Method: FIFO - Inventory Valuation: Automated 3. Create a product P: - Type: Storable - Category: PC - Cost: 1 4. Create and validate a receipt: - Owner: - With: 1 x P 5. Open the generated SVL Error: There isn't any journal entry associated with the SVL When validating the picking, a method filters the SML that will be considered during the SVL creation process. This method filters out the SML that has an owner and if this owner is not the company: https://github.com/odoo/odoo/blob/f8e2f2a4836d23fe507cad3bd5cac92d41ca91a3/addons/stock_account/models/stock_move.py#L69-L70 However, the filter in the journal entries creation is not that accurate and does not correspond to its comment line: https://github.com/odoo/odoo/blob/f8e2f2a4836d23fe507cad3bd5cac92d41ca91a3/addons/stock_account/models/stock_move.py#L475-L476 OPW-2859144 closes odoo/odoo#92716 X-original-commit: 13d4963d10e14c0295a1c7abeefd52b070cd4a58 Signed-off-by: William Henrotin (whe) Signed-off-by: Adrien Widart --- addons/stock_account/models/stock_move.py | 2 +- .../tests/test_stockvaluation.py | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py index d313ad0a481..19de960e066 100644 --- a/addons/stock_account/models/stock_move.py +++ b/addons/stock_account/models/stock_move.py @@ -531,7 +531,7 @@ class StockMove(models.Model): if self.product_id.type != 'product': # no stock valuation for consumable products return am_vals - if self.restrict_partner_id: + if self.restrict_partner_id and self.restrict_partner_id != self.company_id.partner_id: # if the move isn't owned by the company, we don't make any valuation return am_vals diff --git a/addons/stock_account/tests/test_stockvaluation.py b/addons/stock_account/tests/test_stockvaluation.py index ea64311af14..5630af67485 100644 --- a/addons/stock_account/tests/test_stockvaluation.py +++ b/addons/stock_account/tests/test_stockvaluation.py @@ -3904,3 +3904,34 @@ class TestStockValuation(TransactionCase): report_value_2 = report_for_company_2._get_report_values(docids=self.product1.ids) self.assertEqual(report_value_1['docs']['value'], "U 50.00") self.assertEqual(report_value_2['docs']['value'], "48.00 DD") + + def test_fifo_and_sml_owned_by_company(self): + """ + When receiving a FIFO product, if the picking is owned by the company, + there should be a SVL and an account move linked to the product SM + """ + self.product1.categ_id.property_cost_method = 'fifo' + + receipt = self.env['stock.picking'].create({ + 'location_id': self.supplier_location.id, + 'location_dest_id': self.stock_location.id, + 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'owner_id': self.env.company.partner_id.id, + }) + + move = self.env['stock.move'].create({ + 'picking_id': receipt.id, + 'name': 'IN 1 @ 10', + 'location_id': self.supplier_location.id, + 'location_dest_id': self.stock_location.id, + 'product_id': self.product1.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 1.0, + 'price_unit': 10, + }) + receipt.action_confirm() + move.quantity_done = 1 + receipt.button_validate() + + self.assertEqual(move.stock_valuation_layer_ids.value, 10) + self.assertEqual(move.stock_valuation_layer_ids.account_move_id.amount_total, 10)