changeset 590824f11803 in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=590824f11803
description:
        Display general ledger information on account form

        issue11807
        review443791004
diffstat:

 CHANGELOG             |   2 +
 account.py            |  77 +++++++++++++++++++++++++++++++++++++++++++-------
 account.xml           |  11 ++++++-
 move.py               |   3 +-
 move.xml              |  11 ++++++-
 view/account_form.xml |  14 +++++++++
 6 files changed, 103 insertions(+), 15 deletions(-)

diffs (287 lines):

diff -r ca3cf980df97 -r 590824f11803 CHANGELOG
--- a/CHANGELOG Mon Oct 31 16:49:54 2022 +0100
+++ b/CHANGELOG Tue Nov 08 00:38:33 2022 +0100
@@ -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)
diff -r ca3cf980df97 -r 590824f11803 account.py
--- a/account.py        Mon Oct 31 16:49:54 2022 +0100
+++ b/account.py        Tue Nov 08 00:38:33 2022 +0100
@@ -19,7 +19,7 @@
 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 @@
         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 @@
 
     @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 @@
     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 @@
 
     @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 @@
 
     @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 @@
 
     @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 @@
     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 @@
         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 @@
         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 @@
             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 @@
         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 @@
     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'
diff -r ca3cf980df97 -r 590824f11803 account.xml
--- a/account.xml       Mon Oct 31 16:49:54 2022 +0100
+++ b/account.xml       Tue Nov 08 00:38:33 2022 +0100
@@ -692,6 +692,11 @@
             <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 @@
             <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>
diff -r ca3cf980df97 -r 590824f11803 move.py
--- a/move.py   Mon Oct 31 16:49:54 2022 +0100
+++ b/move.py   Tue Nov 08 00:38:33 2022 +0100
@@ -768,8 +768,9 @@
             ],
         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',
diff -r ca3cf980df97 -r 590824f11803 move.xml
--- a/move.xml  Mon Oct 31 16:49:54 2022 +0100
+++ b/move.xml  Tue Nov 08 00:38:33 2022 +0100
@@ -211,6 +211,10 @@
         <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 @@
             <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">
diff -r ca3cf980df97 -r 590824f11803 view/account_form.xml
--- a/view/account_form.xml     Mon Oct 31 16:49:54 2022 +0100
+++ b/view/account_form.xml     Tue Nov 08 00:38:33 2022 +0100
@@ -13,6 +13,20 @@
         <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"/>

Reply via email to