Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FWD][IMP] account_financial_report: analytic info + filters in the open items and aged partner balance reports. #1208

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
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
43 changes: 43 additions & 0 deletions account_financial_report/report/aged_partner_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datetime import date, datetime, timedelta

from odoo import api, models
from odoo.osv import expression
from odoo.tools import float_is_zero


Expand Down Expand Up @@ -148,10 +149,38 @@
date_from,
only_posted_moves,
show_move_line_details,
analytic_account_ids,
no_analytic,
):
domain = self._get_move_lines_domain_not_reconciled(
company_id, account_ids, partner_ids, only_posted_moves, date_from
)
if no_analytic:
domain = expression.AND(

Check warning on line 159 in account_financial_report/report/aged_partner_balance.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/aged_partner_balance.py#L159

Added line #L159 was not covered by tests
[
domain,
[
(
"analytic_account_ids",
"=",
False,
)
],
]
)
elif analytic_account_ids:
domain = expression.AND(

Check warning on line 172 in account_financial_report/report/aged_partner_balance.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/aged_partner_balance.py#L172

Added line #L172 was not covered by tests
[
domain,
[
(
"analytic_account_ids",
"in",
analytic_account_ids,
)
],
]
)
ml_fields = self._get_ml_fields()
line_model = self.env["account.move.line"]
move_lines = line_model.search_read(domain=domain, fields=ml_fields)
Expand Down Expand Up @@ -224,6 +253,14 @@
ref_label = move_line["ref"]
else:
ref_label = move_line["ref"] + str(" - ") + move_line["name"]
if move_line["analytic_account_ids"]:
analytic = ", ".join(

Check warning on line 257 in account_financial_report/report/aged_partner_balance.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/aged_partner_balance.py#L257

Added line #L257 was not covered by tests
self.env["account.analytic.account"]
.browse(move_line["analytic_account_ids"])
.mapped("name")
)
else:
analytic = False
move_line_data.update(
{
"line_rec": line_model.browse(move_line["id"]),
Expand All @@ -235,6 +272,7 @@
"ref_label": ref_label,
"due_date": move_line["date_maturity"],
"residual": move_line["amount_residual"],
"analytic_account_ids": analytic,
}
)
ag_pb_data[acc_id][prt_id]["move_lines"].append(move_line_data)
Expand Down Expand Up @@ -416,6 +454,8 @@
aged_partner_configuration = self.env[
"account.age.report.configuration"
].browse(data["age_partner_config_id"])
analytic_account_ids = data["analytic_account_ids"]
no_analytic = data["no_analytic"]
(ag_pb_data, accounts_data, partners_data, journals_data,) = self.with_context(
age_partner_config=aged_partner_configuration
)._get_move_lines_data(
Expand All @@ -426,6 +466,8 @@
date_from,
only_posted_moves,
show_move_line_details,
analytic_account_ids,
no_analytic,
)
aged_partner_data = self.with_context(
age_partner_config=aged_partner_configuration
Expand Down Expand Up @@ -458,4 +500,5 @@
"amount_residual",
"reconciled",
"date_maturity",
"analytic_account_ids",
]
13 changes: 9 additions & 4 deletions account_financial_report/report/aged_partner_balance_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,22 @@ def _get_report_columns_with_move_line_details(self, report, column_index):
2: {"header": _("Journal"), "field": "journal", "width": 8},
3: {"header": _("Account"), "field": "account", "width": 9},
4: {"header": _("Partner"), "field": "partner", "width": 25},
5: {"header": _("Ref - Label"), "field": "ref_label", "width": 40},
6: {"header": _("Due date"), "field": "due_date", "width": 11},
7: {
5: {
"header": _("Analytic Account"),
"field": "analytic_account_ids",
"width": 25,
},
6: {"header": _("Ref - Label"), "field": "ref_label", "width": 40},
7: {"header": _("Due date"), "field": "due_date", "width": 11},
8: {
"header": _("Residual"),
"field": "residual",
"field_footer_total": "residual",
"field_final_balance": "residual",
"type": "amount",
"width": 14,
},
8: {
9: {
"header": _("Current"),
"field": "current",
"field_footer_total": "current",
Expand Down
50 changes: 49 additions & 1 deletion account_financial_report/report/open_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import date, datetime

from odoo import _, api, models
from odoo.osv import expression
from odoo.tools import float_is_zero


Expand Down Expand Up @@ -68,10 +69,14 @@
company_id,
date_from,
grouped_by,
analytic_account_ids,
no_analytic,
):
domain = self._get_move_lines_domain_not_reconciled(
company_id, account_ids, partner_ids, only_posted_moves, date_from
)
# moved out to avoid too complex method error
domain = self.get_analytic_domain(domain, analytic_account_ids, no_analytic)

Check warning on line 79 in account_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/open_items.py#L79

Added line #L79 was not covered by tests
ml_fields = self._get_ml_fields()
move_lines = self.env["account.move.line"].search_read(
domain=domain, fields=ml_fields
Expand Down Expand Up @@ -148,7 +153,14 @@
ref_label = move_line["ref"]
else:
ref_label = move_line["ref"] + str(" - ") + move_line["name"]

if analytic_account_ids and move_line["analytic_account_ids"]:
analytic_account_ids = ", ".join(

Check warning on line 157 in account_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/open_items.py#L157

Added line #L157 was not covered by tests
self.env["account.analytic.account"]
.browse(move_line["analytic_account_ids"])
.mapped("name")
)
else:
analytic_account_ids = False

Check warning on line 163 in account_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/open_items.py#L163

Added line #L163 was not covered by tests
move_line.update(
{
"date": move_line["date"],
Expand All @@ -167,6 +179,7 @@
"currency_name": move_line["currency_id"][1]
if move_line["currency_id"]
else False,
"analytic_account_ids": analytic_account_ids,
}
)

Expand Down Expand Up @@ -247,6 +260,9 @@
only_posted_moves = data["only_posted_moves"]
show_partner_details = data["show_partner_details"]
grouped_by = data["grouped_by"]
analytic_account_ids = data["analytic_account_ids"]
no_analytic = data["no_analytic"]

Check warning on line 264 in account_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/open_items.py#L263-L264

Added lines #L263 - L264 were not covered by tests

(
move_lines_data,
partners_data,
Expand All @@ -261,6 +277,8 @@
company_id,
date_from,
grouped_by,
analytic_account_ids,
no_analytic,
)

total_amount = self._calculate_amounts(open_items_move_lines_data)
Expand Down Expand Up @@ -288,6 +306,7 @@

def _get_ml_fields(self):
return self.COMMON_ML_FIELDS + [
"analytic_account_ids",
"amount_residual",
"reconciled",
"currency_id",
Expand All @@ -297,3 +316,32 @@
"debit",
"amount_currency",
]

def get_analytic_domain(self, domain, analytic_account_ids, no_analytic):
if no_analytic:
domain = expression.AND(

Check warning on line 322 in account_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/open_items.py#L322

Added line #L322 was not covered by tests
[
domain,
[
(
"analytic_account_ids",
"=",
False,
)
],
]
)
elif analytic_account_ids:
domain = expression.AND(

Check warning on line 335 in account_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/open_items.py#L335

Added line #L335 was not covered by tests
[
domain,
[
(
"analytic_account_ids",
"in",
analytic_account_ids,
)
],
]
)
return domain

Check warning on line 347 in account_financial_report/report/open_items.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/open_items.py#L347

Added line #L347 was not covered by tests
19 changes: 12 additions & 7 deletions account_financial_report/report/open_items_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ def _get_report_columns(self, report):
2: {"header": _("Journal"), "field": "journal", "width": 8},
3: {"header": _("Account"), "field": "account", "width": 9},
4: {"header": _("Partner"), "field": "partner_name", "width": 25},
5: {"header": _("Ref - Label"), "field": "ref_label", "width": 40},
6: {"header": _("Due date"), "field": "date_maturity", "width": 11},
7: {
5: {
"header": _("Analytic Account"),
"field": "analytic_account_id",
"width": 25,
},
6: {"header": _("Ref - Label"), "field": "ref_label", "width": 40},
7: {"header": _("Due date"), "field": "date_maturity", "width": 11},
8: {
"header": _("Original"),
"field": "original",
"type": "amount",
"width": 14,
},
8: {
9: {
"header": _("Residual"),
"field": "amount_residual",
"field_final_balance": "residual",
Expand All @@ -45,21 +50,21 @@ def _get_report_columns(self, report):
}
if report.foreign_currency:
foreign_currency = {
9: {
10: {
"header": _("Cur."),
"field": "currency_name",
"field_currency_balance": "currency_name",
"type": "currency_name",
"width": 7,
},
10: {
11: {
"header": _("Cur. Original"),
"field": "amount_currency",
"field_final_balance": "amount_currency",
"type": "amount_currency",
"width": 14,
},
11: {
12: {
"header": _("Cur. Residual"),
"field": "amount_residual_currency",
"field_final_balance": "amount_currency",
Expand Down
100 changes: 73 additions & 27 deletions account_financial_report/report/templates/aged_partner_balance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,29 @@
<div class="act_as_cell" style="width: 5.00%;">Journal</div>
<!--## account code-->
<div class="act_as_cell" style="width: 6.00%;">Account</div>
<!--## partner-->
<div class="act_as_cell" style="width: 10.50%;">Partner</div>
<!--## ref - label-->
<div class="act_as_cell" style="width: 18.00%;">
Ref -
Label
</div>
<t t-if="analytic_account_ids">
<!--## partner-->
<div class="act_as_cell" style="width: 9.50%;">Partner</div>
<!--## analytic account -->
<div
class="act_as_cell"
style="width: 9.50%;"
>Analytic Accounts</div>
<!--## ref - label-->
<div class="act_as_cell" style="width: 9.50%;">
Ref -
Label
</div>
</t>
<t t-else="">
<!--## partner-->
<div class="act_as_cell" style="width: 10.50%;">Partner</div>
<!--## ref - label-->
<div class="act_as_cell" style="width: 18.00%;">
Ref -
Label
</div>
</t>
<!--## date_due-->
<div class="act_as_cell" style="width: 6.00%;">
Due
Expand Down Expand Up @@ -311,26 +327,56 @@
<t t-out="line['account']" />
</span>
</div>
<!--## partner-->
<div class="act_as_cell left">
<span
t-att-res-id="line['line_rec'].partner_id.id"
res-model="res.partner"
view-type="form"
>
<t t-out="line['partner']" />
</span>
</div>
<!--## ref - label-->
<div class="act_as_cell left">
<span
t-att-res-id="line['line_rec'].id"
res-model="account.move.line"
view-type="form"
>
<t t-out="line['ref_label']" />
</span>
</div>
<t t-if="analytic_account_ids">
<!--## partner-->
<div class="act_as_cell left">
<span
t-att-res-id="line['line_rec'].partner_id.id"
res-model="res.partner"
view-type="form"
>
<t t-out="line['partner']" />
</span>
</div>
<!-- ANAL -->
<div class="act_as_cell left">
<span>
<t t-out="line['analytic_account_ids']" />
</span>
</div>
<!--## ref - label-->
<div class="act_as_cell left">
<span
t-att-res-id="line['line_rec'].id"
res-model="account.move.line"
view-type="form"
>
<t t-out="line['ref_label']" />
</span>
</div>
</t>
<t t-else="">
<!--## partner-->
<div class="act_as_cell left">
<span
t-att-res-id="line['line_rec'].partner_id.id"
res-model="res.partner"
view-type="form"
>
<t t-out="line['partner']" />
</span>
</div>
<!--## ref - label-->
<div class="act_as_cell left">
<span
t-att-res-id="line['line_rec'].id"
res-model="account.move.line"
view-type="form"
>
<t t-out="line['ref_label']" />
</span>
</div>
</t>
<!--## date_due-->
<div class="act_as_cell left">
<span
Expand Down
Loading
Loading