changeset c08395de57a4 in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset;node=c08395de57a4
description:
Add optional debit type on account
The balance of the account is added to the debit type instead of the
regular
type if the debit is greater than the credit.
issue6601
review262771002
diffstat:
CHANGELOG | 1 +
account.py | 48 ++++++++++++++++++++++++++-
account.xml | 4 +-
doc/index.rst | 1 +
tests/test_account.py | 72 ++++++++++++++++++++++++++++++++++++++++++
view/account_form.xml | 6 ++-
view/account_list.xml | 1 +
view/account_template_form.xml | 6 ++-
view/account_template_list.xml | 1 +
view/account_template_tree.xml | 1 +
view/account_tree.xml | 1 +
11 files changed, 135 insertions(+), 7 deletions(-)
diffs (315 lines):
diff -r e56dd6e18a73 -r c08395de57a4 CHANGELOG
--- a/CHANGELOG Thu Mar 19 18:55:49 2020 +0100
+++ b/CHANGELOG Sat Mar 28 14:17:49 2020 +0100
@@ -1,3 +1,4 @@
+* Add optional debit type on account
* Show the move resulting from the GroupLines wizard
* Allow periods to end on any day of the month
* Use a wizard to select parameters when creating periods
diff -r e56dd6e18a73 -r c08395de57a4 account.py
--- a/account.py Thu Mar 19 18:55:49 2020 +0100
+++ b/account.py Sat Mar 28 14:17:49 2020 +0100
@@ -295,8 +295,18 @@
accounts = Account.search([
('type', 'in', [t.id for t in childs]),
])
+ debit_accounts = Account.search([
+ ('type', '!=', None),
+ ('debit_type', 'in', [t.id for t in childs]),
+ ])
for account in accounts:
- type_sum[account.type.id] += (account.credit - account.debit)
+ balance = account.credit - account.debit
+ if not account.debit_type or balance > 0:
+ type_sum[account.type.id] += balance
+ for account in debit_accounts:
+ balance = account.credit - account.debit
+ if balance < 0:
+ type_sum[account.debit_type.id] += balance
for type_ in types:
childs = cls.search([
@@ -531,6 +541,8 @@
__name__ = 'account.account.template'
type = fields.Many2One(
'account.account.type.template', "Type", ondelete="RESTRICT")
+ debit_type = fields.Many2One(
+ 'account.account.type.template', "Debit Type", ondelete="RESTRICT")
parent = fields.Many2One('account.account.template', 'Parent', select=True,
ondelete="RESTRICT")
childs = fields.One2Many('account.account.template', 'parent', 'Children')
@@ -620,6 +632,11 @@
vals['type'] = template2type.get(template.type.id)
else:
vals['type'] = None
+ if template.debit_type:
+ vals['debit_type'] = template2type.get(
+ template.debit_type.id)
+ else:
+ vals['debit_type'] = None
values.append(vals)
created.append(template)
@@ -724,6 +741,17 @@
('company', '=', Eval('company')),
],
depends=['company'])
+ debit_type = fields.Many2One(
+ 'account.account.type', "Debit Type", ondelete='RESTRICT',
+ states={
+ 'readonly': _states['readonly'],
+ 'invisible': ~Eval('type'),
+ },
+ domain=[
+ ('company', '=', Eval('company')),
+ ],
+ depends=['company', 'type'],
+ help="The type used if not empty and debit > credit.")
parent = fields.Many2One(
'account.account', 'Parent', select=True,
left="left", right="right", ondelete="RESTRICT", states=_states)
@@ -993,7 +1021,7 @@
return values
__on_change_parent_fields = ['name', 'code', 'company', 'type',
- 'reconcile', 'deferral', 'party_required',
+ 'debit_type', 'reconcile', 'deferral', 'party_required',
'general_ledger_balance', 'taxes']
@fields.depends('parent', *(__on_change_parent_fields
@@ -1109,6 +1137,15 @@
template_type = None
if current_type != template_type:
vals['type'] = template_type
+ current_debit_type = (
+ child.debit_type.id if child.debit_type else None)
+ if child.template.debit_type:
+ template_debit_type = template2type.get(
+ child.template.debit_type.id)
+ else:
+ template_debit_type = None
+ if current_debit_type != template_debit_type:
+ vals['debit_type'] = template_debit_type
if vals:
values.append([child])
values.append(vals)
@@ -1323,6 +1360,7 @@
code = fields.Char('Code')
company = fields.Many2One('company.company', 'Company')
type = fields.Many2One('account.account.type', 'Type')
+ debit_type = fields.Many2One('account.account.type', 'Debit Type')
start_debit = fields.Function(fields.Numeric('Start Debit',
digits=(16, Eval('currency_digits', 2)),
depends=['currency_digits']),
@@ -2049,12 +2087,14 @@
reconciliation = Reconciliation.__table__()
account = Account.__table__()
type_ = Type.__table__()
+ debit_type = Type.__table__()
company_id = context.get('company')
date = context.get('date')
with Transaction().set_context(date=None):
line_query, _ = MoveLine.query_get(line)
kind = cls.get_kind(type_)
+ debit_kind = cls.get_kind(debit_type)
columns = [
line.party.as_('id'),
Literal(0).as_('create_uid'),
@@ -2090,11 +2130,13 @@
return line.join(move, condition=line.move == move.id
).join(account, condition=line.account == account.id
).join(type_, condition=account.type == type_.id
+ ).join(debit_type, 'LEFT',
+ condition=account.debit_type == debit_type.id
).join(reconciliation, 'LEFT',
condition=reconciliation.id == line.reconciliation
).select(*columns,
where=(line.party != Null)
- & kind
+ & (kind | debit_kind)
& ((line.reconciliation == Null)
| (reconciliation.date > date))
& (move.date <= date)
diff -r e56dd6e18a73 -r c08395de57a4 account.xml
--- a/account.xml Thu Mar 19 18:55:49 2020 +0100
+++ b/account.xml Sat Mar 28 14:17:49 2020 +0100
@@ -364,7 +364,7 @@
eval="[('company', '=', Eval('company', -1))]"
pyson="1"/>
<field name="domain"
- eval="[('type', 'child_of', Eval('active_id'), 'parent'),
('type', '!=', None)]"
+ eval="[['OR', ('type', 'child_of', Eval('active_id'),
'parent'), ('debit_type', 'child_of', Eval('active_id'), 'parent')], ('type',
'!=', None)]"
pyson="1"/>
</record>
<record model="ir.action.act_window.view" id="act_account_list2_view1">
@@ -499,7 +499,7 @@
pyson="1"/>
<field
name="domain"
- eval="[('type', 'child_of', Eval('active_id'), 'parent')]"
+ eval="['OR', ('type', 'child_of', Eval('active_id'),
'parent'), ('debit_type', 'child_of', Eval('active_id'), 'parent')]"
pyson="1"/>
</record>
<record model="ir.action.act_window.view"
id="act_account_general_ledger_view1">
diff -r e56dd6e18a73 -r c08395de57a4 doc/index.rst
--- a/doc/index.rst Thu Mar 19 18:55:49 2020 +0100
+++ b/doc/index.rst Sat Mar 28 14:17:49 2020 +0100
@@ -73,6 +73,7 @@
- Parent Account
- Currency
- Type: The Account Type of the account.
+- Debit Type: The Account Type of the account when debit > credit.
- Start and End Date: The period for which the account can be used.
- Replaced By: the account to use after end date.
- Second currency: Force all moves for the account to have this
diff -r e56dd6e18a73 -r c08395de57a4 tests/test_account.py
--- a/tests/test_account.py Thu Mar 19 18:55:49 2020 +0100
+++ b/tests/test_account.py Sat Mar 28 14:17:49 2020 +0100
@@ -455,6 +455,78 @@
cash_cur.amount_second_currency, Decimal(50))
@with_transaction()
+ def test_account_type_amount(self):
+ "Test account type amount"
+ pool = Pool()
+ Party = pool.get('party.party')
+ FiscalYear = pool.get('account.fiscalyear')
+ Journal = pool.get('account.journal')
+ Account = pool.get('account.account')
+ Move = pool.get('account.move')
+ Type = pool.get('account.account.type')
+
+ party = Party(name='Party')
+ party.save()
+
+ company = create_company()
+ with set_company(company):
+ fiscalyear = get_fiscalyear(company)
+ fiscalyear.save()
+ FiscalYear.create_period([fiscalyear])
+ period = fiscalyear.periods[0]
+ create_chart(company)
+
+ journal_revenue, = Journal.search([
+ ('code', '=', 'REV'),
+ ])
+ revenue, = Account.search([
+ ('type.revenue', '=', True),
+ ])
+ receivable, = Account.search([
+ ('type.receivable', '=', True),
+ ])
+
+ Move.create([{
+ 'period': period.id,
+ 'journal': journal_revenue.id,
+ 'date': period.start_date,
+ 'lines': [
+ ('create', [{
+ 'account': revenue.id,
+ 'credit': Decimal(100),
+ }, {
+ 'account': receivable.id,
+ 'debit': Decimal(100),
+ 'party': party.id,
+ }]),
+ ],
+ }])
+
+ with Transaction().set_context(fiscalyear=fiscalyear.id):
+ revenue_type = Type(revenue.type)
+ receivable_type = Type(receivable.type)
+
+ # Test type amount
+ self.assertEqual(revenue_type.amount, Decimal(100))
+ self.assertEqual(receivable_type.amount, Decimal(100))
+
+ # Set a debit type on receivable
+ with Transaction().set_context(fiscalyear=fiscalyear.id):
+ debit_receivable_type, = Type.copy([receivable_type])
+ receivable.debit_type = debit_receivable_type
+ receivable.save()
+ self.assertEqual(receivable_type.amount, Decimal(0))
+ self.assertEqual(debit_receivable_type.amount, Decimal(100))
+
+ # Set a debit type on revenue
+ with Transaction().set_context(fiscalyear=fiscalyear.id):
+ debit_revenue_type, = Type.copy([revenue_type])
+ revenue.debit_type = debit_revenue_type
+ revenue.save()
+ self.assertEqual(revenue_type.amount, Decimal(100))
+ self.assertEqual(debit_revenue_type.amount, Decimal(0))
+
+ @with_transaction()
def test_move_post(self):
"Test posting move"
pool = Pool()
diff -r e56dd6e18a73 -r c08395de57a4 view/account_form.xml
--- a/view/account_form.xml Thu Mar 19 18:55:49 2020 +0100
+++ b/view/account_form.xml Sat Mar 28 14:17:49 2020 +0100
@@ -21,7 +21,11 @@
<newline/>
<label name="type"/>
- <field name="type"/>
+ <group id="types" col="-1">
+ <field name="type"/>
+ <label name="debit_type"/>
+ <field name="debit_type"/>
+ </group>
<label name="closed"/>
<field name="closed"/>
<label name="general_ledger_balance"/>
diff -r e56dd6e18a73 -r c08395de57a4 view/account_list.xml
--- a/view/account_list.xml Thu Mar 19 18:55:49 2020 +0100
+++ b/view/account_list.xml Sat Mar 28 14:17:49 2020 +0100
@@ -5,4 +5,5 @@
<field name="rec_name" expand="2"/>
<field name="company" expand="1"/>
<field name="type" expand="1"/>
+ <field name="debit_type" expand="1"/>
</tree>
diff -r e56dd6e18a73 -r c08395de57a4 view/account_template_form.xml
--- a/view/account_template_form.xml Thu Mar 19 18:55:49 2020 +0100
+++ b/view/account_template_form.xml Sat Mar 28 14:17:49 2020 +0100
@@ -10,7 +10,11 @@
<field name="parent"/>
<label name="type"/>
- <field name="type"/>
+ <group id="types" col="-1">
+ <field name="type"/>
+ <label name="debit_type"/>
+ <field name="debit_type"/>
+ </group>
<label name="closed"/>
<field name="closed"/>
<label name="general_ledger_balance"/>
diff -r e56dd6e18a73 -r c08395de57a4 view/account_template_list.xml
--- a/view/account_template_list.xml Thu Mar 19 18:55:49 2020 +0100
+++ b/view/account_template_list.xml Sat Mar 28 14:17:49 2020 +0100
@@ -4,4 +4,5 @@
<tree>
<field name="rec_name" expand="2"/>
<field name="type" expand="1"/>
+ <field name="debit_type" expand="1"/>
</tree>
diff -r e56dd6e18a73 -r c08395de57a4 view/account_template_tree.xml
--- a/view/account_template_tree.xml Thu Mar 19 18:55:49 2020 +0100
+++ b/view/account_template_tree.xml Sat Mar 28 14:17:49 2020 +0100
@@ -4,4 +4,5 @@
<tree>
<field name="rec_name" expand="2"/>
<field name="type" expand="1"/>
+ <field name="debit_type" expand="1"/>
</tree>
diff -r e56dd6e18a73 -r c08395de57a4 view/account_tree.xml
--- a/view/account_tree.xml Thu Mar 19 18:55:49 2020 +0100
+++ b/view/account_tree.xml Sat Mar 28 14:17:49 2020 +0100
@@ -5,4 +5,5 @@
<field name="rec_name" expand="2"/>
<field name="company" expand="1"/>
<field name="type" expand="1"/>
+ <field name="debit_type" expand="1"/>
</tree>