[FIX] account_financial_report: general_ledger
* centralization is only calculated on accounts where 'centralized' is True * Cumul. Balance of each move_line fixed * Ordering move_lines by date * Fix trial_balance xlsx when not show_partner_detailspull/868/head
parent
2d7d0617c2
commit
8e51903c67
|
@ -25,6 +25,7 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
"group_id": account.group_id.id,
|
"group_id": account.group_id.id,
|
||||||
"currency_id": account.currency_id or False,
|
"currency_id": account.currency_id or False,
|
||||||
"currency_name": account.currency_id.name,
|
"currency_name": account.currency_id.name,
|
||||||
|
"centralized": account.centralized,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -235,6 +236,7 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
else:
|
else:
|
||||||
prt_id = gl["partner_id"][0]
|
prt_id = gl["partner_id"][0]
|
||||||
prt_name = gl["partner_id"][1]
|
prt_name = gl["partner_id"][1]
|
||||||
|
prt_name = prt_name._value
|
||||||
if prt_id not in partners_ids:
|
if prt_id not in partners_ids:
|
||||||
partners_ids.add(prt_id)
|
partners_ids.add(prt_id)
|
||||||
partners_data.update({prt_id: {"id": prt_id, "name": prt_name}})
|
partners_data.update({prt_id: {"id": prt_id, "name": prt_name}})
|
||||||
|
@ -298,7 +300,7 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
"partner_name": move_line["partner_id"][1]
|
"partner_name": move_line["partner_id"][1]
|
||||||
if move_line["partner_id"]
|
if move_line["partner_id"]
|
||||||
else "",
|
else "",
|
||||||
"ref": move_line["name"],
|
"ref": "" if not move_line["ref"] else move_line["ref"],
|
||||||
"tax_ids": move_line["tax_ids"],
|
"tax_ids": move_line["tax_ids"],
|
||||||
"debit": move_line["debit"],
|
"debit": move_line["debit"],
|
||||||
"credit": move_line["credit"],
|
"credit": move_line["credit"],
|
||||||
|
@ -420,6 +422,7 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
"tax_ids",
|
"tax_ids",
|
||||||
"analytic_tag_ids",
|
"analytic_tag_ids",
|
||||||
"amount_currency",
|
"amount_currency",
|
||||||
|
"ref",
|
||||||
]
|
]
|
||||||
move_lines = self.env["account.move.line"].search_read(
|
move_lines = self.env["account.move.line"].search_read(
|
||||||
domain=domain, fields=ml_fields
|
domain=domain, fields=ml_fields
|
||||||
|
@ -461,19 +464,9 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
if not move_line["partner_id"]:
|
if not move_line["partner_id"]:
|
||||||
prt_id = 0
|
prt_id = 0
|
||||||
partner_name = "Missing Partner"
|
partner_name = "Missing Partner"
|
||||||
if gen_ld_data:
|
partners_ids.append(prt_id)
|
||||||
if prt_id not in gen_ld_data[acc_id]:
|
partners_data.update({prt_id: {"id": prt_id, "name": partner_name}})
|
||||||
if prt_id not in partners_ids:
|
if prt_id not in gen_ld_data[acc_id]:
|
||||||
partners_ids.append(prt_id)
|
|
||||||
partners_data.update(
|
|
||||||
{prt_id: {"id": prt_id, "name": partner_name}}
|
|
||||||
)
|
|
||||||
gen_ld_data = self._initialize_partner(
|
|
||||||
gen_ld_data, acc_id, prt_id, foreign_currency
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
partners_ids.append(prt_id)
|
|
||||||
partners_data.update({prt_id: {"id": prt_id, "name": partner_name}})
|
|
||||||
gen_ld_data = self._initialize_partner(
|
gen_ld_data = self._initialize_partner(
|
||||||
gen_ld_data, acc_id, prt_id, foreign_currency
|
gen_ld_data, acc_id, prt_id, foreign_currency
|
||||||
)
|
)
|
||||||
|
@ -510,6 +503,13 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
tags_data,
|
tags_data,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _recalculate_cumul_balance(self, move_lines, last_cumul_balance):
|
||||||
|
for move_line in move_lines:
|
||||||
|
move_line["balance"] += last_cumul_balance
|
||||||
|
last_cumul_balance = move_line["balance"]
|
||||||
|
return move_lines
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _create_general_ledger(self, gen_led_data, accounts_data):
|
def _create_general_ledger(self, gen_led_data, accounts_data):
|
||||||
general_ledger = []
|
general_ledger = []
|
||||||
|
@ -521,6 +521,7 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
"name": accounts_data[acc_id]["name"],
|
"name": accounts_data[acc_id]["name"],
|
||||||
"type": "account",
|
"type": "account",
|
||||||
"currency_id": accounts_data[acc_id]["currency_id"],
|
"currency_id": accounts_data[acc_id]["currency_id"],
|
||||||
|
"centralized": accounts_data[acc_id]["centralized"],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if not gen_led_data[acc_id]["partners"]:
|
if not gen_led_data[acc_id]["partners"]:
|
||||||
|
@ -530,6 +531,10 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
account.update({ml_id: gen_led_data[acc_id][ml_id]})
|
account.update({ml_id: gen_led_data[acc_id][ml_id]})
|
||||||
else:
|
else:
|
||||||
move_lines += [gen_led_data[acc_id][ml_id]]
|
move_lines += [gen_led_data[acc_id][ml_id]]
|
||||||
|
move_lines = sorted(move_lines, key=lambda k: (k["date"]))
|
||||||
|
move_lines = self._recalculate_cumul_balance(
|
||||||
|
move_lines, gen_led_data[acc_id]["init_bal"]["balance"]
|
||||||
|
)
|
||||||
account.update({"move_lines": move_lines})
|
account.update({"move_lines": move_lines})
|
||||||
else:
|
else:
|
||||||
list_partner = []
|
list_partner = []
|
||||||
|
@ -546,6 +551,11 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
move_lines += [gen_led_data[acc_id][prt_id][ml_id]]
|
move_lines += [gen_led_data[acc_id][prt_id][ml_id]]
|
||||||
|
move_lines = sorted(move_lines, key=lambda k: (k["date"]))
|
||||||
|
move_lines = self._recalculate_cumul_balance(
|
||||||
|
move_lines,
|
||||||
|
gen_led_data[acc_id][prt_id]["init_bal"]["balance"],
|
||||||
|
)
|
||||||
partner.update({"move_lines": move_lines})
|
partner.update({"move_lines": move_lines})
|
||||||
list_partner += [partner]
|
list_partner += [partner]
|
||||||
account.update({"list_partner": list_partner})
|
account.update({"list_partner": list_partner})
|
||||||
|
@ -553,47 +563,60 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
return general_ledger
|
return general_ledger
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_centralized_ml(self, partners, date_to):
|
def _calculate_centralization(self, centralized_ml, move_line, date_to):
|
||||||
|
jnl_id = move_line["journal_id"]
|
||||||
|
month = move_line["date"].month
|
||||||
|
if jnl_id not in centralized_ml.keys():
|
||||||
|
centralized_ml[jnl_id] = {}
|
||||||
|
if month not in centralized_ml[jnl_id].keys():
|
||||||
|
centralized_ml[jnl_id][month] = {}
|
||||||
|
last_day_month = calendar.monthrange(move_line["date"].year, month)
|
||||||
|
date = datetime.date(move_line["date"].year, month, last_day_month[1])
|
||||||
|
if date > date_to:
|
||||||
|
date = date_to
|
||||||
|
centralized_ml[jnl_id][month].update(
|
||||||
|
{
|
||||||
|
"journal_id": jnl_id,
|
||||||
|
"ref": "Centralized entries",
|
||||||
|
"date": date,
|
||||||
|
"debit": 0.0,
|
||||||
|
"credit": 0.0,
|
||||||
|
"balance": 0.0,
|
||||||
|
"bal_curr": 0.0,
|
||||||
|
"partner_id": False,
|
||||||
|
"rec_id": 0,
|
||||||
|
"entry_id": False,
|
||||||
|
"tax_ids": [],
|
||||||
|
"full_reconcile_id": False,
|
||||||
|
"id": False,
|
||||||
|
"tag_ids": False,
|
||||||
|
"currency_id": False,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
centralized_ml[jnl_id][month]["debit"] += move_line["debit"]
|
||||||
|
centralized_ml[jnl_id][month]["credit"] += move_line["credit"]
|
||||||
|
centralized_ml[jnl_id][month]["balance"] += (
|
||||||
|
move_line["debit"] - move_line["credit"]
|
||||||
|
)
|
||||||
|
centralized_ml[jnl_id][month]["bal_curr"] += move_line["bal_curr"]
|
||||||
|
return centralized_ml
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _get_centralized_ml(self, account, date_to):
|
||||||
centralized_ml = {}
|
centralized_ml = {}
|
||||||
if isinstance(date_to, str):
|
if isinstance(date_to, str):
|
||||||
date_to = datetime.datetime.strptime(date_to, "%Y-%m-%d").date()
|
date_to = datetime.datetime.strptime(date_to, "%Y-%m-%d").date()
|
||||||
for partner in partners:
|
if account["partners"]:
|
||||||
for move_line in partner["move_lines"]:
|
for partner in account["list_partner"]:
|
||||||
jnl_id = move_line["journal_id"]
|
for move_line in partner["move_lines"]:
|
||||||
month = move_line["date"].month
|
centralized_ml = self._calculate_centralization(
|
||||||
if jnl_id not in centralized_ml.keys():
|
centralized_ml, move_line, date_to,
|
||||||
centralized_ml[jnl_id] = {}
|
|
||||||
if month not in centralized_ml[jnl_id].keys():
|
|
||||||
centralized_ml[jnl_id][month] = {}
|
|
||||||
last_day_month = calendar.monthrange(move_line["date"].year, month)
|
|
||||||
date = datetime.date(
|
|
||||||
move_line["date"].year, month, last_day_month[1]
|
|
||||||
)
|
)
|
||||||
if date > date_to:
|
else:
|
||||||
date = date_to
|
for move_line in account["move_lines"]:
|
||||||
centralized_ml[jnl_id][month].update(
|
centralized_ml = self._calculate_centralization(
|
||||||
{
|
centralized_ml, move_line, date_to,
|
||||||
"journal_id": jnl_id,
|
)
|
||||||
"ref": "Centralized entries",
|
|
||||||
"date": date,
|
|
||||||
"debit": 0.0,
|
|
||||||
"credit": 0.0,
|
|
||||||
"balance": 0.0,
|
|
||||||
"bal_curr": 0.0,
|
|
||||||
"partner_id": False,
|
|
||||||
"rec_id": 0,
|
|
||||||
"entry_id": False,
|
|
||||||
"tax_ids": [],
|
|
||||||
"full_reconcile_id": False,
|
|
||||||
"id": False,
|
|
||||||
"tag_ids": False,
|
|
||||||
"currency_id": False,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
centralized_ml[jnl_id][month]["debit"] += move_line["debit"]
|
|
||||||
centralized_ml[jnl_id][month]["credit"] += move_line["credit"]
|
|
||||||
centralized_ml[jnl_id][month]["balance"] += move_line["balance"]
|
|
||||||
centralized_ml[jnl_id][month]["bal_curr"] += move_line["bal_curr"]
|
|
||||||
list_centralized_ml = []
|
list_centralized_ml = []
|
||||||
for jnl_id in centralized_ml.keys():
|
for jnl_id in centralized_ml.keys():
|
||||||
list_centralized_ml += list(centralized_ml[jnl_id].values())
|
list_centralized_ml += list(centralized_ml[jnl_id].values())
|
||||||
|
@ -659,13 +682,16 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
general_ledger = self._create_general_ledger(gen_ld_data, accounts_data)
|
general_ledger = self._create_general_ledger(gen_ld_data, accounts_data)
|
||||||
if centralize:
|
if centralize:
|
||||||
for account in general_ledger:
|
for account in general_ledger:
|
||||||
if account["partners"]:
|
if account["centralized"]:
|
||||||
centralized_ml = self._get_centralized_ml(
|
centralized_ml = self._get_centralized_ml(account, date_to)
|
||||||
account["list_partner"], date_to
|
|
||||||
)
|
|
||||||
account["move_lines"] = centralized_ml
|
account["move_lines"] = centralized_ml
|
||||||
account["partners"] = False
|
account["move_lines"] = self._recalculate_cumul_balance(
|
||||||
del account["list_partner"]
|
account["move_lines"],
|
||||||
|
gen_ld_data[account["id"]]["init_bal"]["balance"],
|
||||||
|
)
|
||||||
|
if account["partners"]:
|
||||||
|
account["partners"] = False
|
||||||
|
del account["list_partner"]
|
||||||
general_ledger = sorted(general_ledger, key=lambda k: k["code"])
|
general_ledger = sorted(general_ledger, key=lambda k: k["code"])
|
||||||
return {
|
return {
|
||||||
"doc_ids": [wizard_id],
|
"doc_ids": [wizard_id],
|
||||||
|
|
|
@ -189,6 +189,19 @@ class GeneralLedgerXslx(models.AbstractModel):
|
||||||
{"taxes_description": taxes_description, "tags": tags}
|
{"taxes_description": taxes_description, "tags": tags}
|
||||||
)
|
)
|
||||||
self.write_line_from_dict(line)
|
self.write_line_from_dict(line)
|
||||||
|
# Display ending balance line for account
|
||||||
|
account.update(
|
||||||
|
{
|
||||||
|
"final_debit": account["fin_bal"]["debit"],
|
||||||
|
"final_credit": account["fin_bal"]["credit"],
|
||||||
|
"final_balance": account["fin_bal"]["balance"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if foreign_currency:
|
||||||
|
account.update(
|
||||||
|
{"final_bal_curr": account["fin_bal"]["bal_curr"],}
|
||||||
|
)
|
||||||
|
self.write_ending_balance_from_dict(account)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# For each partner
|
# For each partner
|
||||||
|
@ -258,18 +271,19 @@ class GeneralLedgerXslx(models.AbstractModel):
|
||||||
# Line break
|
# Line break
|
||||||
self.row_pos += 1
|
self.row_pos += 1
|
||||||
|
|
||||||
# Display ending balance line for account
|
if not filter_partner_ids:
|
||||||
if not filter_partner_ids:
|
account.update(
|
||||||
account.update(
|
{
|
||||||
{
|
"final_debit": account["fin_bal"]["debit"],
|
||||||
"final_debit": account["fin_bal"]["debit"],
|
"final_credit": account["fin_bal"]["credit"],
|
||||||
"final_credit": account["fin_bal"]["credit"],
|
"final_balance": account["fin_bal"]["balance"],
|
||||||
"final_balance": account["fin_bal"]["balance"],
|
}
|
||||||
}
|
)
|
||||||
)
|
if foreign_currency:
|
||||||
if foreign_currency:
|
account.update(
|
||||||
account.update({"final_bal_curr": account["fin_bal"]["bal_curr"]})
|
{"final_bal_curr": account["fin_bal"]["bal_curr"],}
|
||||||
self.write_ending_balance_from_dict(account)
|
)
|
||||||
|
self.write_ending_balance_from_dict(account)
|
||||||
|
|
||||||
# 2 lines break
|
# 2 lines break
|
||||||
self.row_pos += 2
|
self.row_pos += 2
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<template id="report_general_ledger_base">
|
<template id="report_general_ledger_base">
|
||||||
<!-- Saved flag fields into variables, used to define columns display -->
|
<!-- Saved flag fields into variables, used to define columns display -->
|
||||||
<t t-set="foreign_currency" t-value="foreign_currency" />
|
<t t-set="foreign_currency" t-value="foreign_currency" />
|
||||||
|
<t t-set="filter_partner_ids" t-value="filter_partner_ids" />
|
||||||
<!-- Defines global variables used by internal layout -->
|
<!-- Defines global variables used by internal layout -->
|
||||||
<t t-set="title">General Ledger - <t t-raw="company_name" /> - <t
|
<t t-set="title">General Ledger - <t t-raw="company_name" /> - <t
|
||||||
t-raw="currency_name"
|
t-raw="currency_name"
|
||||||
|
@ -46,50 +47,59 @@
|
||||||
>
|
>
|
||||||
<t t-set="account_or_partner_object" t-value="account" />
|
<t t-set="account_or_partner_object" t-value="account" />
|
||||||
</t>
|
</t>
|
||||||
|
<!-- Display account footer -->
|
||||||
|
<t
|
||||||
|
t-call="account_financial_report.report_general_ledger_ending_cumul"
|
||||||
|
>
|
||||||
|
<t t-set="account_or_partner_object" t-value="account" />
|
||||||
|
<t t-set="type" t-value='"account_type"' />
|
||||||
|
</t>
|
||||||
</t>
|
</t>
|
||||||
<t t-if="account['partners']">
|
<t t-if="account['partners']">
|
||||||
<!-- Display account partners -->
|
<!-- Display account partners -->
|
||||||
<t t-if="not centralize">
|
<t t-foreach="account['list_partner']" t-as="partner">
|
||||||
<t t-foreach="account['list_partner']" t-as="partner">
|
<t t-set="type" t-value='"partner_type"' />
|
||||||
<t t-set="type" t-value='"partner_type"' />
|
<div class="page_break">
|
||||||
<div class="page_break">
|
<!-- Display partner header -->
|
||||||
<!-- Display partner header -->
|
<div class="act_as_caption account_title">
|
||||||
<div class="act_as_caption account_title">
|
<span
|
||||||
<span
|
t-esc="o._get_atr_from_dict(partner['id'], partners_data, 'name')"
|
||||||
t-esc="o._get_atr_from_dict(partner['id'], partners_data, 'name')"
|
/>
|
||||||
/>
|
</div>
|
||||||
</div>
|
<!-- Display partner move lines -->
|
||||||
<!-- Display partner move lines -->
|
<t
|
||||||
|
t-call="account_financial_report.report_general_ledger_lines"
|
||||||
|
>
|
||||||
<t
|
<t
|
||||||
t-call="account_financial_report.report_general_ledger_lines"
|
t-set="account_or_partner_object"
|
||||||
>
|
t-value="partner"
|
||||||
<t
|
/>
|
||||||
t-set="account_or_partner_object"
|
</t>
|
||||||
t-value="partner"
|
<!-- Display partner footer -->
|
||||||
/>
|
<t
|
||||||
</t>
|
t-call="account_financial_report.report_general_ledger_ending_cumul"
|
||||||
<!-- Display partner footer -->
|
>
|
||||||
|
<t
|
||||||
|
t-set="account_or_partner_object"
|
||||||
|
t-value="partner"
|
||||||
|
/>
|
||||||
|
<t t-set="type" t-value='"partner_type"' />
|
||||||
|
</t>
|
||||||
|
<!-- Display account footer -->
|
||||||
|
<t t-if="not filter_partner_ids">
|
||||||
<t
|
<t
|
||||||
t-call="account_financial_report.report_general_ledger_ending_cumul"
|
t-call="account_financial_report.report_general_ledger_ending_cumul"
|
||||||
>
|
>
|
||||||
<t
|
<t
|
||||||
t-set="account_or_partner_object"
|
t-set="account_or_partner_object"
|
||||||
t-value="partner"
|
t-value="account"
|
||||||
/>
|
/>
|
||||||
<t t-set="type" t-value='"partner_type"' />
|
<t t-set="type" t-value='"account_type"' />
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</t>
|
||||||
</t>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</t>
|
||||||
<!-- Display account footer -->
|
|
||||||
<t
|
|
||||||
t-if="not account['partners']"
|
|
||||||
t-call="account_financial_report.report_general_ledger_ending_cumul"
|
|
||||||
>
|
|
||||||
<t t-set="account_or_partner_object" t-value="account" />
|
|
||||||
<t t-set="type" t-value='"account_type"' />
|
|
||||||
</t>
|
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -45,13 +45,13 @@ class TrialBalanceXslx(models.AbstractModel):
|
||||||
},
|
},
|
||||||
5: {
|
5: {
|
||||||
"header": _("Period balance"),
|
"header": _("Period balance"),
|
||||||
"field": "period_balance",
|
"field": "balance",
|
||||||
"type": "amount",
|
"type": "amount",
|
||||||
"width": 14,
|
"width": 14,
|
||||||
},
|
},
|
||||||
6: {
|
6: {
|
||||||
"header": _("Ending balance"),
|
"header": _("Ending balance"),
|
||||||
"field": "final_balance",
|
"field": "ending_balance",
|
||||||
"type": "amount",
|
"type": "amount",
|
||||||
"width": 14,
|
"width": 14,
|
||||||
},
|
},
|
||||||
|
@ -67,13 +67,13 @@ class TrialBalanceXslx(models.AbstractModel):
|
||||||
},
|
},
|
||||||
8: {
|
8: {
|
||||||
"header": _("Initial balance"),
|
"header": _("Initial balance"),
|
||||||
"field": "initial_balance_foreign_currency",
|
"field": "initial_currency_balance",
|
||||||
"type": "amount_currency",
|
"type": "amount_currency",
|
||||||
"width": 14,
|
"width": 14,
|
||||||
},
|
},
|
||||||
9: {
|
9: {
|
||||||
"header": _("Ending balance"),
|
"header": _("Ending balance"),
|
||||||
"field": "final_balance_foreign_currency",
|
"field": "ending_currency_balance",
|
||||||
"type": "amount_currency",
|
"type": "amount_currency",
|
||||||
"width": 14,
|
"width": 14,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue