[FIX] sale: fix amount to invoice for credit notes
Issue: The `_compute_amount_to_invoice` computation wasn't taking into account the fact that invoices have a direction (i.e. either going outbound(+) or coming inbound(-) (cf. `_compute_direction_sign`)). This, in turn, makes the value of `amount_to_invoice` incorrect for sales order with a credit note. Solution: In `_compute_amount_to_invoice`, multiply the value of `invoice_amount_currency` with the opposite of the `direction_sign` of the invoice, to account for the invoice direction. opw-3360439 X-original-commit: 06ef17f2eefe89abfca64721185ac053fa8de820 [FIX] sale: fix amount to invoice for credit notes Issue: The `_compute_amount_to_invoice` computation wasn't taking into account the fact that invoices have a direction (i.e. either going outbound(+) or coming inbound(-) (cf. `_compute_direction_sign`)). This, in turn, makes the value of `amount_to_invoice` incorrect for sales order with a credit note. Solution: In `_compute_amount_to_invoice`, multiply the value of `invoice_amount_currency` with the opposite of the `direction_sign` of the invoice, to account for the invoice direction. opw-3360439 closes odoo/odoo#127914 X-original-commit: d258774f120fb470d969e68c05cf0d8da0c4557a Signed-off-by: John Laterre (jol) <jol@odoo.com>
This commit is contained in:
@@ -612,7 +612,7 @@ class SaleOrder(models.Model):
|
||||
order.amount_to_invoice = order.amount_total
|
||||
for invoice in order.invoice_ids.filtered(lambda x: x.state == 'posted'):
|
||||
invoice_amount_currency = invoice.currency_id._convert(
|
||||
invoice.tax_totals['amount_total'],
|
||||
invoice.tax_totals['amount_total'] * -invoice.direction_sign,
|
||||
order.currency_id,
|
||||
invoice.company_id,
|
||||
invoice.date,
|
||||
|
||||
@@ -452,16 +452,36 @@ class TestSaleOrderDownPayment(TestSaleCommon):
|
||||
'deposit_account_id': self.revenue_account.id,
|
||||
}).create_invoices()
|
||||
|
||||
invoice = sale_order.invoice_ids
|
||||
|
||||
# Check that the warning does not appear even though we are creating an invoice
|
||||
# that should bring partner_a's credit above its limit.
|
||||
self.assertEqual(sale_order.invoice_ids.partner_credit_warning, '')
|
||||
self.assertEqual(invoice.partner_credit_warning, '')
|
||||
|
||||
|
||||
# Make the down payment invoice amount larger than the Amount to Invoice
|
||||
# and check that the warning appears with the correct amounts,
|
||||
# i.e. 1.500 instead of 2.500 (1.000 SO + 1.500 down payment invoice).
|
||||
sale_order.invoice_ids.invoice_line_ids.quantity = 3
|
||||
invoice.invoice_line_ids.quantity = 3
|
||||
self.assertEqual(
|
||||
sale_order.invoice_ids.partner_credit_warning,
|
||||
invoice.partner_credit_warning,
|
||||
"partner_a has reached its Credit Limit of: $\xa01,000.00\n"
|
||||
"Total amount due (including this document): $\xa01,500.00"
|
||||
)
|
||||
|
||||
invoice.invoice_line_ids.quantity = 1
|
||||
invoice.action_post()
|
||||
|
||||
# Create a credit note reversing the invoice
|
||||
self.env['account.move.reversal'].with_company(self.env.company).create(
|
||||
{
|
||||
'move_ids': [Command.set((invoice.id,))],
|
||||
'journal_id': invoice.journal_id.id
|
||||
}
|
||||
).reverse_moves()
|
||||
|
||||
credit_note = sale_order.invoice_ids[1]
|
||||
credit_note.action_post()
|
||||
|
||||
# Check that the credit note is accounted for correctly for the amount_to_invoice
|
||||
self.assertEqual(sale_order.amount_to_invoice, sale_order.amount_total)
|
||||
|
||||
Reference in New Issue
Block a user