mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Filter on allowed_journal_ids even if onchange of payment_mode_id is not played (for example when the payment line is pushed from the invoice)
This commit is contained in:
committed by
Enric Tobella
parent
72c22b39d1
commit
b505cabcd9
@@ -32,14 +32,7 @@ class AccountInvoice(models.Model):
|
||||
@api.multi
|
||||
def _prepare_new_payment_order(self):
|
||||
self.ensure_one()
|
||||
vals = {
|
||||
'payment_mode_id': self.payment_mode_id.id,
|
||||
'payment_type': self.payment_mode_id.payment_type,
|
||||
}
|
||||
if self.payment_mode_id.bank_account_link == 'fixed':
|
||||
vals['journal_id'] = self.payment_mode_id.fixed_journal_id.id
|
||||
# TODO : else: no filter on allowed bank accounts,
|
||||
# because onchange not played ??
|
||||
vals = {'payment_mode_id': self.payment_mode_id.id}
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -36,6 +36,9 @@ class AccountPaymentOrder(models.Model):
|
||||
journal_id = fields.Many2one(
|
||||
'account.journal', string='Bank Journal',
|
||||
readonly=True, states={'draft': [('readonly', False)]})
|
||||
allowed_journal_ids = fields.Many2many(
|
||||
'account.journal', compute='_compute_allowed_journals', readonly=True,
|
||||
string='Selectable Bank Journals')
|
||||
# The journal_id field is only required at confirm step, to
|
||||
# allow auto-creation of payment order from invoice
|
||||
company_partner_bank_id = fields.Many2one(
|
||||
@@ -110,34 +113,38 @@ class AccountPaymentOrder(models.Model):
|
||||
for order in self:
|
||||
order.bank_line_count = len(order.bank_line_ids)
|
||||
|
||||
@api.multi
|
||||
@api.depends('payment_mode_id')
|
||||
def _compute_allowed_journals(self):
|
||||
for order in self:
|
||||
allowed_journal_ids = False
|
||||
if order.payment_mode_id:
|
||||
if order.payment_mode_id.bank_account_link == 'fixed':
|
||||
allowed_journal_ids = order.payment_mode_id.fixed_journal_id
|
||||
else:
|
||||
allowed_journal_ids = order.payment_mode_id.variable_journal_ids
|
||||
order.allowed_journal_ids = allowed_journal_ids
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get('name', 'New') == 'New':
|
||||
vals['name'] = self.env['ir.sequence'].next_by_code(
|
||||
'account.payment.order') or 'New'
|
||||
if vals.get('payment_mode_id'):
|
||||
payment_mode = self.env['account.payment.mode'].browse(
|
||||
vals['payment_mode_id'])
|
||||
vals['payment_type'] = payment_mode.payment_type
|
||||
if payment_mode.bank_account_link == 'fixed':
|
||||
vals['journal_id'] = payment_mode.fixed_journal_id.id
|
||||
return super(AccountPaymentOrder, self).create(vals)
|
||||
|
||||
@api.onchange('payment_mode_id')
|
||||
def payment_mode_id_change(self):
|
||||
res = {'domain': {}}
|
||||
journal_id = False
|
||||
if self.payment_mode_id:
|
||||
if self.payment_mode_id.bank_account_link == 'fixed':
|
||||
self.journal_id = self.payment_mode_id.fixed_journal_id
|
||||
# journal_id is a required field, so I can't set it readonly
|
||||
# so I restrict the domain so that the user cannot change
|
||||
# the journal
|
||||
res['domain']['journal_id'] = [(
|
||||
'id',
|
||||
'=',
|
||||
self.payment_mode_id.fixed_journal_id.id)]
|
||||
else:
|
||||
res['domain']['journal_id'] = [(
|
||||
'id',
|
||||
'in',
|
||||
self.payment_mode_id.variable_journal_ids.ids)]
|
||||
else:
|
||||
self.journal_id = False
|
||||
return res
|
||||
journal_id = self.payment_mode_id.fixed_journal_id
|
||||
self.journal_id = journal_id
|
||||
|
||||
@api.multi
|
||||
def action_done(self):
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
<field name="payment_mode_id"
|
||||
domain="[('payment_order_ok', '=', True), ('payment_type', '=', payment_type)]"
|
||||
widget="selection"/>
|
||||
<field name="journal_id" widget="selection"/>
|
||||
<field name="journal_id" widget="selection"
|
||||
domain="[('id', 'in', allowed_journal_ids and allowed_journal_ids[0] and allowed_journal_ids[0][2] or False)]"/>
|
||||
<field name="allowed_journal_ids" invisible="1"/>
|
||||
<field name="bank_account_link" invisible="1"/>
|
||||
<field name="company_partner_bank_id" widget="selection"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
|
||||
Reference in New Issue
Block a user