Skip to content
Extraits de code Groupes Projets
Valider 42c85086 rédigé par Juliana's avatar Juliana
Parcourir les fichiers

[UPD]Change cron function

parent c77e027c
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
'data': [ 'data': [
"security/ir.model.access.csv", "security/ir.model.access.csv",
# datas # datas
# 'data/service_cron.xml', 'data/service_cron.xml',
'wizards/enercoop_operation_wizard_views.xml', 'wizards/enercoop_operation_wizard_views.xml',
# views # views
'views/res_config_settings_views.xml', 'views/res_config_settings_views.xml',
......
...@@ -289,6 +289,7 @@ class ApiEnedis(models.AbstractModel): ...@@ -289,6 +289,7 @@ class ApiEnedis(models.AbstractModel):
'operation_id': self.id, 'operation_id': self.id,
'date_start_contract': date.fromisoformat(usage_point['start']), 'date_start_contract': date.fromisoformat(usage_point['start']),
'date_end_contract': date.fromisoformat(usage_point['end']), 'date_end_contract': date.fromisoformat(usage_point['end']),
'partner_id': prm_id.partner_id.id or None
}) })
return True return True
...@@ -40,18 +40,19 @@ class EnercoopOperation(models.Model): ...@@ -40,18 +40,19 @@ class EnercoopOperation(models.Model):
''' This method is called from a cron job. ''' This method is called from a cron job.
It is used to get data from Enedis with API. It is used to get data from Enedis with API.
''' '''
if date.today() == last_day_of_month(date.today()):
date_month_before = date.today() - relativedelta(months=1)
records = self.search([ records = self.search([
('birthday_date', '=', date_month_before.day), ('date_start_contract', '<', date.today()),
('date_end_contract', '>=', fields.Date.context_today(self)), ('client_id', '!=', False),
('secret_id', '!=', False),
('active', '=', True)
]) ])
records._get_curves(date_month_before) for rec in records:
d = rec.date_start_contract + relativedelta(days=10)
def _get_curves(self, date_month_before): if d.day == date.today().day:
for operation in self: date_today_10 = date.today() - relativedelta(days=10)
yesterday = date.today() - relativedelta(days=1) first_date = datetime(date_today_10.year, date_today_10.month - 1, rec.date_start_contract.day)
operation.get_curves(date_month_before, yesterday) last_date = first_date + relativedelta(months=1, days=-1)
rec.get_curves(first_date.date(), last_date.date())
# ------------------------------------------------------ # ------------------------------------------------------
# Actions # Actions
...@@ -74,9 +75,8 @@ class EnercoopOperation(models.Model): ...@@ -74,9 +75,8 @@ class EnercoopOperation(models.Model):
def get_perimeter(self): def get_perimeter(self):
for operation in self: for operation in self:
res = operation.perimeter() res = operation.perimeter()
# ------------------------------------------------------ # ------------------------------------------------------
# Business methods # Business methods
# ------------------------------------------------------ # ------------------------------------------------------
def last_day_of_month(date_value):
return date_value.replace(day=monthrange(date_value.year, date_value.month)[1])
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