From b426b2f0232c8ed4e535cd902b9ad41b3ae6e928 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 18 Jul 2019 07:59:46 +0000 Subject: [PATCH] [FIX] account: invoice context from payment smart button is correct Register a payment on a vendor bill. From the menu Account > Purchase > Payment, clik to see that payment click on the smart button to see the invoices Create a new Bill Before this commit, the default type and journal of the new bill were actually the ones of a customer invoice After this commit, those defaults are the ones of a vendor bill OPW 2038786 closes odoo/odoo#34967 Signed-off-by: Lucas Perais (lpe) --- addons/account/models/account_payment.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 56d6a8a96d9..1d654be0652 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -430,20 +430,25 @@ class account_payment(models.Model): @api.multi def button_invoices(self): - if self.partner_type == 'supplier': - views = [(self.env.ref('account.invoice_supplier_tree').id, 'tree'), (self.env.ref('account.invoice_supplier_form').id, 'form')] - else: - views = [(self.env.ref('account.invoice_tree').id, 'tree'), (self.env.ref('account.invoice_form').id, 'form')] - return { + action = { 'name': _('Paid Invoices'), 'view_type': 'form', 'view_mode': 'tree,form', 'res_model': 'account.invoice', 'view_id': False, - 'views': views, 'type': 'ir.actions.act_window', 'domain': [('id', 'in', [x.id for x in self.invoice_ids])], } + if self.partner_type == 'supplier': + action['views'] = [(self.env.ref('account.invoice_supplier_tree').id, 'tree'), (self.env.ref('account.invoice_supplier_form').id, 'form')] + action['context'] = { + 'journal_type': 'purchase', + 'type': 'in_invoice', + 'default_type': 'in_invoice', + } + else: + action['views'] = [(self.env.ref('account.invoice_tree').id, 'tree'), (self.env.ref('account.invoice_form').id, 'form')] + return action @api.multi def button_dummy(self):