Skip to content

Commit

Permalink
Merge pull request #699 from Som-Energia/fix_som_informe_different_ye…
Browse files Browse the repository at this point in the history
…ars_lines

Fix som_informe more than 1 line when different years
  • Loading branch information
pauboixsom authored Sep 3, 2024
2 parents 2876ec4 + 287279d commit 4025e64
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
8 changes: 4 additions & 4 deletions som_informe/report/components/InvoiceF1NG/InvoiceF1NG.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
from ..component_utils import dateformat, get_description, get_invoice_line, get_unit_magnitude
from ..component_utils import dateformat, get_description, get_invoice_lines, get_unit_magnitude


class InvoiceF1NG:
Expand Down Expand Up @@ -78,11 +78,11 @@ def get_data(self, cursor, uid, wiz, invoice, context={}):
dict_linia["lectura_final"] = linia.lectura_actual
dict_linia["consum_entre"] = linia.lectura_actual - linia.lectura_desde
dict_linia["ajust"] = linia.ajust
i_line = get_invoice_line(invoice, linia.magnitud, linia.periode)
i_lines = get_invoice_lines(invoice, linia.magnitud, linia.periode)
if dict_linia["magnitud_desc"] == "Excesos de potencia":
dict_linia["total_facturat"] = i_line.price_unit if i_line else 0
dict_linia["total_facturat"] = i_lines[0].price_unit if i_lines else 0
else:
dict_linia["total_facturat"] = i_line.quantity if i_line else 0
dict_linia["total_facturat"] = sum(i_line.quantity for i_line in i_lines)
dict_linia["unit"] = get_unit_magnitude(linia.magnitud)
result["linies"].append(dict_linia)
elif f1.tipo_factura_f1 == "otros":
Expand Down
8 changes: 5 additions & 3 deletions som_informe/report/components/InvoiceF1R/InvoiceF1R.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..component_utils import dateformat, get_description, get_invoice_line, get_unit_magnitude
from ..component_utils import dateformat, get_description, get_invoice_lines, get_unit_magnitude


class InvoiceF1R:
Expand Down Expand Up @@ -63,8 +63,10 @@ def get_data(self, cursor, uid, wiz, invoice, context):
dict_linia["lectura_final"] = linia.lectura_actual
dict_linia["consum_entre"] = linia.lectura_actual - linia.lectura_desde
dict_linia["ajust"] = linia.ajust
i_line = get_invoice_line(invoice, linia.magnitud, linia.periode)
dict_linia["total_facturat"] = i_line.quantity if i_line else ""
i_lines = get_invoice_lines(invoice, linia.magnitud, linia.periode)
dict_linia["total_facturat"] = ""
if i_lines:
dict_linia["total_facturat"] = sum(i_line.quantity for i_line in i_lines)
dict_linia["unit"] = get_unit_magnitude(linia.magnitud)

result["linies"].append(dict_linia)
Expand Down
9 changes: 5 additions & 4 deletions som_informe/report/components/component_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,20 @@ def get_unit_magnitude(magnitud):
return magnitud_a_unit.get(magnitud, "eV")


def get_invoice_line(invoice, magnitud, periode):
def get_invoice_lines(invoice, magnitud, periode):
if magnitud == "PM" and periode == "93":
periode = "9392"

tipus = magnitud_a_tipus.get(magnitud, None)
name = periode_a_name.get(periode, None)
if not name or not tipus:
return None
return []

lines = []
for l in invoice.linia_ids: # noqa: E741
if l.name == name and l.tipus == tipus:
return l
return None
lines.append(l)
return lines


def to_date(str_date, hours=False):
Expand Down

0 comments on commit 4025e64

Please sign in to comment.