Browse Source

pb timezone

dev-rcn
root 3 years ago
parent
commit
5e5ea785f0
1 changed files with 17 additions and 14 deletions
  1. +17
    -14
      models/event.py

+ 17
- 14
models/event.py View File

@ -1,6 +1,7 @@
from odoo import models, fields, api from odoo import models, fields, api
from odoo.exceptions import UserError, ValidationError,Warning from odoo.exceptions import UserError, ValidationError,Warning
from psycopg2 import sql, DatabaseError from psycopg2 import sql, DatabaseError
from pytz import timezone
from werkzeug import utils from werkzeug import utils
@ -124,13 +125,14 @@ class KalachakraEvent(models.Model):
delegated_credentials = credentials.with_subject(SUBJECT) delegated_credentials = credentials.with_subject(SUBJECT)
service = build('calendar', 'v3', credentials=delegated_credentials) service = build('calendar', 'v3', credentials=delegated_credentials)
d = datetime.utcnow().date()
tomorrow = datetime(d.year, d.month, d.day, 10)+timedelta(days=1)
start = tomorrow.isoformat()
end = (tomorrow + timedelta(hours=1)).isoformat()
start=self.date_begin.isoformat()
end=self.date_end.isoformat()
start=self.date_begin.astimezone(timezone('Europe/Paris'))
end=self.date_end.astimezone(timezone('Europe/Paris'))
start=start.isoformat()
end=end.isoformat()
diff_date=self.date_end-self.date_begin diff_date=self.date_end-self.date_begin
if diff_date.days>0: if diff_date.days>0:
date_param=self.date_begin.strftime('%Y-%m-%d')+'-'+self.date_end.strftime('%Y-%m-%d')+'-'+str(self.id) date_param=self.date_begin.strftime('%Y-%m-%d')+'-'+self.date_end.strftime('%Y-%m-%d')+'-'+str(self.id)
@ -149,14 +151,15 @@ class KalachakraEvent(models.Model):
} }
#recherche de l'id calendar lié à l'étiquette de l'événément #recherche de l'id calendar lié à l'étiquette de l'événément
calendar_id=self.tag_ids.category_id.calendar_id
if calendar_id:
event = service.events().insert(calendarId=calendar_id, body=body).execute()
self.calendar_event_id=event['id']
self.calendar_id=calendar_id
else:
raise Warning('no calendar id, please check configuration tags')
for tag in self.tag_ids:
if tag.category_id.calendar_id:
calendar_id=tag.category_id.calendar_id
if calendar_id:
event = service.events().insert(calendarId=calendar_id, body=body).execute()
self.calendar_event_id=event['id']
self.calendar_id=calendar_id
def remove_event_to_google_agenda(self): def remove_event_to_google_agenda(self):
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES) credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)


Loading…
Cancel
Save