Use fields.depends decorator
issue3487 review2301002
This commit is contained in:
1 parent
620008059f
commit
a73abc860f
3 files changed
+29
-25
No files matched your search
+7
-6
@@ -1032,7 +1032,7 @@ class PrintGeneralLedgerStart(ModelView):
|
||||
'Print General Ledger'
|
||||
__name__ = 'account.print_general_ledger.start'
|
||||
fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
|
||||
required=True, on_change=['fiscalyear'])
|
||||
required=True)
|
||||
start_period = fields.Many2One('account.period', 'Start Period',
|
||||
domain=[
|
||||
('fiscalyear', '=', Eval('fiscalyear')),
|
||||
@@ -1067,6 +1067,7 @@ class PrintGeneralLedgerStart(ModelView):
|
||||
def default_empty_account():
|
||||
return False
|
||||
|
||||
@fields.depends('fiscalyear')
|
||||
def on_change_fiscalyear(self):
|
||||
return {
|
||||
'start_period': None,
|
||||
@@ -1244,8 +1245,7 @@ class PrintTrialBalanceStart(ModelView):
|
||||
'Print Trial Balance'
|
||||
__name__ = 'account.print_trial_balance.start'
|
||||
fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
|
||||
required=True, on_change=['fiscalyear'],
|
||||
depends=['start_period', 'end_period'])
|
||||
required=True)
|
||||
start_period = fields.Many2One('account.period', 'Start Period',
|
||||
domain=[
|
||||
('fiscalyear', '=', Eval('fiscalyear')),
|
||||
@@ -1281,6 +1281,7 @@ class PrintTrialBalanceStart(ModelView):
|
||||
def default_empty_account():
|
||||
return False
|
||||
|
||||
@fields.depends('fiscalyear')
|
||||
def on_change_fiscalyear(self):
|
||||
return {
|
||||
'start_period': None,
|
||||
@@ -1488,8 +1489,7 @@ class OpenIncomeStatementStart(ModelView):
|
||||
'Open Income Statement'
|
||||
__name__ = 'account.open_income_statement.start'
|
||||
fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
|
||||
required=True, on_change=['fiscalyear'],
|
||||
depends=['start_period', 'end_period'])
|
||||
required=True)
|
||||
start_period = fields.Many2One('account.period', 'Start Period',
|
||||
domain=[
|
||||
('fiscalyear', '=', Eval('fiscalyear')),
|
||||
@@ -1519,11 +1519,12 @@ class OpenIncomeStatementStart(ModelView):
|
||||
def default_posted():
|
||||
return False
|
||||
|
||||
@fields.depends('fiscalyear')
|
||||
def on_change_fiscalyear(self):
|
||||
return {
|
||||
'start_period': None,
|
||||
'end_period': None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class OpenIncomeStatement(Wizard):
|
||||
|
||||
@@ -47,7 +47,7 @@ class Move(ModelSQL, ModelView):
|
||||
journal = fields.Many2One('account.journal', 'Journal', required=True,
|
||||
states=_MOVE_STATES, depends=_MOVE_DEPENDS)
|
||||
date = fields.Date('Effective Date', required=True, states=_MOVE_STATES,
|
||||
depends=_MOVE_DEPENDS, on_change_with=['period', 'journal', 'date'])
|
||||
depends=_MOVE_DEPENDS)
|
||||
post_date = fields.Date('Post Date', readonly=True)
|
||||
description = fields.Char('Description', states=_MOVE_STATES,
|
||||
depends=_MOVE_DEPENDS)
|
||||
@@ -139,6 +139,7 @@ class Move(ModelSQL, ModelView):
|
||||
return period.start_date
|
||||
return Date.today()
|
||||
|
||||
@fields.depends('period', 'journal', 'date')
|
||||
def on_change_with_date(self):
|
||||
Line = Pool().get('account.move.line')
|
||||
date = self.date
|
||||
@@ -494,19 +495,13 @@ class Line(ModelSQL, ModelView):
|
||||
__name__ = 'account.move.line'
|
||||
debit = fields.Numeric('Debit', digits=(16, Eval('currency_digits', 2)),
|
||||
required=True,
|
||||
on_change=['account', 'debit', 'credit', 'tax_lines', 'journal',
|
||||
'move'],
|
||||
depends=['currency_digits', 'credit', 'tax_lines', 'journal'])
|
||||
credit = fields.Numeric('Credit', digits=(16, Eval('currency_digits', 2)),
|
||||
required=True,
|
||||
on_change=['account', 'debit', 'credit', 'tax_lines', 'journal',
|
||||
'move'],
|
||||
depends=['currency_digits', 'debit', 'tax_lines', 'journal'])
|
||||
account = fields.Many2One('account.account', 'Account', required=True,
|
||||
domain=[('kind', '!=', 'view')],
|
||||
select=True,
|
||||
on_change=['account', 'debit', 'credit', 'tax_lines',
|
||||
'journal', 'move'])
|
||||
select=True)
|
||||
move = fields.Many2One('account.move', 'Move', select=True, required=True,
|
||||
states={
|
||||
'required': False,
|
||||
@@ -532,10 +527,7 @@ class Line(ModelSQL, ModelView):
|
||||
depends=['second_currency_digits'])
|
||||
second_currency = fields.Many2One('currency.currency', 'Second Currency',
|
||||
help='The second currency')
|
||||
party = fields.Many2One('party.party', 'Party',
|
||||
on_change=['move', 'party', 'account', 'debit', 'credit',
|
||||
'journal'], select=True, depends=['debit', 'credit', 'account',
|
||||
'journal'])
|
||||
party = fields.Many2One('party.party', 'Party', select=True)
|
||||
maturity_date = fields.Date('Maturity Date',
|
||||
help='This field is used for payable and receivable lines. \n'
|
||||
'You can put the limit date for the payment.')
|
||||
@@ -840,6 +832,8 @@ class Line(ModelSQL, ModelView):
|
||||
Move = Pool().get('account.move')
|
||||
return Move.get_origin()
|
||||
|
||||
@fields.depends('account', 'debit', 'credit', 'tax_lines', 'journal',
|
||||
'move')
|
||||
def on_change_debit(self):
|
||||
changes = {}
|
||||
Journal = Pool().get('account.journal')
|
||||
@@ -853,6 +847,8 @@ class Line(ModelSQL, ModelView):
|
||||
changes['credit'] = Decimal('0.0')
|
||||
return changes
|
||||
|
||||
@fields.depends('account', 'debit', 'credit', 'tax_lines', 'journal',
|
||||
'move')
|
||||
def on_change_credit(self):
|
||||
changes = {}
|
||||
Journal = Pool().get('account.journal')
|
||||
@@ -866,6 +862,8 @@ class Line(ModelSQL, ModelView):
|
||||
changes['debit'] = Decimal('0.0')
|
||||
return changes
|
||||
|
||||
@fields.depends('account', 'debit', 'credit', 'tax_lines', 'journal',
|
||||
'move')
|
||||
def on_change_account(self):
|
||||
Journal = Pool().get('account.journal')
|
||||
|
||||
@@ -936,6 +934,7 @@ class Line(ModelSQL, ModelView):
|
||||
res.setdefault('add', []).append(value)
|
||||
return res
|
||||
|
||||
@fields.depends('move', 'party', 'account', 'debit', 'credit', 'journal')
|
||||
def on_change_party(self):
|
||||
Journal = Pool().get('account.journal')
|
||||
cursor = Transaction().cursor
|
||||
|
||||
@@ -149,8 +149,8 @@ class TaxCode(ModelSQL, ModelView):
|
||||
domain=[('company', '=', Eval('company', 0))], depends=['company'])
|
||||
childs = fields.One2Many('account.tax.code', 'parent', 'Children',
|
||||
domain=[('company', '=', Eval('company', 0))], depends=['company'])
|
||||
currency_digits = fields.Function(fields.Integer('Currency Digits',
|
||||
on_change_with=['company']), 'on_change_with_currency_digits')
|
||||
currency_digits = fields.Function(fields.Integer('Currency Digits'),
|
||||
'on_change_with_currency_digits')
|
||||
sum = fields.Function(fields.Numeric('Sum',
|
||||
digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']),
|
||||
'get_sum')
|
||||
@@ -175,6 +175,7 @@ class TaxCode(ModelSQL, ModelView):
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
@fields.depends('company')
|
||||
def on_change_with_currency_digits(self, name=None):
|
||||
if self.company:
|
||||
return self.company.currency.digits
|
||||
@@ -570,8 +571,8 @@ class Tax(ModelSQL, ModelView):
|
||||
}, depends=['parent'])
|
||||
active = fields.Boolean('Active')
|
||||
sequence = fields.Integer('Sequence', help='Use to order the taxes')
|
||||
currency_digits = fields.Function(fields.Integer('Currency Digits',
|
||||
on_change_with=['company']), 'on_change_with_currency_digits')
|
||||
currency_digits = fields.Function(fields.Integer('Currency Digits'),
|
||||
'on_change_with_currency_digits')
|
||||
amount = fields.Numeric('Amount', digits=(16, Eval('currency_digits', 2)),
|
||||
states={
|
||||
'required': Eval('type') == 'fixed',
|
||||
@@ -725,6 +726,7 @@ class Tax(ModelSQL, ModelView):
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
@fields.depends('company')
|
||||
def on_change_with_currency_digits(self, name=None):
|
||||
if self.company:
|
||||
return self.company.currency.digits
|
||||
@@ -884,22 +886,24 @@ class TaxLine(ModelSQL, ModelView):
|
||||
'Tax Line'
|
||||
__name__ = 'account.tax.line'
|
||||
_rec_name = 'amount'
|
||||
currency_digits = fields.Function(fields.Integer('Currency Digits',
|
||||
on_change_with=['move_line']), 'on_change_with_currency_digits')
|
||||
currency_digits = fields.Function(fields.Integer('Currency Digits'),
|
||||
'on_change_with_currency_digits')
|
||||
amount = fields.Numeric('Amount', digits=(16, Eval('currency_digits', 2)),
|
||||
required=True, depends=['currency_digits'])
|
||||
code = fields.Many2One('account.tax.code', 'Code', select=True,
|
||||
required=True)
|
||||
tax = fields.Many2One('account.tax', 'Tax', select=True,
|
||||
ondelete='RESTRICT', on_change=['tax'])
|
||||
ondelete='RESTRICT')
|
||||
move_line = fields.Many2One('account.move.line', 'Move Line',
|
||||
required=True, select=True, ondelete='CASCADE')
|
||||
|
||||
@fields.depends('move_line')
|
||||
def on_change_with_currency_digits(self, name=None):
|
||||
if self.move_line:
|
||||
return self.move_line.currency_digits
|
||||
return 2
|
||||
|
||||
@fields.depends('tax')
|
||||
def on_change_tax(self):
|
||||
return {
|
||||
'code': None,
|
||||
|
||||
Reference in new issue
Block a user