[FIX] account: don't ignore default journal_id in payments' onchange on amount field

onchange function getting called when modifying the 'amount' field of account.payment always changed the journal of the payment when this amount was equal to zero. This caused a bug with batch deposits, when trying to create a new payment from the tree view contained in the form view of account.batch.deposit: passed default value for journal_id was ignored.
This commit is contained in:
Olivier Colson
2018-01-29 14:42:36 +01:00
parent 6a91ae0c18
commit 75857a2c34
+12 -5
View File
@@ -336,9 +336,16 @@ class account_payment(models.Model):
jrnl_filters = self._compute_journal_domain_and_types()
journal_types = jrnl_filters['journal_types']
domain_on_types = [('type', 'in', list(journal_types))]
if self.journal_id.type not in journal_types:
self.journal_id = self.env['account.journal'].search(domain_on_types, limit=1)
return {'domain': {'journal_id': jrnl_filters['domain'] + domain_on_types}}
journal_domain = jrnl_filters['domain'] + domain_on_types
default_journal_id = self.env.context.get('default_journal_id')
if not default_journal_id:
if self.journal_id.type not in journal_types:
self.journal_id = self.env['account.journal'].search(domain_on_types, limit=1)
else:
journal_domain = journal_domain.append(('id', '=', default_journal_id))
return {'domain': {'journal_id': journal_domain}}
@api.one
@api.depends('invoice_ids', 'payment_type', 'partner_type', 'partner_id')
@@ -502,7 +509,7 @@ class account_payment(models.Model):
@api.multi
def action_draft(self):
return self.write({'state': 'draft'})
def action_validate_invoice_payment(self):
""" Posts a payment used to pay an invoice. This function only posts the
payment by default but can be overridden to apply specific post or pre-processing.
@@ -666,7 +673,7 @@ class account_payment(models.Model):
for inv in invoice:
if inv.move_id:
name += inv.number + ', '
name = name[:len(name)-2]
name = name[:len(name)-2]
return {
'name': name,
'account_id': self.destination_account_id.id,