Browse Source

Convert onchange to computed

pull/736/head
Andrea 5 years ago
committed by Francisco Ivan Anton Prieto
parent
commit
2f0e64754e
  1. 4
      account_tax_balance/tests/test_account_tax_balance.py
  2. 29
      account_tax_balance/wizard/open_tax_balances.py

4
account_tax_balance/tests/test_account_tax_balance.py

@ -95,8 +95,8 @@ class TestAccountTaxBalance(HttpCase):
wizard = self.env['wizard.open.tax.balances'].new({ wizard = self.env['wizard.open.tax.balances'].new({
'date_range_id': current_range[0].id, 'date_range_id': current_range[0].id,
}) })
wizard.onchange_date_range_id()
wizard._convert_to_write(wizard._cache)
self.assertEqual(wizard.from_date, current_range[0].date_start)
self.assertEqual(wizard.to_date, current_range[0].date_end)
action = wizard.open_taxes() action = wizard.open_taxes()
self.assertEqual( self.assertEqual(
action['context']['from_date'], current_range[0].date_start) action['context']['from_date'], current_range[0].date_start)

29
account_tax_balance/wizard/open_tax_balances.py

@ -9,23 +9,32 @@ class WizardOpenTaxBalances(models.TransientModel):
_description = 'Wizard Open Tax Balances' _description = 'Wizard Open Tax Balances'
company_id = fields.Many2one( company_id = fields.Many2one(
'res.company', 'Company', required=True,
'res.company', required=True,
default=lambda self: self.env.user.company_id) default=lambda self: self.env.user.company_id)
from_date = fields.Date('From date', required=True)
to_date = fields.Date('To date', required=True)
date_range_id = fields.Many2one('date.range', 'Date range')
from_date = fields.Date(
required=True,
store=True,
readonly=False,
compute='_compute_date_range')
to_date = fields.Date(
required=True,
store=True,
readonly=False,
compute='_compute_date_range')
date_range_id = fields.Many2one('date.range')
target_move = fields.Selection([ target_move = fields.Selection([
('posted', 'All Posted Entries'), ('posted', 'All Posted Entries'),
('all', 'All Entries'), ('all', 'All Entries'),
], 'Target Moves', required=True, default='posted') ], 'Target Moves', required=True, default='posted')
@api.onchange('date_range_id')
def onchange_date_range_id(self):
if self.date_range_id:
self.from_date = self.date_range_id.date_start
self.to_date = self.date_range_id.date_end
@api.depends('date_range_id')
def _compute_date_range(self):
for wizard in self:
if wizard.date_range_id:
wizard.from_date = wizard.date_range_id.date_start
wizard.to_date = wizard.date_range_id.date_end
else: else:
self.from_date = self.to_date = None
wizard.from_date = wizard.to_date = None
def open_taxes(self): def open_taxes(self):
self.ensure_one() self.ensure_one()

Loading…
Cancel
Save