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

CCPP per contractes amb AUTO VIRTUAL #763

Open
wants to merge 18 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
91 changes: 90 additions & 1 deletion som_polissa_condicions_generals/models/report_backend_ccpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,14 @@ def get_polissa_data(self, cursor, uid, pol, context=None):
if pol.state == 'esborrany':
res['modcon_pendent_indexada'] = False
res['modcon_pendent_periodes'] = False
res['modcon_pendent_auvi'] = False
elif pol.state != 'esborrany' and not res['lead']:
res['last_modcon_state'] = pol.modcontractuals_ids[0].state
res['last_modcon_facturacio'] = pol.modcontractuals_ids[0].mode_facturacio
res['last_modcon_auvi'] = pol.modcontractuals_ids[0].te_auvidi
res['modcon_pendent_indexada'] = res['last_modcon_state'] == 'pendent' and res['last_modcon_facturacio'] == 'index' # noqa: E501
res['modcon_pendent_periodes'] = res['last_modcon_state'] == 'pendent' and res['last_modcon_facturacio'] == 'atr' # noqa: E501
res['modcon_pendent_auvi'] = res['last_modcon_state'] == 'pendent' and res['last_modcon_auvi'] # noqa: E501

if res['modcon_pendent_indexada'] or res['modcon_pendent_periodes']:
res['pricelist'] = pol.modcontractuals_ids[0].llista_preu
Expand Down Expand Up @@ -222,6 +225,88 @@ def get_cups_data(self, cursor, uid, pol, context=None):

return res

def get_mostra_auvi(self, cursor, uid, pol, context=None):
res = False
if pol.state == 'esborrany' and pol.te_auvidi:
# Pol esborrany amb AUVI
res = True
elif pol.state != 'esborrany' and not context.get('lead', False):
# Pol activa
last_modcon_state = pol.modcontractuals_ids[0].state
last_modcon_facturacio = pol.modcontractuals_ids[0].mode_facturacio
last_modcon_auvi = pol.modcontractuals_ids[0].te_auvidi
modcon_pendent_periodes = last_modcon_state == 'pendent' and last_modcon_facturacio == 'atr' # noqa: E501
modcon_pendent_auvi = last_modcon_state == 'pendent' and last_modcon_auvi
modcon_pendent_quit_auvi = last_modcon_state == 'pendent' \
and pol.te_auvidi and not pol.modcontractuals_ids[0].te_auvidi

if (not pol.te_auvidi and not modcon_pendent_auvi) \
or (pol.te_auvidi and (modcon_pendent_periodes or modcon_pendent_quit_auvi)):
res = False
elif (pol.te_auvidi and not modcon_pendent_periodes and not modcon_pendent_quit_auvi) \
or modcon_pendent_auvi:
res = True
return res

def get_pauvi(self, cursor, uid, sgpol, context, ctx):
imd_obj = self.pool.get('ir.model.data')
fp_obj = self.pool.get('account.fiscal.position')
pricelist_index = sgpol.servei_generacio_id.llista_preu_venda_id
if not pricelist_index:
return 0.0

fp_k_id = sgpol.polissa_id.fiscal_position_id \
if sgpol.polissa_id.fiscal_position_id else ctx.get('force_fiscal_position', False)
if fp_k_id:
fp_k = fp_obj.browse(cursor, uid, fp_k_id)
else:
fp_k = False
poduct_pauvi_id = imd_obj.get_object_reference(
cursor, uid, 'giscedata_serveis_generacio', 'facturacio_empresa_preu_fix'
)[1]

pauvi = pricelist_index.get_atr_price(
tipus='', product_id=poduct_pauvi_id, fiscal_position=fp_k,
with_taxes=False)[0]
return pauvi

