[IMP] account_financial_report: general_ledger
* "hide account at 0" hides account/partner if inital cumul balance is 0 and there are not movements in the periodpull/868/head
parent
a6a385b930
commit
d36074655d
|
@ -7,6 +7,7 @@ import datetime
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
from odoo import _, api, models
|
from odoo import _, api, models
|
||||||
|
from odoo.tools import float_is_zero
|
||||||
|
|
||||||
|
|
||||||
class GeneralLedgerReport(models.AbstractModel):
|
class GeneralLedgerReport(models.AbstractModel):
|
||||||
|
@ -177,7 +178,6 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
date_from,
|
date_from,
|
||||||
foreign_currency,
|
foreign_currency,
|
||||||
only_posted_moves,
|
only_posted_moves,
|
||||||
hide_account_at_0,
|
|
||||||
unaffected_earnings_account,
|
unaffected_earnings_account,
|
||||||
fy_start_date,
|
fy_start_date,
|
||||||
analytic_tag_ids,
|
analytic_tag_ids,
|
||||||
|
@ -432,13 +432,11 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
company_id,
|
company_id,
|
||||||
foreign_currency,
|
foreign_currency,
|
||||||
only_posted_moves,
|
only_posted_moves,
|
||||||
hide_account_at_0,
|
|
||||||
date_from,
|
date_from,
|
||||||
date_to,
|
date_to,
|
||||||
partners_data,
|
partners_data,
|
||||||
gen_ld_data,
|
gen_ld_data,
|
||||||
partners_ids,
|
partners_ids,
|
||||||
centralize,
|
|
||||||
analytic_tag_ids,
|
analytic_tag_ids,
|
||||||
cost_center_ids,
|
cost_center_ids,
|
||||||
):
|
):
|
||||||
|
@ -566,23 +564,7 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
move_line["rec_name"] = "(" + _("future") + ") " + move_line["rec_name"]
|
move_line["rec_name"] = "(" + _("future") + ") " + move_line["rec_name"]
|
||||||
return move_lines
|
return move_lines
|
||||||
|
|
||||||
@api.model
|
def _create_account(self, account, acc_id, gen_led_data, rec_after_date_to_ids):
|
||||||
def _create_general_ledger(
|
|
||||||
self, gen_led_data, accounts_data, show_partner_details, rec_after_date_to_ids
|
|
||||||
):
|
|
||||||
general_ledger = []
|
|
||||||
for acc_id in gen_led_data.keys():
|
|
||||||
account = {}
|
|
||||||
account.update(
|
|
||||||
{
|
|
||||||
"code": accounts_data[acc_id]["code"],
|
|
||||||
"name": accounts_data[acc_id]["name"],
|
|
||||||
"type": "account",
|
|
||||||
"currency_id": accounts_data[acc_id]["currency_id"],
|
|
||||||
"centralized": accounts_data[acc_id]["centralized"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if not gen_led_data[acc_id]["partners"]:
|
|
||||||
move_lines = []
|
move_lines = []
|
||||||
for ml_id in gen_led_data[acc_id].keys():
|
for ml_id in gen_led_data[acc_id].keys():
|
||||||
if not isinstance(ml_id, int):
|
if not isinstance(ml_id, int):
|
||||||
|
@ -596,6 +578,62 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
rec_after_date_to_ids,
|
rec_after_date_to_ids,
|
||||||
)
|
)
|
||||||
account.update({"move_lines": move_lines})
|
account.update({"move_lines": move_lines})
|
||||||
|
return account
|
||||||
|
|
||||||
|
def _create_account_not_show_partner(
|
||||||
|
self, account, acc_id, gen_led_data, rec_after_date_to_ids
|
||||||
|
):
|
||||||
|
move_lines = []
|
||||||
|
for prt_id in gen_led_data[acc_id].keys():
|
||||||
|
if not isinstance(prt_id, int):
|
||||||
|
account.update({prt_id: gen_led_data[acc_id][prt_id]})
|
||||||
|
else:
|
||||||
|
for ml_id in gen_led_data[acc_id][prt_id].keys():
|
||||||
|
if isinstance(ml_id, int):
|
||||||
|
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]["init_bal"]["balance"],
|
||||||
|
rec_after_date_to_ids,
|
||||||
|
)
|
||||||
|
account.update({"move_lines": move_lines, "partners": False})
|
||||||
|
return account
|
||||||
|
|
||||||
|
def _create_general_ledger(
|
||||||
|
self,
|
||||||
|
gen_led_data,
|
||||||
|
accounts_data,
|
||||||
|
show_partner_details,
|
||||||
|
rec_after_date_to_ids,
|
||||||
|
hide_account_at_0,
|
||||||
|
):
|
||||||
|
general_ledger = []
|
||||||
|
rounding = self.env.user.company_id.currency_id.rounding
|
||||||
|
for acc_id in gen_led_data.keys():
|
||||||
|
account = {}
|
||||||
|
account.update(
|
||||||
|
{
|
||||||
|
"code": accounts_data[acc_id]["code"],
|
||||||
|
"name": accounts_data[acc_id]["name"],
|
||||||
|
"type": "account",
|
||||||
|
"currency_id": accounts_data[acc_id]["currency_id"],
|
||||||
|
"centralized": accounts_data[acc_id]["centralized"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if not gen_led_data[acc_id]["partners"]:
|
||||||
|
account = self._create_account(
|
||||||
|
account, acc_id, gen_led_data, rec_after_date_to_ids
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
hide_account_at_0
|
||||||
|
and float_is_zero(
|
||||||
|
gen_led_data[acc_id]["init_bal"]["balance"],
|
||||||
|
precision_rounding=rounding,
|
||||||
|
)
|
||||||
|
and account["move_lines"] == []
|
||||||
|
):
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
if show_partner_details:
|
if show_partner_details:
|
||||||
list_partner = []
|
list_partner = []
|
||||||
|
@ -619,24 +657,39 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
rec_after_date_to_ids,
|
rec_after_date_to_ids,
|
||||||
)
|
)
|
||||||
partner.update({"move_lines": move_lines})
|
partner.update({"move_lines": move_lines})
|
||||||
|
if (
|
||||||
|
hide_account_at_0
|
||||||
|
and float_is_zero(
|
||||||
|
gen_led_data[acc_id][prt_id]["init_bal"]["balance"],
|
||||||
|
precision_rounding=rounding,
|
||||||
|
)
|
||||||
|
and partner["move_lines"] == []
|
||||||
|
):
|
||||||
|
continue
|
||||||
list_partner += [partner]
|
list_partner += [partner]
|
||||||
account.update({"list_partner": list_partner})
|
account.update({"list_partner": list_partner})
|
||||||
else:
|
if (
|
||||||
move_lines = []
|
hide_account_at_0
|
||||||
for prt_id in gen_led_data[acc_id].keys():
|
and float_is_zero(
|
||||||
if not isinstance(prt_id, int):
|
|
||||||
account.update({prt_id: gen_led_data[acc_id][prt_id]})
|
|
||||||
else:
|
|
||||||
for ml_id in gen_led_data[acc_id][prt_id].keys():
|
|
||||||
if isinstance(ml_id, int):
|
|
||||||
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]["init_bal"]["balance"],
|
gen_led_data[acc_id]["init_bal"]["balance"],
|
||||||
rec_after_date_to_ids,
|
precision_rounding=rounding,
|
||||||
)
|
)
|
||||||
account.update({"move_lines": move_lines, "partners": False})
|
and account["list_partner"] == []
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
account = self._create_account_not_show_partner(
|
||||||
|
account, acc_id, gen_led_data, rec_after_date_to_ids
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
hide_account_at_0
|
||||||
|
and float_is_zero(
|
||||||
|
gen_led_data[acc_id]["init_bal"]["balance"],
|
||||||
|
precision_rounding=rounding,
|
||||||
|
)
|
||||||
|
and account["move_lines"] == []
|
||||||
|
):
|
||||||
|
continue
|
||||||
general_ledger += [account]
|
general_ledger += [account]
|
||||||
return general_ledger
|
return general_ledger
|
||||||
|
|
||||||
|
@ -728,7 +781,6 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
date_from,
|
date_from,
|
||||||
foreign_currency,
|
foreign_currency,
|
||||||
only_posted_moves,
|
only_posted_moves,
|
||||||
hide_account_at_0,
|
|
||||||
unaffected_earnings_account,
|
unaffected_earnings_account,
|
||||||
fy_start_date,
|
fy_start_date,
|
||||||
analytic_tag_ids,
|
analytic_tag_ids,
|
||||||
|
@ -750,18 +802,20 @@ class GeneralLedgerReport(models.AbstractModel):
|
||||||
company_id,
|
company_id,
|
||||||
foreign_currency,
|
foreign_currency,
|
||||||
only_posted_moves,
|
only_posted_moves,
|
||||||
hide_account_at_0,
|
|
||||||
date_from,
|
date_from,
|
||||||
date_to,
|
date_to,
|
||||||
partners_data,
|
partners_data,
|
||||||
gen_ld_data,
|
gen_ld_data,
|
||||||
partners_ids,
|
partners_ids,
|
||||||
centralize,
|
|
||||||
analytic_tag_ids,
|
analytic_tag_ids,
|
||||||
cost_center_ids,
|
cost_center_ids,
|
||||||
)
|
)
|
||||||
general_ledger = self._create_general_ledger(
|
general_ledger = self._create_general_ledger(
|
||||||
gen_ld_data, accounts_data, show_partner_details, rec_after_date_to_ids
|
gen_ld_data,
|
||||||
|
accounts_data,
|
||||||
|
show_partner_details,
|
||||||
|
rec_after_date_to_ids,
|
||||||
|
hide_account_at_0,
|
||||||
)
|
)
|
||||||
if centralize:
|
if centralize:
|
||||||
for account in general_ledger:
|
for account in general_ledger:
|
||||||
|
|
Loading…
Reference in New Issue