[FIX] account: unbalanced entry with price_unit 0
Steps to reproduce: - Create invoice for a prudict at price X > 0 - Change the price to 0 before saving - Then save it -> Error : Cannot create unbalanced journal entry This bug was introduced in 14.0 with this commit fe7d56dc32c71e04b54de9dbd756a48942a832f4 With this commit, we use an ugly condition to catch the specific case of a tax with price included and amount type division to avoid changing the price unit if the line balance is zero. opw-2822635 closes odoo/odoo#91059 X-original-commit: 2b9592cb0ecef235d708ed7810d0613ccd946124 Signed-off-by: Laurent Smet <las@odoo.com> Signed-off-by: Guillaume Vanleynseele <guva@odoo.com>
This commit is contained in:
@@ -3897,6 +3897,7 @@ class AccountMoveLine(models.Model):
|
||||
if tax.price_include:
|
||||
amount_currency += tax_res['amount']
|
||||
|
||||
tax_included_division_is_zero = any(tax.price_include and tax.amount == 100 and tax.amount_type == 'division' for tax in taxes) and amount_currency == 0
|
||||
discount_factor = 1 - (discount / 100.0)
|
||||
if amount_currency and discount_factor:
|
||||
# discount != 100%
|
||||
@@ -3911,8 +3912,9 @@ class AccountMoveLine(models.Model):
|
||||
'discount': 0.0,
|
||||
'price_unit': amount_currency / (quantity or 1.0),
|
||||
}
|
||||
elif not discount_factor:
|
||||
# balance of line is 0, but discount == 100% so we display the normal unit_price
|
||||
elif not discount_factor or tax_included_division_is_zero:
|
||||
# balance of line is 0, but discount == 100% or taxes (price included) == 100%,
|
||||
# so we display the normal unit_price
|
||||
vals = {}
|
||||
else:
|
||||
# balance is 0, so unit price is 0 as well
|
||||
|
||||
@@ -3449,3 +3449,24 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
|
||||
|
||||
# Tags should be empty since the tax has been removed from the invoice line
|
||||
self.assertRecordValues(invoice.line_ids, [{'tax_tag_ids': []}, {'tax_tag_ids': []}])
|
||||
|
||||
def test_changeprice_unit_to_zero(self):
|
||||
move = self.env['account.move'].create({
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': self.partner_a.id,
|
||||
'invoice_date': fields.Date.from_string('2017-01-01'),
|
||||
'invoice_line_ids': [
|
||||
(0, None, {
|
||||
'product_id': self.product_a.id,
|
||||
'product_uom_id': self.product_a.uom_id.id,
|
||||
'quantity': 1.0,
|
||||
'price_unit': 1000.0,
|
||||
'tax_ids': [(6, 0, [])],
|
||||
})]
|
||||
})
|
||||
|
||||
move.write({'invoice_line_ids': [(1, move.invoice_line_ids.ids[0], {
|
||||
'price_unit': 0.0,
|
||||
})]})
|
||||
|
||||
self.assertTrue(all(line.price_unit == 0 for line in move.line_ids))
|
||||
|
||||
@@ -713,3 +713,41 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon):
|
||||
self.assertRecordValues(invoice.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable'), [{
|
||||
'balance': 686.54
|
||||
}])
|
||||
|
||||
def test_invoice_with_100_percent_division_tax_incl(self):
|
||||
"""
|
||||
Check if the price unit remain the same after affecting a tax
|
||||
100%, price_include and amount_type 'division'
|
||||
"""
|
||||
invoice = self.env['account.move'].create({
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': self.partner_a.id,
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'invoice_date': '2018-01-01',
|
||||
'date': '2018-01-01',
|
||||
'invoice_line_ids': [(0, 0, {
|
||||
'name': 'xxxx',
|
||||
'quantity': 1,
|
||||
'price_unit': 500,
|
||||
})]
|
||||
})
|
||||
|
||||
division_tax_4_incl = self.env['account.tax'].create({
|
||||
'name': '100% incl',
|
||||
'amount_type': 'division',
|
||||
'amount': 100,
|
||||
'price_include': True,
|
||||
'include_base_amount': True,
|
||||
'sequence': 50,
|
||||
})
|
||||
|
||||
self.assertRecordValues(invoice.invoice_line_ids, [
|
||||
{'price_unit': 500}
|
||||
])
|
||||
with Form(invoice) as inv_form:
|
||||
with inv_form.invoice_line_ids.edit(0) as line_form:
|
||||
line_form.tax_ids.add(division_tax_4_incl)
|
||||
|
||||
self.assertRecordValues(invoice.invoice_line_ids, [
|
||||
{'price_unit': 500}
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user