Skip to content

Commit

Permalink
Improve workaround for bug odoo/odoo#14761
Browse files Browse the repository at this point in the history
It replaces the workaround widget="many2many_tags" on field name="account_ids" which prevented from selecting several accounts at the same time (quite useful when you want to select an interval of accounts for example). We now use the regular M2M widget and inherit create()
  • Loading branch information
alexis-via authored and JordiBForgeFlow committed Oct 1, 2018
1 parent 38e6f5f commit faa829e
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 4 deletions.
Expand Up @@ -54,6 +54,27 @@ def onchange_type_accounts_only(self):
else:
self.account_ids = None

@api.model
def create(self, vals):
"""
This is a workaround for bug https://github.com/odoo/odoo/issues/14761
This bug impacts M2M fields in wizards filled-up via onchange
It replaces the workaround widget="many2many_tags" on
field name="account_ids" which prevented from selecting several
accounts at the same time (quite useful when you want to select
an interval of accounts for example)
"""
if 'account_ids' in vals and isinstance(vals['account_ids'], list):
account_ids = []
for account in vals['account_ids']:
if account[0] in (1, 4):
account_ids.append(account[1])
elif account[0] == 6 and isinstance(account[2], list):
account_ids += account[2]
vals['account_ids'] = [(6, 0, account_ids)]
res = super(AgedPartnerBalance, self).create(vals)
return res

@api.multi
def button_export_html(self):
self.ensure_one()
Expand Down
Expand Up @@ -27,7 +27,7 @@
<field name="receivable_accounts_only"/>
<field name="payable_accounts_only"/>
</group>
<field name="account_ids" widget="many2many_tags" nolabel="1" options="{'no_create': True}"/>
<field name="account_ids" nolabel="1" options="{'no_create': True}"/>
<footer>
<button name="button_export_html" string="View"
type="object" default_focus="1" class="oe_highlight"/>
Expand Down
21 changes: 21 additions & 0 deletions account_financial_report_qweb/wizard/general_ledger_wizard.py
Expand Up @@ -110,6 +110,27 @@ def onchange_type_accounts_only(self):
else:
self.account_ids = None

@api.model
def create(self, vals):
"""
This is a workaround for bug https://github.com/odoo/odoo/issues/14761
This bug impacts M2M fields in wizards filled-up via onchange
It replaces the workaround widget="many2many_tags" on
field name="account_ids" which prevented from selecting several
accounts at the same time (quite useful when you want to select
an interval of accounts for example)
"""
if 'account_ids' in vals and isinstance(vals['account_ids'], list):
account_ids = []
for account in vals['account_ids']:
if account[0] in (1, 4):
account_ids.append(account[1])
elif account[0] == 6 and isinstance(account[2], list):
account_ids += account[2]
vals['account_ids'] = [(6, 0, account_ids)]
res = super(GeneralLedgerReportWizard, self).create(vals)
return res

@api.onchange('partner_ids')
def onchange_partner_ids(self):
"""Handle partners change."""
Expand Down
Expand Up @@ -39,7 +39,7 @@
<field name="receivable_accounts_only"/>
<field name="payable_accounts_only"/>
</group>
<field name="account_ids" widget="many2many_tags" nolabel="1" options="{'no_create': True}"/>
<field name="account_ids" nolabel="1" options="{'no_create': True}"/>
</div>
<div attrs="{'invisible': [('not_only_one_unaffected_earnings_account', '=', False)]}">
<field name="not_only_one_unaffected_earnings_account" invisible="1"/>
Expand Down
21 changes: 21 additions & 0 deletions account_financial_report_qweb/wizard/open_items_wizard.py
Expand Up @@ -67,6 +67,27 @@ def onchange_type_accounts_only(self):
else:
self.account_ids = None

@api.model
def create(self, vals):
"""
This is a workaround for bug https://github.com/odoo/odoo/issues/14761
This bug impacts M2M fields in wizards filled-up via onchange
It replaces the workaround widget="many2many_tags" on
field name="account_ids" which prevented from selecting several
accounts at the same time (quite useful when you want to select
an interval of accounts for example)
"""
if 'account_ids' in vals and isinstance(vals['account_ids'], list):
account_ids = []
for account in vals['account_ids']:
if account[0] in (1, 4):
account_ids.append(account[1])
elif account[0] == 6 and isinstance(account[2], list):
account_ids += account[2]
vals['account_ids'] = [(6, 0, account_ids)]
res = super(OpenItemsReportWizard, self).create(vals)
return res

@api.multi
def button_export_html(self):
self.ensure_one()
Expand Down
Expand Up @@ -28,7 +28,7 @@
<field name="receivable_accounts_only"/>
<field name="payable_accounts_only"/>
</group>
<field name="account_ids" widget="many2many_tags" nolabel="1" options="{'no_create': True}"/>
<field name="account_ids" nolabel="1" options="{'no_create': True}"/>
<footer>
<button name="button_export_html" string="View"
type="object" default_focus="1" class="oe_highlight"/>
Expand Down
21 changes: 21 additions & 0 deletions account_financial_report_qweb/wizard/trial_balance_wizard.py
Expand Up @@ -105,6 +105,27 @@ def onchange_type_accounts_only(self):
else:
self.account_ids = None

@api.model
def create(self, vals):
"""
This is a workaround for bug https://github.com/odoo/odoo/issues/14761
This bug impacts M2M fields in wizards filled-up via onchange
It replaces the workaround widget="many2many_tags" on
field name="account_ids" which prevented from selecting several
accounts at the same time (quite useful when you want to select
an interval of accounts for example)
"""
if 'account_ids' in vals and isinstance(vals['account_ids'], list):
account_ids = []
for account in vals['account_ids']:
if account[0] in (1, 4):
account_ids.append(account[1])
elif account[0] == 6 and isinstance(account[2], list):
account_ids += account[2]
vals['account_ids'] = [(6, 0, account_ids)]
res = super(TrialBalanceReportWizard, self).create(vals)
return res

@api.onchange('show_partner_details')
def onchange_show_partner_details(self):
"""Handle partners change."""
Expand Down
Expand Up @@ -35,7 +35,7 @@
<field name="receivable_accounts_only"/>
<field name="payable_accounts_only"/>
</group>
<field name="account_ids" widget="many2many_tags" nolabel="1" options="{'no_create': True}"/>
<field name="account_ids" nolabel="1" options="{'no_create': True}"/>
</div>
<div attrs="{'invisible': [('not_only_one_unaffected_earnings_account', '=', False)]}">
<field name="not_only_one_unaffected_earnings_account" invisible="1"/>
Expand Down

0 comments on commit faa829e

Please sign in to comment.