From da9f3512e7690b481dc8709f42f195e7fc3eadc6 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 13 Dec 2019 11:06:49 +0000 Subject: [PATCH] [IMP] account: remove dynamic domains in register payment wizard It seems very strange that we'd want to use active_ids as invoices to work with when when we already have invoices available, and these are browsed / converted from the active_ids if they weren't provided explicitly. There's also an odd divergence between the filtering on the journal's company here and in the default_get too: in the default_get we get a journal in the user's company but then we only allow selecting a journal from the invoices' company... Task 2115472 closes odoo/odoo#41871 Signed-off-by: Xavier Morel (xmo) --- addons/account/models/account_payment.py | 26 ++++++++++--------- addons/account/views/account_payment_view.xml | 2 ++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 31e364b432b..0748f407a1d 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -703,8 +703,9 @@ class payment_register(models.TransientModel): _description = 'Register Payment' payment_date = fields.Date(required=True, default=fields.Date.context_today) - journal_id = fields.Many2one('account.journal', required=True, domain=[('type', 'in', ('bank', 'cash'))]) + journal_id = fields.Many2one('account.journal', required=True, domain="[('type', 'in', ('bank', 'cash')), ('company_id', '=', invoice_company_id)]") payment_method_id = fields.Many2one('account.payment.method', string='Payment Method Type', required=True, + domain="[('id', 'in', available_payment_methods)]", help="Manual: Get paid by cash, check or any other method outside of Odoo.\n" "Electronic: Get paid automatically through a payment acquirer by requesting a transaction on a card saved by the customer when buying or subscribing online (payment token).\n" "Check: Pay bill by check and print it from Odoo.\n" @@ -713,6 +714,9 @@ class payment_register(models.TransientModel): invoice_ids = fields.Many2many('account.move', 'account_invoice_payment_rel_transient', 'payment_id', 'invoice_id', string="Invoices", copy=False, readonly=True) group_payment = fields.Boolean(help="Only one payment will be created by partner (bank)/ currency.") + invoice_company_id = fields.Many2one(related='invoice_ids.company_id') + available_payment_methods = fields.Many2many('account.payment.method', compute='_compute_available_payment_methods') + @api.model def default_get(self, fields): rec = super(payment_register, self).default_get(fields) @@ -743,18 +747,16 @@ class payment_register(models.TransientModel): rec['payment_method_id'] = self.env['account.payment.method'].search(domain, limit=1).id return rec - @api.onchange('journal_id', 'invoice_ids') - def _onchange_journal(self): - active_ids = self._context.get('active_ids') - invoices = self.env['account.move'].browse(active_ids) - if self.journal_id and invoices: - if invoices[0].is_inbound(): - domain_payment = [('payment_type', '=', 'inbound'), ('id', 'in', self.journal_id.inbound_payment_method_ids.ids)] + @api.depends('invoice_ids', 'journal_id.inbound_payment_method_ids', 'journal_id.outbound_payment_method_ids') + def _compute_available_payment_methods(self): + for p in self: + invoice = p.invoice_ids[:1] + if not invoice: + p.available_payment_methods = self.env['account.payment.method'] + elif invoice.is_inbound(): + p.available_payment_methods = self.journal_id.inbound_payment_method_ids._origin else: - domain_payment = [('payment_type', '=', 'outbound'), ('id', 'in', self.journal_id.outbound_payment_method_ids.ids)] - domain_journal = [('type', 'in', ('bank', 'cash')), ('company_id', '=', invoices[0].company_id.id)] - return {'domain': {'payment_method_id': domain_payment, 'journal_id': domain_journal}} - return {} + p.available_payment_methods = self.journal_id.outbound_payment_method_ids._origin def _prepare_payment_vals(self, invoices): '''Create the payment values. diff --git a/addons/account/views/account_payment_view.xml b/addons/account/views/account_payment_view.xml index 17794a0f4cb..2073c786149 100644 --- a/addons/account/views/account_payment_view.xml +++ b/addons/account/views/account_payment_view.xml @@ -206,6 +206,8 @@ account.payment.register
+ +