def get_auvi_data(self, cursor, uid, pol, context=None, ctx=None):
res = {}
sgpol_obj = self.pool.get('giscedata.servei.generacio.polissa')
auvi = self.get_mostra_auvi(cursor, uid, pol, context=context)
auvi_pauvi = 0.0
auvi_name = ""
auvi_percent = 0.0
if self.get_mostra_auvi(cursor, uid, pol, context=context):
today_str = datetime.today().strftime("%Y-%m-%d")
sgpol_ids = sgpol_obj.search(cursor, uid, [
('polissa_id', '=', pol.id),
('cups_name', '=', pol.cups.name),
'|',
('data_sortida', '=', False),
('data_sortida', '>', today_str),
'|',
'&',
('data_inici', '!=', False),
('data_inici', '<=', today_str),
'&',
('data_inici', '=', False),
('data_incorporacio', '<=', today_str),
])
if len(sgpol_ids) > 0:
sgpol = sgpol_obj.browse(cursor, uid, sgpol_ids[0])
auvi_percent = sgpol.percentatge or 0.0
auvi_name = sgpol.servei_generacio_id.name
auvi_pauvi = self.get_pauvi(cursor, uid, sgpol, context, ctx)

res = {
'auvi': auvi,
'auvi_pauvi': auvi_pauvi,
'auvi_name': auvi_name,
'auvi_percent': auvi_percent,
}
return res

def get_prices_data(self, cursor, uid, pol, context=None): # noqa: C901
res = {}
lead = context.get('lead')
Expand Down Expand Up @@ -283,7 +368,7 @@ def get_prices_data(self, cursor, uid, pol, context=None): # noqa: C901
elif dades_tarifa['date_end'] and dades_tarifa['date_start']:
text_vigencia = _(u"(vigents fins al {})").format(
(datetime.strptime(dades_tarifa['date_end'], '%Y-%m-%d')).strftime('%d/%m/%Y'))
elif datetime.strptime(dades_tarifa['date_start'], '%Y-%m-%d') > datetime.today():
elif dades_tarifa['date_start'] and datetime.strptime(dades_tarifa['date_start'], '%Y-%m-%d') > datetime.today(): # noqa: E501
text_vigencia = _(u"(vigents a partir del {})").format(
datetime.strptime(dades_tarifa['date_start'], '%Y-%m-%d').strftime('%d/%m/%Y'))
ctx.update({'date': datetime.strptime(dades_tarifa['date_start'], '%Y-%m-%d')})
Expand Down Expand Up @@ -405,6 +490,10 @@ def get_prices_data(self, cursor, uid, pol, context=None): # noqa: C901
res['coeficient_k_untaxed'] = coeficient_k_untaxed
res['coeficient_k'] = coeficient_k

# AUVI
auvi_data = self.get_auvi_data(cursor, uid, pol, context, ctx)
res.update(auvi_data)

return res


Expand Down
53 changes: 53 additions & 0 deletions som_polissa_condicions_generals/report/components/auvi.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<%def name="auvi(polissa, prices, untaxed)">
<tr>
<td class="bold">${_(u"Terme energia (€/kWh)")}</td>
<td class="center reset_line_height" colspan="6">
<span class="normal_font_weight">
<b>${_(u"Tarifa autoconsum virtual")}</b>${_(u"(2) - el preu horari (PH) es calcula d'acord amb la fórmula:")}
</span>
<br/>
<!-- Pendent agafar el PAUVI des del ERP -->
<span>${_(u"PHAUVI = 1,015 * [(PAUVI + Pc + Sc + Dsv + GdO + POsOm) (1 + Perd) + FE + F] + PTD + CA")}</span>

%if polissa['tarifa'] != "2.0TD" and untaxed:
<br/>
<span class="normal_font_weight">${_(u"on la franja de la cooperativa")}</span>
<span>&nbsp;${("(F) = %s €/kWh</B>") % formatLang(prices['coeficient_k_untaxed'], digits=6)}</span>
%endif
%if polissa['tarifa'] != "2.0TD" and not untaxed:
<br/>
<span class="normal_font_weight">${_(u"on la franja de la cooperativa")}</span>
<span>&nbsp;${("(F) = %s €/kWh</B>") % formatLang(prices['coeficient_k'], digits=6)}</span>
%endif

