From 6ae8854005dc01e151c1e5f69f2aa41d3ca734dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20-=20Le=20Filament?= <remi@le-filament.com> Date: Wed, 27 Dec 2023 11:53:38 +0100 Subject: [PATCH] [UPD] date naming --- models/acc_operation.py | 58 +++++++++---------- wizards/acc_operation_wizard.py | 20 +++---- wizards/acc_operation_wizard_confirm.py | 8 +-- .../acc_operation_wizard_confirm_views.xml | 4 +- wizards/acc_operation_wizard_views.xml | 4 +- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/models/acc_operation.py b/models/acc_operation.py index 80300be..925a668 100644 --- a/models/acc_operation.py +++ b/models/acc_operation.py @@ -82,7 +82,7 @@ class AccOperation(models.Model): # API functions # ------------------------------------------------------ def curves( - self, date_start, date_end, usage_point_cons_ids=None, usage_point_prod_ids=None + self, start_date, end_date, usage_point_cons_ids=None, usage_point_prod_ids=None ): """ Récupère les données de l'opération concernant le périmètre: @@ -105,7 +105,7 @@ class AccOperation(models.Model): + str(fields.Datetime.now()) + "</h1>" "Appels API pour la période " - "" + str(date_start) + " " + str(date_end) + "<br/>" + "" + str(start_date) + " " + str(end_date) + "<br/>" ) if usage_point_cons_ids: @@ -123,13 +123,13 @@ class AccOperation(models.Model): + " - Date: " + str(fields.Datetime.today()) + " - Période: du " - + str(date_start) + + str(start_date) + " au " - + str(date_end) + + str(end_date) ) message += desc + "<br/>" self.with_delay(description=desc).get_definitive_load_curves( - date_end, date_start, usage_point_id, "cons" + start_date, end_date, usage_point_id, "cons" ) if usage_point_prod_ids: @@ -147,14 +147,14 @@ class AccOperation(models.Model): + " - Date: " + str(fields.Datetime.today()) + " - Période: du " - + str(date_start) + + str(start_date) + " au " - + str(date_end) + + str(end_date) ) message += desc + "<br/>" self.with_delay(description=desc).get_definitive_load_curves( - date_end, - date_start, + start_date, + end_date, usage_point_id, "prod", ) @@ -172,9 +172,9 @@ class AccOperation(models.Model): "name": "Appel API Enedis Courbes du " + str(fields.Date.today()) + " - Période " - + str(date_start) + + str(start_date) + " " - + str(date_end), + + str(end_date), "date_launched": fields.Datetime.now(), "type_log": "api", "message": message, @@ -183,15 +183,15 @@ class AccOperation(models.Model): ) def get_definitive_load_curves( - self, date_end, date_start, usage_point_id, type_prm + self, start_date, end_date, usage_point_id, type_prm ): message = "" message += "PRM " + usage_point_id.name + "\n" message += "Appel API ...\n" curves_data = self._get_definitive_load_curves( self.name, - date_end, - date_start, + start_date, + end_date, usage_point_id.name, self.client_id, self.secret_id, @@ -202,7 +202,7 @@ class AccOperation(models.Model): curves = curves_data.get("curves") if curves: - name = usage_point_id.name + "_" + str(date_start) + "_" + str(date_end) + name = usage_point_id.name + "_" + str(start_end) + "_" + str(end_date) for curve in curves: type_curve = curve["type"] @@ -244,16 +244,16 @@ class AccOperation(models.Model): date.today().month - self.date_start_contract.month ) - date_start_it = self.date_start_contract - date_end_it = self.date_start_contract + relativedelta(months=1) + start_date_it = self.date_start_contract + end_date_it = self.date_start_contract + relativedelta(months=1) i = 1 while i < nb_months: self.curves( - date_start_it, date_end_it, usage_point_cons_ids, usage_point_prod_ids + start_date_it, end_date_it, usage_point_cons_ids, usage_point_prod_ids ) - date_start_it = date_start_it + relativedelta(months=1) - date_end_it = date_start_it + relativedelta(months=1) + start_date_it = start_date_it + relativedelta(months=1) + end_date_it = start_date_it + relativedelta(months=1) i += 1 def perimeter(self): @@ -310,18 +310,18 @@ class AccOperation(models.Model): message += "PRM existe dans Odoo<br/>" counter_period_ids = counter_id.period_ids if counter_period_ids.filtered( - lambda p: p.date_start == usage_point_start - and p.date_end == usage_point_end + lambda p: p.start_date == usage_point_start + and p.end_date == usage_point_end ): message += ( "période existante avec les mêmes dates, pas de modif<br/>" ) elif counter_period_ids.filtered( - lambda p: p.date_start == usage_point_start + lambda p: p.start_date == usage_point_start ): counter_period_ids.filtered( - lambda p: p.date_start == usage_point_start - ).date_end = usage_point_end + lambda p: p.start_date == usage_point_start + ).end_date = usage_point_end message += ( "période existante avec la même date de début, mais date de " "fin différente, mise à jour date de fin<br/>" @@ -333,8 +333,8 @@ class AccOperation(models.Model): "acc_counter_id": counter_id.id, "prm_type": usage_point_prm_type, "acc_operation_id": self.id, - "date_start": usage_point_start, - "date_end": usage_point_end, + "start_date": usage_point_start, + "end_date": usage_point_end, } ) message += ( @@ -370,8 +370,8 @@ class AccOperation(models.Model): "acc_counter_id": counter_id.id, "prm_type": usage_point_prm_type, "acc_operation_id": self.id, - "date_start": usage_point_start, - "date_end": usage_point_end, + "start_date": usage_point_start, + "end_date": usage_point_end, } ) message += "Fin de la création du PRM<br/>" diff --git a/wizards/acc_operation_wizard.py b/wizards/acc_operation_wizard.py index 0876854..aaa659f 100644 --- a/wizards/acc_operation_wizard.py +++ b/wizards/acc_operation_wizard.py @@ -23,8 +23,8 @@ class AccOperationWizard(models.TransientModel): operation_id = fields.Many2one( "acc.operation", default=lambda self: self._default_operation_id() ) - date_start = fields.Date("Date de début") - date_end = fields.Date("Date de fin (exclue)") + start_date = fields.Date("Date de début") + end_date = fields.Date("Date de fin (exclue)") prm_cons_ids = fields.Many2many( "acc.counter", relation="acc_counter_cons_rel", @@ -68,21 +68,21 @@ class AccOperationWizard(models.TransientModel): # Actions # ------------------------------------------------------ def get_curves(self): - if not self.date_end and not self.date_start: + if not self.end_date and not self.start_date: raise UserError( _("Les champs Date de début et Date de fin sont obligatoires") ) - if (self.date_end - self.date_start).days > 31: + if (self.end_date - self.start_date).days > 31: raise UserError(_("L'intervalle de temps ne doit pas dépasser 31 Jours")) - if self.date_end <= self.date_start: + if self.end_date <= self.start_date: raise UserError(_("La date de fin doit être supérieure à la date de début")) # Vérification si des données existent déjà # pour cet intervalle de date domain_all = [ - ("date_slot", ">=", self.date_start), - ("date_slot", "<", self.date_end), + ("date_slot", ">=", self.start_date), + ("date_slot", "<", self.end_date), ("acc_operation_id", "=", self.operation_id.id), ] if self.prm_cons_ids and self.prm_prod_ids: @@ -111,8 +111,8 @@ class AccOperationWizard(models.TransientModel): wizard = self.env["acc.operation.wizard.confirm"].create( { "operation_id": self.operation_id.id, - "date_start": self.date_start, - "date_end": self.date_end, + "start_date": self.start_date, + "end_date": self.end_date, "prm_cons_ids": self.prm_cons_ids, "prm_prod_ids": self.prm_prod_ids, "rec_ids": rec_ids, @@ -132,7 +132,7 @@ class AccOperationWizard(models.TransientModel): } else: self.operation_id.curves( - self.date_start, self.date_end, self.prm_cons_ids, self.prm_prod_ids + self.start_date, self.end_date, self.prm_cons_ids, self.prm_prod_ids ) return {"type": "ir.actions.act_window_close"} diff --git a/wizards/acc_operation_wizard_confirm.py b/wizards/acc_operation_wizard_confirm.py index b9754d1..abf7cfd 100644 --- a/wizards/acc_operation_wizard_confirm.py +++ b/wizards/acc_operation_wizard_confirm.py @@ -12,8 +12,8 @@ class AccOperationWizardConfirm(models.TransientModel): # Fields declaration # ------------------------------------------------------ operation_id = fields.Many2one("acc.operation") - date_start = fields.Date("Date de début") - date_end = fields.Date("Date de fin (exclue)") + start_date = fields.Date("Date de début") + end_date = fields.Date("Date de fin (exclue)") prm_cons_ids = fields.Many2many( "acc.counter", relation="acc_counter_cons_confirm_rel", @@ -65,9 +65,9 @@ class AccOperationWizardConfirm(models.TransientModel): # Appels API # Si date présente, appel pour la période - if self.date_start: + if self.start_date: self.operation_id.curves( - self.date_start, self.date_end, self.prm_cons_ids, self.prm_prod_ids + self.start_date, self.end_date, self.prm_cons_ids, self.prm_prod_ids ) else: # Pas de date renseignée, récupération de toutes les données diff --git a/wizards/acc_operation_wizard_confirm_views.xml b/wizards/acc_operation_wizard_confirm_views.xml index a39029a..b79af11 100644 --- a/wizards/acc_operation_wizard_confirm_views.xml +++ b/wizards/acc_operation_wizard_confirm_views.xml @@ -13,8 +13,8 @@ <field name="operation_id" invisible="1" /> <field name="prm_cons_ids" invisible="1" /> <field name="prm_prod_ids" invisible="1" /> - <field name="date_start" invisible="1" /> - <field name="date_end" invisible="1" /> + <field name="start_date" invisible="1" /> + <field name="end_date" invisible="1" /> <field name="rec_ids" invisible="1" /> </group> <footer> diff --git a/wizards/acc_operation_wizard_views.xml b/wizards/acc_operation_wizard_views.xml index 793ac05..2f53d7a 100644 --- a/wizards/acc_operation_wizard_views.xml +++ b/wizards/acc_operation_wizard_views.xml @@ -23,8 +23,8 @@ <!-- TODO rework domain="[('is_injection', '=', True), ('acc_operation_id', '=', operation_id)]" --> </group> <group name="period" string="Période" col="2"> - <field name="date_start" /> - <field name="date_end" /> + <field name="start_date" /> + <field name="end_date" /> </group> <footer> <button -- GitLab