Skip to content

Commit

Permalink
[IMP] account_financial_report
Browse files Browse the repository at this point in the history
- added join_entry_ml flag to general ledger wizard. This field when flagged joins
	rows from the same parent record
- added flag that hides rows with both "credit" and "debit" coluns with value 0
  • Loading branch information
techgrrow committed Aug 5, 2024
1 parent 9f3c12b commit e4d7810
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 2 deletions.
2 changes: 1 addition & 1 deletion account_financial_report/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Account Financial Reports",
"version": "16.0.1.5.4",
"version": "16.0.1.9.0",
"category": "Reporting",
"summary": "OCA Financial Reports",
"author": "Camptocamp SA,"
Expand Down
35 changes: 35 additions & 0 deletions account_financial_report/report/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,29 @@ def _get_centralized_ml(self, account, date_to, grouped_by):
list_centralized_ml += list(centralized_ml[jnl_id].values())
return list_centralized_ml

@api.model
def _get_joined_entries_ml(self, account):
ml = {}

Check warning on line 769 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L769

Added line #L769 was not covered by tests
for entry in account.get("move_lines", []):
entry_id = entry["entry_id"]

Check warning on line 771 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L771

Added line #L771 was not covered by tests
if not ml.get(entry_id, False):
ml[entry_id] = entry

Check warning on line 773 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L773

Added line #L773 was not covered by tests
else:
if not ml[entry_id].get("is_joined_entry", False):
ml[entry_id]["is_joined_entry"] = True
ml[entry_id]["name"] = self.env["account.move"].browse(

Check warning on line 777 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L776-L777

Added lines #L776 - L777 were not covered by tests
entry["entry_id"]).name
ml[entry_id]["ref_label"] = ml[entry_id]["ref"]
ml[entry_id]["id"] = None
ml[entry_id]["balance"] += (entry["debit"] - entry["credit"])
ml[entry_id]["bal_curr"] += entry["bal_curr"]
ml[entry_id]["credit"] += entry["credit"]
ml[entry_id]["debit"] += entry["debit"]
ml[entry_id]["tax_ids"] += entry["tax_ids"]
ml[entry_id]["tax_ids"] = list(set(ml[entry_id]["tax_ids"]))

Check warning on line 786 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L779-L786

Added lines #L779 - L786 were not covered by tests
# filtered_ml = {k: v for k, v in ml.items() if v["name"] == "Joined Entries"}
return list(ml.values())

Check warning on line 788 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L788

Added line #L788 was not covered by tests

