Skip to content

Commit 6b7140b

Browse files
committedNov 6, 2024·
[IMP] mis_builder_kpi_code: make account code column optional
1 parent 0e623a4 commit 6b7140b

File tree

9 files changed

+112
-59
lines changed

9 files changed

+112
-59
lines changed
 

‎mis_builder_kpi_code/README.rst

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ MIS Builder KPI Code
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:de0015ad668a8823ac2513115d7e71cae0d60124519c91a708190607873cbf07
10+
!! source digest: sha256:e08acc01e952349ee396d1373c87c16382a8be1e691f86542925bd92451a4eb9
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -22,7 +22,9 @@ MIS Builder KPI Code
2222

2323
|badge1| |badge2| |badge3|
2424

25-
This module includes the option to fill in the code field when creating a KPI in the MIS Report Template. This code field will be visible in the MIS Report Preview in the first column and will also be included when exporting documents to PDF or XLSX formats.
25+
This module includes the option to use the account code column in MIS Report.
26+
The column will be visible in the Preview and will also be included
27+
when exporting documents to PDF or XLSX formats.
2628

2729
**Table of contents**
2830

@@ -34,8 +36,9 @@ Usage
3436

3537
To use this module, you need to:
3638

37-
1. Fill in the code field when creating or editing a KPI in a MIS Report Template.
38-
2. Open a MIS Report using this Template and see the new column in Preview Mode or in the exported PDF or XLSX files.
39+
1. Create a MIS Report and mark the field Use Code Column.
40+
2. Fill in the account code in the description when creating a KPI in a MIS Report.
41+
3. Open a MIS Report Instance Preview and see the new column in it, or in the exported PDF or XLSX files.
3942

4043
Bug Tracker
4144
===========

‎mis_builder_kpi_code/models/mis_report.py

+16
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,19 @@ class MisReportKpi(models.Model):
99
_inherit = "mis.report.kpi"
1010

1111
code = fields.Char()
12+
use_code_column = fields.Boolean(related="report_id.use_code_column")
13+
14+
15+
class MisReport(models.Model):
16+
17+
_inherit = "mis.report"
18+
19+
use_code_column = fields.Boolean(default=False)
20+
21+
def computed_code(self, description):
22+
code = ""
23+
if description:
24+
first_character = description[0]
25+
if first_character.isdigit():
26+
code = description.split(" ")[0]
27+
return code
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
# Copyright 2024 - TODAY, Wesley Oliveira <wesley.oliveira@escodoo.com.br>
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
from odoo import models
4+
from odoo import fields, models
55

66

77
class MisReportInstance(models.Model):
88

99
_inherit = "mis.report.instance"
1010

11+
use_code_column = fields.Boolean(related="report_id.use_code_column")
12+
1113
def compute(self):
1214
self.ensure_one()
13-
kpi_matrix = self._compute_matrix()
14-
kpi_matrix_dict = kpi_matrix.as_dict()
15-
16-
empty_col = [{"label": "", "description": "", "colspan": 1}]
17-
kpi_matrix_dict["header"][0]["cols"] = (
18-
empty_col + kpi_matrix_dict["header"][0]["cols"]
19-
)
20-
kpi_matrix_dict["header"][1]["cols"] = (
21-
empty_col + kpi_matrix_dict["header"][1]["cols"]
22-
)
23-
24-
for idx, row in enumerate(kpi_matrix_dict["body"]):
25-
code = self.report_id.kpi_ids.filtered(
26-
lambda k: k.name == row["row_id"]
27-
).code
28-
kpi_matrix_dict["body"][idx].update({"code": code})
29-
30-
return kpi_matrix_dict
15+
if not self.use_code_column:
16+
return super(MisReportInstance, self).compute()
17+
else:
18+
kpi_matrix = self._compute_matrix()
19+
kpi_matrix_dict = kpi_matrix.as_dict()
20+
21+
empty_col = [{"label": "", "description": "", "colspan": 1}]
22+
kpi_matrix_dict["header"][0]["cols"] = (
23+
empty_col + kpi_matrix_dict["header"][0]["cols"]
24+
)
25+
kpi_matrix_dict["header"][1]["cols"] = (
26+
empty_col + kpi_matrix_dict["header"][1]["cols"]
27+
)
28+
29+
for idx, row in enumerate(kpi_matrix_dict["body"]):
30+
label = row["label"]
31+
code = self.report_id.computed_code(row["label"])
32+
if code:
33+
label = label.split(" ")[1]
34+
kpi_matrix_dict["body"][idx].update(
35+
{
36+
"code": code,
37+
"label": label,
38+
}
39+
)
40+
41+
return kpi_matrix_dict
+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
This module includes the option to fill in the code field when creating a KPI in the MIS Report Template. This code field will be visible in the MIS Report Preview in the first column and will also be included when exporting documents to PDF or XLSX formats.
1+
This module includes the option to use the account code column in MIS Report.
2+
The column will be visible in the Preview and will also be included
3+
when exporting documents to PDF or XLSX formats.

