odoo-addon-account-financial-report 15.0.1.1.0.1__py3-none-any.whl → 18.0.1.4.4.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- odoo/addons/account_financial_report/README.rst +131 -74
- odoo/addons/account_financial_report/__manifest__.py +6 -9
- odoo/addons/account_financial_report/i18n/account_financial_report.pot +313 -188
- odoo/addons/account_financial_report/i18n/ar.po +579 -433
- odoo/addons/account_financial_report/i18n/ca.po +474 -289
- odoo/addons/account_financial_report/i18n/{fr_FR.po → ca_AD.po} +539 -491
- odoo/addons/account_financial_report/i18n/ca_ES.po +1891 -0
- odoo/addons/account_financial_report/i18n/de.po +455 -295
- odoo/addons/account_financial_report/i18n/es.po +458 -394
- odoo/addons/account_financial_report/i18n/es_AR.po +464 -283
- odoo/addons/account_financial_report/i18n/es_MX.po +315 -220
- odoo/addons/account_financial_report/i18n/fr.po +620 -435
- odoo/addons/account_financial_report/i18n/fr_CH.po +616 -462
- odoo/addons/account_financial_report/i18n/hr.po +506 -355
- odoo/addons/account_financial_report/i18n/hr_HR.po +331 -232
- odoo/addons/account_financial_report/i18n/it.po +538 -356
- odoo/addons/account_financial_report/i18n/ja.po +339 -240
- odoo/addons/account_financial_report/i18n/nl.po +462 -324
- odoo/addons/account_financial_report/i18n/nl_NL.po +318 -220
- odoo/addons/account_financial_report/i18n/pt.po +429 -242
- odoo/addons/account_financial_report/i18n/pt_BR.po +588 -438
- odoo/addons/account_financial_report/i18n/ro.po +499 -342
- odoo/addons/account_financial_report/i18n/sl.po +1945 -0
- odoo/addons/account_financial_report/i18n/sv.po +1997 -0
- odoo/addons/account_financial_report/i18n/tr.po +1947 -0
- odoo/addons/account_financial_report/menuitems.xml +1 -1
- odoo/addons/account_financial_report/models/__init__.py +2 -0
- odoo/addons/account_financial_report/models/account_age_report_configuration.py +49 -0
- odoo/addons/account_financial_report/models/account_group.py +62 -23
- odoo/addons/account_financial_report/models/account_move_line.py +33 -3
- odoo/addons/account_financial_report/models/ir_actions_report.py +6 -4
- odoo/addons/account_financial_report/models/res_config_settings.py +36 -0
- odoo/addons/account_financial_report/readme/CONFIGURE.md +26 -0
- odoo/addons/account_financial_report/readme/CONTRIBUTORS.md +38 -0
- odoo/addons/account_financial_report/readme/CREDITS.md +1 -0
- odoo/addons/account_financial_report/readme/DESCRIPTION.md +21 -0
- odoo/addons/account_financial_report/readme/HISTORY.md +16 -0
- odoo/addons/account_financial_report/readme/ROADMAP.md +6 -0
- odoo/addons/account_financial_report/report/abstract_report.py +73 -23
- odoo/addons/account_financial_report/report/abstract_report_xlsx.py +28 -23
- odoo/addons/account_financial_report/report/aged_partner_balance.py +131 -30
- odoo/addons/account_financial_report/report/aged_partner_balance_xlsx.py +158 -118
- odoo/addons/account_financial_report/report/general_ledger.py +421 -340
- odoo/addons/account_financial_report/report/general_ledger_xlsx.py +127 -75
- odoo/addons/account_financial_report/report/journal_ledger.py +84 -68
- odoo/addons/account_financial_report/report/journal_ledger_xlsx.py +14 -8
- odoo/addons/account_financial_report/report/open_items.py +113 -70
- odoo/addons/account_financial_report/report/open_items_xlsx.py +152 -19
- odoo/addons/account_financial_report/report/templates/aged_partner_balance.xml +408 -311
- odoo/addons/account_financial_report/report/templates/general_ledger.xml +273 -213
- odoo/addons/account_financial_report/report/templates/journal_ledger.xml +70 -76
- odoo/addons/account_financial_report/report/templates/layouts.xml +12 -1
- odoo/addons/account_financial_report/report/templates/open_items.xml +181 -55
- odoo/addons/account_financial_report/report/templates/trial_balance.xml +304 -195
- odoo/addons/account_financial_report/report/templates/vat_report.xml +10 -10
- odoo/addons/account_financial_report/report/trial_balance.py +463 -211
- odoo/addons/account_financial_report/report/trial_balance_xlsx.py +37 -38
- odoo/addons/account_financial_report/report/vat_report.py +36 -25
- odoo/addons/account_financial_report/report/vat_report_xlsx.py +1 -1
- odoo/addons/account_financial_report/security/ir.model.access.csv +2 -0
- odoo/addons/account_financial_report/security/security.xml +8 -0
- odoo/addons/account_financial_report/static/description/index.html +106 -55
- odoo/addons/account_financial_report/static/src/css/report.css +77 -42
- odoo/addons/account_financial_report/static/src/css/report_html.css +10 -0
- odoo/addons/account_financial_report/static/src/js/report.esm.js +72 -0
- odoo/addons/account_financial_report/static/src/js/report_action.esm.js +39 -0
- odoo/addons/account_financial_report/static/src/xml/report.xml +10 -9
- odoo/addons/account_financial_report/tests/__init__.py +1 -0
- odoo/addons/account_financial_report/tests/test_age_report_configuration.py +42 -0
- odoo/addons/account_financial_report/tests/test_aged_partner_balance.py +99 -9
- odoo/addons/account_financial_report/tests/test_general_ledger.py +19 -9
- odoo/addons/account_financial_report/tests/test_journal_ledger.py +18 -9
- odoo/addons/account_financial_report/tests/test_open_items.py +42 -2
- odoo/addons/account_financial_report/tests/test_trial_balance.py +114 -223
- odoo/addons/account_financial_report/tests/test_vat_report.py +17 -9
- odoo/addons/account_financial_report/view/account_age_report_configuration_views.xml +41 -0
- odoo/addons/account_financial_report/view/res_config_settings_views.xml +51 -0
- odoo/addons/account_financial_report/wizard/abstract_wizard.py +23 -0
- odoo/addons/account_financial_report/wizard/aged_partner_balance_wizard.py +22 -8
- odoo/addons/account_financial_report/wizard/aged_partner_balance_wizard_view.xml +2 -3
- odoo/addons/account_financial_report/wizard/general_ledger_wizard.py +42 -36
- odoo/addons/account_financial_report/wizard/general_ledger_wizard_view.xml +26 -41
- odoo/addons/account_financial_report/wizard/journal_ledger_wizard.py +19 -7
- odoo/addons/account_financial_report/wizard/journal_ledger_wizard_view.xml +15 -14
- odoo/addons/account_financial_report/wizard/open_items_wizard.py +34 -8
- odoo/addons/account_financial_report/wizard/open_items_wizard_view.xml +16 -14
- odoo/addons/account_financial_report/wizard/trial_balance_wizard.py +68 -45
- odoo/addons/account_financial_report/wizard/trial_balance_wizard_view.xml +40 -39
- odoo/addons/account_financial_report/wizard/vat_report_wizard.py +9 -3
- odoo/addons/account_financial_report/wizard/vat_report_wizard_view.xml +14 -14
- odoo_addon_account_financial_report-18.0.1.4.4.3.dist-info/METADATA +234 -0
- odoo_addon_account_financial_report-18.0.1.4.4.3.dist-info/RECORD +107 -0
- {odoo_addon_account_financial_report-15.0.1.1.0.1.dist-info → odoo_addon_account_financial_report-18.0.1.4.4.3.dist-info}/WHEEL +1 -1
- odoo_addon_account_financial_report-18.0.1.4.4.3.dist-info/top_level.txt +1 -0
- odoo/addons/account_financial_report/readme/CONTRIBUTORS.rst +0 -35
- odoo/addons/account_financial_report/readme/DESCRIPTION.rst +0 -16
- odoo/addons/account_financial_report/readme/HISTORY.rst +0 -19
- odoo/addons/account_financial_report/readme/ROADMAP.rst +0 -7
- odoo/addons/account_financial_report/static/src/js/action_manager_report.js +0 -37
- odoo/addons/account_financial_report/static/src/js/client_action.js +0 -58
- odoo/addons/account_financial_report/static/src/js/report.js +0 -58
- odoo_addon_account_financial_report-15.0.1.1.0.1.dist-info/METADATA +0 -179
- odoo_addon_account_financial_report-15.0.1.1.0.1.dist-info/RECORD +0 -95
- odoo_addon_account_financial_report-15.0.1.1.0.1.dist-info/top_level.txt +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# © 2016 Julien Coux (Camptocamp)
|
|
2
2
|
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
|
|
3
|
+
# Copyright 2022 Tecnativa - V??ctor Mart??nez
|
|
3
4
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
4
5
|
|
|
5
6
|
import calendar
|
|
@@ -15,15 +16,24 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
15
16
|
_description = "General Ledger Report"
|
|
16
17
|
_inherit = "report.account_financial_report.abstract_report"
|
|
17
18
|
|
|
18
|
-
def
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
def _get_analytic_data(self, account_ids):
|
|
20
|
+
analytic_accounts = self.env["account.analytic.account"].search_fetch(
|
|
21
|
+
[("id", "in", account_ids)], ["name", "code"]
|
|
22
|
+
)
|
|
23
|
+
analytic_data = {}
|
|
24
|
+
for account in analytic_accounts:
|
|
25
|
+
name = f"[{account.code}] {account.name}" if account.code else account.name
|
|
26
|
+
analytic_data.update({account.id: {"name": name}})
|
|
27
|
+
return analytic_data
|
|
24
28
|
|
|
25
29
|
def _get_taxes_data(self, taxes_ids):
|
|
26
|
-
taxes =
|
|
30
|
+
taxes = (
|
|
31
|
+
self.env["account.tax"]
|
|
32
|
+
.with_context(active_test=False)
|
|
33
|
+
.search_fetch(
|
|
34
|
+
[("id", "in", taxes_ids)], ["amount", "amount_type", "display_name"]
|
|
35
|
+
)
|
|
36
|
+
)
|
|
27
37
|
taxes_data = {}
|
|
28
38
|
for tax in taxes:
|
|
29
39
|
taxes_data.update(
|
|
@@ -49,20 +59,28 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
49
59
|
)
|
|
50
60
|
return taxes_data
|
|
51
61
|
|
|
52
|
-
def
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
def _get_account_type_domain(self, grouped_by):
|
|
63
|
+
"""To avoid set all possible types, set in or not in as operator of the types
|
|
64
|
+
we are interested in. In v15 we used the internal_type field (type of
|
|
65
|
+
account.account.type)."""
|
|
66
|
+
at_op = "in" if grouped_by != "taxes" else "not in"
|
|
67
|
+
return [
|
|
68
|
+
("account_type", at_op, ["asset_receivable", "liability_payable"]),
|
|
56
69
|
]
|
|
70
|
+
|
|
71
|
+
def _get_acc_prt_accounts_ids(self, company_id, grouped_by):
|
|
72
|
+
accounts_domain = [
|
|
73
|
+
("company_ids", "in", [company_id]),
|
|
74
|
+
] + self._get_account_type_domain(grouped_by)
|
|
57
75
|
acc_prt_accounts = self.env["account.account"].search(accounts_domain)
|
|
58
76
|
return acc_prt_accounts.ids
|
|
59
77
|
|
|
60
78
|
def _get_initial_balances_bs_ml_domain(
|
|
61
|
-
self, account_ids, company_id, date_from, base_domain, acc_prt=False
|
|
79
|
+
self, account_ids, company_id, date_from, base_domain, grouped_by, acc_prt=False
|
|
62
80
|
):
|
|
63
81
|
accounts_domain = [
|
|
64
|
-
("
|
|
65
|
-
("
|
|
82
|
+
("company_ids", "in", [company_id]),
|
|
83
|
+
("include_initial_balance", "=", True),
|
|
66
84
|
]
|
|
67
85
|
if account_ids:
|
|
68
86
|
accounts_domain += [("id", "in", account_ids)]
|
|
@@ -72,15 +90,15 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
72
90
|
accounts = self.env["account.account"].search(accounts_domain)
|
|
73
91
|
domain += [("account_id", "in", accounts.ids)]
|
|
74
92
|
if acc_prt:
|
|
75
|
-
domain +=
|
|
93
|
+
domain += self._get_account_type_domain(grouped_by)
|
|
76
94
|
return domain
|
|
77
95
|
|
|
78
96
|
def _get_initial_balances_pl_ml_domain(
|
|
79
97
|
self, account_ids, company_id, date_from, fy_start_date, base_domain
|
|
80
98
|
):
|
|
81
99
|
accounts_domain = [
|
|
82
|
-
("
|
|
83
|
-
("
|
|
100
|
+
("company_ids", "in", [company_id]),
|
|
101
|
+
("include_initial_balance", "=", False),
|
|
84
102
|
]
|
|
85
103
|
if account_ids:
|
|
86
104
|
accounts_domain += [("id", "in", account_ids)]
|
|
@@ -94,12 +112,12 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
94
112
|
def _get_accounts_initial_balance(self, initial_domain_bs, initial_domain_pl):
|
|
95
113
|
gl_initial_acc_bs = self.env["account.move.line"].read_group(
|
|
96
114
|
domain=initial_domain_bs,
|
|
97
|
-
fields=["account_id", "debit", "credit", "balance", "amount_currency"],
|
|
115
|
+
fields=["account_id", "debit", "credit", "balance", "amount_currency:sum"],
|
|
98
116
|
groupby=["account_id"],
|
|
99
117
|
)
|
|
100
118
|
gl_initial_acc_pl = self.env["account.move.line"].read_group(
|
|
101
119
|
domain=initial_domain_pl,
|
|
102
|
-
fields=["account_id", "debit", "credit", "balance", "amount_currency"],
|
|
120
|
+
fields=["account_id", "debit", "credit", "balance", "amount_currency:sum"],
|
|
103
121
|
groupby=["account_id"],
|
|
104
122
|
)
|
|
105
123
|
gl_initial_acc = gl_initial_acc_bs + gl_initial_acc_pl
|
|
@@ -109,15 +127,19 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
109
127
|
self, account_ids, company_id, fy_start_date, base_domain
|
|
110
128
|
):
|
|
111
129
|
accounts_domain = [
|
|
112
|
-
("
|
|
113
|
-
("
|
|
130
|
+
("company_ids", "in", [company_id]),
|
|
131
|
+
("include_initial_balance", "=", False),
|
|
114
132
|
]
|
|
115
133
|
if account_ids:
|
|
116
134
|
accounts_domain += [("id", "in", account_ids)]
|
|
117
135
|
domain = []
|
|
118
136
|
domain += base_domain
|
|
119
137
|
domain += [("date", "<", fy_start_date)]
|
|
120
|
-
accounts =
|
|
138
|
+
accounts = (
|
|
139
|
+
self.env["account.account"]
|
|
140
|
+
.with_context(active_test=False)
|
|
141
|
+
.search(accounts_domain)
|
|
142
|
+
)
|
|
121
143
|
domain += [("account_id", "in", accounts.ids)]
|
|
122
144
|
return domain
|
|
123
145
|
|
|
@@ -129,7 +151,7 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
129
151
|
)
|
|
130
152
|
initial_balances = self.env["account.move.line"].read_group(
|
|
131
153
|
domain=domain,
|
|
132
|
-
fields=["account_id", "debit", "credit", "balance", "amount_currency"],
|
|
154
|
+
fields=["account_id", "debit", "credit", "balance", "amount_currency:sum"],
|
|
133
155
|
groupby=["account_id"],
|
|
134
156
|
)
|
|
135
157
|
pl_initial_balance = {
|
|
@@ -145,154 +167,168 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
145
167
|
pl_initial_balance["bal_curr"] += initial_balance["amount_currency"]
|
|
146
168
|
return pl_initial_balance
|
|
147
169
|
|
|
148
|
-
def
|
|
170
|
+
def _get_gl_initial_acc(
|
|
149
171
|
self,
|
|
150
172
|
account_ids,
|
|
151
|
-
partner_ids,
|
|
152
173
|
company_id,
|
|
153
174
|
date_from,
|
|
154
|
-
foreign_currency,
|
|
155
|
-
only_posted_moves,
|
|
156
|
-
unaffected_earnings_account,
|
|
157
175
|
fy_start_date,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
extra_domain,
|
|
176
|
+
base_domain,
|
|
177
|
+
grouped_by,
|
|
161
178
|
):
|
|
162
|
-
# If explicit list of accounts is provided,
|
|
163
|
-
# don't include unaffected earnings account
|
|
164
|
-
if account_ids:
|
|
165
|
-
unaffected_earnings_account = False
|
|
166
|
-
base_domain = []
|
|
167
|
-
if company_id:
|
|
168
|
-
base_domain += [("company_id", "=", company_id)]
|
|
169
|
-
if partner_ids:
|
|
170
|
-
base_domain += [("partner_id", "in", partner_ids)]
|
|
171
|
-
if only_posted_moves:
|
|
172
|
-
base_domain += [("move_id.state", "=", "posted")]
|
|
173
|
-
else:
|
|
174
|
-
base_domain += [("move_id.state", "in", ["posted", "draft"])]
|
|
175
|
-
if analytic_tag_ids:
|
|
176
|
-
base_domain += [("analytic_tag_ids", "in", analytic_tag_ids)]
|
|
177
|
-
if cost_center_ids:
|
|
178
|
-
base_domain += [("analytic_account_id", "in", cost_center_ids)]
|
|
179
|
-
if extra_domain:
|
|
180
|
-
base_domain += extra_domain
|
|
181
179
|
initial_domain_bs = self._get_initial_balances_bs_ml_domain(
|
|
182
|
-
account_ids, company_id, date_from, base_domain
|
|
180
|
+
account_ids, company_id, date_from, base_domain, grouped_by
|
|
183
181
|
)
|
|
184
182
|
initial_domain_pl = self._get_initial_balances_pl_ml_domain(
|
|
185
183
|
account_ids, company_id, date_from, fy_start_date, base_domain
|
|
186
184
|
)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
185
|
+
return self._get_accounts_initial_balance(initial_domain_bs, initial_domain_pl)
|
|
186
|
+
|
|
187
|
+
def _prepare_gen_ld_data_item(self, gl):
|
|
188
|
+
res = {}
|
|
189
|
+
for key_bal in ["init_bal", "fin_bal"]:
|
|
190
|
+
res[key_bal] = {}
|
|
191
|
+
for key_field in ["credit", "debit", "balance", "bal_curr"]:
|
|
192
|
+
field_name = key_field if key_field != "bal_curr" else "amount_currency"
|
|
193
|
+
res[key_bal][key_field] = gl[field_name]
|
|
194
|
+
return res
|
|
195
|
+
|
|
196
|
+
def _prepare_gen_ld_data(self, gl_initial_acc, domain, grouped_by):
|
|
197
|
+
data = {}
|
|
198
|
+
for gl in gl_initial_acc:
|
|
199
|
+
acc_id = gl["account_id"][0]
|
|
200
|
+
data[acc_id] = self._prepare_gen_ld_data_item(gl)
|
|
201
|
+
data[acc_id]["id"] = acc_id
|
|
202
|
+
data[acc_id][grouped_by] = False
|
|
203
|
+
method = f"_prepare_gen_ld_data_group_{grouped_by}"
|
|
204
|
+
if not hasattr(self, method):
|
|
205
|
+
return data
|
|
206
|
+
return getattr(self, method)(data, domain, grouped_by)
|
|
207
|
+
|
|
208
|
+
def _prepare_gen_ld_data_group_partners(self, data, domain, grouped_by):
|
|
193
209
|
gl_initial_acc_prt = self.env["account.move.line"].read_group(
|
|
194
|
-
domain=
|
|
210
|
+
domain=domain,
|
|
195
211
|
fields=[
|
|
196
212
|
"account_id",
|
|
197
213
|
"partner_id",
|
|
198
214
|
"debit",
|
|
199
215
|
"credit",
|
|
200
216
|
"balance",
|
|
201
|
-
"amount_currency",
|
|
217
|
+
"amount_currency:sum",
|
|
202
218
|
],
|
|
203
219
|
groupby=["account_id", "partner_id"],
|
|
204
220
|
lazy=False,
|
|
205
221
|
)
|
|
206
|
-
gen_ld_data = {}
|
|
207
|
-
for gl in gl_initial_acc:
|
|
208
|
-
acc_id = gl["account_id"][0]
|
|
209
|
-
gen_ld_data[acc_id] = {}
|
|
210
|
-
gen_ld_data[acc_id]["id"] = acc_id
|
|
211
|
-
gen_ld_data[acc_id]["partners"] = False
|
|
212
|
-
gen_ld_data[acc_id]["init_bal"] = {}
|
|
213
|
-
gen_ld_data[acc_id]["init_bal"]["credit"] = gl["credit"]
|
|
214
|
-
gen_ld_data[acc_id]["init_bal"]["debit"] = gl["debit"]
|
|
215
|
-
gen_ld_data[acc_id]["init_bal"]["balance"] = gl["balance"]
|
|
216
|
-
gen_ld_data[acc_id]["fin_bal"] = {}
|
|
217
|
-
gen_ld_data[acc_id]["fin_bal"]["credit"] = gl["credit"]
|
|
218
|
-
gen_ld_data[acc_id]["fin_bal"]["debit"] = gl["debit"]
|
|
219
|
-
gen_ld_data[acc_id]["fin_bal"]["balance"] = gl["balance"]
|
|
220
|
-
gen_ld_data[acc_id]["init_bal"]["bal_curr"] = gl["amount_currency"]
|
|
221
|
-
gen_ld_data[acc_id]["fin_bal"]["bal_curr"] = gl["amount_currency"]
|
|
222
|
-
partners_data = {}
|
|
223
|
-
partners_ids = set()
|
|
224
222
|
if gl_initial_acc_prt:
|
|
225
223
|
for gl in gl_initial_acc_prt:
|
|
226
224
|
if not gl["partner_id"]:
|
|
227
225
|
prt_id = 0
|
|
228
|
-
prt_name = "Missing Partner"
|
|
226
|
+
prt_name = _("Missing Partner")
|
|
229
227
|
else:
|
|
230
228
|
prt_id = gl["partner_id"][0]
|
|
231
229
|
prt_name = gl["partner_id"][1]
|
|
232
|
-
prt_name = prt_name._value
|
|
233
|
-
if prt_id not in partners_ids:
|
|
234
|
-
partners_ids.add(prt_id)
|
|
235
|
-
partners_data.update({prt_id: {"id": prt_id, "name": prt_name}})
|
|
236
230
|
acc_id = gl["account_id"][0]
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
231
|
+
data[acc_id][prt_id] = self._prepare_gen_ld_data_item(gl)
|
|
232
|
+
data[acc_id][prt_id]["id"] = prt_id
|
|
233
|
+
data[acc_id][prt_id]["name"] = prt_name
|
|
234
|
+
data[acc_id][grouped_by] = True
|
|
235
|
+
return data
|
|
236
|
+
|
|
237
|
+
def _prepare_gen_ld_data_group_taxes(self, data, domain, grouped_by):
|
|
238
|
+
gl_initial_acc_prt = self.env["account.move.line"].read_group(
|
|
239
|
+
domain=domain,
|
|
240
|
+
fields=[
|
|
241
|
+
"account_id",
|
|
242
|
+
"debit",
|
|
243
|
+
"credit",
|
|
244
|
+
"balance",
|
|
245
|
+
"amount_currency:sum",
|
|
246
|
+
"tax_line_id",
|
|
247
|
+
],
|
|
248
|
+
groupby=["account_id"],
|
|
249
|
+
lazy=False,
|
|
250
|
+
)
|
|
251
|
+
if gl_initial_acc_prt:
|
|
252
|
+
for gl in gl_initial_acc_prt:
|
|
253
|
+
if "tax_line_id" in gl and gl["tax_line_id"]:
|
|
254
|
+
tax_id = gl["tax_line_id"][0]
|
|
255
|
+
tax_name = gl["tax_line_id"][1]
|
|
256
|
+
else:
|
|
257
|
+
tax_id = 0
|
|
258
|
+
tax_name = "Missing Tax"
|
|
259
|
+
acc_id = gl["account_id"][0]
|
|
260
|
+
data[acc_id][tax_id] = self._prepare_gen_ld_data_item(gl)
|
|
261
|
+
data[acc_id][tax_id]["id"] = tax_id
|
|
262
|
+
data[acc_id][tax_id]["name"] = tax_name
|
|
263
|
+
data[acc_id][grouped_by] = True
|
|
264
|
+
return data
|
|
265
|
+
|
|
266
|
+
def _get_initial_balance_data(
|
|
267
|
+
self,
|
|
268
|
+
account_ids,
|
|
269
|
+
partner_ids,
|
|
270
|
+
company_id,
|
|
271
|
+
date_from,
|
|
272
|
+
foreign_currency,
|
|
273
|
+
only_posted_moves,
|
|
274
|
+
unaffected_earnings_account,
|
|
275
|
+
fy_start_date,
|
|
276
|
+
cost_center_ids,
|
|
277
|
+
extra_domain,
|
|
278
|
+
grouped_by,
|
|
279
|
+
):
|
|
280
|
+
# If explicit list of accounts is provided,
|
|
281
|
+
# don't include unaffected earnings account
|
|
282
|
+
if account_ids:
|
|
283
|
+
unaffected_earnings_account = False
|
|
284
|
+
base_domain = []
|
|
285
|
+
if company_id:
|
|
286
|
+
base_domain += [("company_id", "in", [company_id])]
|
|
287
|
+
if partner_ids:
|
|
288
|
+
base_domain += [("partner_id", "in", partner_ids)]
|
|
289
|
+
if only_posted_moves:
|
|
290
|
+
base_domain += [("move_id.state", "=", "posted")]
|
|
291
|
+
else:
|
|
292
|
+
base_domain += [("move_id.state", "in", ["posted", "draft"])]
|
|
293
|
+
if cost_center_ids:
|
|
294
|
+
base_domain += [("analytic_account_ids", "in", cost_center_ids)]
|
|
295
|
+
if extra_domain:
|
|
296
|
+
base_domain += extra_domain
|
|
297
|
+
gl_initial_acc = self._get_gl_initial_acc(
|
|
298
|
+
account_ids, company_id, date_from, fy_start_date, base_domain, grouped_by
|
|
299
|
+
)
|
|
300
|
+
domain = self._get_initial_balances_bs_ml_domain(
|
|
301
|
+
account_ids, company_id, date_from, base_domain, grouped_by, acc_prt=True
|
|
302
|
+
)
|
|
303
|
+
data = self._prepare_gen_ld_data(gl_initial_acc, domain, grouped_by)
|
|
304
|
+
accounts_ids = list(data.keys())
|
|
255
305
|
unaffected_id = unaffected_earnings_account
|
|
256
306
|
if unaffected_id:
|
|
257
307
|
if unaffected_id not in accounts_ids:
|
|
258
308
|
accounts_ids.append(unaffected_id)
|
|
259
|
-
self.
|
|
309
|
+
data[unaffected_id] = self._initialize_data(foreign_currency)
|
|
310
|
+
data[unaffected_id]["id"] = unaffected_id
|
|
311
|
+
data[unaffected_id]["mame"] = ""
|
|
312
|
+
data[unaffected_id][grouped_by] = False
|
|
260
313
|
pl_initial_balance = self._get_pl_initial_balance(
|
|
261
314
|
account_ids, company_id, fy_start_date, foreign_currency, base_domain
|
|
262
315
|
)
|
|
263
|
-
|
|
264
|
-
"debit"
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
gen_ld_data[unaffected_id]["fin_bal"]["debit"] += pl_initial_balance[
|
|
273
|
-
"debit"
|
|
274
|
-
]
|
|
275
|
-
gen_ld_data[unaffected_id]["fin_bal"]["credit"] += pl_initial_balance[
|
|
276
|
-
"credit"
|
|
277
|
-
]
|
|
278
|
-
gen_ld_data[unaffected_id]["fin_bal"]["balance"] += pl_initial_balance[
|
|
279
|
-
"balance"
|
|
280
|
-
]
|
|
281
|
-
if foreign_currency:
|
|
282
|
-
gen_ld_data[unaffected_id]["init_bal"][
|
|
283
|
-
"bal_curr"
|
|
284
|
-
] += pl_initial_balance["bal_curr"]
|
|
285
|
-
gen_ld_data[unaffected_id]["fin_bal"]["bal_curr"] += pl_initial_balance[
|
|
286
|
-
"bal_curr"
|
|
287
|
-
]
|
|
288
|
-
return gen_ld_data, partners_data, partner_ids
|
|
316
|
+
for key_bal in ["init_bal", "fin_bal"]:
|
|
317
|
+
fields_balance = ["credit", "debit", "balance"]
|
|
318
|
+
if foreign_currency:
|
|
319
|
+
fields_balance.append("bal_curr")
|
|
320
|
+
for field_name in fields_balance:
|
|
321
|
+
data[unaffected_id][key_bal][field_name] += pl_initial_balance[
|
|
322
|
+
field_name
|
|
323
|
+
]
|
|
324
|
+
return data
|
|
289
325
|
|
|
290
326
|
@api.model
|
|
291
327
|
def _get_move_line_data(self, move_line):
|
|
292
328
|
move_line_data = {
|
|
293
329
|
"id": move_line["id"],
|
|
294
330
|
"date": move_line["date"],
|
|
295
|
-
"entry": move_line["
|
|
331
|
+
"entry": move_line["move_name"],
|
|
296
332
|
"entry_id": move_line["move_id"][0],
|
|
297
333
|
"journal_id": move_line["journal_id"][0],
|
|
298
334
|
"account_id": move_line["account_id"][0],
|
|
@@ -305,6 +341,7 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
305
341
|
"ref": "" if not move_line["ref"] else move_line["ref"],
|
|
306
342
|
"name": "" if not move_line["name"] else move_line["name"],
|
|
307
343
|
"tax_ids": move_line["tax_ids"],
|
|
344
|
+
"tax_line_id": move_line["tax_line_id"],
|
|
308
345
|
"debit": move_line["debit"],
|
|
309
346
|
"credit": move_line["credit"],
|
|
310
347
|
"balance": move_line["balance"],
|
|
@@ -312,17 +349,11 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
312
349
|
"rec_id": move_line["full_reconcile_id"][0]
|
|
313
350
|
if move_line["full_reconcile_id"]
|
|
314
351
|
else False,
|
|
315
|
-
"rec_name": move_line["
|
|
352
|
+
"rec_name": move_line["matching_number"]
|
|
316
353
|
if move_line["full_reconcile_id"]
|
|
317
354
|
else "",
|
|
318
|
-
"tag_ids": move_line["analytic_tag_ids"],
|
|
319
355
|
"currency_id": move_line["currency_id"],
|
|
320
|
-
"
|
|
321
|
-
if move_line["analytic_account_id"]
|
|
322
|
-
else "",
|
|
323
|
-
"analytic_account_id": move_line["analytic_account_id"][0]
|
|
324
|
-
if move_line["analytic_account_id"]
|
|
325
|
-
else False,
|
|
356
|
+
"analytic_distribution": move_line["analytic_distribution"] or {},
|
|
326
357
|
}
|
|
327
358
|
if (
|
|
328
359
|
move_line_data["ref"] == move_line_data["name"]
|
|
@@ -332,7 +363,7 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
332
363
|
elif move_line_data["name"] == "":
|
|
333
364
|
ref_label = move_line_data["ref"]
|
|
334
365
|
else:
|
|
335
|
-
ref_label = move_line_data["ref"] +
|
|
366
|
+
ref_label = move_line_data["ref"] + " - " + move_line_data["name"]
|
|
336
367
|
move_line_data.update({"ref_label": ref_label})
|
|
337
368
|
return move_line_data
|
|
338
369
|
|
|
@@ -345,11 +376,10 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
345
376
|
only_posted_moves,
|
|
346
377
|
date_to,
|
|
347
378
|
date_from,
|
|
348
|
-
analytic_tag_ids,
|
|
349
379
|
cost_center_ids,
|
|
350
380
|
):
|
|
351
381
|
domain = [
|
|
352
|
-
("display_type", "
|
|
382
|
+
("display_type", "not in", ["line_note", "line_section"]),
|
|
353
383
|
("date", ">=", date_from),
|
|
354
384
|
("date", "<=", date_to),
|
|
355
385
|
]
|
|
@@ -363,46 +393,19 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
363
393
|
domain += [("move_id.state", "=", "posted")]
|
|
364
394
|
else:
|
|
365
395
|
domain += [("move_id.state", "in", ["posted", "draft"])]
|
|
366
|
-
if analytic_tag_ids:
|
|
367
|
-
domain += [("analytic_tag_ids", "in", analytic_tag_ids)]
|
|
368
396
|
if cost_center_ids:
|
|
369
|
-
domain += [("
|
|
397
|
+
domain += [("analytic_account_ids", "in", cost_center_ids)]
|
|
370
398
|
return domain
|
|
371
399
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
gen_ld_data[acc_id][prt_id]["fin_bal"] = {}
|
|
382
|
-
gen_ld_data[acc_id][prt_id]["fin_bal"]["credit"] = 0.0
|
|
383
|
-
gen_ld_data[acc_id][prt_id]["fin_bal"]["debit"] = 0.0
|
|
384
|
-
gen_ld_data[acc_id][prt_id]["fin_bal"]["balance"] = 0.0
|
|
385
|
-
if foreign_currency:
|
|
386
|
-
gen_ld_data[acc_id][prt_id]["init_bal"]["bal_curr"] = 0.0
|
|
387
|
-
gen_ld_data[acc_id][prt_id]["fin_bal"]["bal_curr"] = 0.0
|
|
388
|
-
return gen_ld_data
|
|
389
|
-
|
|
390
|
-
def _initialize_account(self, gen_ld_data, acc_id, foreign_currency):
|
|
391
|
-
gen_ld_data[acc_id] = {}
|
|
392
|
-
gen_ld_data[acc_id]["id"] = acc_id
|
|
393
|
-
gen_ld_data[acc_id]["partners"] = False
|
|
394
|
-
gen_ld_data[acc_id]["init_bal"] = {}
|
|
395
|
-
gen_ld_data[acc_id]["init_bal"]["balance"] = 0.0
|
|
396
|
-
gen_ld_data[acc_id]["init_bal"]["credit"] = 0.0
|
|
397
|
-
gen_ld_data[acc_id]["init_bal"]["debit"] = 0.0
|
|
398
|
-
gen_ld_data[acc_id]["fin_bal"] = {}
|
|
399
|
-
gen_ld_data[acc_id]["fin_bal"]["credit"] = 0.0
|
|
400
|
-
gen_ld_data[acc_id]["fin_bal"]["debit"] = 0.0
|
|
401
|
-
gen_ld_data[acc_id]["fin_bal"]["balance"] = 0.0
|
|
402
|
-
if foreign_currency:
|
|
403
|
-
gen_ld_data[acc_id]["init_bal"]["bal_curr"] = 0.0
|
|
404
|
-
gen_ld_data[acc_id]["fin_bal"]["bal_curr"] = 0.0
|
|
405
|
-
return gen_ld_data
|
|
400
|
+
def _initialize_data(self, foreign_currency):
|
|
401
|
+
res = {}
|
|
402
|
+
for key_bal in ["init_bal", "fin_bal"]:
|
|
403
|
+
res[key_bal] = {}
|
|
404
|
+
for key_field in ["balance", "credit", "debit"]:
|
|
405
|
+
res[key_bal][key_field] = 0.0
|
|
406
|
+
if foreign_currency:
|
|
407
|
+
res[key_bal]["bal_curr"] = 0.0
|
|
408
|
+
return res
|
|
406
409
|
|
|
407
410
|
def _get_reconciled_after_date_to_ids(self, full_reconcile_ids, date_to):
|
|
408
411
|
full_reconcile_ids = list(full_reconcile_ids)
|
|
@@ -420,6 +423,35 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
420
423
|
rec_after_date_to_ids = [i[0] for i in rec_after_date_to_ids]
|
|
421
424
|
return rec_after_date_to_ids
|
|
422
425
|
|
|
426
|
+
def _prepare_ml_items(self, move_line, grouped_by):
|
|
427
|
+
res = []
|
|
428
|
+
if grouped_by == "partners":
|
|
429
|
+
item_id = move_line["partner_id"][0] if move_line["partner_id"] else 0
|
|
430
|
+
item_name = (
|
|
431
|
+
move_line["partner_id"][1]
|
|
432
|
+
if move_line["partner_id"]
|
|
433
|
+
else _("Missing Partner")
|
|
434
|
+
)
|
|
435
|
+
res.append({"id": item_id, "name": item_name})
|
|
436
|
+
elif grouped_by == "taxes":
|
|
437
|
+
if move_line["tax_line_id"]:
|
|
438
|
+
item_id = move_line["tax_line_id"][0]
|
|
439
|
+
item_name = move_line["tax_line_id"][1]
|
|
440
|
+
res.append({"id": item_id, "name": item_name})
|
|
441
|
+
elif move_line["tax_ids"]:
|
|
442
|
+
for tax_id in move_line["tax_ids"]:
|
|
443
|
+
tax_item = (
|
|
444
|
+
self.env["account.tax"]
|
|
445
|
+
.with_context(active_test=False)
|
|
446
|
+
.search_fetch([("id", "=", tax_id)], ["name"])
|
|
447
|
+
)
|
|
448
|
+
res.append({"id": tax_item.id, "name": tax_item.name})
|
|
449
|
+
else:
|
|
450
|
+
res.append({"id": 0, "name": "Missing Tax"})
|
|
451
|
+
else:
|
|
452
|
+
res.append({"id": 0, "name": ""})
|
|
453
|
+
return res
|
|
454
|
+
|
|
423
455
|
def _get_period_ml_data(
|
|
424
456
|
self,
|
|
425
457
|
account_ids,
|
|
@@ -429,12 +461,10 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
429
461
|
only_posted_moves,
|
|
430
462
|
date_from,
|
|
431
463
|
date_to,
|
|
432
|
-
partners_data,
|
|
433
464
|
gen_ld_data,
|
|
434
|
-
partners_ids,
|
|
435
|
-
analytic_tag_ids,
|
|
436
465
|
cost_center_ids,
|
|
437
466
|
extra_domain,
|
|
467
|
+
grouped_by,
|
|
438
468
|
):
|
|
439
469
|
domain = self._get_period_domain(
|
|
440
470
|
account_ids,
|
|
@@ -443,46 +473,27 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
443
473
|
only_posted_moves,
|
|
444
474
|
date_to,
|
|
445
475
|
date_from,
|
|
446
|
-
analytic_tag_ids,
|
|
447
476
|
cost_center_ids,
|
|
448
477
|
)
|
|
449
478
|
if extra_domain:
|
|
450
479
|
domain += extra_domain
|
|
451
|
-
ml_fields =
|
|
452
|
-
"id",
|
|
453
|
-
"name",
|
|
454
|
-
"date",
|
|
455
|
-
"move_id",
|
|
456
|
-
"journal_id",
|
|
457
|
-
"account_id",
|
|
458
|
-
"partner_id",
|
|
459
|
-
"debit",
|
|
460
|
-
"credit",
|
|
461
|
-
"balance",
|
|
462
|
-
"currency_id",
|
|
463
|
-
"full_reconcile_id",
|
|
464
|
-
"tax_ids",
|
|
465
|
-
"analytic_tag_ids",
|
|
466
|
-
"amount_currency",
|
|
467
|
-
"ref",
|
|
468
|
-
"name",
|
|
469
|
-
"analytic_account_id",
|
|
470
|
-
]
|
|
480
|
+
ml_fields = self._get_ml_fields()
|
|
471
481
|
move_lines = self.env["account.move.line"].search_read(
|
|
472
|
-
domain=domain, fields=ml_fields
|
|
482
|
+
domain=domain, fields=ml_fields, order="date,move_name"
|
|
473
483
|
)
|
|
474
484
|
journal_ids = set()
|
|
475
485
|
full_reconcile_ids = set()
|
|
476
486
|
taxes_ids = set()
|
|
477
|
-
|
|
487
|
+
analytic_ids = set()
|
|
478
488
|
full_reconcile_data = {}
|
|
479
|
-
acc_prt_account_ids = self._get_acc_prt_accounts_ids(company_id)
|
|
489
|
+
acc_prt_account_ids = self._get_acc_prt_accounts_ids(company_id, grouped_by)
|
|
480
490
|
for move_line in move_lines:
|
|
481
491
|
journal_ids.add(move_line["journal_id"][0])
|
|
482
492
|
for tax_id in move_line["tax_ids"]:
|
|
483
493
|
taxes_ids.add(tax_id)
|
|
484
|
-
for
|
|
485
|
-
|
|
494
|
+
for analytic_account in move_line["analytic_distribution"] or {}:
|
|
495
|
+
for analytic_account_id in analytic_account.split(","):
|
|
496
|
+
analytic_ids.add(int(analytic_account_id))
|
|
486
497
|
if move_line["full_reconcile_id"]:
|
|
487
498
|
rec_id = move_line["full_reconcile_id"][0]
|
|
488
499
|
if rec_id not in full_reconcile_ids:
|
|
@@ -490,40 +501,45 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
490
501
|
{
|
|
491
502
|
rec_id: {
|
|
492
503
|
"id": rec_id,
|
|
493
|
-
"name": move_line["
|
|
504
|
+
"name": move_line["matching_number"],
|
|
494
505
|
}
|
|
495
506
|
}
|
|
496
507
|
)
|
|
497
508
|
full_reconcile_ids.add(rec_id)
|
|
498
509
|
acc_id = move_line["account_id"][0]
|
|
499
510
|
ml_id = move_line["id"]
|
|
500
|
-
if move_line["partner_id"]:
|
|
501
|
-
prt_id = move_line["partner_id"][0]
|
|
502
|
-
partner_name = move_line["partner_id"][1]
|
|
503
511
|
if acc_id not in gen_ld_data.keys():
|
|
504
|
-
gen_ld_data = self.
|
|
505
|
-
|
|
506
|
-
|
|
512
|
+
gen_ld_data[acc_id] = self._initialize_data(foreign_currency)
|
|
513
|
+
gen_ld_data[acc_id]["id"] = acc_id
|
|
514
|
+
gen_ld_data[acc_id]["mame"] = move_line["account_id"][1]
|
|
515
|
+
gen_ld_data[acc_id][grouped_by] = False
|
|
507
516
|
if acc_id in acc_prt_account_ids:
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
517
|
+
item_ids = self._prepare_ml_items(move_line, grouped_by)
|
|
518
|
+
for item in item_ids:
|
|
519
|
+
item_id = item["id"]
|
|
520
|
+
if item_id not in gen_ld_data[acc_id]:
|
|
521
|
+
gen_ld_data[acc_id][grouped_by] = True
|
|
522
|
+
gen_ld_data[acc_id][item_id] = self._initialize_data(
|
|
523
|
+
foreign_currency
|
|
524
|
+
)
|
|
525
|
+
gen_ld_data[acc_id][item_id]["id"] = item_id
|
|
526
|
+
gen_ld_data[acc_id][item_id]["name"] = item["name"]
|
|
527
|
+
gen_ld_data[acc_id][item_id][ml_id] = self._get_move_line_data(
|
|
528
|
+
move_line
|
|
516
529
|
)
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
"amount_currency"
|
|
530
|
+
gen_ld_data[acc_id][item_id]["fin_bal"]["credit"] += move_line[
|
|
531
|
+
"credit"
|
|
532
|
+
]
|
|
533
|
+
gen_ld_data[acc_id][item_id]["fin_bal"]["debit"] += move_line[
|
|
534
|
+
"debit"
|
|
535
|
+
]
|
|
536
|
+
gen_ld_data[acc_id][item_id]["fin_bal"]["balance"] += move_line[
|
|
537
|
+
"balance"
|
|
526
538
|
]
|
|
539
|
+
if foreign_currency:
|
|
540
|
+
gen_ld_data[acc_id][item_id]["fin_bal"]["bal_curr"] += (
|
|
541
|
+
move_line["amount_currency"]
|
|
542
|
+
)
|
|
527
543
|
else:
|
|
528
544
|
gen_ld_data[acc_id][ml_id] = self._get_move_line_data(move_line)
|
|
529
545
|
gen_ld_data[acc_id]["fin_bal"]["credit"] += move_line["credit"]
|
|
@@ -536,18 +552,17 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
536
552
|
journals_data = self._get_journals_data(list(journal_ids))
|
|
537
553
|
accounts_data = self._get_accounts_data(gen_ld_data.keys())
|
|
538
554
|
taxes_data = self._get_taxes_data(list(taxes_ids))
|
|
539
|
-
|
|
555
|
+
analytic_data = self._get_analytic_data(list(analytic_ids))
|
|
540
556
|
rec_after_date_to_ids = self._get_reconciled_after_date_to_ids(
|
|
541
557
|
full_reconcile_data.keys(), date_to
|
|
542
558
|
)
|
|
543
559
|
return (
|
|
544
560
|
gen_ld_data,
|
|
545
561
|
accounts_data,
|
|
546
|
-
partners_data,
|
|
547
562
|
journals_data,
|
|
548
563
|
full_reconcile_data,
|
|
549
564
|
taxes_data,
|
|
550
|
-
|
|
565
|
+
analytic_data,
|
|
551
566
|
rec_after_date_to_ids,
|
|
552
567
|
)
|
|
553
568
|
|
|
@@ -578,14 +593,14 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
578
593
|
account.update({"move_lines": move_lines})
|
|
579
594
|
return account
|
|
580
595
|
|
|
581
|
-
def
|
|
582
|
-
self, account, acc_id, gen_led_data, rec_after_date_to_ids
|
|
596
|
+
def _create_account_not_show_item(
|
|
597
|
+
self, account, acc_id, gen_led_data, rec_after_date_to_ids, grouped_by
|
|
583
598
|
):
|
|
584
599
|
move_lines = []
|
|
585
600
|
for prt_id in gen_led_data[acc_id].keys():
|
|
586
601
|
if not isinstance(prt_id, int):
|
|
587
602
|
account.update({prt_id: gen_led_data[acc_id][prt_id]})
|
|
588
|
-
|
|
603
|
+
elif isinstance(gen_led_data[acc_id][prt_id], dict):
|
|
589
604
|
for ml_id in gen_led_data[acc_id][prt_id].keys():
|
|
590
605
|
if isinstance(ml_id, int):
|
|
591
606
|
move_lines += [gen_led_data[acc_id][prt_id][ml_id]]
|
|
@@ -595,14 +610,48 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
595
610
|
gen_led_data[acc_id]["init_bal"]["balance"],
|
|
596
611
|
rec_after_date_to_ids,
|
|
597
612
|
)
|
|
598
|
-
account.update({"move_lines": move_lines,
|
|
613
|
+
account.update({"move_lines": move_lines, grouped_by: False})
|
|
599
614
|
return account
|
|
600
615
|
|
|
616
|
+
def _get_list_grouped_item(
|
|
617
|
+
self, data, account, rec_after_date_to_ids, hide_account_at_0, rounding
|
|
618
|
+
):
|
|
619
|
+
list_grouped = []
|
|
620
|
+
for data_id in data.keys():
|
|
621
|
+
group_item = {}
|
|
622
|
+
move_lines = []
|
|
623
|
+
if not isinstance(data_id, int):
|
|
624
|
+
account.update({data_id: data[data_id]})
|
|
625
|
+
else:
|
|
626
|
+
for ml_id in data[data_id].keys():
|
|
627
|
+
if not isinstance(ml_id, int):
|
|
628
|
+
group_item.update({ml_id: data[data_id][ml_id]})
|
|
629
|
+
else:
|
|
630
|
+
move_lines += [data[data_id][ml_id]]
|
|
631
|
+
move_lines = sorted(move_lines, key=lambda k: (k["date"]))
|
|
632
|
+
move_lines = self._recalculate_cumul_balance(
|
|
633
|
+
move_lines,
|
|
634
|
+
data[data_id]["init_bal"]["balance"],
|
|
635
|
+
rec_after_date_to_ids,
|
|
636
|
+
)
|
|
637
|
+
group_item.update({"move_lines": move_lines})
|
|
638
|
+
if (
|
|
639
|
+
hide_account_at_0
|
|
640
|
+
and float_is_zero(
|
|
641
|
+
data[data_id]["init_bal"]["balance"],
|
|
642
|
+
precision_rounding=rounding,
|
|
643
|
+
)
|
|
644
|
+
and group_item["move_lines"] == []
|
|
645
|
+
):
|
|
646
|
+
continue
|
|
647
|
+
list_grouped += [group_item]
|
|
648
|
+
return account, list_grouped
|
|
649
|
+
|
|
601
650
|
def _create_general_ledger(
|
|
602
651
|
self,
|
|
603
652
|
gen_led_data,
|
|
604
653
|
accounts_data,
|
|
605
|
-
|
|
654
|
+
grouped_by,
|
|
606
655
|
rec_after_date_to_ids,
|
|
607
656
|
hide_account_at_0,
|
|
608
657
|
):
|
|
@@ -617,9 +666,10 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
617
666
|
"type": "account",
|
|
618
667
|
"currency_id": accounts_data[acc_id]["currency_id"],
|
|
619
668
|
"centralized": accounts_data[acc_id]["centralized"],
|
|
669
|
+
"grouped_by": grouped_by,
|
|
620
670
|
}
|
|
621
671
|
)
|
|
622
|
-
if not gen_led_data[acc_id][
|
|
672
|
+
if not gen_led_data[acc_id][grouped_by]:
|
|
623
673
|
account = self._create_account(
|
|
624
674
|
account, acc_id, gen_led_data, rec_after_date_to_ids
|
|
625
675
|
)
|
|
@@ -633,61 +683,23 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
633
683
|
):
|
|
634
684
|
continue
|
|
635
685
|
else:
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
else:
|
|
650
|
-
move_lines += [gen_led_data[acc_id][prt_id][ml_id]]
|
|
651
|
-
move_lines = sorted(move_lines, key=lambda k: (k["date"]))
|
|
652
|
-
move_lines = self._recalculate_cumul_balance(
|
|
653
|
-
move_lines,
|
|
654
|
-
gen_led_data[acc_id][prt_id]["init_bal"]["balance"],
|
|
655
|
-
rec_after_date_to_ids,
|
|
656
|
-
)
|
|
657
|
-
partner.update({"move_lines": move_lines})
|
|
658
|
-
if (
|
|
659
|
-
hide_account_at_0
|
|
660
|
-
and float_is_zero(
|
|
661
|
-
gen_led_data[acc_id][prt_id]["init_bal"]["balance"],
|
|
662
|
-
precision_rounding=rounding,
|
|
663
|
-
)
|
|
664
|
-
and partner["move_lines"] == []
|
|
665
|
-
):
|
|
666
|
-
continue
|
|
667
|
-
list_partner += [partner]
|
|
668
|
-
account.update({"list_partner": list_partner})
|
|
669
|
-
if (
|
|
670
|
-
hide_account_at_0
|
|
671
|
-
and float_is_zero(
|
|
672
|
-
gen_led_data[acc_id]["init_bal"]["balance"],
|
|
673
|
-
precision_rounding=rounding,
|
|
674
|
-
)
|
|
675
|
-
and account["list_partner"] == []
|
|
676
|
-
):
|
|
677
|
-
continue
|
|
678
|
-
else:
|
|
679
|
-
account = self._create_account_not_show_partner(
|
|
680
|
-
account, acc_id, gen_led_data, rec_after_date_to_ids
|
|
686
|
+
account, list_grouped = self._get_list_grouped_item(
|
|
687
|
+
gen_led_data[acc_id],
|
|
688
|
+
account,
|
|
689
|
+
rec_after_date_to_ids,
|
|
690
|
+
hide_account_at_0,
|
|
691
|
+
rounding,
|
|
692
|
+
)
|
|
693
|
+
account.update({"list_grouped": list_grouped})
|
|
694
|
+
if (
|
|
695
|
+
hide_account_at_0
|
|
696
|
+
and float_is_zero(
|
|
697
|
+
gen_led_data[acc_id]["init_bal"]["balance"],
|
|
698
|
+
precision_rounding=rounding,
|
|
681
699
|
)
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
gen_led_data[acc_id]["init_bal"]["balance"],
|
|
686
|
-
precision_rounding=rounding,
|
|
687
|
-
)
|
|
688
|
-
and account["move_lines"] == []
|
|
689
|
-
):
|
|
690
|
-
continue
|
|
700
|
+
and account["list_grouped"] == []
|
|
701
|
+
):
|
|
702
|
+
continue
|
|
691
703
|
general_ledger += [account]
|
|
692
704
|
return general_ledger
|
|
693
705
|
|
|
@@ -716,11 +728,11 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
716
728
|
"rec_id": 0,
|
|
717
729
|
"entry_id": False,
|
|
718
730
|
"tax_ids": [],
|
|
731
|
+
"tax_line_id": False,
|
|
719
732
|
"full_reconcile_id": False,
|
|
720
733
|
"id": False,
|
|
721
|
-
"tag_ids": False,
|
|
722
734
|
"currency_id": False,
|
|
723
|
-
"
|
|
735
|
+
"analytic_distribution": {},
|
|
724
736
|
}
|
|
725
737
|
)
|
|
726
738
|
centralized_ml[jnl_id][month]["debit"] += move_line["debit"]
|
|
@@ -732,13 +744,13 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
732
744
|
return centralized_ml
|
|
733
745
|
|
|
734
746
|
@api.model
|
|
735
|
-
def _get_centralized_ml(self, account, date_to):
|
|
747
|
+
def _get_centralized_ml(self, account, date_to, grouped_by):
|
|
736
748
|
centralized_ml = {}
|
|
737
749
|
if isinstance(date_to, str):
|
|
738
750
|
date_to = datetime.datetime.strptime(date_to, "%Y-%m-%d").date()
|
|
739
|
-
if account[
|
|
740
|
-
for
|
|
741
|
-
for move_line in
|
|
751
|
+
if account[grouped_by]:
|
|
752
|
+
for item in account["list_grouped"]:
|
|
753
|
+
for move_line in item["move_lines"]:
|
|
742
754
|
centralized_ml = self._calculate_centralization(
|
|
743
755
|
centralized_ml,
|
|
744
756
|
move_line,
|
|
@@ -756,28 +768,25 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
756
768
|
list_centralized_ml += list(centralized_ml[jnl_id].values())
|
|
757
769
|
return list_centralized_ml
|
|
758
770
|
|
|
771
|
+
# flake8: noqa: C901
|
|
759
772
|
def _get_report_values(self, docids, data):
|
|
773
|
+
res = super()._get_report_values(docids, data)
|
|
760
774
|
wizard_id = data["wizard_id"]
|
|
761
775
|
company = self.env["res.company"].browse(data["company_id"])
|
|
762
776
|
company_id = data["company_id"]
|
|
763
777
|
date_to = data["date_to"]
|
|
764
778
|
date_from = data["date_from"]
|
|
765
779
|
partner_ids = data["partner_ids"]
|
|
766
|
-
if not partner_ids:
|
|
767
|
-
filter_partner_ids = False
|
|
768
|
-
else:
|
|
769
|
-
filter_partner_ids = True
|
|
770
780
|
account_ids = data["account_ids"]
|
|
771
|
-
analytic_tag_ids = data["analytic_tag_ids"]
|
|
772
781
|
cost_center_ids = data["cost_center_ids"]
|
|
773
|
-
|
|
782
|
+
grouped_by = data["grouped_by"]
|
|
774
783
|
hide_account_at_0 = data["hide_account_at_0"]
|
|
775
784
|
foreign_currency = data["foreign_currency"]
|
|
776
785
|
only_posted_moves = data["only_posted_moves"]
|
|
777
786
|
unaffected_earnings_account = data["unaffected_earnings_account"]
|
|
778
787
|
fy_start_date = data["fy_start_date"]
|
|
779
788
|
extra_domain = data["domain"]
|
|
780
|
-
gen_ld_data
|
|
789
|
+
gen_ld_data = self._get_initial_balance_data(
|
|
781
790
|
account_ids,
|
|
782
791
|
partner_ids,
|
|
783
792
|
company_id,
|
|
@@ -786,19 +795,18 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
786
795
|
only_posted_moves,
|
|
787
796
|
unaffected_earnings_account,
|
|
788
797
|
fy_start_date,
|
|
789
|
-
analytic_tag_ids,
|
|
790
798
|
cost_center_ids,
|
|
791
799
|
extra_domain,
|
|
800
|
+
grouped_by,
|
|
792
801
|
)
|
|
793
802
|
centralize = data["centralize"]
|
|
794
803
|
(
|
|
795
804
|
gen_ld_data,
|
|
796
805
|
accounts_data,
|
|
797
|
-
partners_data,
|
|
798
806
|
journals_data,
|
|
799
807
|
full_reconcile_data,
|
|
800
808
|
taxes_data,
|
|
801
|
-
|
|
809
|
+
analytic_data,
|
|
802
810
|
rec_after_date_to_ids,
|
|
803
811
|
) = self._get_period_ml_data(
|
|
804
812
|
account_ids,
|
|
@@ -808,55 +816,128 @@ class GeneralLedgerReport(models.AbstractModel):
|
|
|
808
816
|
only_posted_moves,
|
|
809
817
|
date_from,
|
|
810
818
|
date_to,
|
|
811
|
-
partners_data,
|
|
812
819
|
gen_ld_data,
|
|
813
|
-
partners_ids,
|
|
814
|
-
analytic_tag_ids,
|
|
815
820
|
cost_center_ids,
|
|
816
821
|
extra_domain,
|
|
822
|
+
grouped_by,
|
|
817
823
|
)
|
|
818
824
|
general_ledger = self._create_general_ledger(
|
|
819
825
|
gen_ld_data,
|
|
820
826
|
accounts_data,
|
|
821
|
-
|
|
827
|
+
grouped_by,
|
|
822
828
|
rec_after_date_to_ids,
|
|
823
829
|
hide_account_at_0,
|
|
824
830
|
)
|
|
825
831
|
if centralize:
|
|
826
832
|
for account in general_ledger:
|
|
827
833
|
if account["centralized"]:
|
|
828
|
-
centralized_ml = self._get_centralized_ml(
|
|
834
|
+
centralized_ml = self._get_centralized_ml(
|
|
835
|
+
account, date_to, grouped_by
|
|
836
|
+
)
|
|
829
837
|
account["move_lines"] = centralized_ml
|
|
830
838
|
account["move_lines"] = self._recalculate_cumul_balance(
|
|
831
839
|
account["move_lines"],
|
|
832
840
|
gen_ld_data[account["id"]]["init_bal"]["balance"],
|
|
833
841
|
rec_after_date_to_ids,
|
|
834
842
|
)
|
|
835
|
-
if account[
|
|
836
|
-
account[
|
|
837
|
-
del account["
|
|
843
|
+
if account[grouped_by]:
|
|
844
|
+
account[grouped_by] = False
|
|
845
|
+
del account["list_grouped"]
|
|
838
846
|
general_ledger = sorted(general_ledger, key=lambda k: k["code"])
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
"
|
|
862
|
-
|
|
847
|
+
# Set the bal_curr of the initial balance to 0 if it does not correspond
|
|
848
|
+
# (reducing the corresponding of the bal_curr of the initial balance).
|
|
849
|
+
for gl_item in general_ledger:
|
|
850
|
+
if not foreign_currency:
|
|
851
|
+
continue
|
|
852
|
+
if (
|
|
853
|
+
not gl_item["currency_id"]
|
|
854
|
+
or gl_item["currency_id"] != company.currency_id.id
|
|
855
|
+
):
|
|
856
|
+
gl_item["fin_bal"]["bal_curr"] -= gl_item["init_bal"]["bal_curr"]
|
|
857
|
+
gl_item["init_bal"]["bal_curr"] = 0
|
|
858
|
+
if "list_grouped" in gl_item:
|
|
859
|
+
for lg_item in gl_item["list_grouped"]:
|
|
860
|
+
lg_item["fin_bal"]["bal_curr"] -= lg_item["init_bal"][
|
|
861
|
+
"bal_curr"
|
|
862
|
+
]
|
|
863
|
+
lg_item["init_bal"]["bal_curr"] = 0
|
|
864
|
+
# Set the fin_bal_currency_id value if the account does not have it set
|
|
865
|
+
# and there are move lines in a currency different from that of
|
|
866
|
+
# the company (USD for example).
|
|
867
|
+
for gl_item in general_ledger:
|
|
868
|
+
fin_bal_currency_ids = []
|
|
869
|
+
fin_bal_currency_id = gl_item["currency_id"]
|
|
870
|
+
if gl_item["currency_id"] or not foreign_currency:
|
|
871
|
+
gl_item["fin_bal_currency_id"] = fin_bal_currency_id
|
|
872
|
+
continue
|
|
873
|
+
gl_item["fin_bal"]["bal_curr"] = gl_item["init_bal"]["bal_curr"]
|
|
874
|
+
if "move_lines" in gl_item:
|
|
875
|
+
for ml in gl_item["move_lines"]:
|
|
876
|
+
ml_currency_id = (
|
|
877
|
+
ml["currency_id"][0] if ml["currency_id"] else False
|
|
878
|
+
)
|
|
879
|
+
if ml_currency_id and ml_currency_id != company.currency_id.id:
|
|
880
|
+
gl_item["fin_bal"]["bal_curr"] += ml["bal_curr"]
|
|
881
|
+
if ml_currency_id not in fin_bal_currency_ids:
|
|
882
|
+
fin_bal_currency_ids.append(ml_currency_id)
|
|
883
|
+
elif "list_grouped" in gl_item:
|
|
884
|
+
fin_bal_currency_ids = []
|
|
885
|
+
for lg_item in gl_item["list_grouped"]:
|
|
886
|
+
lg_item["fin_bal"]["bal_curr"] = lg_item["init_bal"]["bal_curr"]
|
|
887
|
+
for ml in lg_item["move_lines"]:
|
|
888
|
+
ml_currency_id = (
|
|
889
|
+
ml["currency_id"][0] if ml["currency_id"] else False
|
|
890
|
+
)
|
|
891
|
+
if ml_currency_id and ml_currency_id != company.currency_id.id:
|
|
892
|
+
lg_item["fin_bal"]["bal_curr"] += ml["bal_curr"]
|
|
893
|
+
gl_item["fin_bal"]["bal_curr"] += ml["bal_curr"]
|
|
894
|
+
if ml_currency_id not in fin_bal_currency_ids:
|
|
895
|
+
fin_bal_currency_ids.append(ml_currency_id)
|
|
896
|
+
# If there is only 1 currency, we set that one as fin_bal_currency_id
|
|
897
|
+
# The use of different move lines with different currencies (EUR + GBP)
|
|
898
|
+
# will be excluded. We use a different field to avoid showing the initial
|
|
899
|
+
# balance and/or distorting data.
|
|
900
|
+
if not gl_item["currency_id"] and len(fin_bal_currency_ids) == 1:
|
|
901
|
+
fin_bal_currency_id = fin_bal_currency_ids[0]
|
|
902
|
+
gl_item["fin_bal_currency_id"] = fin_bal_currency_id
|
|
903
|
+
res.update(
|
|
904
|
+
{
|
|
905
|
+
"doc_ids": [wizard_id],
|
|
906
|
+
"doc_model": "general.ledger.report.wizard",
|
|
907
|
+
"docs": self.env["general.ledger.report.wizard"].browse(wizard_id),
|
|
908
|
+
"foreign_currency": data["foreign_currency"],
|
|
909
|
+
"company_name": company.display_name,
|
|
910
|
+
"company_currency": company.currency_id,
|
|
911
|
+
"currency_name": company.currency_id.name,
|
|
912
|
+
"date_from": data["date_from"],
|
|
913
|
+
"date_to": data["date_to"],
|
|
914
|
+
"only_posted_moves": data["only_posted_moves"],
|
|
915
|
+
"hide_account_at_0": data["hide_account_at_0"],
|
|
916
|
+
"show_cost_center": data["show_cost_center"],
|
|
917
|
+
"general_ledger": general_ledger,
|
|
918
|
+
"accounts_data": accounts_data,
|
|
919
|
+
"journals_data": journals_data,
|
|
920
|
+
"full_reconcile_data": full_reconcile_data,
|
|
921
|
+
"taxes_data": taxes_data,
|
|
922
|
+
"centralize": centralize,
|
|
923
|
+
"analytic_data": analytic_data,
|
|
924
|
+
"filter_partner_ids": True if partner_ids else False,
|
|
925
|
+
"currency_model": self.env["res.currency"],
|
|
926
|
+
}
|
|
927
|
+
)
|
|
928
|
+
return res
|
|
929
|
+
|
|
930
|
+
def _get_ml_fields(self):
|
|
931
|
+
return self.COMMON_ML_FIELDS + [
|
|
932
|
+
"analytic_distribution",
|
|
933
|
+
"full_reconcile_id",
|
|
934
|
+
"tax_line_id",
|
|
935
|
+
"currency_id",
|
|
936
|
+
"credit",
|
|
937
|
+
"debit",
|
|
938
|
+
"amount_currency",
|
|
939
|
+
"balance",
|
|
940
|
+
"tax_ids",
|
|
941
|
+
"move_name",
|
|
942
|
+
"matching_number",
|
|
943
|
+
]
|