account_report_show_all/models/account_report.py
2026-01-19 16:54:43 +07:00

41 lines
1.7 KiB
Python

from odoo import models
class AccountReport(models.Model):
_inherit = 'account.report'
def _get_lines(self, options, all_column_groups_expression_totals=None, warnings=None):
# Get the standard lines
lines = super()._get_lines(options, all_column_groups_expression_totals, warnings=warnings)
# Filter logic to hide accounts ending in '0' if they have zero balance
filtered_lines = []
for line in lines:
keep_line = True
# Only check lines that represent accounts
if line.get('caret_options') == 'account.account':
# Attempt to get the code from the name.
# Account names usually start with the code (e.g., "110100 Stock Valuation")
name = line.get('name', '').strip()
code_part = name.split(' ')[0]
# Check if code appears to be numeric and ends with '0'
# We interpret this as a summary/view account that should be hidden if unused
if code_part.isdigit() and code_part.endswith('0'):
has_balance = False
for col in line.get('columns', []):
val = col.get('no_format', 0.0)
if val is None: val = 0.0
if not self.env.company.currency_id.is_zero(val):
has_balance = True
break
if not has_balance:
keep_line = False
if keep_line:
filtered_lines.append(line)
return filtered_lines