[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 <oco-odoo@users.noreply.github.com>
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
Laurent Smet
2020-07-31 15:17:53 +00:00
parent 90033c95ea
commit 0ca24b9af1
3 changed files with 89 additions and 5 deletions
+2
View File
@@ -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:
@@ -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
@@ -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