From b21d0f77af968a9df095306d3cbb112a7f66d5fb Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Thu, 28 Nov 2019 12:51:21 +0000 Subject: [PATCH] [FIX] account: Don't generate 0 balance payment term lines In the Mexican Localisation (l10n_mx), there is a "custom" behavior made when there is more than one payment term lines. Before the account-pocalypse, the receivable lines having a balance equals to zero was ignored. This commit aims to restore this behavior and then, fix l10n_mx. --issue: 2121973 X-original-commit: 6a4f9a2666b7414d208248da52862428c04bb4a6 --- addons/account/models/account_move.py | 3 ++ .../tests/test_account_move_out_invoice.py | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index d9cc34b9ff3..bad53674f3f 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -800,6 +800,9 @@ class AccountMove(models.Model): # Recompute amls: update existing line or create new one for each payment term. new_terms_lines = self.env['account.move.line'] for date_maturity, balance, amount_currency in to_compute: + if self.journal_id.company_id.currency_id.is_zero(balance) and len(to_compute) > 1: + continue + if existing_terms_lines_index < len(existing_terms_lines): # Update existing line. candidate = existing_terms_lines[existing_terms_lines_index] diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index e8420e612ba..cadb7dc40ea 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -1799,3 +1799,46 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): {'amount_currency': -120.0, 'debit': 0.0, 'credit': 60.0, 'account_id': self.product_line_vals_2['account_id'], 'reconciled': False}, {'amount_currency': 120.0, 'debit': 60.0, 'credit': 0.0, 'account_id': wizard.revenue_accrual_account.id, 'reconciled': True}, ]) + + def test_out_invoice_filter_zero_balance_lines(self): + zero_balance_payment_term = self.env['account.payment.term'].create({ + 'name': 'zero_balance_payment_term', + 'line_ids': [ + (0, 0, { + 'value': 'percent', + 'value_amount': 100.0, + 'sequence': 10, + 'days': 0, + 'option': 'day_after_invoice_date', + }), + (0, 0, { + 'value': 'balance', + 'value_amount': 0.0, + 'sequence': 20, + 'days': 0, + 'option': 'day_after_invoice_date', + }), + ], + }) + + zero_balance_tax = self.env['account.tax'].create({ + 'name': 'zero_balance_tax', + 'amount_type': 'percent', + 'amount': 0.0, + }) + + invoice = self.env['account.move'].create({ + 'type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'invoice_date': fields.Date.from_string('2019-01-01'), + 'invoice_payment_term_id': zero_balance_payment_term.id, + 'invoice_line_ids': [(0, None, { + 'name': 'whatever', + 'quantity': 1.0, + 'price_unit': 1000.0, + 'tax_ids': [(6, 0, zero_balance_tax.ids)], + })] + }) + + self.assertEqual(len(invoice.invoice_line_ids), 1) + self.assertEqual(len(invoice.line_ids), 2)