changeset f7646c044c62 in modules/analytic_account:default
details:
https://hg.tryton.org/modules/analytic_account?cmd=changeset;node=f7646c044c62
description:
Merge account kind and account type
issue4990
review68401002
diffstat:
CHANGELOG | 1 +
account.py | 15 ++++-----------
line.py | 24 +++++++-----------------
tests/test_analytic_account.py | 12 ++++++------
view/account_form.xml | 3 +--
5 files changed, 19 insertions(+), 36 deletions(-)
diffs (167 lines):
diff -r b3e78cee74ed -r f7646c044c62 CHANGELOG
--- a/CHANGELOG Fri Mar 22 15:33:43 2019 +0100
+++ b/CHANGELOG Sun Mar 24 18:00:01 2019 +0100
@@ -1,3 +1,4 @@
+* Remove display balance
* Apply rules only on income statement lines
* Remove mandatory on analytic roots
* Remove positive constraint on debit/credit
diff -r b3e78cee74ed -r f7646c044c62 account.py
--- a/account.py Fri Mar 22 15:33:43 2019 +0100
+++ b/account.py Sun Mar 24 18:00:01 2019 +0100
@@ -86,10 +86,6 @@
('closed', 'Closed'),
], 'State', required=True)
note = fields.Text('Note')
- display_balance = fields.Selection([
- ('debit-credit', 'Debit - Credit'),
- ('credit-debit', 'Credit - Debit'),
- ], 'Display Balance', required=True)
distributions = fields.One2Many(
'analytic_account.account.distribution', 'parent',
"Distributions",
@@ -116,6 +112,9 @@
# Migration from 4.0: remove currency
table.not_null_action('currency', action='remove')
+ # Migration from 5.0: remove display_balance
+ table.drop_column('display_balance')
+
@staticmethod
def default_company():
return Transaction().context.get('company')
@@ -128,10 +127,6 @@
def default_state():
return 'draft'
- @staticmethod
- def default_display_balance():
- return 'credit-debit'
-
@classmethod
def validate(cls, accounts):
super(Account, cls).validate(accounts)
@@ -193,7 +188,7 @@
).join(move_line, 'LEFT',
condition=move_line.id == line.move_line
).select(table.id,
- Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0)),
+ Sum(Coalesce(line.credit, 0) - Coalesce(line.debit, 0)),
where=(table.type != 'view')
& table.id.in_(all_ids)
& (table.active == True) & line_query,
@@ -214,8 +209,6 @@
])
for child in childs:
balance += account_sum[child.id]
- if account.display_balance == 'credit-debit' and balance:
- balance *= -1
exp = Decimal(str(10.0 ** -account.currency_digits))
balances[account.id] = balance.quantize(exp)
return balances
diff -r b3e78cee74ed -r f7646c044c62 line.py
--- a/line.py Fri Mar 22 15:33:43 2019 +0100
+++ b/line.py Sun Mar 24 18:00:01 2019 +0100
@@ -211,30 +211,21 @@
'party': self.party.id if self.party else None,
}
- @classmethod
- def _analytic_types(cls):
- "Return account types for which analytic lines should be set"
- pool = Pool()
- AccountType = pool.get('account.account.type')
- income_types = AccountType.search([
- ('income_statement', '=', True),
- ])
- income_types = AccountType.search([
- ('parent', 'child_of', [t.id for t in income_types]),
- ])
- income_types = set(income_types)
- return income_types
+ @property
+ def must_have_analytic(self):
+ "If the line must have analytic lines set"
+ if self.account.type:
+ return self.account.type.statement == 'income'
@classmethod
def apply_rule(cls, lines):
pool = Pool()
Rule = pool.get('analytic_account.rule')
- analytic_types = cls._analytic_types()
rules = Rule.search([])
for line in lines:
- if line.account.type not in analytic_types:
+ if not line.must_have_analytic:
continue
if line.analytic_lines:
continue
@@ -255,14 +246,13 @@
pool = Pool()
AnalyticAccount = pool.get('analytic_account.account')
- analytic_types = cls._analytic_types()
roots = AnalyticAccount.search([
('parent', '=', None),
])
roots = set(roots)
for line in lines:
- if line.account.type not in analytic_types:
+ if not line.must_have_analytic:
if not line.analytic_lines:
line.analytic_state = 'valid'
else:
diff -r b3e78cee74ed -r f7646c044c62 tests/test_analytic_account.py
--- a/tests/test_analytic_account.py Fri Mar 22 15:33:43 2019 +0100
+++ b/tests/test_analytic_account.py Sun Mar 24 18:00:01 2019 +0100
@@ -56,16 +56,16 @@
('code', '=', 'EXP'),
])
revenue, = Account.search([
- ('kind', '=', 'revenue'),
+ ('type.revenue', '=', True),
])
receivable, = Account.search([
- ('kind', '=', 'receivable'),
+ ('type.receivable', '=', True),
])
expense, = Account.search([
- ('kind', '=', 'expense'),
+ ('type.expense', '=', True),
])
payable, = Account.search([
- ('kind', '=', 'payable'),
+ ('type.payable', '=', True),
])
first_account_line = {
@@ -175,10 +175,10 @@
('code', '=', 'EXP'),
])
expense, = Account.search([
- ('kind', '=', 'expense'),
+ ('type.expense', '=', True),
])
payable, = Account.search([
- ('kind', '=', 'payable'),
+ ('type.payable', '=', True),
])
move = Move()
diff -r b3e78cee74ed -r f7646c044c62 view/account_form.xml
--- a/view/account_form.xml Fri Mar 22 15:33:43 2019 +0100
+++ b/view/account_form.xml Sun Mar 24 18:00:01 2019 +0100
@@ -12,8 +12,7 @@
<page string="General Information" id="general">
<label name="type"/>
<field name="type"/>
- <label name="display_balance"/>
- <field name="display_balance"/>
+ <newline/>
<label name="root"/>
<field name="root"/>
<label name="parent"/>