From 0e2bacfd51b4882346980a70eca1f35e93017765 Mon Sep 17 00:00:00 2001 From: "Merel Geens (mege)" Date: Wed, 7 Jun 2023 11:10:16 +0000 Subject: [PATCH] [FIX] stock_account: don't create 0 amount COGS lines After creating a sales order for a product with cost 0, automatic inventory valuation and AVCO, and validating the delivery, no account move is created for the stock move. If an invoice is then created from the sales order, it will create 0 amount COGS lines. Automatic reconciliation of the invoice with the corresponding stock account move will fail because no such entry exists, resulting in unreconciled lines remaining in the invoices. This issue can be prevented by either creating a 0 amount journal entry for the stock move, or preventing the creation of the 0 amount COGS lines on the invoice. Not creating unnecessary COGS lines is preferable and this was also the solution used for the same problem with purchase order invoices: https://github.com/odoo/odoo/pull/106785 . So this fix does the same for sales order invoices. opw-3000320 closes odoo/odoo#125185 X-original-commit: 999451e6ea0b2b1591a3644725b5313c6e062b39 Signed-off-by: Brice Bartoletti (bib) Signed-off-by: Merel Geens --- addons/sale_mrp/tests/test_sale_mrp_anglo_saxon_valuation.py | 2 -- addons/sale_stock/tests/test_anglo_saxon_valuation.py | 4 ---- addons/stock_account/models/account_move.py | 5 +++++ 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/sale_mrp/tests/test_sale_mrp_anglo_saxon_valuation.py b/addons/sale_mrp/tests/test_sale_mrp_anglo_saxon_valuation.py index dde258af42c..2cbd8d735d9 100644 --- a/addons/sale_mrp/tests/test_sale_mrp_anglo_saxon_valuation.py +++ b/addons/sale_mrp/tests/test_sale_mrp_anglo_saxon_valuation.py @@ -472,8 +472,6 @@ class TestSaleMRPAngloSaxonValuation(ValuationReconciliationTestCommon): # pylint: disable=bad-whitespace {'account_id': self.company_data['default_account_revenue'].id, 'debit': 0, 'credit': 5}, {'account_id': self.company_data['default_account_receivable'].id, 'debit': 5, 'credit': 0}, - {'account_id': self.company_data['default_account_stock_out'].id, 'debit': 0, 'credit': 0}, - {'account_id': self.company_data['default_account_expense'].id, 'debit': 0, 'credit': 0}, ]) def test_kit_avco_partially_owned_and_delivered_invoice_post_delivery(self): diff --git a/addons/sale_stock/tests/test_anglo_saxon_valuation.py b/addons/sale_stock/tests/test_anglo_saxon_valuation.py index 1b8de31822b..e18dd97f176 100644 --- a/addons/sale_stock/tests/test_anglo_saxon_valuation.py +++ b/addons/sale_stock/tests/test_anglo_saxon_valuation.py @@ -668,8 +668,6 @@ class TestAngloSaxonValuation(ValuationReconciliationTestCommon): # pylint: disable=bad-whitespace {'account_id': self.company_data['default_account_revenue'].id, 'debit': 0, 'credit': 12}, {'account_id': self.company_data['default_account_receivable'].id, 'debit': 12, 'credit': 0}, - {'account_id': self.company_data['default_account_stock_out'].id, 'debit': 0, 'credit': 0}, - {'account_id': self.company_data['default_account_expense'].id, 'debit': 0, 'credit': 0}, ]) def test_avco_fully_owned_and_delivered_invoice_post_delivery(self): @@ -696,8 +694,6 @@ class TestAngloSaxonValuation(ValuationReconciliationTestCommon): # pylint: disable=bad-whitespace {'account_id': self.company_data['default_account_revenue'].id, 'debit': 0, 'credit': 24}, {'account_id': self.company_data['default_account_receivable'].id, 'debit': 24, 'credit': 0}, - {'account_id': self.company_data['default_account_stock_out'].id, 'debit': 0, 'credit': 0}, - {'account_id': self.company_data['default_account_expense'].id, 'debit': 0, 'credit': 0}, ]) # ------------------------------------------------------------------------- diff --git a/addons/stock_account/models/account_move.py b/addons/stock_account/models/account_move.py index 466d553ff35..c90c48f481a 100644 --- a/addons/stock_account/models/account_move.py +++ b/addons/stock_account/models/account_move.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from odoo import fields, models, api +from odoo.tools import float_is_zero class AccountMove(models.Model): @@ -106,6 +107,7 @@ class AccountMove(models.Model): :return: A list of Python dictionary to be passed to env['account.move.line'].create. ''' lines_vals_list = [] + price_unit_prec = self.env['decimal.precision'].precision_get('Product Price') for move in self: # Make the loop multi-company safe when accessing models like product.product move = move.with_company(move.company_id) @@ -131,6 +133,9 @@ class AccountMove(models.Model): price_unit = line._stock_account_get_anglo_saxon_price_unit() amount_currency = sign * line.quantity * price_unit + if move.currency_id.is_zero(amount_currency) or float_is_zero(price_unit, precision_digits=price_unit_prec): + continue + # Add interim account line. lines_vals_list.append({ 'name': line.name[:64],