From 9cc4c453d6e913258a3a14e7abc035756ae09d98 Mon Sep 17 00:00:00 2001 From: Olivier Colson Date: Tue, 19 Jun 2018 17:55:54 +0200 Subject: [PATCH] [FIX] account: creation of account.payment Allow to give the value of the payment method by the key 'default_payment_method_id' of the context, as the regular usage wants. --- addons/account/models/account_payment.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 9ab03dae624..354f72693ef 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -137,10 +137,18 @@ class account_abstract_payment(models.AbstractModel): if self.journal_id: # Set default payment method (we consider the first to be the default one) payment_methods = self.payment_type == 'inbound' and self.journal_id.inbound_payment_method_ids or self.journal_id.outbound_payment_method_ids - self.payment_method_id = payment_methods and payment_methods[0] or False + payment_methods_list = payment_methods.ids + + default_payment_method_id = self.env.context.get('default_payment_method_id') + if default_payment_method_id: + # Ensure the domain will accept the provided default value + payment_methods_list.append(default_payment_method_id) + else: + self.payment_method_id = payment_methods and payment_methods[0] or False + # Set payment method domain (restrict to methods enabled for the journal and to selected payment type) payment_type = self.payment_type in ('outbound', 'transfer') and 'outbound' or 'inbound' - return {'domain': {'payment_method_id': [('payment_type', '=', payment_type), ('id', 'in', payment_methods.ids)]}} + return {'domain': {'payment_method_id': [('payment_type', '=', payment_type), ('id', 'in', payment_methods_list)]}} return {} def _compute_journal_domain_and_types(self):