From 1f8880831bbf1f40e8d6c815d87ae147464bd199 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Mon, 7 Aug 2023 16:02:10 +0000 Subject: [PATCH] [FIX] account: epd missing in credit note MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Accounting settings set 'Cash Discount Tax Reduction' to Always Create an invoice Add a line with tax Add as payment terms "2/7 Net 30" Confirm Click "Add a credit note" and create the credit note Confirm Issue: Credit note is missing the epd vals from the invocie so the moves cannot fully reconcile opw-3429678 closes odoo/odoo#145653 X-original-commit: f7b371be24a842392a8b46f337256ef13bf8a5ae Signed-off-by: William André (wan) Signed-off-by: Andrea Grazioso (agr) --- .../tests/test_early_payment_discount.py | 66 +++++++++++++++++++ .../account/wizard/account_move_reversal.py | 3 +- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/addons/account/tests/test_early_payment_discount.py b/addons/account/tests/test_early_payment_discount.py index a8de15c7f47..bc1dfa74c37 100644 --- a/addons/account/tests/test_early_payment_discount.py +++ b/addons/account/tests/test_early_payment_discount.py @@ -781,3 +781,69 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon): {'amount_currency': 1000.0}, {'amount_currency': 2000}, ]) + + def test_mixed_epd_with_tax_refund(self): + """ + Ensure epd line are addeed to refunds + """ + self.early_pay_10_percents_10_days.write({'early_pay_discount_computation': 'mixed'}) + + invoice = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'invoice_date': '2022-02-21', + 'invoice_payment_term_id': self.early_pay_10_percents_10_days.id, + 'invoice_line_ids': [ + Command.create({ + 'price_unit': 100.0, + 'quantity': 1, + 'tax_ids': [Command.set(self.product_a.taxes_id.ids)], + }) + ] + }) + invoice.action_post() + + move_reversal = self.env['account.move.reversal'].with_context(active_model="account.move", active_ids=invoice.ids).create({ + 'date': fields.Date.from_string('2017-01-01'), + 'reason': 'no reason again', + 'journal_id': invoice.journal_id.id, + }) + + receivable_line = invoice.line_ids.filtered(lambda x: x.account_id.account_type == 'asset_receivable') + reversal = move_reversal.modify_moves() + reverse_move = self.env['account.move'].browse(reversal['res_id']) + + self.assertEqual(invoice.payment_state, 'reversed', "After cancelling it with a reverse invoice, an invoice should be in 'reversed' state.") + + self.assertRecordValues(reverse_move.line_ids.sorted('id'), [ + { + 'balance': -100.0, + 'tax_base_amount': 0.0, + 'display_type': 'product', + }, + { + 'balance': 10.0, + 'tax_base_amount': 0.0, + 'display_type': 'epd', + }, + { + 'balance': -10.0, + 'tax_base_amount': 0.0, + 'display_type': 'epd', + }, + { + 'balance': -15.0, + 'tax_base_amount': 100.0, + 'display_type': 'tax', + }, + { + 'balance': 1.5, + 'tax_base_amount': -10.0, + 'display_type': 'tax', + }, + { + 'balance': receivable_line.balance, + 'tax_base_amount': 0.0, + 'display_type': 'payment_term', + }, + ]) diff --git a/addons/account/wizard/account_move_reversal.py b/addons/account/wizard/account_move_reversal.py index 08ce8f86abf..2d20a38619c 100644 --- a/addons/account/wizard/account_move_reversal.py +++ b/addons/account/wizard/account_move_reversal.py @@ -86,6 +86,7 @@ class AccountMoveReversal(models.TransientModel): def _prepare_default_reversal(self, move): reverse_date = self.date + mixed_payment_term = move.invoice_payment_term_id.id if move.invoice_payment_term_id.early_pay_discount_computation == 'mixed' else None return { 'ref': _('Reversal of: %(move_name)s, %(reason)s', move_name=move.name, reason=self.reason) if self.reason @@ -94,7 +95,7 @@ class AccountMoveReversal(models.TransientModel): 'invoice_date_due': reverse_date, 'invoice_date': move.is_invoice(include_receipts=True) and (self.date or move.date) or False, 'journal_id': self.journal_id.id, - 'invoice_payment_term_id': None, + 'invoice_payment_term_id': mixed_payment_term, 'invoice_user_id': move.invoice_user_id.id, 'auto_post': 'at_date' if reverse_date > fields.Date.context_today(self) else 'no', }