diff --git a/modules/account/__init__.py b/modules/account/__init__.py index 3e8d0f2..11a8096 100755 --- a/modules/account/__init__.py +++ b/modules/account/__init__.py @@ -120,6 +120,7 @@ def register(): Pool.register( account.AccountTypeStatement, account.GeneralLedger, + account.GeneralLedgerDetailReport, account.TrialBalance, account.AgedBalanceReport, move.GeneralJournal, diff --git a/modules/account/account.py b/modules/account/account.py index 1856c08..a21212c 100755 --- a/modules/account/account.py +++ b/modules/account/account.py @@ -3145,6 +3145,52 @@ class GeneralLedger(Report): return report_context +class GeneralLedgerDetailReport(Report): + __name__ = 'account.general_ledger.detail.report' + + @classmethod + def get_context(cls, records, header, data): + pool = Pool() + Company = pool.get('company.company') + Fiscalyear = pool.get('account.fiscalyear') + Period = pool.get('account.period') + context = Transaction().context + + report_context = super().get_context(records, header, data) + report_context['company'] = Company(context['company']) + report_context['fiscalyear'] = Fiscalyear(context['fiscalyear']) + for period in ['start_period', 'end_period']: + if context.get(period): + report_context[period] = Period(context[period]) + else: + report_context[period] = None + report_context['from_date'] = context.get('from_date') + report_context['to_date'] = context.get('to_date') + report_context['groups'] = cls._groups(records) + return report_context + + @classmethod + def _groups(cls, records): + groups = [] + current_key = None + current = None + for line in records: + currency = getattr(line, 'transaction_currency', None) + key = ( + getattr(line, 'account_code', None), + getattr(currency, 'id', None)) + if key != current_key: + current = { + 'account': line.account_code or line.account_name or '', + 'currency': currency, + 'lines': [], + } + groups.append(current) + current_key = key + current['lines'].append(line) + return groups + + class TrialBalance(Report): __name__ = 'account.trial_balance' diff --git a/modules/account/account.xml b/modules/account/account.xml index fd22196..2b59e62 100755 --- a/modules/account/account.xml +++ b/modules/account/account.xml @@ -823,6 +823,18 @@ this repository contains the full copyright notices and license terms. --> + + General Ledger Detail + listed + account.general_ledger.detail + account.general_ledger.detail.report + account/general_ledger_detail.fodt + + + form_print + account.general_ledger.detail,-1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + General Ledger Detail + + <company.rec_name> + - Fiscal Year: + <fiscalyear.rec_name> + + + From + <format_date(from_date, user.language) if from_date else ''> + to + <format_date(to_date, user.language) if to_date else ''> + + <for each="group in groups"> + + + + + + + + + + + + + + + + + <group['account']> + / + <group['currency'].rec_name if group['currency'] else ''> + + + + + + + Type + Date + Journal + Entry + Document + Party + Description + Reference + Debit + Credit + Balance + Running + + + + <for each="line in group['lines']"><line.row_type.title() if line.row_type else ''> + + <format_date(line.posting_date, user.language) if line.posting_date else ''> + <line.journal.rec_name if line.journal else ''> + <line.journal_entry_number or ''> + <line.document_number or line.voucher_number or ''> + <line.party.rec_name if line.party else ''> + <line.description or line.move_description or ''> + <line.reference or ''> + <format_currency(line.debit_base_currency or 0, user.language, line.base_currency or company.currency)> + <format_currency(line.credit_base_currency or 0, user.language, line.base_currency or company.currency)> + <format_currency(line.balance_base_currency or 0, user.language, line.base_currency or company.currency)> + <format_currency(line.running_balance_base_currency or 0, user.language, line.base_currency or company.currency)></for> + + + + </for> + + + diff --git a/modules/account/tests/test_module.py b/modules/account/tests/test_module.py index 80278dd..87b333a 100755 --- a/modules/account/tests/test_module.py +++ b/modules/account/tests/test_module.py @@ -2103,6 +2103,8 @@ class AccountTestCase( pool = Pool() Detail = pool.get('account.general_ledger.detail') DetailContext = pool.get('account.general_ledger.detail.context') + DetailReport = pool.get( + 'account.general_ledger.detail.report', type='report') for name in [ 'row_type', 'account_code', 'transaction_currency', @@ -2124,6 +2126,41 @@ class AccountTestCase( self.assertIn('||', str(account_label)) self.assertNotIn(' + ', str(account_label)) self.assertEqual(account_label.params, ('', ' - ', '')) + self.assertEqual( + DetailReport.__name__, 'account.general_ledger.detail.report') + + @with_transaction() + def test_general_ledger_detail_report_groups_by_account_currency(self): + "Test General Ledger Detail report groups lines by account and currency" + DetailReport = Pool().get( + 'account.general_ledger.detail.report', type='report') + currency = type('Currency', (), {'id': 1})() + other_currency = type('Currency', (), {'id': 2})() + first = type('Line', (), { + 'account_code': '1000 - Cash', + 'account_name': 'Cash', + 'transaction_currency': currency, + })() + second = type('Line', (), { + 'account_code': '1000 - Cash', + 'account_name': 'Cash', + 'transaction_currency': currency, + })() + third = type('Line', (), { + 'account_code': '2000 - Revenue', + 'account_name': 'Revenue', + 'transaction_currency': other_currency, + })() + + groups = DetailReport._groups([first, second, third]) + + self.assertEqual(len(groups), 2) + self.assertEqual(groups[0]['account'], '1000 - Cash') + self.assertEqual(groups[0]['currency'], currency) + self.assertEqual(groups[0]['lines'], [first, second]) + self.assertEqual(groups[1]['account'], '2000 - Revenue') + self.assertEqual(groups[1]['currency'], other_currency) + self.assertEqual(groups[1]['lines'], [third]) @with_transaction() def test_general_ledger_detail_date_contexts(self):