From c7c3f69453fa90beecadc7e35f14958cbe7ff3d2 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Thu, 6 Apr 2023 13:58:57 +0000 Subject: [PATCH] [FIX] stock_account: avoid reinvoice on cogs entry Create a product category [FIFO] with: - Costing Method: First In First Out (FIFO) - Inventory Valuation: Automated Create a product [PROD] having: - Product category: [FIFO] - Product Type: Storable Product - Invoicing Policy: Delivered quantities - Can be expensed: True - Re-Invoice Expenses: At cost Create a sales order with [PROD] Confirm, Deliver Open the created STJ journal entry: - Reset to draft - Add analytic account on a line - Post again To the sale order is added a reinvoice line with negative quantity. This should not occur with cogs lines opw-3199428 closes odoo/odoo#119048 X-original-commit: 347975d6d9b07db521e02ee12694aa834708abbe Signed-off-by: William Henrotin (whe) Signed-off-by: Grazioso Andrea (agr) --- addons/sale_stock/models/account_move.py | 2 +- .../tests/test_anglo_saxon_valuation.py | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/addons/sale_stock/models/account_move.py b/addons/sale_stock/models/account_move.py index 6faf4eb0b5f..7bf34ae2174 100644 --- a/addons/sale_stock/models/account_move.py +++ b/addons/sale_stock/models/account_move.py @@ -113,7 +113,7 @@ class AccountMoveLine(models.Model): def _sale_can_be_reinvoice(self): self.ensure_one() - return self.display_type != 'cogs' and super(AccountMoveLine, self)._sale_can_be_reinvoice() + return self.move_type != 'entry' and self.display_type != 'cogs' and super(AccountMoveLine, self)._sale_can_be_reinvoice() def _stock_account_get_anglo_saxon_price_unit(self): self.ensure_one() diff --git a/addons/sale_stock/tests/test_anglo_saxon_valuation.py b/addons/sale_stock/tests/test_anglo_saxon_valuation.py index 0532d616dea..4423c0881a9 100644 --- a/addons/sale_stock/tests/test_anglo_saxon_valuation.py +++ b/addons/sale_stock/tests/test_anglo_saxon_valuation.py @@ -1686,3 +1686,31 @@ class TestAngloSaxonValuation(ValuationReconciliationTestCommon): cogs_aml = amls.filtered(lambda aml: aml.account_id == self.company_data['default_account_expense']) self.assertEqual(cogs_aml.debit, 10) self.assertEqual(cogs_aml.credit, 0) + + def test_fifo_edit_svl_without_reinvoice(self): + """Edit SVL move line after delivering. Check no reinvoicing occurs.""" + self.product.categ_id.property_cost_method = 'fifo' + self.product.invoice_policy = 'delivery' + self.product.standard_price = 10 + self.product.expense_policy = 'cost' + + self._fifo_in_one_eight_one_ten() + + # Create and confirm a sale order for 2@12 + sale_order = self._so_and_confirm_two_units() + self.assertEqual(len(sale_order.order_line), 1) + self.assertEqual(sale_order.order_line.product_uom_qty, 2.0) + + # Deliver one. + sale_order.picking_ids.move_ids.quantity_done = 2 + sale_order.picking_ids.button_validate() + svl_am = sale_order.order_line.move_ids.stock_valuation_layer_ids.account_move_id + svl_am.button_draft() + svl_line = svl_am.line_ids.filtered(lambda aml: aml.account_id == self.company_data['default_account_stock_out']) + + svl_line.write({'analytic_distribution': {sale_order.analytic_account_id.id: 100}}) + svl_am.action_post() + + # Check no reinvoice line addded to the sale order + self.assertEqual(len(sale_order.order_line), 1) + self.assertEqual(sale_order.order_line.product_uom_qty, 2.0)