‎mis_builder_kpi_code/readme/USAGE.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
To use this module, you need to:
22

3-
1. Fill in the code field when creating or editing a KPI in a MIS Report Template.
4-
2. Open a MIS Report using this Template and see the new column in Preview Mode or in the exported PDF or XLSX files.
3+
1. Create a MIS Report and mark the field Use Code Column.
4+
2. Fill in the account code in the description when creating a KPI in a MIS Report.
5+
3. Open a MIS Report Instance Preview and see the new column in it, or in the exported PDF or XLSX files.

‎mis_builder_kpi_code/report/mis_report_instance_qweb.xml

+31-7
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,52 @@
2222
expr="//div[hasclass('mis_thead')]/div[hasclass('mis_row')][1]/div[hasclass('mis_collabel')][1]"
2323
position="before"
2424
>
25-
<div class="mis_cell mis_collabel" />
25+
<t t-if="o.report_id.use_code_column">
26+
<div class="mis_cell mis_collabel" />
27+
</t>
2628
</xpath>
2729
<xpath
2830
expr="//div[hasclass('mis_thead')]/div[hasclass('mis_row')][2]/div[hasclass('mis_collabel')][1]"
2931
position="before"
3032
>
31-
<div class="mis_cell mis_collabel" />
33+
<t t-if="o.report_id.use_code_column">
34+
<div class="mis_cell mis_collabel" />
35+
</t>
3236
</xpath>
3337
<xpath
3438
expr="//div[hasclass('mis_tbody')]/t[@t-as='row']/div[hasclass('mis_row')]/div[hasclass('mis_rowlabel')]"
35-
position="before"
39+
position="replace"
3640
>
3741
<div
3842
t-att-style="style_obj.to_css_style(row.style_props)"
3943
class="mis_cell mis_rowlabel"
4044
>
4145
<t
42-
t-set="code"
43-
t-value="o.report_id.kpi_ids.filtered(lambda k: k.id == row.kpi.id).code"
44-
/>
45-
<t t-esc="code or ''" />
46+
t-if="o.report_id.use_code_column and o.report_id.computed_code(row.label)"
47+
>
48+
<t t-esc="row.label.split(' ')[1]" />
49+
</t>
50+
<t t-else="">
51+
<t t-esc="row.label" />
52+
<t t-if="row.description">
53+
<br />
54+
<t t-esc="row.description" />
55+
</t>
56+
</t>
4657
</div>
4758
</xpath>
59+
<xpath
60+
expr="//div[hasclass('mis_tbody')]/t[@t-as='row']/div[hasclass('mis_row')]/div[hasclass('mis_rowlabel')]"
61+
position="before"
62+
>
63+
<t t-if="o.report_id.use_code_column">
64+
<div
65+
t-att-style="style_obj.to_css_style(row.style_props)"
66+
class="mis_cell mis_rowlabel"
67+
>
68+
<t t-esc="o.report_id.computed_code(row.label)" />
69+
</div>
70+
</t>
71+
</xpath>
4872
</template>
4973
</odoo>

‎mis_builder_kpi_code/report/mis_report_instance_xlsx.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@
2424
class MisBuilderXlsx(models.AbstractModel):
2525
_inherit = "report.mis_builder.mis_report_instance_xlsx"
2626

27+
# flake8: noqa: C901
2728
def generate_xlsx_report(self, workbook, data, objects):
28-
29+
if not objects[0].report_id.use_code_column:
30+
return super(MisBuilderXlsx, self).generate_xlsx_report(
31+
workbook, data, objects
32+
)
2933
# get the computed result of the report
3034
matrix = objects._compute_matrix()
3135
style_obj = self.env["mis.report.style"]
3236

