From 75857a2c34611c496c949ee5cd16fa809f31e455 Mon Sep 17 00:00:00 2001 From: Olivier Colson Date: Mon, 29 Jan 2018 14:42:36 +0100 Subject: [PATCH] [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. --- addons/account/models/account_payment.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 70a54f967f6..741f3fde668 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -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,