From 0f97f285de8eb1f7f55dcf7362754fa2c79b781d Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Tue, 9 Jun 2026 17:17:59 +0700 Subject: [PATCH] first commit --- .gitignore | 3 ++ README.md | 11 +++++++ __init__.py | 2 ++ __manifest__.py | 15 ++++++++++ models/__init__.py | 2 ++ models/account_general_ledger.py | 51 ++++++++++++++++++++++++++++++++ views/account_report_views.xml | 40 +++++++++++++++++++++++++ 7 files changed, 124 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 __init__.py create mode 100644 __manifest__.py create mode 100644 models/__init__.py create mode 100644 models/account_general_ledger.py create mode 100644 views/account_report_views.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d1a15e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +*.pyo +__pycache__/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..6070cdf --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +Account General Ledger Company Column +===================================== + +This module adds a "Company" column to the General Ledger report in Odoo 19, allowing users to identify which company a transaction line belongs to when running reports in a multi-company environment. + +Features +-------- + +- Adds a "Company" column to the General Ledger report. +- Retrieves company names in a single batch query for optimal performance. +- Supports multi-company contexts without altering base Odoo SQL views. diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..a0fdc10 --- /dev/null +++ b/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import models diff --git a/__manifest__.py b/__manifest__.py new file mode 100644 index 0000000..249700a --- /dev/null +++ b/__manifest__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +{ + 'name': 'Account General Ledger Company Column', + 'version': '1.0', + 'summary': 'Adds Company column to the General Ledger report', + 'category': 'Accounting/Reporting', + 'author': 'Suherdy Yacob', + 'depends': ['account_reports'], + 'data': [ + 'views/account_report_views.xml', + ], + 'installable': True, + 'auto_install': False, + 'license': 'LGPL-3', +} diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..9b56e8e --- /dev/null +++ b/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import account_general_ledger diff --git a/models/account_general_ledger.py b/models/account_general_ledger.py new file mode 100644 index 0000000..9fd41a0 --- /dev/null +++ b/models/account_general_ledger.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +import json +from odoo import models + +class AccountGeneralLedgerReportHandler(models.AbstractModel): + _inherit = 'account.general.ledger.report.handler' + + def _report_custom_engine_general_ledger(self, expressions, options, date_scope, current_groupby, next_groupby, offset=0, limit=None, warnings=None): + # 1. Fetch default general ledger rows + res = super()._report_custom_engine_general_ledger( + expressions, options, date_scope, current_groupby, next_groupby, + offset=offset, limit=limit, warnings=warnings + ) + + # 2. Inject company name for transaction rows + if isinstance(res, list): + if current_groupby == 'id_with_accumulated_balance': + aml_ids = [] + aml_entries = [] + for aml_key, entry in res: + entry['company_name'] = '' + # Exclude the "Initial Balance" summary lines + if aml_key and not aml_key.startswith('balance_line_'): + try: + key_list = json.loads(aml_key) + if len(key_list) > 1: + aml_ids.append(key_list[1]) + aml_entries.append((key_list[1], entry)) + except (json.JSONDecodeError, TypeError, ValueError): + pass + + # Fetch company names in one fast batch query + if aml_ids: + self.env.cr.execute(""" + SELECT aml.id, c.name + FROM account_move_line aml + JOIN res_company c ON c.id = aml.company_id + WHERE aml.id IN %s + """, [tuple(aml_ids)]) + company_map = dict(self.env.cr.fetchall()) + + for aml_id, entry in aml_entries: + entry['company_name'] = company_map.get(aml_id, '') + else: + # For non-transaction rows (like summary accounts), keep it blank + for aml_key, entry in res: + entry['company_name'] = '' + elif isinstance(res, dict): + res['company_name'] = '' + + return res diff --git a/views/account_report_views.xml b/views/account_report_views.xml new file mode 100644 index 0000000..f627dbf --- /dev/null +++ b/views/account_report_views.xml @@ -0,0 +1,40 @@ + + + + + + 1 + + + 2 + + + Company + company_name + string + 3 + + + + 4 + + + 5 + + + 6 + + + 7 + + + + + company_name + custom + _report_custom_engine_general_ledger + company_name + + + +