From e4152792fff0781b62ec10758b7a84bc953503a7 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Fri, 2 Jun 2017 14:28:38 +0200 Subject: [PATCH] [IMP] payment: Set automatically a default value for journal_id if not set Purpose ======= The field journal_id on a payment.acquired is required on the view. The only issue is that the journals cannot be created before having installed a localization. When the payment acquire module is installed before the localization, the journal id is not set on the payment acquire and it's impossible to make a call to `write` (For example publish the acquire) Specification ============= When making a write or a create on a payment acquire, udpate the journal_id with a default value if not set. --- addons/payment/models/payment_acquirer.py | 9 +++++++++ addons/payment/views/payment_views.xml | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index e36b344a52d..bbb054a7a0b 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -185,13 +185,22 @@ class PaymentAcquirer(models.Model): @api.model def create(self, vals): image_resize_images(vals) + vals = self._check_journal_id(vals) return super(PaymentAcquirer, self).create(vals) @api.multi def write(self, vals): image_resize_images(vals) + vals = self._check_journal_id(vals) return super(PaymentAcquirer, self).write(vals) + def _check_journal_id(self, vals): + if not vals.get('journal_id', False): + default_journal = self.env['account.journal'].search([('type', '=', 'bank')], limit=1) + if default_journal: + vals.update({'journal_id': default_journal.id}) + return vals + @api.multi def toggle_website_published(self): self.write({'website_published': not self.website_published}) diff --git a/addons/payment/views/payment_views.xml b/addons/payment/views/payment_views.xml index e40c7e9049b..deaf1dee0bd 100644 --- a/addons/payment/views/payment_views.xml +++ b/addons/payment/views/payment_views.xml @@ -88,7 +88,7 @@ - +