Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Bug #353 crash when selecting a payment mode that has a variable link to bank accounts #354

Merged
merged 1 commit into from
May 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions account_payment_order/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class AccountPaymentOrder(models.Model):
'account.journal', string='Bank Journal', ondelete='restrict',
readonly=True, states={'draft': [('readonly', False)]},
track_visibility='onchange')
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(
Expand Down Expand Up @@ -133,19 +130,6 @@ def _bank_line_count(self):
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:
mode = order.payment_mode_id
if mode.bank_account_link == 'fixed':
allowed_journal_ids = mode.fixed_journal_id
else:
allowed_journal_ids = mode.variable_journal_ids
order.allowed_journal_ids = allowed_journal_ids

@api.model
def create(self, vals):
if vals.get('name', 'New') == 'New':
Expand All @@ -162,10 +146,18 @@ def create(self, vals):
@api.onchange('payment_mode_id')
def payment_mode_id_change(self):
journal_id = False
res = {'domain': {
'journal_id': "[('id', '=', False)]",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be {'journal_id': []}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I make your modification, then I have access to all journals when no payment mode is selected, which is not what I want : I want the user to select a payement mode first. So I prefer my solution, which works well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then please hide the field when no payment mode is selected in the view via attrs attribute.

}}
if self.payment_mode_id:
if self.payment_mode_id.bank_account_link == 'fixed':
journal_id = self.payment_mode_id.fixed_journal_id
journal_id = self.payment_mode_id.fixed_journal_id.id
res['domain']['journal_id'] = "[('id', '=', %d)]" % journal_id
elif self.payment_mode_id.bank_account_link == 'variable':
jrl_ids = self.payment_mode_id.variable_journal_ids.ids
res['domain']['journal_id'] = "[('id', 'in', %s)]" % jrl_ids
self.journal_id = journal_id
return res

@api.multi
def action_done(self):
Expand Down
4 changes: 1 addition & 3 deletions account_payment_order/views/account_payment_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
<field name="payment_mode_id"
domain="[('payment_order_ok', '=', True), ('payment_type', '=', payment_type)]"
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 [])]"/>
<field name="allowed_journal_ids" invisible="1"/>
<field name="journal_id" widget="selection"/>
<field name="bank_account_link" invisible="1"/>
<field name="company_partner_bank_id"/>
<field name="company_id" groups="base.group_multi_company"/>
Expand Down