</td>
</tr>
<tr>
<td class="bold">${_(u"on PAUVI")}</td>
<td class="center reset_line_height" colspan="6">
<span class="">
${formatLang(prices['auvi_pauvi'], digits=6)}
</span>
<span class="">${_(u" €/MWh")}</span>
</td>
</tr>
<tr>
<td class="bold">${_(u"percentatge assignat")}</td>
<td class="center reset_line_height" colspan="6">
<span class="">
${("%s") % prices['auvi_name']} ${formatLang(prices['auvi_percent'], digits=2)} ${_(u"%")}
</span>
</td>
</tr>
%if polissa['tarifa'] == "2.0TD":
<tr>
<td class="bold">${_(u"on la franja de la cooperativa")}</td>
<td class="center" colspan="3">
<span class="">${("(F) = %s €/kWh</B>") % formatLang(prices['coeficient_k_untaxed'], digits=6)}</span>
</td>
<td class="center divisio_impostos" colspan="3">
<span class="">${("(F) = %s €/kWh</B>") % formatLang(prices['coeficient_k'], digits=6)}</span>
</td>
</tr>
%endif
</%def>
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<%def name="disclaimers(polissa)">
<%def name="disclaimers(polissa, prices)">
<div class="modi_condicions">
<p>
${_(u"Al contractar saccepten aquestes ")}
%if (polissa['mode_facturacio'] == 'index' and not polissa['modcon_pendent_periodes']) or polissa['modcon_pendent_indexada']:
${_(u"Al contractar s'accepten aquestes ")}
%if not prices['auvi'] and ((polissa['mode_facturacio'] == 'index' and not polissa['modcon_pendent_periodes']) or polissa['modcon_pendent_indexada']):
${_(u"Condicions Particulars, Específiques i les Condicions Generals,")}
%elif prices['auvi']:
${_(u"Condicions Particulars, Específiques de l'Autoconsum Virtual, Específiques de la tarifa Indexada i les Condicions Generals,")}
%else:
${_(u"Condicions Particulars i les Condicions Generals")}
${_(u"Condicions Particulars i les Condicions Generals,")}
%endif
${_(u"que es poden consultar a les pàgines següents. Si ens cal modificar-les, a la clàusula 9 de les Condicions Generals sexplica el procediment que seguirem. En cas que hi hagi alguna discrepància, prevaldrà el que estigui previst en aquestes Condicions Particulars.")}
${_(u"que es poden consultar a les pàgines següents. Si ens cal modificar-les, a la clàusula 9 de les Condicions Generals s'explica el procediment que seguirem. En cas que hi hagi alguna discrepància, prevaldrà el que estigui previst en aquestes Condicions Particulars.")}
</p>
</div>
</%def>
12 changes: 10 additions & 2 deletions som_polissa_condicions_generals/report/components/prices_info.mako
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@
</th>
%endfor
%endif
%endif
%if prices['auvi']:
<%namespace file="/som_polissa_condicions_generals/report/components/auvi.mako" import="auvi"/>
${auvi(polissa, prices, True)}
%endif
<tr>
<td class="bold">${_(u"Terme energia (€/kWh)")}</td>
Expand Down Expand Up @@ -184,7 +188,7 @@
%endif
%endif
%endfor
</tr>
</tr>
%endif
<!-- INICI Bloc Generationkwh -->
%if polissa['te_assignacio_gkwh']:
Expand Down Expand Up @@ -270,7 +274,7 @@
%if polissa['te_assignacio_gkwh']:
<span class="bold">(1) </span> ${_(u"Terme d'energia en cas de participar-hi, segons condicions del contracte GenerationkWh.")}<br/>
%endif
%if (polissa['mode_facturacio'] == 'index' and not polissa['modcon_pendent_periodes']) or polissa['modcon_pendent_indexada']:
%if (polissa['mode_facturacio'] == 'index' and not polissa['modcon_pendent_periodes']) or polissa['modcon_pendent_indexada'] or prices['auvi']:
<span class="bold">(2) </span> ${_(u"Pots consultar el significat de les variables a les condicions específiques que trobaràs a continuació.")}
%endif
</div>
Expand Down Expand Up @@ -314,6 +318,10 @@
%endif
%endfor
</tr>
%if prices['auvi']:
<%namespace file="/som_polissa_condicions_generals/report/components/auvi.mako" import="auvi"/>
${auvi(polissa, prices, False)}
%endif
<tr>
<td class="bold">${_(u"Terme energia (€/kWh)")}</td>
%if prices['mostra_indexada']:
Expand Down
Loading
Loading