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

Add wizard select date + calcul cron birthday + add pivot view

parent 112eb93c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -2,3 +2,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
from . import wizards
......@@ -12,11 +12,12 @@
"security/ir.model.access.csv",
# datas
'data/service_cron.xml',
'wizards/enercoop_operation_wizard_views.xml',
# views
'views/res_config_settings_views.xml',
'views/enercoop_operation_views.xml'
'views/enercoop_operation_views.xml',
# views menu
# wizard
],
'qweb': [
# "static/src/xml/*.xml",
......
......@@ -141,9 +141,9 @@ class ApiEnedis(models.AbstractModel):
url = 'v1/collective_self_consumption/agreements/' + self.name + '/definitive_load_curves'
if usage_point_name:
name = usage_point_name + '_' + date_start + '_' + date_end + '_' + type
name = usage_point_name + '_' + str(date_start) + '_' + str(date_end) + '_' + type
else:
name = self.name + '_' + date_start + '_' + date_end + '_' + type
name = self.name + '_' + str(date_start) + '_' + str(date_end) + '_' + type
log_id = self.env['enercoop.enedis.import.logs'].search([
('name', '=', name),
......@@ -188,12 +188,14 @@ class ApiEnedis(models.AbstractModel):
# Get the counter ID from data
counter_id = self.env['enercoop.counter']
if usage_point_name:
counter_id = self.env['enercoop.counter'].search([('name', '=', usage_point_name)])
counter_id = self.env['enercoop.counter'].search([
('name', '=', usage_point_name),
('enercoop_operation_id', '=', self.id)])
type = curve['type']
if counter_id:
name = counter_id.name + '_' + date_start + '_' + date_end + '_' + type
name = counter_id.name + '_' + str(date_start) + '_' + str(date_end) + '_' + type
else:
name = self.name + '_' + date_start + '_' + date_end + '_' + type
name = self.name + '_' + str(date_start) + '_' + str(date_end) + '_' + type
for point in curve['interval_reading']:
date_slot = datetime.strptime(point['timestamp'], "%Y-%m-%dT%H:%M:%SZ")
......@@ -237,4 +239,30 @@ class ApiEnedis(models.AbstractModel):
'date_start_contract': date.fromisoformat(usage_point['start']),
'date_end_contract': date.fromisoformat(usage_point['end']),
})
else:
prm_id = self.env['enercoop.counter'].search([
('enercoop_operation_id', '=', self.id),
('name', '=', usage_point['usage_point_id'])])
if not prm_id:
is_delivery = False
is_injection = False
if usage_point['type'] == 'CONS':
is_delivery = True
if usage_point['type'] == 'PROD':
is_injection = True
prm_id = self.env['enercoop.counter'].create({
'name': usage_point['usage_point_id'],
'enercoop_operation_id': self.id,
'is_delivery': is_delivery,
'is_injection': is_injection,
})
self.env['enercoop.counter.operation'].create({
'enercoop_counter_id': prm_id.id,
'operation_id': self.id,
'date_start_contract': date.fromisoformat(usage_point['start']),
'date_end_contract': date.fromisoformat(usage_point['end']),
})
return True
\ No newline at end of file
......@@ -40,9 +40,10 @@ class EnercoopOperation(models.Model):
''' This method is called from a cron job.
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([
('date_start_contract', '=', date_month_before),
('birthday_date', '=', date_month_before.day),
('date_end_contract', '>=', fields.Date.context_today(self)),
])
records._get_curves(date_month_before)
......@@ -76,3 +77,6 @@ class EnercoopOperation(models.Model):
# ------------------------------------------------------
# Business methods
# ------------------------------------------------------
def last_day_of_month(date_value):
return date_value.replace(day=monthrange(date_value.year, date_value.month)[1])
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
"access_api_enedis_group_partner_manager","api_enedis group_partner_manager","model_api_enedis","base.group_partner_manager",1,1,1,1
"access_api_enedis_group_user","api_enedis group_user","model_api_enedis","base.group_user",1,0,0,0
"access_enercoop_operation_wizard_group_partner_manager","enercoop_operation_wizard group_partner_manager","model_enercoop_operation_wizard","base.group_partner_manager",1,1,1,1
"access_enercoop_operation_wizard_group_user","enercoop_operation_wizard group_user","model_enercoop_operation_wizard","base.group_user",1,0,0,0
\ No newline at end of file
......@@ -8,8 +8,11 @@
<field name="inherit_id" ref="enercoop_partner.enercoop_operation_form_view"/>
<field name="arch" type="xml">
<header position="inside">
<button string="Récupération des courbes" type="object" class="btn-primary" name="get_curves"/>
<button string="Périmètre" type="object" class="btn-primary" name="get_perimeter"/>
<button
string="Récupération des courbes"
type="action"
name="%(enercoop_enedis_api.enercoop_operation_wizard_action)d"/>
<button string="Périmètre" type="object" name="get_perimeter" attrs="{'invisible':[('client_id','=', False), ('secret_id','=', False)]}"/>
</header>
<xpath expr="//notebook" position="inside">
<page string="API Enedis" name="api">
......
......@@ -38,8 +38,10 @@ class EnercoopOperationWizard(models.TransientModel):
# Actions
# ------------------------------------------------------
def get_curves(self):
for operation in self:
return True
context = dict(self._context or {})
if context.get('active_ids', False):
self.env['enercoop.operation'].browse(context.get('active_ids')).get_curves(self.date_start, self.date_end)
return {'type': 'ir.actions.act_window_close'}
# ------------------------------------------------------
# Business methods
# ------------------------------------------------------
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