Skip to content

Commit d0518be

Browse files
committed
Merge PR #1528 into 19.0
Signed-off-by pedrobaeza
2 parents 3855ea0 + 6be7ba3 commit d0518be

6 files changed

Lines changed: 145 additions & 215 deletions

File tree

account_financial_report/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ Contributors
175175
- Alexandre D. D??az
176176
- V??ctor Mart??nez
177177
- Carolina Fernandez
178+
- Eduardo Ezerouali
178179

179180
- `Sygel <https://www.sygel.es>`__:
180181

account_financial_report/readme/CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- Alexandre D. D??az
2525
- V??ctor Mart??nez
2626
- Carolina Fernandez
27+
- Eduardo Ezerouali
2728
- [Sygel](https://www.sygel.es):
2829
- Harald Panten
2930
- Valentin Vinagre

account_financial_report/report/abstract_report_xlsx.py

Lines changed: 40 additions & 211 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ class AbstractReportXslx(models.AbstractModel):
1010
_description = "Abstract XLSX Account Financial Report"
1111
_inherit = "report.report_xlsx.abstract"
1212

13+
def _get_currency_from_company(self):
14+
model = self.env.context.get("active_model")
15+
active_id = self.env.context.get("active_id")
16+
wizard = self.env[model].browse(active_id)
17+
return wizard.company_id.currency_id
18+
19+
def _round_value_by_currency(self, value, currency=None):
20+
if isinstance(currency, tuple):
21+
currency = currency[0]
22+
if currency:
23+
return self.env["res.currency"].browse(currency).round(value)
24+
else:
25+
return self._get_currency_from_company().round(value)
26+
1327
def get_workbook_options(self):
1428
vals = super().get_workbook_options()
1529
vals.update({"constant_memory": True})
@@ -54,7 +68,7 @@ def _define_formats(self, workbook, report_data):
5468
* format_amount
5569
* format_percent_bold_italic
5670
"""
57-
currency_id = self.env["res.company"]._default_currency_id()
71+
currency_id = self._get_currency_from_company()
5872
report_data["formats"] = {
5973
"format_bold": workbook.add_format({"bold": True}),
6074
"format_right": workbook.add_format({"align": "right"}),
@@ -185,54 +199,6 @@ def write_array_header(self, report_data):
185199
)
186200
report_data["row_pos"] += 1
187201

188-
def write_line(self, line_object, report_data):
189-
"""Write a line on current line using all defined columns field name.
190-
Columns are defined with `_get_report_columns` method.
191-
"""
192-
for col_pos, column in report_data["columns"].items():
193-
value = getattr(line_object, column["field"])
194-
cell_type = column.get("type", "string")
195-
if cell_type == "many2one":
196-
report_data["sheet"].write_string(
197-
report_data["row_pos"],
198-
col_pos,
199-
value.name or "",
200-
report_data["formats"]["format_right"],
201-
)
202-
elif cell_type == "string":
203-
if (
204-
hasattr(line_object, "account_group_id")
205-
and line_object.account_group_id
206-
):
207-
report_data["sheet"].write_string(
208-
report_data["row_pos"],
209-
col_pos,
210-
value or "",
211-
report_data["formats"]["format_bold"],
212-
)
213-
else:
214-
report_data["sheet"].write_string(
215-
report_data["row_pos"], col_pos, value or ""
216-
)
217-
elif cell_type == "amount":
218-
if (
219-
hasattr(line_object, "account_group_id")
220-
and line_object.account_group_id
221-
):
222-
cell_format = report_data["formats"]["format_amount_bold"]
223-
else:
224-
cell_format = report_data["formats"]["format_amount"]
225-
report_data["sheet"].write_number(
226-
report_data["row_pos"], col_pos, float(value), cell_format
227-
)
228-
elif cell_type == "amount_currency":
229-
if line_object.currency_id:
230-
format_amt = self._get_currency_amt_format(line_object, report_data)
231-
report_data["sheet"].write_number(
232-
report_data["row_pos"], col_pos, float(value), format_amt
233-
)
234-
report_data["row_pos"] += 1
235-
236202
def write_line_from_dict(self, line_dict, report_data):
237203
"""Write a line on current line"""
238204
for col_pos, column in report_data["columns"].items():
@@ -265,15 +231,23 @@ def write_line_from_dict(self, line_dict, report_data):
265231
else:
266232
cell_format = report_data["formats"]["format_amount"]
267233
report_data["sheet"].write_number(
268-
report_data["row_pos"], col_pos, float(value), cell_format
234+
report_data["row_pos"],
235+
col_pos,
236+
self._round_value_by_currency(value),
237+
cell_format,
269238
)
270239
elif cell_type == "amount_currency":
271240
if line_dict.get("currency_name", False):
272241
format_amt = self._get_currency_amt_format_dict(
273242
line_dict, report_data
274243
)
275244
report_data["sheet"].write_number(
276-
report_data["row_pos"], col_pos, float(value), format_amt
245+
report_data["row_pos"],
246+
col_pos,
247+
self._round_value_by_currency(
248+
value, line_dict.get("currency_id")
249+
),
250+
format_amt,
277251
)
278252
elif cell_type == "currency_name":
279253
report_data["sheet"].write_string(
@@ -286,54 +260,6 @@ def write_line_from_dict(self, line_dict, report_data):
286260
self.write_non_standard_column(cell_type, col_pos, value)
287261
report_data["row_pos"] += 1
288262

289-
def write_initial_balance(self, my_object, label, report_data):
290-
"""Write a specific initial balance line on current line
291-
using defined columns field_initial_balance name.
292-
Columns are defined with `_get_report_columns` method.
293-
"""
294-
col_pos_label = self._get_col_pos_initial_balance_label()
295-
report_data["sheet"].write(
296-
report_data["row_pos"],
297-
col_pos_label,
298-
label,
299-
report_data["formats"]["format_right"],
300-
)
301-
for col_pos, column in report_data["columns"].items():
302-
if column.get("field_initial_balance"):
303-
value = getattr(my_object, column["field_initial_balance"])
304-
cell_type = column.get("type", "string")
305-
if cell_type == "string":
306-
report_data["sheet"].write_string(
307-
report_data["row_pos"], col_pos, value or ""
308-
)
309-
elif cell_type == "amount":
310-
report_data["sheet"].write_number(
311-
report_data["row_pos"],
312-
col_pos,
313-
float(value),
314-
report_data["formats"]["format_amount"],
315-
)
316-
elif cell_type == "amount_currency":
317-
if my_object.currency_id:
318-
format_amt = self._get_currency_amt_format(
319-
my_object, report_data
320-
)
321-
report_data["sheet"].write_number(
322-
report_data["row_pos"], col_pos, float(value), format_amt
323-
)
324-
elif column.get("field_currency_balance"):
325-
value = getattr(my_object, column["field_currency_balance"])
326-
cell_type = column.get("type", "string")
327-
if cell_type == "many2one":
328-
if my_object.currency_id:
329-
report_data["sheet"].write_string(
330-
report_data["row_pos"],
331-
col_pos,
332-
value.name or "",
333-
report_data["formats"]["format_right"],
334-
)
335-
report_data["row_pos"] += 1
336-
337263
def write_initial_balance_from_dict(self, my_object, label, report_data):
338264
"""Write a specific initial balance line on current line
339265
using defined columns field_initial_balance name.
@@ -358,16 +284,21 @@ def write_initial_balance_from_dict(self, my_object, label, report_data):
358284
report_data["sheet"].write_number(
359285
report_data["row_pos"],
360286
col_pos,
361-
float(value),
287+
self._round_value_by_currency(value),
362288
report_data["formats"]["format_amount"],
363289
)
364290
elif cell_type == "amount_currency":
365291
if my_object["currency_id"]:
366-
format_amt = self._get_currency_amt_format(
292+
format_amt = self._get_currency_amt_format_dict(
367293
my_object, report_data
368294
)
369295
report_data["sheet"].write_number(
370-
report_data["row_pos"], col_pos, float(value), format_amt
296+
report_data["row_pos"],
297+
col_pos,
298+
self._round_value_by_currency(
299+
value, my_object.get("currency_id")
300+
),
301+
format_amt,
371302
)
372303
elif column.get("field_currency_balance"):
373304
value = my_object.get(column["field_currency_balance"], False)
@@ -382,73 +313,6 @@ def write_initial_balance_from_dict(self, my_object, label, report_data):
382313
)
383314
report_data["row_pos"] += 1
384315

385-
def write_ending_balance(self, my_object, name, label, report_data):
386-
"""Write a specific ending balance line on current line
387-
using defined columns field_final_balance name.
388-
Columns are defined with `_get_report_columns` method.
389-
"""
390-
for i in range(0, len(report_data["columns"])):
391-
report_data["sheet"].write(
392-
report_data["row_pos"],
393-
i,
394-
"",
395-
report_data["formats"]["format_header_right"],
396-
)
397-
row_count_name = self._get_col_count_final_balance_name()
398-
col_pos_label = self._get_col_pos_final_balance_label()
399-
report_data["sheet"].merge_range(
400-
report_data["row_pos"],
401-
0,
402-
report_data["row_pos"],
403-
row_count_name - 1,
404-
name,
405-
report_data["formats"]["format_header_left"],
406-
)
407-
report_data["sheet"].write(
408-
report_data["row_pos"],
409-
col_pos_label,
410-
label,
411-
report_data["formats"]["format_header_right"],
412-
)
413-
for col_pos, column in report_data["columns"].items():
414-
if column.get("field_final_balance"):
415-
value = getattr(my_object, column["field_final_balance"])
416-
cell_type = column.get("type", "string")
417-
if cell_type == "string":
418-
report_data["sheet"].write_string(
419-
report_data["row_pos"],
420-
col_pos,
421-
value or "",
422-
report_data["formats"]["format_header_right"],
423-
)
424-
elif cell_type == "amount":
425-
report_data["sheet"].write_number(
426-
report_data["row_pos"],
427-
col_pos,
428-
float(value),
429-
report_data["formats"]["format_header_amount"],
430-
)
431-
elif cell_type == "amount_currency":
432-
if my_object.currency_id:
433-
format_amt = self._get_currency_amt_header_format(
434-
my_object, report_data
435-
)
436-
report_data["sheet"].write_number(
437-
report_data["row_pos"], col_pos, float(value), format_amt
438-
)
439-
elif column.get("field_currency_balance"):
440-
value = getattr(my_object, column["field_currency_balance"])
441-
cell_type = column.get("type", "string")
442-
if cell_type == "many2one":
443-
if my_object.currency_id:
444-
report_data["sheet"].write_string(
445-
report_data["row_pos"],
446-
col_pos,
447-
value.name or "",
448-
report_data["formats"]["format_header_right"],
449-
)
450-
report_data["row_pos"] += 1
451-
452316
def write_ending_balance_from_dict(self, my_object, name, label, report_data):
453317
"""Write a specific ending balance line on current line
454318
using defined columns field_final_balance name.
@@ -492,7 +356,7 @@ def write_ending_balance_from_dict(self, my_object, name, label, report_data):
492356
report_data["sheet"].write_number(
493357
report_data["row_pos"],
494358
col_pos,
495-
float(value),
359+
self._round_value_by_currency(value),
496360
report_data["formats"]["format_header_amount"],
497361
)
498362
elif cell_type == "amount_currency":
@@ -501,7 +365,12 @@ def write_ending_balance_from_dict(self, my_object, name, label, report_data):
501365
my_object, report_data
502366
)
503367
report_data["sheet"].write_number(
504-
report_data["row_pos"], col_pos, float(value), format_amt
368+
report_data["row_pos"],
369+
col_pos,
370+
self._round_value_by_currency(
371+
value, my_object.get("currency_id")
372+
),
373+
format_amt,
505374
)
506375
elif column.get("field_currency_balance"):
507376
value = my_object.get(column["field_currency_balance"], False)
@@ -523,28 +392,6 @@ def write_ending_balance_from_dict(self, my_object, name, label, report_data):
523392
)
524393
report_data["row_pos"] += 1
525394

526-
def _get_currency_amt_format(self, line_object, report_data):
527-
"""Return amount format specific for each currency."""
528-
if "account_group_id" in line_object and line_object["account_group_id"]:
529-
format_amt = report_data["formats"]["format_amount_bold"]
530-
field_prefix = "format_amount_bold"
531-
else:
532-
format_amt = report_data["formats"]["format_amount"]
533-
field_prefix = "format_amount"
534-
if "currency_id" in line_object and line_object.get("currency_id", False):
535-
if isinstance(line_object["currency_id"], int):
536-
currency = self.env["res.currency"].browse(line_object["currency_id"])
537-
else:
538-
currency = line_object["currency_id"]
539-
field_name = f"{field_prefix}_{currency.name}"
540-
if hasattr(self, field_name):
541-
format_amt = getattr(self, field_name)
542-
else:
543-
format_amt = report_data["workbook"].add_format()
544-
report_data["field_name"] = format_amt
545-
format_amt.set_num_format(self._report_xlsx_currency_format(currency))
546-
return format_amt
547-
548395
def _get_currency_amt_format_dict(self, line_dict, report_data):
549396
"""Return amount format specific for each currency."""
550397
if line_dict.get("account_group_id", False) and line_dict["account_group_id"]:
@@ -567,24 +414,6 @@ def _get_currency_amt_format_dict(self, line_dict, report_data):
567414
format_amt.set_num_format(self._report_xlsx_currency_format(currency))
568415
return format_amt
569416

570-
def _get_currency_amt_header_format(self, line_object, report_data):
571-
"""Return amount header format for each currency."""
572-
format_amt = report_data["formats"]["format_header_amount"]
573-
if line_object.currency_id:
574-
field_name = f"format_header_amount_{line_object.currency_id.name}"
575-
if hasattr(self, field_name):
576-
format_amt = getattr(self, field_name)
577-
else:
578-
format_amt = report_data["workbook"].add_format(
579-
{"bold": True, "border": True, "bg_color": "#FFFFCC"}
580-
)
581-
report_data["field_name"] = format_amt
582-
format_amount = "#,##0." + (
583-
"0" * line_object.currency_id.decimal_places
584-
)
585-
format_amt.set_num_format(format_amount)
586-
return format_amt
587-
588417
def _get_currency_amt_header_format_dict(self, line_object, report_data):
589418
"""Return amount header format for each currency."""
590419
format_amt = report_data["formats"]["format_header_amount"]

account_financial_report/report/general_ledger_xlsx.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,20 @@ def _generate_report_content(self, workbook, report, data, report_data):
309309
for account_ids, value in line[
310310
"analytic_distribution"
311311
].items():
312-
for account_id in account_ids.split(","):
312+
names = " ".join(
313+
analytic_data[int(account_id.strip())]["name"]
314+
for account_id in account_ids.split(",")
315+
)
316+
if value < 100:
313317
analytic_distribution += (
314-
f"{analytic_data[int(account_id)]['name']} "
318+
"%s %d%% ",
319+
(
320+
names,
321+
value,
322+
),
315323
)
316-
if value < 100:
317-
analytic_distribution += f"{value:d}% "
324+
else:
325+
analytic_distribution += f"{names} "
318326
line.update(
319327
{
320328
"taxes_description": taxes_description,

account_financial_report/static/description/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ <h3><a class="toc-backref" href="#toc-entry-10">Contributors</a></h3>
521521
<li>Alexandre D. D??az</li>
522522
<li>V??ctor Mart??nez</li>
523523
<li>Carolina Fernandez</li>
524+
<li>Eduardo Ezerouali</li>
524525
</ul>
525526
</li>
526527
<li><a class="reference external" href="https://www.sygel.es">Sygel</a>:<ul>

0 commit comments

Comments
 (0)