[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) <bib@odoo.com> Signed-off-by: Merel Geens <mege@odoo.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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},
|
||||
])
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user