def _get_report_values(self, docids, data):
wizard_id = data["wizard_id"]
company = self.env["res.company"].browse(data["company_id"])
Expand All @@ -780,6 +803,8 @@ 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"]
join_entry_ml = data["join_entry_ml"]
hide_rows_at_0 = data["hide_rows_at_0"]
gen_ld_data = self._get_initial_balance_data(
account_ids,
partner_ids,
Expand Down Expand Up @@ -837,6 +862,15 @@ def _get_report_values(self, docids, data):
if grouped_by and account[grouped_by]:
account[grouped_by] = False
del account["list_grouped"]
elif join_entry_ml:
for account in general_ledger:
if account.get("move_lines", []):
joined_entries_ml = self._get_joined_entries_ml(account)
account["move_lines"] = joined_entries_ml

Check warning on line 869 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L868-L869

Added lines #L868 - L869 were not covered by tests
if grouped_by and account[grouped_by]:
for item in account.get("list_grouped", []):
joined_entries_ml = self._get_joined_entries_ml(item)
item["move_lines"] = joined_entries_ml

Check warning on line 873 in account_financial_report/report/general_ledger.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/general_ledger.py#L872-L873

Added lines #L872 - L873 were not covered by tests
general_ledger = sorted(general_ledger, key=lambda k: k["code"])
return {
"doc_ids": [wizard_id],
Expand All @@ -860,6 +894,7 @@ def _get_report_values(self, docids, data):
"analytic_data": analytic_data,
"filter_partner_ids": True if partner_ids else False,
"currency_model": self.env["res.currency"],
"hide_rows_at_0": hide_rows_at_0,
}

def _get_ml_fields(self):
Expand Down
69 changes: 68 additions & 1 deletion account_financial_report/report/templates/general_ledger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,16 @@
t-set="total_bal_curr"
t-value="account_or_group_item_object['init_bal'].get('bal_curr', 0)"
/>
<t t-foreach="account_or_group_item_object['move_lines']" t-as="line">
<!-- If field hide_rows_at_0, do not show lines with both credit and debit == 0 -->
<t t-if="hide_rows_at_0">
<t t-if="account_or_group_item_object and account_or_group_item_object['move_lines']">
<t t-set="account_or_group_item_move_lines" t-value="o.filter_move_lines(account_or_group_item_object['move_lines'])"/>
</t>
</t>
<t t-else="">
<t t-set="account_or_group_item_move_lines" t-value="account_or_group_item_object['move_lines']"/>
</t>
<t t-foreach="account_or_group_item_move_lines" t-as="line">
<!-- # lines or centralized lines -->
<div class="act_as_row lines">
<!--## date-->
Expand All @@ -389,6 +398,19 @@
/>
</span>
</t>
<t t-elif="line['entry_id']">
<!--## We don't use t-field because it throws an error on click -->
<span
t-att-res-id="line['entry_id']"
res-model="account.move"
view-type="form"
>
<t
t-esc="line['date']"
t-options="{'widget': 'date'}"
/>
</span>
</t>
<t t-else="">
<span>
<!--## We don't use t-field because it throws an error on click -->
Expand Down Expand Up @@ -469,6 +491,15 @@
<t t-out="line['ref_label']" />
</span>
</t>
<t t-elif="line['entry_id']">
<span
t-att-res-id="line['entry_id']"
res-model="account.move"
view-type="form"
>
<t t-out="line['ref_label']" />
</span>
</t>
<t t-else="">
<span>
<t t-out="line['ref_label']" />
Expand Down Expand Up @@ -541,6 +572,18 @@
/>
</span>
</t>
<t t-elif="line['entry_id']">
<span
t-att-res-id="line['entry_id']"
res-model="account.move"
view-type="form"
>
<t
t-out="line['debit']"
t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"
/>
</span>
</t>
<t t-else="">
<span>
<t
Expand All @@ -564,6 +607,18 @@
/>
</span>
</t>
<t t-elif="line['entry_id']">
<span
t-att-res-id="line['entry_id']"
res-model="account.move"
view-type="form"
>
<t
t-out="line['credit']"
t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"
/>
</span>
</t>
<t t-else="">
<span>
<t
Expand All @@ -587,6 +642,18 @@
/>
</span>
</t>
<t t-elif="line['entry_id']">
<span
t-att-res-id="line['entry_id']"
res-model="account.move"
view-type="form"
>
<t
t-out="line['balance']"
t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"
/>
</span>
</t>
<t t-else="">
<span>
<t
Expand Down
24 changes: 24 additions & 0 deletions account_financial_report/wizard/general_ledger_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ def _prepare_report_general_ledger(self):
"unaffected_earnings_account": self.unaffected_earnings_account.id,
"account_financial_report_lang": self.env.lang,
"domain": self._get_account_move_lines_domain(),
"join_entry_ml": self.join_entry_ml,
"hide_rows_at_0": self.hide_rows_at_0,
}

def _export(self, report_type):
Expand All @@ -314,3 +316,25 @@ def _get_atr_from_dict(self, obj_id, data, key):
return data[obj_id][key]
except KeyError:
return data[str(obj_id)][key]

join_entry_ml = fields.Boolean('Join Entry Lines', default=False,
help='If checked, the report will join records from the same entry. \
Can be used with either the "Partners" or "Taxes" grouping option.\
Automatically sets the "Centralize" option to False.')

hide_rows_at_0 = fields.Boolean('Hide rows at 0', default=False,
help='If checked, the report will hide rows with Debit and Credit at 0.')

@api.onchange('join_entry_ml')
def onchange_join_entry_ml(self):
if self.join_entry_ml:
self.centralize = False

Check warning on line 331 in account_financial_report/wizard/general_ledger_wizard.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/wizard/general_ledger_wizard.py#L331

Added line #L331 was not covered by tests

@api.onchange('centralize')
def onchange_centralize(self):
if self.centralize:
self.join_entry_ml = False

Check warning on line 336 in account_financial_report/wizard/general_ledger_wizard.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/wizard/general_ledger_wizard.py#L336

Added line #L336 was not covered by tests

@api.model
def filter_move_lines(self, move_lines):
return [l for l in move_lines if not (l['credit'] == 0.0 and l['debit'] == 0.0)]
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
</group>
<group name="other_filters">
<field name="grouped_by" />
<field name="join_entry_ml" />
<field name="centralize" />
<field name="hide_rows_at_0" />
<field name="hide_account_at_0" />
<field name="foreign_currency" />
<field name="show_cost_center" />
Expand Down

0 comments on commit e4d7810

Please sign in to comment.