Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 45 additions & 28 deletions account_financial_report/report/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ def _get_account_type_domain(self, grouped_by):
("account_type", at_op, ["asset_receivable", "liability_payable"]),
]

def _get_acc_prt_accounts_ids(self, company_id, grouped_by):
def _get_acc_prt_accounts_ids(self, company_ids, grouped_by):
accounts_domain = [
("company_id", "=", company_id),
("company_id", "in", company_ids),
] + self._get_account_type_domain(grouped_by)
acc_prt_accounts = self.env["account.account"].search(accounts_domain)
return acc_prt_accounts.ids

def _get_initial_balances_bs_ml_domain(
self, account_ids, company_id, date_from, base_domain, grouped_by, acc_prt=False
self, account_ids, company_ids, date_from, base_domain, grouped_by, acc_prt=False
):
accounts_domain = [
("company_id", "=", company_id),
("company_id", "in", company_ids),
("include_initial_balance", "=", True),
]
if account_ids:
Expand All @@ -86,10 +86,10 @@ def _get_initial_balances_bs_ml_domain(
return domain

def _get_initial_balances_pl_ml_domain(
self, account_ids, company_id, date_from, fy_start_date, base_domain
self, account_ids, company_ids, date_from, fy_start_date, base_domain
):
accounts_domain = [
("company_id", "=", company_id),
("company_id", "in", company_ids),
("include_initial_balance", "=", False),
]
if account_ids:
Expand All @@ -116,10 +116,16 @@ def _get_accounts_initial_balance(self, initial_domain_bs, initial_domain_pl):
return gl_initial_acc

def _get_initial_balance_fy_pl_ml_domain(
self, account_ids, company_id, fy_start_date, base_domain
self,
account_ids,
company_ids,
date_from,
base_domain,
grouped_by,
acc_prt=False,
):
accounts_domain = [
("company_id", "=", company_id),
("company_id", "in", company_ids),
("include_initial_balance", "=", False),
]
if account_ids:
Expand All @@ -132,10 +138,10 @@ def _get_initial_balance_fy_pl_ml_domain(
return domain

def _get_pl_initial_balance(
self, account_ids, company_id, fy_start_date, foreign_currency, base_domain
self, account_ids, company_ids, fy_start_date, foreign_currency, base_domain
):
domain = self._get_initial_balance_fy_pl_ml_domain(
account_ids, company_id, fy_start_date, base_domain
account_ids, company_ids, fy_start_date, base_domain
)
initial_balances = self.env["account.move.line"].read_group(
domain=domain,
Expand All @@ -156,13 +162,19 @@ def _get_pl_initial_balance(
return pl_initial_balance

def _get_gl_initial_acc(
self, account_ids, company_id, date_from, fy_start_date, base_domain, grouped_by
self,
account_ids,
company_ids,
date_from,
fy_start_date,
base_domain,
grouped_by,
):
initial_domain_bs = self._get_initial_balances_bs_ml_domain(
account_ids, company_id, date_from, base_domain, grouped_by
account_ids, company_ids, date_from, base_domain, grouped_by
)
initial_domain_pl = self._get_initial_balances_pl_ml_domain(
account_ids, company_id, date_from, fy_start_date, base_domain
account_ids, company_ids, date_from, fy_start_date, base_domain
)
return self._get_accounts_initial_balance(initial_domain_bs, initial_domain_pl)

Expand Down Expand Up @@ -250,7 +262,7 @@ def _get_initial_balance_data(
self,
account_ids,
partner_ids,
company_id,
company_ids,
date_from,
foreign_currency,
only_posted_moves,
Expand All @@ -265,8 +277,8 @@ def _get_initial_balance_data(
if account_ids:
unaffected_earnings_account = False
base_domain = []
if company_id:
base_domain += [("company_id", "=", company_id)]
if company_ids:
base_domain += [("company_id", "in", company_ids)]
if partner_ids:
base_domain += [("partner_id", "in", partner_ids)]
if only_posted_moves:
Expand All @@ -278,10 +290,10 @@ def _get_initial_balance_data(
if extra_domain:
base_domain += extra_domain
gl_initial_acc = self._get_gl_initial_acc(
account_ids, company_id, date_from, fy_start_date, base_domain, grouped_by
account_ids, company_ids, date_from, fy_start_date, base_domain, grouped_by
)
domain = self._get_initial_balances_bs_ml_domain(
account_ids, company_id, date_from, base_domain, grouped_by, acc_prt=True
account_ids, company_ids, date_from, base_domain, grouped_by, acc_prt=True
)
data = self._prepare_gen_ld_data(gl_initial_acc, domain, grouped_by)
accounts_ids = list(data.keys())
Expand All @@ -294,7 +306,7 @@ def _get_initial_balance_data(
data[unaffected_id]["mame"] = ""
data[unaffected_id][grouped_by] = False
pl_initial_balance = self._get_pl_initial_balance(
account_ids, company_id, fy_start_date, foreign_currency, base_domain
account_ids, company_ids, fy_start_date, foreign_currency, base_domain
)
for key_bal in ["init_bal", "fin_bal"]:
fields_balance = ["credit", "debit", "balance"]
Expand Down Expand Up @@ -355,7 +367,7 @@ def _get_period_domain(
self,
account_ids,
partner_ids,
company_id,
company_ids,
only_posted_moves,
date_to,
date_from,
Expand All @@ -368,8 +380,8 @@ def _get_period_domain(
]
if account_ids:
domain += [("account_id", "in", account_ids)]
if company_id:
domain += [("company_id", "=", company_id)]
if company_ids:
domain += [("company_id", "in", company_ids)]
if partner_ids:
domain += [("partner_id", "in", partner_ids)]
if only_posted_moves:
Expand Down Expand Up @@ -436,7 +448,7 @@ def _get_period_ml_data(
self,
account_ids,
partner_ids,
company_id,
company_ids,
foreign_currency,
only_posted_moves,
date_from,
Expand All @@ -449,7 +461,7 @@ def _get_period_ml_data(
domain = self._get_period_domain(
account_ids,
partner_ids,
company_id,
company_ids,
only_posted_moves,
date_to,
date_from,
Expand All @@ -466,7 +478,7 @@ def _get_period_ml_data(
taxes_ids = set()
analytic_ids = set()
full_reconcile_data = {}
acc_prt_account_ids = self._get_acc_prt_accounts_ids(company_id, grouped_by)
acc_prt_account_ids = self._get_acc_prt_accounts_ids(company_ids, grouped_by)
for move_line in move_lines:
journal_ids.add(move_line["journal_id"][0])
for tax_id in move_line["tax_ids"]:
Expand Down Expand Up @@ -767,7 +779,9 @@ def _get_centralized_ml(self, account, date_to, grouped_by):
def _get_report_values(self, docids, data):
wizard_id = data["wizard_id"]
company = self.env["res.company"].browse(data["company_id"])
company_id = data["company_id"]
company_ids = company.all_child_ids.ids + [
company.id
] # Include all child companies
date_to = data["date_to"]
date_from = data["date_from"]
partner_ids = data["partner_ids"]
Expand All @@ -780,10 +794,12 @@ def _get_report_values(self, docids, data):
unaffected_earnings_account = data["unaffected_earnings_account"]
fy_start_date = data["fy_start_date"]
extra_domain = data["domain"]


gen_ld_data = self._get_initial_balance_data(
account_ids,
partner_ids,
company_id,
company_ids,
date_from,
foreign_currency,
only_posted_moves,
Expand All @@ -805,7 +821,7 @@ def _get_report_values(self, docids, data):
) = self._get_period_ml_data(
account_ids,
partner_ids,
company_id,
company_ids,
foreign_currency,
only_posted_moves,
date_from,
Expand Down Expand Up @@ -931,3 +947,4 @@ def _get_ml_fields(self):
"tax_ids",
"move_name",
]

3 changes: 2 additions & 1 deletion account_financial_report/report/journal_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _get_journal_ledger_data(self, journal):
def _get_journal_ledgers_domain(self, wizard, journal_ids, company):
domain = []
if company:
domain += [("company_id", "=", company.id)]
domain += [("company_id", "in", company.all_child_ids.ids + [company.id])]
if journal_ids:
domain += [("id", "in", journal_ids)]
return domain
Expand Down Expand Up @@ -373,3 +373,4 @@ def _get_report_values(self, docids, data):
"Journal_Ledgers": journal_ledgers_data,
"Moves": moves_data,
}

Loading
Loading