diff --git a/models/acc_operation.py b/models/acc_operation.py index 73619b563b13a25a4e168115c6483be684688477..9e06e338bef2db4aa2de8f66bd508c0fb542c44f 100644 --- a/models/acc_operation.py +++ b/models/acc_operation.py @@ -1,10 +1,12 @@ # Copyright 2023 Le Filament (<http://www.le-filament.com>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import pytz from datetime import datetime, time + +import pytz from dateutil.relativedelta import relativedelta + from odoo import _, models -from odoo.exceptions import ValidationError, UserError +from odoo.exceptions import UserError, ValidationError from odoo.osv import expression from odoo.tools import date_utils @@ -46,10 +48,11 @@ class AccOperation(models.Model): # Get last date slot recorded last_record = self.get_last_cdc_record() start_date, end_date = self.get_interval("month", last_record) - end_date_mounth = end_date + relativedelta(days=1) + end_date_month = end_date + relativedelta(days=1) query = """ SELECT - date_trunc('month', cdc.date_slot AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Paris') AS date_slot, + date_trunc('month', cdc.date_slot AT TIME ZONE 'UTC' \ + AT TIME ZONE 'Europe/Paris') AS date_slot, (SUM( (CASE WHEN cdc.comp_data_type = 'cons' THEN cdc.power ELSE 0 END) )/2) / 1000 as conso_tot, @@ -67,12 +70,13 @@ class AccOperation(models.Model): cdc.acc_operation_id = %s AND cdc.date_slot >= %s AND cdc.date_slot < %s - GROUP BY date_trunc('month', cdc.date_slot AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Paris'); + GROUP BY date_trunc('month', cdc.date_slot AT TIME ZONE 'UTC' \ + AT TIME ZONE 'Europe/Paris'); """ query_params = ( self.id, self._convert_time(start_date), - self._convert_time(end_date_mounth), + self._convert_time(end_date_month), ) self.env.cr.execute(query, query_params) raw_data = self.env.cr.fetchone() @@ -197,7 +201,8 @@ class AccOperation(models.Model): query = """ SELECT - date_trunc(%s, cdc.date_slot AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Paris') AS date_slot, + date_trunc(%s, cdc.date_slot AT TIME ZONE 'UTC' \ + AT TIME ZONE 'Europe/Paris') AS date_slot, (SUM( (CASE WHEN cdc.comp_data_type = 'cons' THEN cdc.power ELSE 0 END) )/2) / 1000 as cons, @@ -217,7 +222,8 @@ class AccOperation(models.Model): AND cdc.date_slot >= %s AND cdc.date_slot <= %s AND cdc.partner_id IN %s - GROUP BY date_trunc(%s, cdc.date_slot AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Paris') + GROUP BY date_trunc(%s, cdc.date_slot AT TIME ZONE 'UTC' \ + AT TIME ZONE 'Europe/Paris') ORDER BY date_slot ASC; """ query_params = ( @@ -266,7 +272,8 @@ class AccOperation(models.Model): query = """ SELECT - date_trunc('day', cdc.date_slot AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Paris') AS date_slot, + date_trunc('day', cdc.date_slot AT TIME ZONE 'UTC' \ + AT TIME ZONE 'Europe/Paris') AS date_slot, (SUM( (CASE WHEN cdc.comp_data_type = 'autocons' THEN cdc.power ELSE 0 END) )/2) / 1000 as autocons, @@ -284,7 +291,8 @@ class AccOperation(models.Model): AND cdc.date_slot >= %s AND cdc.date_slot <= %s AND cdc.partner_id IN %s - GROUP BY date_trunc('day', cdc.date_slot AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Paris') + GROUP BY date_trunc('day', cdc.date_slot AT TIME ZONE 'UTC' \ + AT TIME ZONE 'Europe/Paris') ORDER BY date_slot ASC; """ query_params = ( @@ -329,7 +337,8 @@ class AccOperation(models.Model): query = """ SELECT - date_trunc(%s, cdc.date_slot AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Paris') AS date_slot, + date_trunc(%s, cdc.date_slot AT TIME ZONE 'UTC' \ + AT TIME ZONE 'Europe/Paris') AS date_slot, ((SUM((CASE WHEN cdc.comp_data_type = 'prod' THEN cdc.power ELSE 0 END)) @@ -348,7 +357,8 @@ class AccOperation(models.Model): AND cdc.date_slot >= %s AND cdc.date_slot <= %s AND cdc.partner_id IN %s - GROUP BY date_trunc(%s, cdc.date_slot AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Paris') + GROUP BY date_trunc(%s, cdc.date_slot AT TIME ZONE 'UTC' \ + AT TIME ZONE 'Europe/Paris') ORDER BY date_slot ASC; """ query_params = ( @@ -393,7 +403,8 @@ class AccOperation(models.Model): query = """ SELECT - date_trunc('day', cdc.date_slot AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Paris') AS date_slot, + date_trunc('day', cdc.date_slot AT TIME ZONE 'UTC' \ + AT TIME ZONE 'Europe/Paris') AS date_slot, ((SUM((CASE WHEN cdc.comp_data_type = 'prod' THEN cdc.power ELSE 0 END)) @@ -412,7 +423,8 @@ class AccOperation(models.Model): AND cdc.date_slot >= %s AND cdc.date_slot <= %s AND cdc.partner_id IN %s - GROUP BY date_trunc('day', cdc.date_slot AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Paris') + GROUP BY date_trunc('day', cdc.date_slot AT TIME ZONE 'UTC' \ + AT TIME ZONE 'Europe/Paris') ORDER BY date_slot ASC; """ query_params = (