Skip to content

Commit

Permalink
Merge pull request #115 from Som-Energia/NEW_enviromental_impact_grap…
Browse files Browse the repository at this point in the history
…hic_component

Afegim el nou component simplificat per mandat del BOE-A-2021-20574
  • Loading branch information
FranciscoCubero committed Apr 20, 2022
2 parents dcc79e5 + 0db77ad commit 1a33e77
Show file tree
Hide file tree
Showing 16 changed files with 651 additions and 140 deletions.
20 changes: 20 additions & 0 deletions giscedata_facturacio_comer_som/giscedata_facturacio_comer_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,25 @@ div.back{
<field name="description">Data d'emisió de la factura a partir de la qual ha d'aparèixer el codi QR i potències màximes demandades a la factura</field>
<field name="value">2021-09-01</field>
</record>
<record model="res.config" id="gdo_and_impact_yearly_switch_date">
<field name="name">gdo_and_impact_yearly_switch_date</field>
<field name="description">Darrera data de publicació de canvi annual dels valors de Impacte Ambiental i de Garantia d'Origen. Alerta: cal modificar també: 1) Valors de la taula d'impacto ambiental de Som Energia, 2) Valors de la taula d'impacto ambiental mitjana nacional i 3) Valors de la taula de Garantia d'Origen (gdo)</field>
<field name="value">2022-05-01</field>
</record>
<record model="res.config" id="som_environmental_impact_data">
<field name="name">som_environmental_impact_data</field>
<field name="description">Valors de la taula d'impacto ambiental de Som Energia</field>
<field name="value">{'renovable':100.0,'cae':0.0,'gasNatural':0.0,'carbo':0.0,'fuelGas': 0.0,'nuclear': 0.0,'altres': 0.0,'emisionCo2': 0.0,'residuRadio': 0.0,'year': '2021'}</field>
</record>
<record model="res.config" id="mitjana_environmental_impact_data">
<field name="name">mitjana_environmental_impact_data</field>
<field name="description">Valors de la taula d'impacto ambiental mitjana nacional</field>
<field name="value">{'renovable':46.7,'cae':3.5,'gasNatural':17.9,'carbo':2.0,'fuelGas': 1.1,'nuclear': 21.2,'altres': 7.6,'emisionCo2': 136,'residuRadio': 535,'year': '2021'}</field>
</record>
<record model="res.config" id="component_gdo_data">
<field name="name">component_gdo_data</field>
<field name="description">Valors de la taula de Garantia d'Origen (gdo)</field>
<field name="value">{'wind_power':350207,'photovoltaic':167755,'hydraulics':4959,'biogas':3555,'total': 526476,'year': '2021'}</field>
</record>
</data>
</openerp>
119 changes: 101 additions & 18 deletions giscedata_facturacio_comer_som/giscedata_facturacio_report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from logging import exception
from osv import osv
from yamlns import namespace as ns
from datetime import datetime,timedelta
Expand Down Expand Up @@ -759,15 +760,38 @@ def get_component_gdo_data(self, fact, pol):
return a dictionary with all GdO clock data needs, data from 2020
"""
lang = fact.lang_partner.lower()[0:2]
data = {

example_data_2020 = """{{
'wind_power': 359390,
'photovoltaic': 75672,
'hydraulics': 30034,
'biogas': 7194,
'total': 472290,
'lang': lang,
'graph': 'gdo_graf_{}.png'.format(lang),
}
'lang': '{}',
'graph': 'gdo_graf_{}_2020.png',
'year': 2020}}""".format(lang,lang)

conf_obj = fact.pool.get('res.config')

swich_date = conf_obj.get(self.cursor, self.uid, 'gdo_and_impact_yearly_switch_date', '2099-05-01')

if fact.date_invoice < swich_date:
data = eval(example_data_2020)
data = json.dumps(data)
data = json.loads(data)
else:
gdo_som = conf_obj.get(self.cursor, self.uid, 'component_gdo_data', example_data_2020)
try:
gdo_som = eval(gdo_som)
gdo_som = json.dumps(gdo_som)
data = json.loads(gdo_som)
data['lang'] = lang
data['graph'] = 'gdo_graf_{}_{}.png'.format(lang, data['year'])
except Exception as e:
data = eval(example_data_2020)
data = json.dumps(data)
data = json.loads(data)

return data

def get_component_flags_data(self, fact, pol):
Expand Down Expand Up @@ -1418,20 +1442,29 @@ def get_component_maximeter_readings_table_data(self, fact, pol):
return data

def get_component_environmental_impact_data(self, fact, pol):

conf_obj = fact.pool.get('res.config')
swich_date = conf_obj.get(self.cursor, self.uid, 'gdo_and_impact_yearly_switch_date', '2099-05-01')

data = {
'is_visible': fact.date_invoice < swich_date,
'c02_emissions': {
'national_average': '0,15',
'som_energia': '0,00',
},
'radioactive_waste': {
'national_average': '0,49',
'som_energia': '0,00',
},
}
}, }
return data

def get_component_electricity_information_data(self, fact, pol):

conf_obj = fact.pool.get('res.config')
swich_date = conf_obj.get(self.cursor, self.uid, 'gdo_and_impact_yearly_switch_date', '2099-05-01')

data = {
'is_visible': fact.date_invoice < swich_date,
'year_graph': 2020,
'is_inport': True,
'inport_export_value': 1.3,
Expand Down Expand Up @@ -1760,19 +1793,19 @@ def get_component_invoice_details_td_data(self, fact, pol):
def get_sub_component_invoice_details_td(self, fact, pol, linies, lectures = None):
readings = {}
if lectures != None:
for key,comptador in lectures.items():
estimada = False
num_lectures = len(comptador)
while not estimada and num_lectures > 0:
num_lectures -= 1
lectura = comptador[num_lectures]
data = str(datetime.strptime(lectura[4], '%d/%m/%Y').date() + timedelta(days=1))
if lectura[6] != 'real' or lectura[7] !='real':
for comptador_name, lectures_comptador in lectures.items():
for lectura in lectures_comptador:
if lectura[0] == u'P1':
data = str(datetime.strptime(lectura[4], '%d/%m/%Y').date() + timedelta(days=1))
origin = _(u'estimada')
estimada = True
else:
origin = _(u'real')
readings[data] = origin
if lectura[6] == 'real' and lectura[7] =='real':
origin = _(u'real')
elif (lectura[6] == 'estimada distribuïdora' or lectura[6] == 'real') and lectura[7] == 'calculada segons CCH':
origin = _(u'calculada')
elif lectura[6] == 'calculada segons CCH' and (lectura[7] =='calculada segons CCH' or lectura[7] == 'real'):
origin = _(u'calculada')

readings[data] = origin

lines_data = {}
block = 0
Expand Down Expand Up @@ -2614,4 +2647,54 @@ def get_component_cnmc_comparator_qr_link_data(self, fact, pol):
}
return data

def get_component_simplified_enviromental_impact_data(self, fact, pol):
example_mitjana_2020 = """{
'renovable': 4.9,
'cae': 4.9,
'gasNatural': 21.5,
'carbo': 1.9,
'fuelGas': 2.2,
'nuclear': 21.8,
'altres': 7.7,
'emisionCo2': 204,
'residuRadio': 530,
'year': '2020'}"""
example_som_2020 = """{
'renovable': 100.0,
'cae': 0.0,
'gasNatural': 0.0,
'carbo': 0.0,
'fuelGas': 0.0,
'nuclear': 0.0,
'altres': 0.0,
'emisionCo2': 0,
'residuRadio': 0,
'year': '2020'}"""

def eval_and_json(text):
text_eval = eval(text)
text_json = json.dumps(text_eval)
return json.loads(text_json)

conf_obj = fact.pool.get('res.config')
swich_date = conf_obj.get(self.cursor, self.uid, 'gdo_and_impact_yearly_switch_date', '2099-05-01')

data = {'is_visible': fact.date_invoice >= swich_date}

seid_som = conf_obj.get(self.cursor, self.uid, 'som_environmental_impact_data', example_som_2020)
try:
data['som'] = eval_and_json(seid_som)
except Exception as e:
data['som'] = eval_and_json(example_som_2020)

seid_mit = conf_obj.get(self.cursor, self.uid, 'mitjana_environmental_impact_data', example_mitjana_2020)
try:
data['mitjana'] = eval_and_json(seid_mit)
except Exception as e:
data['mitjana'] = eval_and_json(example_mitjana_2020)

return data



GiscedataFacturacioFacturaReport()
Loading

0 comments on commit 1a33e77

Please sign in to comment.