Add support for chart of account evolution
* Add replacement account * Add period on account and tax code issue7417 review45671002
This commit is contained in:
1 parent
3d09c0ea57
commit
317858703d
13 files changed
+446
-73
No files matched your search
@@ -1,3 +1,5 @@
|
||||
* Add replacement account
|
||||
* Add period on account and tax code
|
||||
* Add template override mechanism to tax rules and tax rule lines
|
||||
* Remove support for Python 2.7
|
||||
* Remove journal type
|
||||
|
||||
+87
-57
@@ -11,8 +11,7 @@ from sql.aggregate import Sum, Max
|
||||
from sql.conditionals import Coalesce, Case
|
||||
|
||||
from trytond.model import (
|
||||
ModelView, ModelSQL, DeactivableMixin, fields, Unique, sequence_ordered,
|
||||
tree)
|
||||
ModelView, ModelSQL, fields, Unique, sequence_ordered, tree)
|
||||
from trytond.wizard import Wizard, StateView, StateAction, StateTransition, \
|
||||
Button
|
||||
from trytond.report import Report
|
||||
@@ -21,6 +20,8 @@ from trytond.pyson import Eval, If, PYSONEncoder, Bool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
|
||||
from .common import PeriodMixin, ActivePeriodMixin
|
||||
|
||||
__all__ = ['TypeTemplate', 'Type', 'OpenType',
|
||||
'AccountTemplate', 'AccountTemplateTaxTemplate',
|
||||
'Account', 'AccountDeferral', 'AccountTax',
|
||||
@@ -326,7 +327,7 @@ class OpenType(Wizard):
|
||||
do_ledger_account = open_action
|
||||
|
||||
|
||||
class AccountTemplate(tree(), ModelSQL, ModelView):
|
||||
class AccountTemplate(PeriodMixin, tree(), ModelSQL, ModelView):
|
||||
'Account Template'
|
||||
__name__ = 'account.account.template'
|
||||
name = fields.Char('Name', size=None, required=True, select=True)
|
||||
@@ -376,6 +377,11 @@ class AccountTemplate(tree(), ModelSQL, ModelView):
|
||||
taxes = fields.Many2Many('account.account.template-account.tax.template',
|
||||
'account', 'tax', 'Default Taxes',
|
||||
domain=[('parent', '=', None)])
|
||||
replaced_by = fields.Many2One(
|
||||
'account.account.template', "Replaced By",
|
||||
states={
|
||||
'invisible': ~Eval('end_date'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
@@ -431,6 +437,10 @@ class AccountTemplate(tree(), ModelSQL, ModelView):
|
||||
res['code'] = self.code
|
||||
if not account or account.kind != self.kind:
|
||||
res['kind'] = self.kind
|
||||
if not account or account.start_date != self.start_date:
|
||||
res['start_date'] = self.start_date
|
||||
if not account or account.end_date != self.end_date:
|
||||
res['end_date'] = self.end_date
|
||||
if not account or account.reconcile != self.reconcile:
|
||||
res['reconcile'] = self.reconcile
|
||||
if not account or account.deferral != self.deferral:
|
||||
@@ -492,10 +502,10 @@ class AccountTemplate(tree(), ModelSQL, ModelView):
|
||||
create(childs)
|
||||
childs = sum((c.childs for c in childs), ())
|
||||
|
||||
def update_account_taxes(self, template2account, template2tax,
|
||||
def update_account2(self, template2account, template2tax,
|
||||
template_done=None):
|
||||
'''
|
||||
Update recursively account taxes based on template.
|
||||
Update recursively account taxes and replaced_by based on template.
|
||||
template2account is a dictionary with template id as key and account id
|
||||
as value, used to convert template id into account.
|
||||
template2tax is a dictionary with tax template id as key and tax id as
|
||||
@@ -516,15 +526,20 @@ class AccountTemplate(tree(), ModelSQL, ModelView):
|
||||
to_write = []
|
||||
for template in templates:
|
||||
if template.id not in template_done:
|
||||
account = Account(template2account[template.id])
|
||||
if template.taxes and not account.template_override:
|
||||
tax_ids = [template2tax[x.id] for x in template.taxes]
|
||||
to_write.append([account])
|
||||
to_write.append({
|
||||
'taxes': [
|
||||
('add', tax_ids)],
|
||||
})
|
||||
template_done.append(template.id)
|
||||
account = Account(template2account[template.id])
|
||||
if account.template_override:
|
||||
continue
|
||||
values = {}
|
||||
if template.taxes:
|
||||
tax_ids = [template2tax[x.id] for x in template.taxes]
|
||||
values['taxes'] = [('add', tax_ids)]
|
||||
if template.replaced_by:
|
||||
values['replaced_by'] = template2account[
|
||||
template.replaced_by.id]
|
||||
if values:
|
||||
to_write.append([account])
|
||||
to_write.append(values)
|
||||
if to_write:
|
||||
Account.write(*to_write)
|
||||
|
||||
@@ -544,7 +559,7 @@ class AccountTemplateTaxTemplate(ModelSQL):
|
||||
ondelete='RESTRICT', select=True, required=True)
|
||||
|
||||
|
||||
class Account(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
class Account(ActivePeriodMixin, tree(), ModelSQL, ModelView):
|
||||
'Account'
|
||||
__name__ = 'account.account'
|
||||
_states = {
|
||||
@@ -661,6 +676,14 @@ class Account(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
help=('Default tax for manual encoding of move lines \n'
|
||||
'for journal types: "expense" and "revenue"'),
|
||||
depends=['company'])
|
||||
replaced_by = fields.Many2One(
|
||||
'account.account', "Replaced By",
|
||||
domain=[('company', '=', Eval('company', -1))],
|
||||
states={
|
||||
'readonly': _states['readonly'],
|
||||
'invisible': ~Eval('end_date'),
|
||||
},
|
||||
depends=['company'])
|
||||
template = fields.Many2One('account.account.template', 'Template')
|
||||
template_override = fields.Boolean('Override Template',
|
||||
help="Check to override template definition",
|
||||
@@ -673,6 +696,11 @@ class Account(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Account, cls).__setup__()
|
||||
for date in [cls.start_date, cls.end_date]:
|
||||
date.states = {
|
||||
'readonly': (Bool(Eval('template', -1))
|
||||
& ~Eval('template_override', False)),
|
||||
}
|
||||
cls._error_messages.update({
|
||||
'delete_account_containing_move_lines': ('You can not delete '
|
||||
'account "%s" because it has move lines.'),
|
||||
@@ -708,10 +736,6 @@ class Account(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
def default_right():
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def default_active():
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company') or None
|
||||
@@ -774,7 +798,7 @@ class Account(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
).select(
|
||||
table_a.id,
|
||||
Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0)),
|
||||
where=red_sql & line_query & (table_c.active == True),
|
||||
where=red_sql & line_query,
|
||||
group_by=table_a.id))
|
||||
result = cursor.fetchall()
|
||||
balances.update(dict(result))
|
||||
@@ -978,25 +1002,6 @@ class Account(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
cls._rebuild_tree('parent', None, 0)
|
||||
return new_accounts
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
pool = Pool()
|
||||
MoveLine = pool.get('account.move.line')
|
||||
actions = iter(args)
|
||||
args = []
|
||||
for accounts, values in zip(actions, actions):
|
||||
if not values.get('active', True):
|
||||
childs = cls.search([
|
||||
('parent', 'child_of', [a.id for a in accounts]),
|
||||
])
|
||||
if MoveLine.search([
|
||||
('account', 'in', [a.id for a in childs]),
|
||||
]):
|
||||
values = values.copy()
|
||||
del values['active']
|
||||
args.extend((accounts, values))
|
||||
super(Account, cls).write(*args)
|
||||
|
||||
@classmethod
|
||||
def delete(cls, accounts):
|
||||
MoveLine = Pool().get('account.move.line')
|
||||
@@ -1048,9 +1053,9 @@ class Account(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
if values:
|
||||
self.write(*values)
|
||||
|
||||
def update_account_taxes(self, template2account, template2tax):
|
||||
def update_account2(self, template2account, template2tax):
|
||||
'''
|
||||
Update recursively account taxes base on template.
|
||||
Update recursively account taxes and replaced_by base on template.
|
||||
template2account is a dictionary with template id as key and account id
|
||||
as value, used to convert template id into account.
|
||||
template2tax is a dictionary with tax template id as key and tax id as
|
||||
@@ -1062,7 +1067,7 @@ class Account(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
if template2tax is None:
|
||||
template2tax = {}
|
||||
|
||||
values = []
|
||||
to_write = []
|
||||
childs = [self]
|
||||
while childs:
|
||||
for child in childs:
|
||||
@@ -1070,22 +1075,49 @@ class Account(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
continue
|
||||
if not child.template.taxes:
|
||||
continue
|
||||
values = {}
|
||||
tax_ids = [template2tax[x.id] for x in child.template.taxes
|
||||
if x.id in template2tax]
|
||||
old_tax_ids = [x.id for x in child.taxes]
|
||||
for tax_id in tax_ids:
|
||||
if tax_id not in old_tax_ids:
|
||||
values.append([child])
|
||||
values.append({
|
||||
'taxes': [
|
||||
('add', template2tax[x.id])
|
||||
for x in self.template.taxes
|
||||
if x.id in template2tax],
|
||||
})
|
||||
values['taxes'] = [
|
||||
('add', template2tax[x.id])
|
||||
for x in self.template.taxes
|
||||
if x.id in template2tax]
|
||||
break
|
||||
if child.template.replaced_by:
|
||||
replaced_by = template2account[
|
||||
child.template.replaced_by.id]
|
||||
else:
|
||||
replaced_by = None
|
||||
old_replaced_by = (
|
||||
child.replaced_by.id if child.replaced_by else None)
|
||||
if old_replaced_by != replaced_by:
|
||||
values['replaced_by'] = replaced_by
|
||||
if values:
|
||||
to_write.append([child])
|
||||
to_write.append(values)
|
||||
childs = sum((c.childs for c in childs), ())
|
||||
if values:
|
||||
self.write(*values)
|
||||
if to_write:
|
||||
self.write(*to_write)
|
||||
|
||||
def current(self, date=None):
|
||||
"Return the actual account for the date"
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
context = Transaction().context
|
||||
if date is None:
|
||||
date = context.get('date') or Date.today()
|
||||
if self.start_date and date < self.start_date:
|
||||
return None
|
||||
elif self.end_date and self.end_date < date:
|
||||
if self.replaced_by:
|
||||
return self.replaced_by.current(date=date)
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
return self
|
||||
|
||||
|
||||
class AccountDeferral(ModelSQL, ModelView):
|
||||
@@ -1221,7 +1253,7 @@ class OpenChartAccount(Wizard):
|
||||
return 'end'
|
||||
|
||||
|
||||
class GeneralLedgerAccount(DeactivableMixin, ModelSQL, ModelView):
|
||||
class GeneralLedgerAccount(ActivePeriodMixin, ModelSQL, ModelView):
|
||||
'General Ledger Account'
|
||||
__name__ = 'account.general_ledger.account'
|
||||
|
||||
@@ -1986,7 +2018,6 @@ class AgedBalance(ModelSQL, ModelView):
|
||||
condition=reconciliation.id == line.reconciliation
|
||||
).select(*columns,
|
||||
where=(line.party != Null)
|
||||
& (account.active == True)
|
||||
& account.kind.in_(kind)
|
||||
& ((line.reconciliation == Null)
|
||||
| (reconciliation.date > date))
|
||||
@@ -2188,9 +2219,8 @@ class CreateChart(Wizard):
|
||||
template2tax_code=template2tax_code,
|
||||
template2tax_code_line=template2tax_code_line)
|
||||
|
||||
# Update taxes on accounts
|
||||
account_template.update_account_taxes(template2account,
|
||||
template2tax)
|
||||
# Update taxes and replaced_by on accounts
|
||||
account_template.update_account2(template2account, template2tax)
|
||||
|
||||
# Create tax rules
|
||||
template2rule = {}
|
||||
@@ -2327,8 +2357,8 @@ class UpdateChart(Wizard):
|
||||
template2tax_code=template2tax_code,
|
||||
template2tax_code_line=template2tax_code_line)
|
||||
|
||||
# Update taxes on accounts
|
||||
account.update_account_taxes(template2account, template2tax)
|
||||
# Update taxes and replaced_by on accounts
|
||||
account.update_account2(template2account, template2tax)
|
||||
|
||||
# Update tax rules
|
||||
template2rule = {}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import datetime
|
||||
|
||||
from sql.conditionals import Coalesce
|
||||
|
||||
from trytond.model import Model, fields
|
||||
from trytond.pyson import Eval, If, Bool
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class PeriodMixin(Model):
|
||||
|
||||
start_date = fields.Date(
|
||||
"Start Date",
|
||||
domain=[
|
||||
If(Eval('start_date') & Eval('end_date'),
|
||||
('start_date', '<=', Eval('end_date')),
|
||||
()),
|
||||
],
|
||||
depends=['end_date'])
|
||||
end_date = fields.Date(
|
||||
"End Date",
|
||||
domain=[
|
||||
If(Eval('start_date') & Eval('end_date'),
|
||||
('end_date', '>=', Eval('start_date')),
|
||||
()),
|
||||
],
|
||||
depends=['start_date'])
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
if hasattr(cls, 'parent') and hasattr(cls, 'childs'):
|
||||
cls.parent.domain = [cls.parent.domain,
|
||||
['OR',
|
||||
If(Bool(Eval('start_date')),
|
||||
('start_date', '>=', Eval('start_date', None)),
|
||||
()),
|
||||
('start_date', '=', None),
|
||||
],
|
||||
['OR',
|
||||
If(Bool(Eval('end_date')),
|
||||
('end_date', '<=', Eval('end_date', None)),
|
||||
()),
|
||||
('end_date', '=', None),
|
||||
],
|
||||
]
|
||||
cls.parent.depends.extend(['start_date', 'end_date'])
|
||||
|
||||
cls.childs.domain = [cls.childs.domain,
|
||||
If(Bool(Eval('start_date')),
|
||||
('start_date', '>=', Eval('start_date', None)),
|
||||
()),
|
||||
If(Bool(Eval('end_date')),
|
||||
('end_date', '<=', Eval('end_date', None)),
|
||||
()),
|
||||
]
|
||||
cls.childs.depends.extend(['start_date', 'end_date'])
|
||||
|
||||
|
||||
class ActivePeriodMixin(PeriodMixin):
|
||||
|
||||
active = fields.Function(
|
||||
fields.Boolean("Active"), 'get_active', searcher='search_active')
|
||||
|
||||
@classmethod
|
||||
def _active_dates(cls):
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
FiscalYear = pool.get('account.fiscalyear')
|
||||
Period = pool.get('account.period')
|
||||
context = Transaction().context
|
||||
today = Date.today()
|
||||
|
||||
date = context.get('date')
|
||||
from_date, to_date = context.get('from_date'), context.get('to_date')
|
||||
period_ids = context.get('periods')
|
||||
fiscalyear_id = context.get('fiscalyear')
|
||||
if date:
|
||||
fiscalyears = FiscalYear.search([
|
||||
('start_date', '<=', date),
|
||||
('end_date', '>=', date),
|
||||
])
|
||||
elif from_date or to_date:
|
||||
domain = []
|
||||
if from_date:
|
||||
domain.append(('end_date', '>=', from_date))
|
||||
if to_date:
|
||||
domain.append(('start_date', '<=', to_date))
|
||||
fiscalyears = FiscalYear.search(domain)
|
||||
elif period_ids:
|
||||
periods = Period.browse(period_ids)
|
||||
fiscalyears = list(set(p.fiscalyear for p in periods))
|
||||
elif fiscalyear_id:
|
||||
fiscalyears = FiscalYear.browse([fiscalyear_id])
|
||||
else:
|
||||
fiscalyears = FiscalYear.search([
|
||||
('start_date', '<=', today),
|
||||
('end_date', '>=', today),
|
||||
], limit=1)
|
||||
if not fiscalyears:
|
||||
return (from_date or date or today, to_date or date or today)
|
||||
return (
|
||||
min(f.start_date for f in fiscalyears),
|
||||
max(f.end_date for f in fiscalyears))
|
||||
|
||||
def get_active(self, name):
|
||||
from_date, to_date = self._active_dates()
|
||||
start_date = self.start_date or datetime.date.min
|
||||
end_date = self.end_date or datetime.date.max
|
||||
return (start_date <= to_date <= end_date
|
||||
or start_date <= from_date <= end_date
|
||||
or (from_date <= start_date and end_date <= to_date))
|
||||
|
||||
@classmethod
|
||||
def search_active(cls, name, domain):
|
||||
table = cls.__table__()
|
||||
_, operator, value = domain
|
||||
|
||||
if operator in {'=', '!='}:
|
||||
if (operator == '=') == value:
|
||||
operator = 'in'
|
||||
else:
|
||||
operator = 'not in'
|
||||
elif operator in {'in', 'not in'}:
|
||||
if True in value and False not in value:
|
||||
operator = 'in'
|
||||
elif False in value and True not in value:
|
||||
operator = 'not in'
|
||||
else:
|
||||
return []
|
||||
else:
|
||||
return []
|
||||
|
||||
from_date, to_date = cls._active_dates()
|
||||
start_date = Coalesce(table.start_date, datetime.date.min)
|
||||
end_date = Coalesce(table.end_date, datetime.date.max)
|
||||
|
||||
query = table.select(table.id,
|
||||
where=((start_date <= to_date) & (end_date >= to_date))
|
||||
| ((start_date <= from_date) & (end_date >= from_date))
|
||||
| ((start_date >= from_date) & (end_date <= to_date)))
|
||||
return [('id', operator, query)]
|
||||
@@ -79,6 +79,8 @@ An Account is defined by these fields:
|
||||
- Other: For other accounts.
|
||||
|
||||
- Type: The Account Type of the account.
|
||||
- Start and End Date: The period for which the account can be used.
|
||||
- Replaced By: the account to use after end date.
|
||||
- Deferral: A checkbox. If set to true, credit and debit are carried
|
||||
over form fiscal year to fiscal year.
|
||||
- Second currency: Force all moves for the account to have this
|
||||
@@ -183,6 +185,7 @@ of the invoices. The Tax Code model contains the following fields:
|
||||
- Active: A checkbox that allow to disable the tax code.
|
||||
- Company: The company for which the tax code is defined.
|
||||
- Parent, Children: Parent and children tax codes.
|
||||
- Start and End date: The period for which the tax code is reported.
|
||||
- Amount: The sum of lines for the selected periods:
|
||||
|
||||
- Operator: `+` or `-`
|
||||
|
||||
@@ -566,8 +566,18 @@ class Line(ModelSQL, ModelView):
|
||||
depends=['currency_digits', 'debit', 'tax_lines', 'journal'] +
|
||||
_depends)
|
||||
account = fields.Many2One('account.account', 'Account', required=True,
|
||||
domain=[('kind', '!=', 'view')],
|
||||
select=True, states=_states, depends=_depends)
|
||||
domain=[
|
||||
('kind', '!=', 'view'),
|
||||
['OR',
|
||||
('start_date', '=', None),
|
||||
('start_date', '<=', Eval('date', None)),
|
||||
],
|
||||
['OR',
|
||||
('end_date', '=', None),
|
||||
('end_date', '>=', Eval('date', None)),
|
||||
],
|
||||
],
|
||||
select=True, states=_states, depends=_depends + ['date'])
|
||||
move = fields.Many2One('account.move', 'Move', select=True, required=True,
|
||||
ondelete='CASCADE',
|
||||
states={
|
||||
@@ -586,7 +596,7 @@ class Line(ModelSQL, ModelView):
|
||||
searcher='search_move_field')
|
||||
date = fields.Function(fields.Date('Effective Date', required=True,
|
||||
states=_states, depends=_depends),
|
||||
'get_move_field', setter='set_move_field',
|
||||
'on_change_with_date', setter='set_move_field',
|
||||
searcher='search_move_field')
|
||||
origin = fields.Function(fields.Reference('Origin',
|
||||
selection='get_origin'),
|
||||
@@ -693,8 +703,6 @@ class Line(ModelSQL, ModelView):
|
||||
'no journal defined.'),
|
||||
'move_view_account': ('You can not create a move line with '
|
||||
'account "%s" because it is a view account.'),
|
||||
'move_inactive_account': ('You can not create a move line '
|
||||
'with account "%s" because it is inactive.'),
|
||||
'already_reconciled': 'Line "%s" (%d) already reconciled.',
|
||||
'party_required': 'Party is required on line "%s"',
|
||||
'party_set': 'Party must not be set on line "%s"',
|
||||
@@ -846,6 +854,11 @@ class Line(ModelSQL, ModelView):
|
||||
return value.id
|
||||
return value
|
||||
|
||||
@fields.depends('move', '_parent_move.date')
|
||||
def on_change_with_date(self, name=None):
|
||||
if self.move:
|
||||
return self.move.date
|
||||
|
||||
@classmethod
|
||||
def set_move_field(cls, lines, name, value):
|
||||
if name.startswith('move_'):
|
||||
@@ -1000,9 +1013,6 @@ class Line(ModelSQL, ModelView):
|
||||
if self.account.kind in ('view',):
|
||||
self.raise_user_error('move_view_account', (
|
||||
self.account.rec_name,))
|
||||
if not self.account.active:
|
||||
self.raise_user_error('move_inactive_account', (
|
||||
self.account.rec_name,))
|
||||
if bool(self.party) != bool(self.account.party_required):
|
||||
error = 'party_set' if self.party else 'party_required'
|
||||
self.raise_user_error(error, self.rec_name)
|
||||
|
||||
@@ -151,8 +151,7 @@ class Party(CompanyMultiValueMixin, metaclass=PoolMeta):
|
||||
cursor.execute(*line.join(account,
|
||||
condition=account.id == line.account
|
||||
).select(line.party, amount,
|
||||
where=(account.active
|
||||
& (account.kind == code)
|
||||
where=((account.kind == code)
|
||||
& (line.reconciliation == Null)
|
||||
& (account.company == company_id)
|
||||
& party_where
|
||||
@@ -204,8 +203,7 @@ class Party(CompanyMultiValueMixin, metaclass=PoolMeta):
|
||||
value = cast_(Literal(Decimal(value or 0)))
|
||||
query = line.join(account, condition=account.id == line.account
|
||||
).select(line.party,
|
||||
where=account.active
|
||||
& (account.kind == code)
|
||||
where=(account.kind == code)
|
||||
& (line.party != Null)
|
||||
& (line.reconciliation == Null)
|
||||
& (account.company == company_id)
|
||||
@@ -227,7 +225,8 @@ class Party(CompanyMultiValueMixin, metaclass=PoolMeta):
|
||||
self.raise_user_error('missing_payable_account', {
|
||||
'name': self.rec_name,
|
||||
})
|
||||
return account
|
||||
if account:
|
||||
return account.current()
|
||||
|
||||
@property
|
||||
def account_receivable_used(self):
|
||||
@@ -242,7 +241,8 @@ class Party(CompanyMultiValueMixin, metaclass=PoolMeta):
|
||||
self.raise_user_error('missing_receivable_account', {
|
||||
'name': self.rec_name,
|
||||
})
|
||||
return account
|
||||
if account:
|
||||
return account.current()
|
||||
|
||||
|
||||
class PartyAccount(ModelSQL, CompanyValueMixin):
|
||||
|
||||
@@ -19,6 +19,8 @@ from trytond.transaction import Transaction
|
||||
from trytond.tools import cursor_dict
|
||||
from trytond.pool import Pool
|
||||
|
||||
from .common import PeriodMixin, ActivePeriodMixin
|
||||
|
||||
__all__ = ['TaxGroup', 'TaxCodeTemplate', 'TaxCode',
|
||||
'TaxCodeLineTemplate', 'TaxCodeLine',
|
||||
'OpenChartTaxCodeStart', 'OpenChartTaxCode',
|
||||
@@ -46,7 +48,7 @@ class TaxGroup(ModelSQL, ModelView):
|
||||
return 'both'
|
||||
|
||||
|
||||
class TaxCodeTemplate(tree(), ModelSQL, ModelView):
|
||||
class TaxCodeTemplate(PeriodMixin, tree(), ModelSQL, ModelView):
|
||||
'Tax Code Template'
|
||||
__name__ = 'account.tax.code.template'
|
||||
name = fields.Char('Name', required=True)
|
||||
@@ -73,6 +75,10 @@ class TaxCodeTemplate(tree(), ModelSQL, ModelView):
|
||||
res['name'] = self.name
|
||||
if not code or code.code != self.code:
|
||||
res['code'] = self.code
|
||||
if not code or code.start_date != self.start_date:
|
||||
res['start_date'] = self.start_date
|
||||
if not code or code.end_date != self.end_date:
|
||||
res['end_date'] = self.end_date
|
||||
if not code or code.description != self.description:
|
||||
res['description'] = self.description
|
||||
if not code or code.template.id != self.id:
|
||||
@@ -120,7 +126,7 @@ class TaxCodeTemplate(tree(), ModelSQL, ModelView):
|
||||
childs = sum((c.childs for c in childs), ())
|
||||
|
||||
|
||||
class TaxCode(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
class TaxCode(ActivePeriodMixin, tree(), ModelSQL, ModelView):
|
||||
'Tax Code'
|
||||
__name__ = 'account.tax.code'
|
||||
_states = {
|
||||
@@ -157,6 +163,11 @@ class TaxCode(DeactivableMixin, tree(), ModelSQL, ModelView):
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(TaxCode, cls).__setup__()
|
||||
for date in [cls.start_date, cls.end_date]:
|
||||
date.states = {
|
||||
'readonly': (Bool(Eval('template', -1))
|
||||
& ~Eval('template_override', False)),
|
||||
}
|
||||
cls._order.insert(0, ('code', 'ASC'))
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
=======================
|
||||
Account Active Scenario
|
||||
=======================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> from dateutil.relativedelta import relativedelta
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
>>> from trytond.modules.company.tests.tools import create_company, \
|
||||
... get_company
|
||||
>>> from trytond.modules.account.tests.tools import create_fiscalyear, \
|
||||
... create_chart, get_accounts
|
||||
|
||||
Install account::
|
||||
|
||||
>>> config = activate_modules('account')
|
||||
|
||||
Create company::
|
||||
|
||||
>>> _ = create_company()
|
||||
>>> company = get_company()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear(company)
|
||||
>>> fiscalyear.click('create_period')
|
||||
>>> period = fiscalyear.periods[1]
|
||||
|
||||
Create chart of accounts::
|
||||
|
||||
>>> Account = Model.get('account.account')
|
||||
>>> _ = create_chart(company)
|
||||
>>> accounts = get_accounts(company)
|
||||
>>> cash = accounts['cash']
|
||||
|
||||
Check active without start or end date::
|
||||
|
||||
>>> cash.active
|
||||
True
|
||||
>>> len(Account.find([('id', '=', cash.id)]))
|
||||
1
|
||||
|
||||
Check active with a start date::
|
||||
|
||||
>>> cash.start_date = period.start_date
|
||||
>>> cash.save()
|
||||
|
||||
>>> with config.set_context(date=period.start_date):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
>>> with config.set_context(date=period.end_date):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
>>> with config.set_context(date=fiscalyear.start_date):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
>>> with config.set_context(date=fiscalyear.start_date - relativedelta(days=1)):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
False
|
||||
0
|
||||
>>> with config.set_context(date=fiscalyear.end_date - relativedelta(days=1)):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
|
||||
Check active with an end date::
|
||||
|
||||
>>> cash.start_date = None
|
||||
>>> cash.end_date = period.end_date
|
||||
>>> cash.save()
|
||||
|
||||
>>> with config.set_context(date=period.start_date):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
>>> with config.set_context(date=period.end_date):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
>>> with config.set_context(date=fiscalyear.end_date):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
>>> with config.set_context(date=fiscalyear.start_date - relativedelta(days=1)):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
>>> with config.set_context(date=fiscalyear.end_date + relativedelta(days=1)):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
False
|
||||
0
|
||||
|
||||
Check active with start and end date::
|
||||
|
||||
>>> cash.start_date = period.start_date
|
||||
>>> cash.end_date = period.end_date
|
||||
>>> cash.save()
|
||||
|
||||
>>> with config.set_context(date=period.start_date):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
>>> with config.set_context(date=period.end_date):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
>>> with config.set_context(date=fiscalyear.start_date):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
>>> with config.set_context(date=fiscalyear.end_date):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
True
|
||||
1
|
||||
>>> with config.set_context(date=fiscalyear.start_date - relativedelta(days=1)):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
False
|
||||
0
|
||||
>>> with config.set_context(date=fiscalyear.end_date + relativedelta(days=1)):
|
||||
... Account(cash.id).active
|
||||
... len(Account.find([('id', '=', cash.id)]))
|
||||
False
|
||||
0
|
||||
@@ -1092,4 +1092,9 @@ def suite():
|
||||
tearDown=doctest_teardown, encoding='utf-8',
|
||||
checker=doctest_checker,
|
||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
|
||||
suite.addTests(doctest.DocFileSuite(
|
||||
'scenario_account_active.rst',
|
||||
tearDown=doctest_teardown, encoding='utf-8',
|
||||
checker=doctest_checker,
|
||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
|
||||
return suite
|
||||
@@ -22,6 +22,15 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="kind"/>
|
||||
<label name="type"/>
|
||||
<field name="type"/>
|
||||
<newline/>
|
||||
<label name="start_date"/>
|
||||
<group col="3" colspan="1" id="dates">
|
||||
<field name="start_date"/>
|
||||
<label name="end_date"/>
|
||||
<field name="end_date"/>
|
||||
</group>
|
||||
<label name="replaced_by"/>
|
||||
<field name="replaced_by"/>
|
||||
<label name="deferral"/>
|
||||
<field name="deferral"/>
|
||||
<label name="reconcile"/>
|
||||
|
||||
@@ -13,6 +13,12 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<label name="type"/>
|
||||
<field name="type"/>
|
||||
<newline/>
|
||||
<label name="start_date"/>
|
||||
<field name="start_date"/>
|
||||
<label name="end_date"/>
|
||||
<field name="end_date"/>
|
||||
<label name="replaced_by"/>
|
||||
<field name="replaced_by"/>
|
||||
<label name="deferral"/>
|
||||
<field name="deferral"/>
|
||||
<label name="reconcile"/>
|
||||
|
||||
@@ -16,6 +16,11 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="company"/>
|
||||
<label name="parent"/>
|
||||
<field name="parent"/>
|
||||
<newline/>
|
||||
<label name="start_date"/>
|
||||
<field name="start_date"/>
|
||||
<label name="end_date"/>
|
||||
<field name="end_date"/>
|
||||
<notebook colspan="6">
|
||||
<page name="lines">
|
||||
<field name="lines" colspan="4"/>
|
||||
|
||||
@@ -10,6 +10,10 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="account"/>
|
||||
<label name="parent"/>
|
||||
<field name="parent"/>
|
||||
<label name="start_date"/>
|
||||
<field name="start_date"/>
|
||||
<label name="end_date"/>
|
||||
<field name="end_date"/>
|
||||
<notebook colspan="4">
|
||||
<page name="lines">
|
||||
<field name="lines" colspan="4"/>
|
||||
|
||||
Reference in new issue
Block a user