[FIX] account: Impossible to make a partial credit note

Steps to reproduce the bug:

- Create a credit note for an amount of 100$
- Validate it and register a payment
- Let's pay an amount of 90$ and mark this credit note as fully paid

Bug:

An error message was raised saying: Wrong credit or debit value in accounting entry !

DO NOT FORWARD-PORT

opw:1893570

closes odoo/odoo#28433
This commit is contained in:
Goffin Simon
2018-11-07 09:01:14 +00:00
parent 392a8d8f9e
commit 69a0af9e86
2 changed files with 43 additions and 1 deletions
+17 -1
View File
@@ -569,8 +569,24 @@ class account_payment(models.Model):
# to avoid loss of precision during the currency rate computations. See revision 20935462a0cabeb45480ce70114ff2f4e91eaf79 for a detailed example.
total_residual_company_signed = sum(invoice.residual_company_signed for invoice in self.invoice_ids)
total_payment_company_signed = self.currency_id.with_context(date=self.payment_date).compute(self.amount, self.company_id.currency_id)
if self.invoice_ids[0].type in ['in_invoice', 'out_refund']:
# amout_wo must be positive for out_invoice and in_refund and negative for in_invoice and out_refund in standard use case
# | total_payment_company_signed | total_residual_company_signed | amount_wo
#----------------------------------------------------------------------------------------------------------------------
# in_invoice | positive | positive | negative
#----------------------------------------------------------------------------------------------------------------------
# in_refund | positive | negative | positive
#----------------------------------------------------------------------------------------------------------------------
# out_invoice | positive | positive | positive
#----------------------------------------------------------------------------------------------------------------------
# out_refund | positive | negative | negative
#----------------------------------------------------------------------------------------------------------------------
# DO NOT FORWARD-PORT
if self.invoice_ids[0].type == 'in_invoice':
amount_wo = total_payment_company_signed - total_residual_company_signed
elif self.invoice_ids[0].type == 'in_refund':
amount_wo = - total_payment_company_signed - total_residual_company_signed
elif self.invoice_ids[0].type == 'out_refund':
amount_wo = total_payment_company_signed + total_residual_company_signed
else:
amount_wo = total_residual_company_signed - total_payment_company_signed
# Align the sign of the secondary currency writeoff amount with the sign of the writeoff
+26
View File
@@ -370,3 +370,29 @@ class TestPayment(AccountingTestCase):
{'account_id': self.account_payable.id, 'debit': 0.0, 'credit': 8.65, 'amount_currency': -13.22, 'currency_id': self.currency_usd_id},
{'account_id': self.account_receivable.id, 'debit': 0.0, 'credit': 7.7, 'amount_currency': -11.78, 'currency_id': self.currency_usd_id},
])
def test_payment_and_writeoff_out_refund(self):
# Use case:
# Company is in EUR, create a credit note for 100 EUR and register payment of 90.
# Mark invoice as fully paid with a write_off
# Check that all the aml are correctly created.
invoice = self.create_invoice(amount=100, type='out_refund', currency_id=self.currency_eur_id, partner=self.partner_agrolait.id)
# register payment on invoice
payment = self.payment_model.create({'payment_type': 'outbound',
'payment_method_id': self.env.ref('account.account_payment_method_manual_in').id,
'partner_type': 'customer',
'partner_id': self.partner_agrolait.id,
'amount': 90,
'payment_date': time.strftime('%Y') + '-07-15',
'payment_difference_handling': 'reconcile',
'writeoff_account_id': self.account_payable.id,
'journal_id': self.bank_journal_euro.id,
'invoice_ids': [(4, invoice.id, None)]
})
payment.post()
self.check_journal_items(payment.move_line_ids, [
{'account_id': self.account_eur.id, 'debit': 0.0, 'credit': 90.0, 'amount_currency': 0.0, 'currency_id': False},
{'account_id': self.account_payable.id, 'debit': 0.0, 'credit': 10.0, 'amount_currency': 0.0, 'currency_id': False},
{'account_id': self.account_receivable.id, 'debit': 100.0, 'credit': 0.0, 'amount_currency': 0.0, 'currency_id': False},
])
self.assertEqual(invoice.state, 'paid')