Skip to content
Extraits de code Groupes Projets
Valider 58f0e887 rédigé par Benjamin - Le Filament's avatar Benjamin - Le Filament
Parcourir les fichiers

[fix] error variable referenced before assignment & clean code

parent f549a7c5
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -418,86 +418,63 @@ class EnercoopOperation(models.Model): ...@@ -418,86 +418,63 @@ class EnercoopOperation(models.Model):
if type == 'week': if type == 'week':
type_date = 'date_slot:hour' type_date = 'date_slot:hour'
enercoop_counter_id = self.env['enercoop.counter'] domain_all = [
if prm_id: ('enercoop_operation_id', 'in', self.ids),
enercoop_counter_id = self.env['enercoop.counter'].browse(prm_id) ('date_slot', '>=', date_start),
('date_slot', '<', date_end),
]
# Get PRM object if defined
enercoop_counter_id = self.env['enercoop.counter'].browse(prm_id) if prm_id else False
if enercoop_counter_id: if enercoop_counter_id:
domain_prm = domain_all + [('enercoop_counter_id', '=', enercoop_counter_id.id)]
# Get all data group by curves type and date # Get all data group by curves type and date
cdc_ids = self.env['enercoop.enedis.cdc'].sudo().read_group( cdc_ids = self.env['enercoop.enedis.cdc'].sudo().read_group(
[('enercoop_operation_id', 'in', self.ids), domain_prm,
('date_slot', '>=', date_start),
('date_slot', '<', date_end),
'|', ('enercoop_counter_id', '=', False), ('enercoop_counter_id', '=', enercoop_counter_id.id)
],
['power', 'enercoop_operation_id', 'date_slot'], ['power', 'enercoop_operation_id', 'date_slot'],
['comp_data_type', type_date], orderby='comp_data_type, date_slot ASC', lazy=False) ['comp_data_type', type_date], orderby='comp_data_type, date_slot ASC', lazy=False)
if type == 'week': if type == 'week':
cdc_histo_ids = self.env['enercoop.enedis.cdc'].sudo().read_group( cdc_histo_ids = self.env['enercoop.enedis.cdc'].sudo().read_group(
[('enercoop_operation_id', 'in', self.ids), domain_prm,
('date_slot', '>=', date_start),
('date_slot', '<', date_end),
'|', ('enercoop_counter_id', '=', False), ('enercoop_counter_id', '=', enercoop_counter_id.id)
],
['power', 'enercoop_operation_id', 'date_slot'], ['power', 'enercoop_operation_id', 'date_slot'],
['comp_data_type', type_date_histo], orderby='comp_data_type, date_slot ASC', lazy=False) ['comp_data_type', type_date_histo], orderby='comp_data_type, date_slot ASC', lazy=False)
# Get the date for the abscissa axis # Get the date for the abscissa axis
cdc_date_ids = self.env['enercoop.enedis.cdc'].sudo().read_group( cdc_date_ids = self.env['enercoop.enedis.cdc'].sudo().read_group(
[('enercoop_operation_id', 'in', self.ids), domain_prm,
('date_slot', '>=', date_start),
('date_slot', '<', date_end),
'|', ('enercoop_counter_id', '=', False), ('enercoop_counter_id', '=', enercoop_counter_id.id)
],
['enercoop_operation_id', 'date_slot'], ['enercoop_operation_id', 'date_slot'],
[type_date_abs], orderby='date_slot ASC', lazy=False) [type_date_abs], orderby='date_slot ASC', lazy=False)
# Get the date for the abscissa axis (histo) # Get the date for the abscissa axis (histo)
if type == 'day': if type == 'day':
cdc_date_histo_ids = self.env['enercoop.enedis.cdc'].sudo().read_group( cdc_date_histo_ids = self.env['enercoop.enedis.cdc'].sudo().read_group(
[('enercoop_operation_id', 'in', self.ids), domain_prm,
('date_slot', '>=', date_start),
('date_slot', '<', date_end),
'|', ('enercoop_counter_id', '=', False), ('enercoop_counter_id', '=', enercoop_counter_id.id)
],
['enercoop_operation_id', 'date_slot'], ['enercoop_operation_id', 'date_slot'],
[type_date], orderby='date_slot ASC', lazy=False) [type_date], orderby='date_slot ASC', lazy=False)
else: else:
# Get all data group by curves type and date # Get all data group by curves type and date
cdc_ids = self.env['enercoop.enedis.cdc'].sudo().read_group( cdc_ids = self.env['enercoop.enedis.cdc'].sudo().read_group(
[('enercoop_operation_id', 'in', self.ids), domain_all,
('date_slot', '>=', date_start),
('date_slot', '<', date_end)
],
['power', 'enercoop_operation_id', 'date_slot'], ['power', 'enercoop_operation_id', 'date_slot'],
['comp_data_type', type_date], orderby='comp_data_type, date_slot ASC', lazy=False) ['comp_data_type', type_date], orderby='comp_data_type, date_slot ASC', lazy=False)
if type == 'week': if type == 'week':
cdc_histo_ids = self.env['enercoop.enedis.cdc'].sudo().read_group( cdc_histo_ids = self.env['enercoop.enedis.cdc'].sudo().read_group(
[('enercoop_operation_id', 'in', self.ids), domain_all,
('date_slot', '>=', date_start),
('date_slot', '<', date_end)
],
['power', 'enercoop_operation_id', 'date_slot'], ['power', 'enercoop_operation_id', 'date_slot'],
['comp_data_type', type_date_histo], orderby='comp_data_type, date_slot ASC', lazy=False) ['comp_data_type', type_date_histo], orderby='comp_data_type, date_slot ASC', lazy=False)
# Get the date for the abscissa axis # Get the date for the abscissa axis
cdc_date_ids = self.env['enercoop.enedis.cdc'].sudo().read_group( cdc_date_ids = self.env['enercoop.enedis.cdc'].sudo().read_group(
[('enercoop_operation_id', 'in', self.ids), domain_all,
('date_slot', '>=', date_start),
('date_slot', '<', date_end),
],
['enercoop_operation_id', 'date_slot'], ['enercoop_operation_id', 'date_slot'],
[type_date_abs], orderby='date_slot ASC', lazy=False) [type_date_abs], orderby='date_slot ASC', lazy=False)
# Get the date for the abscissa axis (histo) # Get the date for the abscissa axis (histo)
if type == 'day': if type == 'day':
cdc_date_histo_ids = self.env['enercoop.enedis.cdc'].sudo().read_group( cdc_date_histo_ids = self.env['enercoop.enedis.cdc'].sudo().read_group(
[('enercoop_operation_id', 'in', self.ids), domain_all,
('date_slot', '>=', date_start),
('date_slot', '<', date_end),
],
['enercoop_operation_id', 'date_slot'], ['enercoop_operation_id', 'date_slot'],
[type_date], orderby='date_slot ASC', lazy=False) [type_date], orderby='date_slot ASC', lazy=False)
...@@ -547,6 +524,7 @@ class EnercoopOperation(models.Model): ...@@ -547,6 +524,7 @@ class EnercoopOperation(models.Model):
if cdc['comp_data_type'] == 'surplus': if cdc['comp_data_type'] == 'surplus':
data_surplus.append(value_power) data_surplus.append(value_power)
# SQL Data Query
if type == 'day' or type == 'week': if type == 'day' or type == 'week':
if enercoop_counter_id: if enercoop_counter_id:
query = """ query = """
...@@ -604,21 +582,17 @@ class EnercoopOperation(models.Model): ...@@ -604,21 +582,17 @@ class EnercoopOperation(models.Model):
# Get the data to build the chart Bilan # Get the data to build the chart Bilan
if enercoop_counter_id: if enercoop_counter_id:
bilan_cdc = self.env['enercoop.enedis.cdc'].sudo().read_group( bilan_cdc = self.env['enercoop.enedis.cdc'].sudo().read_group(
[('enercoop_operation_id', 'in', self.ids), domain_prm,
('date_slot', '>=', date_start),
('date_slot', '<', date_end),
'|', ('enercoop_counter_id', '=', False), ('enercoop_counter_id', '=', enercoop_counter_id.id)],
['power', 'enercoop_operation_id'], ['power', 'enercoop_operation_id'],
['comp_data_type'], orderby='comp_data_type', lazy=False) ['comp_data_type'], orderby='comp_data_type', lazy=False)
else: else:
bilan_cdc = self.env['enercoop.enedis.cdc'].sudo().read_group( bilan_cdc = self.env['enercoop.enedis.cdc'].sudo().read_group(
[('enercoop_operation_id', 'in', self.ids), domain_all,
('date_slot', '>=', date_start),
('date_slot', '<', date_end)],
['power', 'enercoop_operation_id'], ['power', 'enercoop_operation_id'],
['comp_data_type'], orderby='comp_data_type', lazy=False) ['comp_data_type'], orderby='comp_data_type', lazy=False)
# Build the ordinate axis for each data type (autoconso/conso/prod/surplus) # Build the ordinate axis for each data type (autoconso/conso/prod/surplus)
power_autocons = power_cons = power_surplus = power_prod = 0
for bilan in bilan_cdc: for bilan in bilan_cdc:
if bilan['comp_data_type'] == 'autocons': if bilan['comp_data_type'] == 'autocons':
power_autocons = bilan['power'] / 1000 / 2 power_autocons = bilan['power'] / 1000 / 2
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter