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

Nou sub component per mostrar l'informació dels autoconsums col·lectius al pdf de la factura #691

Open
wants to merge 2 commits into
base: main
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
86 changes: 82 additions & 4 deletions giscedata_facturacio_comer_som/giscedata_facturacio_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,24 @@ def te_autoconsum_amb_excedents(fact, pol):

def te_autoconsum_collectiu(fact, pol):
if te_autoconsum(fact, pol):
if pol.autoconsum_id:
if pol.autoconsum_id.collectiu:
for cups_autoconsum in pol.autoconsum_cups_ids:
if cups_autoconsum.autoconsum_id and cups_autoconsum.autoconsum_id.collectiu:
return True
return False


def te_autoconsum_no_collectiu(fact, pol):
if te_autoconsum(fact, pol):
if len(pol.autoconsum_cups_ids) == 0: # old cases not migrated
return True

for cups_autoconsum in pol.autoconsum_cups_ids:
if cups_autoconsum.autoconsum_id:
if cups_autoconsum.autoconsum_id.collectiu is False:
return True
return False


def te_gkwh(fact):
return fact.is_gkwh

Expand Down Expand Up @@ -3485,9 +3497,19 @@ def get_component_energy_consumption_detail_td_data(self, fact, pol):

adjust_reason.append(data["adjust_reason"])

collectives = []
for coll in pol.autoconsum_cups_ids:
if coll.autoconsum_id.collectiu:
data = self.get_sub_component_energy_consumption_detail_collective_td_data(
fact, pol, coll)
if data["is_visible"]:
collectives.append(data)
adjust_reason.append(data["adjust_reason"])

highest_adjust_reason = self.adjust_readings_priority(adjust_reason)
data = {
"meters": meters,
"collectives": collectives,
"info": self.get_sub_component_energy_consumption_detail_td_info_data(
fact, pol, highest_adjust_reason
),
Expand Down Expand Up @@ -3597,8 +3619,10 @@ def get_sub_component_energy_consumption_detail_td_surplus_data(self, fact, pol,

adjust_reason = []
if meter.name in lectures:
data["is_visible"] = len(lectures[meter.name]) > 0 and te_autoconsum_amb_excedents(
fact, pol
data["is_visible"] = (
len(lectures[meter.name]) > 0
and te_autoconsum_amb_excedents(fact, pol)
and te_autoconsum_no_collectiu(fact, pol)
)
for reading in lectures[meter.name]:
data[reading[0]] = {
Expand Down Expand Up @@ -3730,6 +3754,60 @@ def get_sub_component_energy_consumption_detail_td_info_data(self, fact, pol, ad
}
return data

def get_sub_component_energy_consumption_detail_collective_td_data(self, fact, pol, collective):

def adjust_reason(subs):
return [sub["adjust_reason"] for sub in subs]

def visibility(subs):
return any([sub["is_visible"] for sub in subs])

generated = self.get_sub_component_energy_consumption_detail_td_collective_data_data(
fact, pol, collective)
generated["last_visible"] = True
data = {
"name": collective.autoconsum_id.cau,
"showing_periods": self.get_matrix_show_periods(pol),
"generated": generated,
"is_visible": visibility([generated]),
"adjust_reason": self.adjust_readings_priority(
adjust_reason([generated])
),
}
return data

def get_sub_component_energy_consumption_detail_td_collective_data_data(self, fact, pol, collective): # noqa: E501
# TODO: this function generates dummy data for developing purposes
(a, a, a, a, a, a, a, lectures_g, a, a, a, a, a, a, a, a, a, a, a) = self.get_readings_data(
fact
)
lectures = lectures_g
data = {
"showing_periods": self.get_matrix_show_periods(pol),
"is_visible": False,
"title": _(u"Autoconsum compartit (kWh)"),
"is_active": False,
}

meter_name = "304798778"
adjust_reason = []
if meter_name in lectures:
data["is_visible"] = len(lectures[meter_name]) > 0 and te_autoconsum_amb_excedents(
fact, pol
)
for reading in lectures[meter_name]:
data[reading[0]] = {
"generated_coef": reading[1],
"auto_consumed": reading[2],
"surplus": reading[3],
}
data["initial_date"] = reading[4]
data["final_date"] = reading[5]
adjust_reason.append(reading[9])

data["adjust_reason"] = self.adjust_readings_priority(adjust_reason)
return data

def get_component_cnmc_comparator_qr_link_data(self, fact, pol):
# fact needs to have max_potencies_demandades for the QR to be correct
required_max_requested_powers, max_potencies_demandades = self.max_requested_powers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@
</table>
</div>
% endfor
%for coll in id.collectives:
<h1>${_(u"Autoconsum col·lectiu: %s") %(coll.name)}</h1>
<table id="energy_consumption_detail_td">
<tr>
<th class="concepte_td">${_(u"Tipus")}</th>
<th class="detall_td">${_(u"Detall de lectures")}</th>
% if len(coll.showing_periods) == 3:
<th class="periods_td">${_(u"Punta")}</th>
<th class="periods_td">${_(u"Pla")}</th>
<th class="periods_td">${_(u"Vall")}</th>
% else:
% for period in coll.showing_periods:
<th class="periods_td">${_(u"%s") %(period)}</th>
% endfor
% endif
<th class="info_td"></th>
<%include file="/giscedata_facturacio_comer_som/report/components/energy_consumption_detail_td_collective/energy_consumption_detail_td_collective.mako" args="coll=coll.generated" />
</tr>
</table>
% endfor
<div class="energy_consumption_detail_td_block">
<%include file="/giscedata_facturacio_comer_som/report/components/energy_consumption_detail_td_info/energy_consumption_detail_td_info.mako" args="id_info=id.info" />
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<%page args="coll" />
<%import locale%>
% if False:
${}
% endif
% if coll.is_visible:
<tr>
<td class="td_first concepte_td" rowspan="3">${_(u"Autoconsum compartit (kWh)")}</td>
<td class="detall_td">${_(u"Generació segons coeficient de repartiment (periode del %s fins al %s)") % (coll.initial_date, coll.final_date)}</td>
% for p in coll.showing_periods:
% if p in coll:
<td>${_(u"%s") %(int(coll[p]["generated_coef"]))}</td>
% else:
<td></td>
% endif
% endfor
<td></td>
</tr>
<tr>
<td class="detall_td">${_(u"Energia autoconsumida (periode del %s fins al %s)") % (coll.initial_date, coll.final_date)}</td>
% for p in coll.showing_periods:
% if p in coll:
<td>${_(u"%s") %(int(coll[p]["auto_consumed"]))}</td>
% else:
<td></td>
% endif
% endfor
<td></td>
</tr>
% if coll.last_visible:
<tr class="tr_bold">
% else:
<tr class="tr_bold last_row">
% endif
<td class="detall_td">${_(u"Excedent")}
% if coll.is_active:
<sup class="sup_bold">(1)</sup>
% endif
</td>
% for p in coll.showing_periods:
% if p in coll:
<td>${_(u"%s") %(int(round(coll[p]["surplus"])))}</td>
% else:
<td></td>
% endif
% endfor
<td>
% if coll.adjust_reason != False:
<sup>(2)</sup>
% endif
</td>
</tr>
% endif
Loading