Skip to content

Commit

Permalink
Merge pull request #673 from gisce/improve/60704_potencia_adscrita_A1
Browse files Browse the repository at this point in the history
A1: Cambiar la forma de extraer la potencia adscrita de un CUPS
  • Loading branch information
ecarreras authored Jan 15, 2025
2 parents 7951ccb + f243be3 commit bb8c3a7
Showing 1 changed file with 45 additions and 22 deletions.
67 changes: 45 additions & 22 deletions libcnmc/cir_8_2021/FA1.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,49 @@ def get_tensio(self, cups, year, tensio_modcon):

return tensio

def get_pot_adscrita(self, cups, year, o_potencia):
O = self.connection
o_pot_ads = 0
if cups.get('cups_estadistiques'):
search_params = [
('year', '=', year),
('id', 'in', cups['cups_estadistiques'])
]
estadist_id = O.GiscedataCupsEstadistiques.search(
search_params,
0,
0,
False,
{'active_test': False}
)
if estadist_id:
estadist_id = estadist_id[0]
estadist = O.GiscedataCupsEstadistiques.read(estadist_id, ['potencia_adscrita'])
if estadist['potencia_adscrita']:
o_pot_ads = estadist['potencia_adscrita']
else:
if cups['force_potencia_adscrita']:
o_pot_ads = cups['potencia_adscrita']
else:
# Buscar butlletins vigents en data circular i agafgar el màxim
current_date = '{}-01-01'.format(year)
but_ids = O.GiscedataButlleti.search(
[('cups_id', '=', cups['id']), '|', '|', '|', '&',
('data', '=', False), ('data_vigencia', '=', False),
'&', ('data', '<=', current_date),
('data_vigencia', '=', False), '&',
('data', '=', False),
('data_vigencia', '>=', current_date), '&',
('data', '<=', current_date),
('data_vigencia', '>=', current_date), ], 0, 0, False,
{'active_test': False})
if but_ids:
o_pot_ads = max(b['pot_max_admisible'] for b in
O.GiscedataButlleti.read(but_ids, ['pot_max_admisible']))
if o_pot_ads < o_potencia:
o_pot_ads = o_potencia
return o_pot_ads

def get_baixa_cups(self, cups_id):
"""
Devuelve si un CUPS ha estado de baja durante el año
Expand Down Expand Up @@ -447,6 +490,7 @@ def consumer(self):
'cnmc_factures_estimades', 'cnmc_factures_total',
'cnmc_energia_autoconsumida', 'cnmc_energia_excedentaria',
'force_potencia_adscrita', 'cnmc_conexion_autoconsumo',
'cups_estadistiques'
]
cups = O.GiscedataCupsPs.read(item, fields_to_read)
if not cups or not cups.get('name'):
Expand Down Expand Up @@ -704,28 +748,7 @@ def consumer(self):
o_cod_tfa = self.default_o_cod_tfa

# potencia adscrita
o_pot_ads = 0

if cups['force_potencia_adscrita']:
o_pot_ads = cups['potencia_adscrita']
else:
# Buscar butlletins vigents en data circular i agafgar el màxim
current_date = '{}-01-01'.format(self.year)
but_ids = self.connection.GiscedataButlleti.search([
('cups_id', '=', cups['id']),
'|', '|', '|',
'&', ('data', '=', False), ('data_vigencia', '=', False),
'&', ('data', '<=', current_date), ('data_vigencia', '=', False),
'&', ('data', '=', False), ('data_vigencia', '>=', current_date),
'&', ('data', '<=', current_date), ('data_vigencia', '>=', current_date),
], 0, 0, False, {'active_test': False})
if but_ids:
o_pot_ads = max(
b['pot_max_admisible']
for b in self.connection.GiscedataButlleti.read(but_ids, ['pot_max_admisible'])
)
if o_pot_ads < o_potencia:
o_pot_ads = o_potencia
o_pot_ads = self.get_pot_adscrita(cups, self.year, o_potencia)

res_srid = ['', '']
if vertex:
Expand Down

0 comments on commit bb8c3a7

Please sign in to comment.