[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.
This commit is contained in:
Yannick Tivisse
2017-06-02 15:53:09 +02:00
parent 783746f579
commit e4152792ff
2 changed files with 10 additions and 1 deletions
@@ -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})
+1 -1
View File
@@ -88,7 +88,7 @@
<field name="fees_dom_var" attrs="{'invisible': [('fees_active', '=', False)]}"/>
<field name="fees_int_fixed" attrs="{'invisible': [('fees_active', '=', False)]}"/>
<field name="fees_int_var" attrs="{'invisible': [('fees_active', '=', False)]}"/>
<field name="journal_id" context="{'default_type': 'bank'}" required="1"/>
<field name="journal_id" context="{'default_type': 'bank'}"/>
<field name="specific_countries"/>
<field name="country_ids" widget="many2many_tags" attrs="{'invisible': [('specific_countries', '=', False)]}"/>
<label for="view_template_id" groups="base.group_no_one"/>