From 0ca24b9af1d78cdb0067ffe5dc17f247ab0adb4b Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Fri, 31 Jul 2020 13:21:12 +0000 Subject: [PATCH] [FIX] account: Fix register payment with mark as fully paid on vendor bills - Create a vendor bill with amount X - Register payment of X - 5 and mark as fully paid => The vendor bill is not fully paid. closes odoo/odoo#55271 X-original-commit: 5c729d4cb7dacc46409259850ed7a5620fd6eb64 Signed-off-by: oco-odoo Signed-off-by: Laurent Smet --- addons/account/models/account_payment.py | 2 + .../tests/test_account_payment_register.py | 90 ++++++++++++++++++- .../wizard/account_payment_register.py | 2 +- 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index d1c0de1dc71..fa0470265ed 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -181,11 +181,13 @@ class AccountPayment(models.Model): if self.payment_type == 'inbound': # Receive money. counterpart_amount = -self.amount + write_off_amount *= -1 elif self.payment_type == 'outbound': # Send money. counterpart_amount = self.amount else: counterpart_amount = 0.0 + write_off_amount = 0.0 # Manage currency. if self.currency_id == self.company_id.currency_id: diff --git a/addons/account/tests/test_account_payment_register.py b/addons/account/tests/test_account_payment_register.py index af142f72b5a..ba6e6c6c63c 100644 --- a/addons/account/tests/test_account_payment_register.py +++ b/addons/account/tests/test_account_payment_register.py @@ -153,7 +153,7 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): }, ]) - def test_register_payment_single_batch_grouped_writeoff_lower_amount(self): + def test_register_payment_single_batch_grouped_writeoff_lower_amount_debit(self): ''' Pay 800.0 with 'reconcile' as payment difference handling on two customer invoices (1000 + 2000). ''' active_ids = (self.out_invoice_1 + self.out_invoice_2).ids payments = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=active_ids).create({ @@ -162,7 +162,6 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): 'payment_difference_handling': 'reconcile', 'writeoff_account_id': self.company_data['default_account_revenue'].id, 'writeoff_label': 'writeoff', - 'currency_id': self.currency_data['currency'].id, 'payment_method_id': self.custom_payment_method_in.id, })._create_payments() @@ -196,7 +195,7 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): }, ]) - def test_register_payment_single_batch_grouped_writeoff_higher_amount(self): + def test_register_payment_single_batch_grouped_writeoff_higher_amount_debit(self): ''' Pay 3100.0 with 'reconcile' as payment difference handling on two customer invoices (1000 + 2000). ''' active_ids = (self.out_invoice_1 + self.out_invoice_2).ids payments = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=active_ids).create({ @@ -205,7 +204,6 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): 'payment_difference_handling': 'reconcile', 'writeoff_account_id': self.company_data['default_account_revenue'].id, 'writeoff_label': 'writeoff', - 'currency_id': self.currency_data['currency'].id, 'payment_method_id': self.custom_payment_method_in.id, })._create_payments() @@ -239,6 +237,90 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): }, ]) + def test_register_payment_single_batch_grouped_writeoff_lower_amount_credit(self): + ''' Pay 800.0 with 'reconcile' as payment difference handling on two vendor billes (1000 + 2000). ''' + active_ids = (self.in_invoice_1 + self.in_invoice_2).ids + payments = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=active_ids).create({ + 'amount': 800.0, + 'group_payment': True, + 'payment_difference_handling': 'reconcile', + 'writeoff_account_id': self.company_data['default_account_revenue'].id, + 'writeoff_label': 'writeoff', + 'payment_method_id': self.custom_payment_method_in.id, + })._create_payments() + + self.assertRecordValues(payments, [{ + 'payment_method_id': self.custom_payment_method_in.id, + }]) + self.assertRecordValues(payments.line_ids.sorted('balance'), [ + # Writeoff line: + { + 'debit': 0.0, + 'credit': 2200.0, + 'currency_id': False, + 'amount_currency': 0.0, + 'reconciled': False, + }, + # Liquidity line: + { + 'debit': 0.0, + 'credit': 800.0, + 'currency_id': False, + 'amount_currency': 0.0, + 'reconciled': False, + }, + # Payable line: + { + 'debit': 3000.0, + 'credit': 0.0, + 'currency_id': False, + 'amount_currency': 0.0, + 'reconciled': True, + }, + ]) + + def test_register_payment_single_batch_grouped_writeoff_higher_amount_credit(self): + ''' Pay 3100.0 with 'reconcile' as payment difference handling on two vendor billes (1000 + 2000). ''' + active_ids = (self.in_invoice_1 + self.in_invoice_2).ids + payments = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=active_ids).create({ + 'amount': 3100.0, + 'group_payment': True, + 'payment_difference_handling': 'reconcile', + 'writeoff_account_id': self.company_data['default_account_revenue'].id, + 'writeoff_label': 'writeoff', + 'payment_method_id': self.custom_payment_method_in.id, + })._create_payments() + + self.assertRecordValues(payments, [{ + 'payment_method_id': self.custom_payment_method_in.id, + }]) + self.assertRecordValues(payments.line_ids.sorted('balance'), [ + # Liquidity line: + { + 'debit': 0.0, + 'credit': 3100.0, + 'currency_id': False, + 'amount_currency': 0.0, + 'reconciled': False, + }, + # Writeoff line: + { + 'debit': 100.0, + 'credit': 0.0, + 'currency_id': False, + 'amount_currency': 0.0, + 'reconciled': False, + }, + # Payable line: + { + 'debit': 3000.0, + 'credit': 0.0, + 'currency_id': False, + 'amount_currency': 0.0, + 'reconciled': True, + }, + ]) + def test_register_payment_single_batch_not_grouped(self): ''' Choose to pay two customer invoices with separated payments (1000 + 2000). ''' active_ids = (self.out_invoice_1 + self.out_invoice_2).ids diff --git a/addons/account/wizard/account_payment_register.py b/addons/account/wizard/account_payment_register.py index c36f5bbfb9c..a4a6fdca2a4 100644 --- a/addons/account/wizard/account_payment_register.py +++ b/addons/account/wizard/account_payment_register.py @@ -419,7 +419,7 @@ class AccountPaymentRegister(models.TransientModel): if self.payment_difference and self.payment_difference_handling == 'reconcile': payment_vals['write_off_line_vals'] = { 'name': self.writeoff_label, - 'amount': -self.payment_difference, + 'amount': self.payment_difference, 'account_id': self.writeoff_account_id.id, } return payment_vals