[FIX] account: epd missing in credit note

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) <wan@odoo.com>
Signed-off-by: Andrea Grazioso (agr) <agr@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2023-12-11 09:56:53 +00:00
parent 3e66c037b9
commit 1f8880831b
2 changed files with 68 additions and 1 deletions
@@ -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',
},
])
@@ -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',
}