Display general ledger information on account form

issue11807
review443791004
This commit is contained in:
Cédric Krier
2022-11-08 00:38:33 +01:00
parent 636434d18b
commit 717486389b
6 changed files with 103 additions and 15 deletions
+2
View File
@@ -1,3 +1,5 @@
* Display general ledger information on account form
Version 6.6.0 - 2022-10-31
--------------------------
* Bug fixes (see mercurial logs for details)
+65 -12
View File
@@ -19,7 +19,7 @@ from trytond.model import (
from trytond.model.exceptions import AccessError
from trytond.modules.currency.fields import Monetary
from trytond.pool import Pool
from trytond.pyson import Bool, Eval, If, PYSONEncoder
from trytond.pyson import Bool, Eval, Id, If, PYSONEncoder
from trytond.report import Report
from trytond.tools import (
grouped_slice, is_full_text, lstrip_wildcard, reduce_ids)
@@ -1414,6 +1414,20 @@ class Account(
else:
return self
@classmethod
def view_attributes(cls):
return super().view_attributes() + [
('//page[@id="general_ledger"]', 'states', {
'invisible': ((Eval('id', -1) < 0)
| ~Id('account', 'group_account').in_(
Eval('context', {}).get('groups', []))),
}),
('//link[@name="account.act_general_ledger_account_party_form"]',
'states', {
'invisible': ~Eval('party_required', False),
}),
]
class AccountParty(ActivePeriodMixin, ModelSQL):
"Account Party"
@@ -1861,7 +1875,10 @@ class _GeneralLedgerAccount(ActivePeriodMixin, ModelSQL, ModelView):
@classmethod
def table_query(cls):
context = Transaction().context
pool = Pool()
LedgerAccountContext = pool.get(
'account.general_ledger.account.context')
context = LedgerAccountContext.get_context()
Account = cls._get_account()
account = Account.__table__()
columns = []
@@ -1882,7 +1899,9 @@ class _GeneralLedgerAccount(ActivePeriodMixin, ModelSQL, ModelView):
def get_period_ids(cls, name):
pool = Pool()
Period = pool.get('account.period')
context = Transaction().context
LedgerAccountContext = pool.get(
'account.general_ledger.account.context')
context = LedgerAccountContext.get_context()
period = None
if name.startswith('start_'):
@@ -1925,7 +1944,10 @@ class _GeneralLedgerAccount(ActivePeriodMixin, ModelSQL, ModelView):
@classmethod
def get_dates(cls, name):
context = Transaction().context
pool = Pool()
LedgerAccountContext = pool.get(
'account.general_ledger.account.context')
context = LedgerAccountContext.get_context()
if name.startswith('start_'):
from_date = context.get('from_date')
if from_date:
@@ -1937,10 +1959,13 @@ class _GeneralLedgerAccount(ActivePeriodMixin, ModelSQL, ModelView):
@classmethod
def get_account(cls, records, name):
pool = Pool()
LedgerAccountContext = pool.get(
'account.general_ledger.account.context')
Account = cls._get_account()
period_ids, from_date, to_date = None, None, None
context = Transaction().context
context = LedgerAccountContext.get_context()
if context.get('start_period') or context.get('end_period'):
period_ids = cls.get_period_ids(name)
elif context.get('from_date') or context.get('end_date'):
@@ -1991,8 +2016,11 @@ class _GeneralLedgerAccount(ActivePeriodMixin, ModelSQL, ModelView):
@classmethod
def _debit_credit_context(cls):
pool = Pool()
LedgerAccountContext = pool.get(
'account.general_ledger.account.context')
period_ids, from_date, to_date = None, None, None
context = Transaction().context
context = LedgerAccountContext.get_context()
if context.get('start_period') or context.get('end_period'):
start_period_ids = set(cls.get_period_ids('start_balance'))
end_period_ids = set(cls.get_period_ids('end_balance'))
@@ -2124,10 +2152,15 @@ class GeneralLedgerAccountContext(ModelView):
def default_fiscalyear(cls):
pool = Pool()
FiscalYear = pool.get('account.fiscalyear')
Period = pool.get('account.period')
context = Transaction().context
return context.get(
'fiscalyear',
FiscalYear.find(context.get('company'), exception=False))
if context.get('fiscalyear', -1) >= 0:
return context['fiscalyear']
elif context.get('period', -1) >= 0:
period = Period(context['period'])
return period.fiscalyear.id
else:
return FiscalYear.find(context.get('company'), exception=False)
@classmethod
def default_start_period(cls):
@@ -2192,6 +2225,14 @@ class GeneralLedgerAccountContext(ModelView):
if self.to_date:
self.start_period = self.end_period = None
@classmethod
def get_context(cls, fields_names=None):
fields_names = fields_names.copy() if fields_names is not None else []
fields_names += [
'fiscalyear', 'start_period', 'end_period', 'from_date', 'to_date',
'company', 'posted', 'journal']
return cls.default_get(fields_names, with_rec_name=False)
class GeneralLedgerAccountParty(_GeneralLedgerAccount):
"General Ledger Account Party"
@@ -2304,10 +2345,12 @@ class GeneralLedgerLine(ModelSQL, ModelView):
Line = pool.get('account.move.line')
Move = pool.get('account.move')
LedgerAccount = pool.get('account.general_ledger.account')
LedgerLineContext = pool.get(
'account.general_ledger.line.context')
Account = pool.get('account.account')
transaction = Transaction()
database = transaction.database
context = transaction.context
context = LedgerLineContext.get_context()
line = Line.__table__()
move = Move.__table__()
account = Account.__table__()
@@ -2338,7 +2381,8 @@ class GeneralLedgerLine(ModelSQL, ModelView):
else:
column = Column(line, fname).as_(fname)
columns.append(column)
with Transaction().set_context(LedgerAccount._debit_credit_context()):
with Transaction().set_context(
context, **LedgerAccount._debit_credit_context()):
line_query, fiscalyear_ids = Line.query_get(line)
return line.join(move, condition=line.move == move.id
).join(account, condition=line.account == account.id
@@ -2353,8 +2397,11 @@ class GeneralLedgerLine(ModelSQL, ModelView):
return Line.get_origin()
def get_balance(self, name):
pool = Pool()
LedgerLineContext = pool.get(
'account.general_ledger.line.context')
transaction = Transaction()
context = transaction.context
context = LedgerLineContext.get_context()
database = transaction.database
balance = self.internal_balance
if database.has_window_functions():
@@ -2411,6 +2458,12 @@ class GeneralLedgerLineContext(GeneralLedgerAccountContext):
def default_party_cumulate(cls):
return False
@classmethod
def get_context(cls, fields_names=None):
fields_names = fields_names.copy() if fields_names is not None else []
fields_names.append('party_cumulate')
return super().get_context(fields_names=fields_names)
class GeneralLedger(Report):
__name__ = 'account.general_ledger'
+10 -1
View File
@@ -692,6 +692,11 @@ this repository contains the full copyright notices and license terms. -->
<field name="model">account.general_ledger.account,-1</field>
<field name="action" ref="act_general_ledger_account_party_form"/>
</record>
<record model="ir.action.keyword" id="act_general_ledger_account_party_form_keyword_account">
<field name="keyword">form_relate</field>
<field name="model">account.account,-1</field>
<field name="action" ref="act_general_ledger_account_party_form"/>
</record>
<record model="ir.action.wizard" id="act_general_ledger_account_party_open">
<field name="name">Open General Ledger Account Parties</field>
@@ -773,7 +778,11 @@ this repository contains the full copyright notices and license terms. -->
<field name="model">account.general_ledger.account,-1</field>
<field name="action" ref="act_general_ledger_line_form"/>
</record>
<!-- TODO relate from account -->
<record model="ir.action.keyword" id="act_general_ledger_line_form_keyword_account">
<field name="keyword">form_relate</field>
<field name="model">account.account,-1</field>
<field name="action" ref="act_general_ledger_line_form"/>
</record>
<record model="ir.rule.group" id="rule_group_general_ledger_line_companies">
<field name="name">User in companies</field>
+2 -1
View File
@@ -768,8 +768,9 @@ class Line(MoveLineMixin, ModelSQL, ModelView):
],
context={
'company': Eval('company', -1),
'period': Eval('period', -1),
},
states=_states, depends={'company'})
states=_states, depends={'company', 'period'})
move = fields.Many2One(
'account.move', "Move", required=True,
ondelete='CASCADE',
+10 -1
View File
@@ -211,6 +211,10 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.action.act_window" id="act_move_line_form">
<field name="name">Account Move Lines</field>
<field name="res_model">account.move.line</field>
<field
name="domain"
eval="[('account', 'in', Eval('active_ids', [])), ('state', '=', 'valid')]"
pyson="1"/>
</record>
<record model="ir.action.act_window.view" id="act_move_line_form_view1">
<field name="sequence" eval="10"/>
@@ -227,11 +231,16 @@ this repository contains the full copyright notices and license terms. -->
<field name="wiz_name">account.move.open_account</field>
<field name="model">account.account</field>
</record>
<record model="ir.action.keyword" id="act_open_account_keyword">
<record model="ir.action.keyword" id="act_open_account_keyword1">
<field name="keyword">tree_open</field>
<field name="model">account.account,-1</field>
<field name="action" ref="act_open_account"/>
</record>
<record model="ir.action.keyword" id="act_open_account_keyword2">
<field name="keyword">form_relate</field>
<field name="model">account.account,-1</field>
<field name="action" ref="act_open_account"/>
</record>
<record model="ir.action.act_window"
id="act_move_line_payable_receivable">
+14
View File
@@ -13,6 +13,20 @@ this repository contains the full copyright notices and license terms. -->
<field name="template_override" xexpand="0" width="100"/>
</group>
<notebook colspan="6">
<page string="General Ledger" id="general_ledger" col="6">
<label name="debit"/>
<field name="debit"/>
<label name="credit"/>
<field name="credit"/>
<label name="balance"/>
<field name="balance"/>
<group id="general_ledger_links" col="-1" colspan="6">
<link icon="tryton-list" name="account.act_general_ledger_line_form"/>
<link icon="tryton-list" name="account.act_general_ledger_account_party_form"/>
<link icon="tryton-list" name="account.act_move_line_form"/>
</group>
</page>
<page string="General Information" id="general" col="6">
<label name="company"/>
<field name="company"/>