first commit

This commit is contained in:
Suherdy Yacob 2026-06-09 17:17:59 +07:00
commit 0f97f285de
7 changed files with 124 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.pyc
*.pyo
__pycache__/

11
README.md Normal file
View File

@ -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.

2
__init__.py Normal file
View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import models

15
__manifest__.py Normal file
View File

@ -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',
}

2
models/__init__.py Normal file
View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import account_general_ledger

View File

@ -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

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- Re-order existing columns and insert Company column after Partner -->
<record id="account_reports.general_ledger_report_date" model="account.report.column">
<field name="sequence">1</field>
</record>
<record id="account_reports.general_ledger_report_partner_name" model="account.report.column">
<field name="sequence">2</field>
</record>
<record id="general_ledger_report_company" model="account.report.column">
<field name="name">Company</field>
<field name="expression_label">company_name</field>
<field name="figure_type">string</field>
<field name="sequence">3</field>
<field name="report_id" ref="account_reports.general_ledger_report"/>
</record>
<record id="account_reports.general_ledger_report_amount_currency" model="account.report.column">
<field name="sequence">4</field>
</record>
<record id="account_reports.general_ledger_report_debit" model="account.report.column">
<field name="sequence">5</field>
</record>
<record id="account_reports.general_ledger_report_credit" model="account.report.column">
<field name="sequence">6</field>
</record>
<record id="account_reports.general_ledger_report_balance" model="account.report.column">
<field name="sequence">7</field>
</record>
<!-- Bind the expression to the Custom Engine handler on the GL Line -->
<record id="general_ledger_line_company_name" model="account.report.expression">
<field name="label">company_name</field>
<field name="engine">custom</field>
<field name="formula">_report_custom_engine_general_ledger</field>
<field name="subformula">company_name</field>
<field name="report_line_id" ref="account_reports.general_ledger_custom_engine_line"/>
</record>
</data>
</odoo>