3337
# create worksheet
3438
report_name = "{} - {}".format(
35-
objects[0].name, ", ".join([a.name for a in objects[0].query_company_ids])
39+
objects[0].name,
40+
", ".join([a.name for a in objects[0].query_company_ids]),
3641
)
3742
sheet = workbook.add_worksheet(report_name[:31])
3843
row_pos = 0
@@ -78,7 +83,9 @@ def generate_xlsx_report(self, workbook, data, objects):
7883
else:
7984
sheet.write(row_pos, col_pos, label, header_format)
8085
col_width[col_pos] = max(
81-
col_width[col_pos], len(col.label or ""), len(col.description or "")
86+
col_width[col_pos],
87+
len(col.label or ""),
88+
len(col.description or ""),
8289
)
8390
col_pos += col.colspan
8491
row_pos += 1
@@ -111,13 +118,13 @@ def generate_xlsx_report(self, workbook, data, objects):
111118
row_format = workbook.add_format(row_xlsx_style)
112119
col_pos = 0
113120

114-
code = (
115-
objects[0].report_id.kpi_ids.filtered(lambda k: k.id == row.kpi.id).code
116-
)
121+
code = objects[0].report_id.computed_code(row.label)
117122
sheet.write(row_pos, col_pos, code, row_format)
118123
col_pos += 1
119124

120125
label = row.label
126+
if code:
127+
label = label.split(" ")[1]
121128
if row.description:
122129
label += "\n" + row.description
123130
sheet.set_row(row_pos, ROW_HEIGHT * 2)

‎mis_builder_kpi_code/static/description/index.html

+7-4
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,12 @@ <h1 class="title">MIS Builder KPI Code</h1>
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370-
!! source digest: sha256:de0015ad668a8823ac2513115d7e71cae0d60124519c91a708190607873cbf07
370+
!! source digest: sha256:e08acc01e952349ee396d1373c87c16382a8be1e691f86542925bd92451a4eb9
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372372
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/Escodoo/account-addons/tree/14.0/mis_builder_kpi_code"><img alt="Escodoo/account-addons" src="https://img.shields.io/badge/github-Escodoo%2Faccount--addons-lightgray.png?logo=github" /></a></p>
373-
<p>This module includes the option to fill in the code field when creating a KPI in the MIS Report Template. This code field will be visible in the MIS Report Preview in the first column and will also be included when exporting documents to PDF or XLSX formats.</p>
373+
<p>This module includes the option to use the account code column in MIS Report.
374+
The column will be visible in the Preview and will also be included
375+
when exporting documents to PDF or XLSX formats.</p>
374376
<p><strong>Table of contents</strong></p>
375377
<div class="contents local topic" id="contents">
376378
<ul class="simple">
@@ -388,8 +390,9 @@ <h1 class="title">MIS Builder KPI Code</h1>
388390
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
389391
<p>To use this module, you need to:</p>
390392
<ol class="arabic simple">
391-
<li>Fill in the code field when creating or editing a KPI in a MIS Report Template.</li>
392-
<li>Open a MIS Report using this Template and see the new column in Preview Mode or in the exported PDF or XLSX files.</li>
393+
<li>Create a MIS Report and mark the field Use Code Column.</li>
394+
<li>Fill in the account code in the description when creating a KPI in a MIS Report.</li>
395+
<li>Open a MIS Report Instance Preview and see the new column in it, or in the exported PDF or XLSX files.</li>
393396
</ol>
394397
</div>
395398
<div class="section" id="bug-tracker">

‎mis_builder_kpi_code/views/mis_report.xml

+2-16
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,8 @@
2020
<field name="model">mis.report</field>
2121
<field name="inherit_id" ref="mis_builder.mis_report_view_form" />
2222
<field name="arch" type="xml">
23-
<xpath
24-
expr="//field[@name='kpi_ids']/tree/field[@name='description']"
25-
position="before"
26-
>
27-
<field name="code" />
28-
</xpath>
29-
</field>
30-
</record>
31-
32-
<record model="ir.ui.view" id="mis_report_view_kpi_form">
33-
<field name="name">mis.report.view.kpi.form (in mis_builder_kpi_code)</field>
34-
<field name="model">mis.report.kpi</field>
35-
<field name="inherit_id" ref="mis_builder.mis_report_view_kpi_form" />
36-
<field name="arch" type="xml">
37-
<xpath expr="//field[@name='description']" position="before">
38-
<field name="code" />
23+
<xpath expr="//field[@name='move_lines_source']" position="after">
24+
<field name="use_code_column" />
3925
</xpath>
4026
</field>
4127
</record>

0 commit comments

Comments
 (0)
Please sign in to comment.