From ed4cbf57dc8d5850bf1e700dea0c35ea2f64c191 Mon Sep 17 00:00:00 2001 From: Hiral Bhavsar Date: Fri, 9 Mar 2018 13:38:45 +0100 Subject: [PATCH] [FIX] account: fix account.payment creation from dashboard From 'Accounting Dashboard', creating a new payment was raising an error 'Record does not exist or has been deleted.'. That's because since cdca5d4751a979f6b694f02d88160843f81a77f5 the default_get() was expecting to be called directly from the account.invoice model, using 'active_ids' to compute default values. Since it was incorrect, we now also check for the active_model to avoid raising this error. Was PR #23548 Was task: 1824893 --- addons/account/models/account_payment.py | 3 ++- addons/account/tests/test_payment.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index b03e5f8f684..2090d03bc30 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -70,9 +70,10 @@ class account_abstract_payment(models.AbstractModel): def default_get(self, fields): rec = super(account_abstract_payment, self).default_get(fields) active_ids = self._context.get('active_ids') + active_model = self._context.get('active_model') # Check for selected invoices ids - if not active_ids: + if not active_ids or active_model != 'account.invoice': return rec invoices = self.env['account.invoice'].browse(active_ids) diff --git a/addons/account/tests/test_payment.py b/addons/account/tests/test_payment.py index 3e0e1c8961d..3c22a127180 100644 --- a/addons/account/tests/test_payment.py +++ b/addons/account/tests/test_payment.py @@ -8,7 +8,7 @@ class TestPayment(AccountingTestCase): def setUp(self): super(TestPayment, self).setUp() - self.register_payments_model = self.env['account.register.payments'] + self.register_payments_model = self.env['account.register.payments'].with_context(active_model='account.invoice') self.payment_model = self.env['account.payment'] self.invoice_model = self.env['account.invoice'] self.invoice_line_model = self.env['account.invoice.line']