diff --git a/models/acc_operation.py b/models/acc_operation.py index fd260013376a7d62de0a0c71238d226bfc9c6ffa..bd62b8161ca432d163cd12934515a5f26dfa6dcb 100644 --- a/models/acc_operation.py +++ b/models/acc_operation.py @@ -98,17 +98,18 @@ class AccOperation(models.Model): message = "" message += ( - "<h1>API Enedis OACC - Appel Courbes " + "<h1>API Enedis OACC - Création des jobs de récupération des Courbes " + str(fields.Datetime.now()) + "</h1>" - "Appel API pour la période " + "Appels API pour la période " "" + str(date_start) + " " + str(date_end) + "<br/>" ) if usage_point_cons_ids: # Traitement données de cons message += ( - "<br/><strong>Traitement des données de consommation</strong><br/>" + "<br/><strong>Création des jobs de récupération des courbes " + "de consommation</strong><br/>" ) for usage_point_id in usage_point_cons_ids: desc = ( @@ -118,14 +119,22 @@ class AccOperation(models.Model): + usage_point_id.name + " - Date: " + str(fields.Datetime.today()) + + " - Période: du " + + str(date_start) + + " au " + + str(date_end) ) + message += desc + "<br/>" self.with_delay(description=desc).get_definitive_load_curves( date_end, date_start, usage_point_id, "cons" ) if usage_point_prod_ids: # Traitement données de prod - message += "<br/><strong>Traitement des données de production</strong><br/>" + message += ( + "<br/><strong>Création des jobs de récupération des courbes " + "de production</strong><br/>" + ) for usage_point_id in usage_point_prod_ids: desc = ( "Opération: " @@ -134,7 +143,12 @@ class AccOperation(models.Model): + usage_point_id.name + " - Date: " + str(fields.Datetime.today()) + + " - Période: du " + + str(date_start) + + " au " + + str(date_end) ) + message += desc + "<br/>" self.with_delay(description=desc).get_definitive_load_curves( date_end, date_start, @@ -143,7 +157,9 @@ class AccOperation(models.Model): ) message += ( - "<br/><h1>Fin appel API Courbes: " + str(fields.Datetime.now()) + "</h1>" + "<br/><h1>Fin de création des jobs de récupération des courbes: " + + str(fields.Datetime.now()) + + "</h1>" ) if not self.is_cdc_data_exists: self.is_cdc_data_exists = True @@ -213,7 +229,7 @@ class AccOperation(models.Model): _logger.info(message) return message - def get_curves_all(self): + def get_curves_all(self, usage_point_cons_ids=None, usage_point_prod_ids=None): """ Récupère les données de l'opération depuis le début de la mise en place de l'opération. A partir de la date de début de contrat, calcul du nombre @@ -229,7 +245,9 @@ class AccOperation(models.Model): i = 1 while i < nb_months: - self.curves(date_start_it, date_end_it) + self.curves( + date_start_it, date_end_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) i += 1 @@ -258,29 +276,63 @@ class AccOperation(models.Model): list_soutirage = [] for usage_point in usage_points: + usage_point_start = date.fromisoformat(usage_point["start"]) + usage_point_end = ( + date.fromisoformat(usage_point["end"]) + if usage_point["end"] != "9999-12-31" + else False + ) usage_id = self.env["acc.counter"].search( [ ("acc_operation_id", "=", self.id), ("name", "=", usage_point["usage_point_id"]), ] ) - message += "<br/>PRM " + usage_point["usage_point_id"] + "<br/>" - if usage_id: - message += ( - "PRM existe : mise à jour des dates - " - "Du " + usage_point["start"] + " au " + usage_point["end"] + "<br/>" - ) - usage_id.write( - { - "date_start_contract": date.fromisoformat(usage_point["start"]), - } - ) - if usage_point["end"] != "9999-12-31": - usage_id.write( - { - "date_end_contract": date.fromisoformat(usage_point["end"]), - } + message += ( + "<br/>PRM " + + usage_point["usage_point_id"] + + " - Dates Enedis : " + + usage_point["start"] + + " - " + + usage_point["end"] + + "<br/>" + ) + if usage_id and len(usage_id) == 1: + message += "PRM existe dans Odoo<br/>" + if not usage_id.date_start_contract: + usage_id.date_start_contract = usage_point_start + message += ( + "mise à jour date de début " + usage_point["start"] + "<br/>" + ) + elif usage_id.date_start_contract != usage_point_start: + message += ( + "date de début ne correspond pas, " + "merci de vérifier manuellement ce PRM : " + "date de début Odoo : " + + fields.Date.to_string(usage_id.date_start_contract) + + "<br/>" + ) + if usage_point_end and not usage_id.date_end_contract: + usage_id.date_end_contract = usage_point_end + message += ( + "mise à jour date de fin : " + usage_point["end"] + "<br/>" + ) + elif usage_id.date_end_contract != usage_point_end: + message += ( + "date de fin ne correspond pas" + ", merci de vérifier manuellement ce PRM : " + "date de fin Odoo : " + + fields.Date.to_string(usage_id.date_end_contract) + + "<br/>" ) + if usage_point["type"] == "CONS" and not usage_id.is_delivery: + usage_id.is_delivery = True + message += "PRM configuré comme point de soutirage <br/>" + if usage_point["type"] == "PROD" and not usage_id.is_injection: + usage_id.is_injection = True + message += "PRM configuré comme point d'injection <br/>" + elif len(usage_id) > 1: + message += "Plusieurs PRMs trouvés avec ce numéro - pas de modif<br/>" else: message += "PRM n'existe pas : Création ...<br/>" is_delivery = False @@ -289,33 +341,31 @@ class AccOperation(models.Model): is_delivery = True if usage_point["type"] == "PROD": is_injection = True - self.date_start_contract = date.fromisoformat(usage_point["start"]) - if usage_point["end"] != "9999-12-31": - self.date_end_contract = date.fromisoformat(usage_point["end"]) - else: - self.date_end_contract = None - - if usage_point["end"] != "9999-12-31": - date_end = date.fromisoformat(usage_point["end"]) - else: - date_end = None + # Si la date de l'opération n'est pas renseignée ou + # après la date de démarrage du point d'injection + # alors on force la date à celle du point d'injection + if ( + not self.date_start_contract + or self.date_start_contract > usage_point_start + ): + self.date_start_contract = usage_point_start usage_id = self.env["acc.counter"].create( { "name": usage_point["usage_point_id"], "is_delivery": is_delivery, "is_injection": is_injection, "acc_operation_id": self.id, - "date_start_contract": date.fromisoformat(usage_point["start"]), - "date_end_contract": date_end, + "date_start_contract": usage_point_start, + "date_end_contract": usage_point_end, } ) message += "Fin de la création du PRM<br/>" - if usage_id.is_injection: - if usage_id.name not in list_injection: - list_injection.append(usage_id.name) - if usage_id.is_delivery: - if usage_id.name not in list_soutirage: - list_soutirage.append(usage_id.name) + if usage_point["type"] == "PROD": + if usage_point["usage_point_id"] not in list_injection: + list_injection.append(usage_point["usage_point_id"]) + if usage_point["type"] == "CONS": + if usage_point["usage_point_id"] not in list_soutirage: + list_soutirage.append(usage_point["usage_point_id"]) message += "<p>LISTE TOTAL DE PRMs: </br>" "PRM Injection </br>" diff --git a/wizards/acc_operation_wizard.py b/wizards/acc_operation_wizard.py index d6cf026d4bd33c7974b570e84a3c9fcbb72d8dab..8f5ed7de8de0da9db9ed5096a3fa6575506143fe 100644 --- a/wizards/acc_operation_wizard.py +++ b/wizards/acc_operation_wizard.py @@ -86,13 +86,23 @@ class AccOperationWizard(models.TransientModel): if self.prm_cons_ids and self.prm_prod_ids: domain_all += [ "|", + "&", ("acc_counter_id", "in", self.prm_cons_ids.ids), + ("comp_data_type", "in", ("autocons", "cons")), + "&", ("acc_counter_id", "in", self.prm_prod_ids.ids), + ("comp_data_type", "in", ("prod", "surplus")), ] elif self.prm_cons_ids: - domain_all += [("acc_counter_id", "in", self.prm_cons_ids.ids)] + domain_all += [ + ("acc_counter_id", "in", self.prm_cons_ids.ids), + ("comp_data_type", "in", ("autocons", "cons")), + ] elif self.prm_prod_ids: - domain_all += [("acc_counter_id", "in", self.prm_prod_ids.ids)] + domain_all += [ + ("acc_counter_id", "in", self.prm_prod_ids.ids), + ("comp_data_type", "in", ("prod", "surplus")), + ] rec_ids = self.env["acc.enedis.cdc"].search(domain_all) if rec_ids: @@ -106,7 +116,7 @@ class AccOperationWizard(models.TransientModel): "rec_ids": rec_ids, "mess": _( "Des données existent déjà pour cette période. Etes-vous" - " sûr de vouloir écraser les données existantes?" + " sûr de vouloir écraser les données existantes ?" ), } ) @@ -140,6 +150,8 @@ class AccOperationWizard(models.TransientModel): wizard = self.env["acc.operation.wizard.confirm"].create( { "operation_id": self.operation_id.id, + "prm_cons_ids": self.prm_cons_ids, + "prm_prod_ids": self.prm_prod_ids, "rec_ids": rec_ids, "mess": _( "Des données existent pour cette période. Etes-vous" @@ -156,7 +168,7 @@ class AccOperationWizard(models.TransientModel): "target": "new", } else: - self.operation_id.get_curves_all() + self.operation_id.get_curves_all(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 548842c651c71446fce26ca4db9d93f66224468b..463d401f1a77373384bb1e4033534b6795ae0994 100644 --- a/wizards/acc_operation_wizard_confirm.py +++ b/wizards/acc_operation_wizard_confirm.py @@ -69,7 +69,7 @@ class AccOperationWizardConfirm(models.TransientModel): ) else: # Pas de date renseignée, récupération de toutes les données - self.operation_id.get_curves_all() + self.operation_id.get_curves_all(self.prm_cons_ids, self.prm_prod_ids) return {"type": "ir.actions.act_window_close"} # ------------------------------------------------------