|
@ -29,48 +29,51 @@ class EventEvent(models.Model): |
|
|
for event in self: |
|
|
for event in self: |
|
|
event.in_user_agenda = uid in event.meeting_ids.mapped("user_id").ids |
|
|
event.in_user_agenda = uid in event.meeting_ids.mapped("user_id").ids |
|
|
|
|
|
|
|
|
def add_to_agenda(self, user_id=False): |
|
|
|
|
|
vals_list = [] |
|
|
|
|
|
|
|
|
def _prepare_agenda_vals(self, user_id=False): |
|
|
|
|
|
self.ensure_one() |
|
|
self_model_id = self.env["ir.model"]._get_id(self._name) |
|
|
self_model_id = self.env["ir.model"]._get_id(self._name) |
|
|
uid = user_id or self.env.uid |
|
|
uid = user_id or self.env.uid |
|
|
to_add = self.filtered( |
|
|
|
|
|
lambda ee: uid not in ee.meeting_ids.mapped("user_id.id") |
|
|
|
|
|
) |
|
|
|
|
|
for event in to_add: |
|
|
|
|
|
groupped_tags = {} |
|
|
groupped_tags = {} |
|
|
for tag in event.tag_ids: |
|
|
|
|
|
|
|
|
for tag in self.tag_ids: |
|
|
categ = tag.category_id.name |
|
|
categ = tag.category_id.name |
|
|
if categ in groupped_tags: |
|
|
if categ in groupped_tags: |
|
|
groupped_tags[categ] += ", {}".format(tag.name) |
|
|
groupped_tags[categ] += ", {}".format(tag.name) |
|
|
else: |
|
|
else: |
|
|
groupped_tags[categ] = tag.name |
|
|
groupped_tags[categ] = tag.name |
|
|
event_tz = pytz.timezone(event.date_tz) |
|
|
|
|
|
vals_list.append( |
|
|
|
|
|
{ |
|
|
|
|
|
"name": event.name + " (event Odoo)", |
|
|
|
|
|
|
|
|
event_tz = pytz.timezone(self.date_tz) |
|
|
|
|
|
return { |
|
|
|
|
|
"name": self.name + " (event Odoo)", |
|
|
"description": _("<p>Organizer: {}{}<br/>Note:\n</p>").format( |
|
|
"description": _("<p>Organizer: {}{}<br/>Note:\n</p>").format( |
|
|
event.organizer_id.display_name, |
|
|
|
|
|
|
|
|
self.organizer_id.display_name, |
|
|
"".join( |
|
|
"".join( |
|
|
[ |
|
|
[ |
|
|
"<br/>{} : {}".format(tag_group[0], tag_group[1]) |
|
|
"<br/>{} : {}".format(tag_group[0], tag_group[1]) |
|
|
for tag_group in groupped_tags.items() |
|
|
for tag_group in groupped_tags.items() |
|
|
] |
|
|
] |
|
|
), |
|
|
), |
|
|
event.note, |
|
|
|
|
|
|
|
|
self.note, |
|
|
), |
|
|
), |
|
|
"user_id": uid, |
|
|
"user_id": uid, |
|
|
"location": event.address_inline, |
|
|
|
|
|
"start": event_tz.localize(event.date_begin) |
|
|
|
|
|
|
|
|
"location": self.address_inline, |
|
|
|
|
|
"start": event_tz.localize(self.date_begin) |
|
|
.astimezone(pytz.timezone(self.env.user.tz)) |
|
|
.astimezone(pytz.timezone(self.env.user.tz)) |
|
|
.replace(tzinfo=None), |
|
|
.replace(tzinfo=None), |
|
|
"stop": event_tz.localize(event.date_end) |
|
|
|
|
|
|
|
|
"stop": event_tz.localize(self.date_end) |
|
|
.astimezone(pytz.timezone(self.env.user.tz)) |
|
|
.astimezone(pytz.timezone(self.env.user.tz)) |
|
|
.replace(tzinfo=None), |
|
|
.replace(tzinfo=None), |
|
|
"res_id": event.id, |
|
|
|
|
|
|
|
|
"res_id": self.id, |
|
|
"res_model_id": self_model_id, |
|
|
"res_model_id": self_model_id, |
|
|
# "event_tz": event.date_tz, |
|
|
# "event_tz": event.date_tz, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def add_to_agenda(self, user_id=False): |
|
|
|
|
|
vals_list = [] |
|
|
|
|
|
uid = user_id or self.env.uid |
|
|
|
|
|
to_add = self.filtered( |
|
|
|
|
|
lambda ee: uid not in ee.meeting_ids.mapped("user_id.id") |
|
|
) |
|
|
) |
|
|
|
|
|
for event in to_add: |
|
|
|
|
|
vals_list.append(event._prepare_agenda_vals()) |
|
|
if vals_list: |
|
|
if vals_list: |
|
|
self.env["calendar.event"].create(vals_list) |
|
|
self.env["calendar.event"].create(vals_list) |
|
|
|
|
|
|
|
@ -99,23 +102,37 @@ class EventEvent(models.Model): |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@api.model |
|
|
@api.model |
|
|
def agenda_fields(self): |
|
|
|
|
|
return [ |
|
|
|
|
|
"name", |
|
|
|
|
|
"date_begin_located", |
|
|
|
|
|
"date_end_located", |
|
|
|
|
|
"tag_ids", |
|
|
|
|
|
"organizer_id", |
|
|
|
|
|
"adress_inline", |
|
|
|
|
|
"note", |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
def agenda_fields_mapping(self): |
|
|
|
|
|
return { |
|
|
|
|
|
"name": "name", |
|
|
|
|
|
"adress_inline": "location", |
|
|
|
|
|
"date_begin_located": "start", |
|
|
|
|
|
"date_end_located": "stop", |
|
|
|
|
|
"organizer_id": "description", |
|
|
|
|
|
"tag_ids": "description", |
|
|
|
|
|
"note": "description", |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def update_agenda_events(self, ce_fields): |
|
|
|
|
|
self.ensure_one() |
|
|
|
|
|
ce_vals = self._prepare_agenda_vals() |
|
|
|
|
|
self.meeting_ids.write(dict([(field, ce_vals[field]) for field in ce_fields])) |
|
|
|
|
|
|
|
|
def write(self, vals): |
|
|
def write(self, vals): |
|
|
res = super().write(vals) |
|
|
res = super().write(vals) |
|
|
agenda_fields = self.agenda_fields() |
|
|
|
|
|
|
|
|
agenda_fields_map = self.agenda_fields_mapping() |
|
|
|
|
|
agenda_fields = agenda_fields_map.keys() |
|
|
meetings = self.mapped("meeting_ids") |
|
|
meetings = self.mapped("meeting_ids") |
|
|
if any(field in agenda_fields for field in vals.keys()) and meetings: |
|
|
|
|
|
meetings.write( |
|
|
|
|
|
dict([(field, vals[field]) for field in agenda_fields & vals.keys()]) |
|
|
|
|
|
|
|
|
if meetings and any(field in agenda_fields for field in vals.keys()): |
|
|
|
|
|
for event in self.filtered("meeting_ids"): |
|
|
|
|
|
event.update_agenda_events( |
|
|
|
|
|
ce_fields=set( |
|
|
|
|
|
agenda_fields_map[agenda_field] |
|
|
|
|
|
for agenda_field in agenda_fields & vals.keys() |
|
|
) |
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
# meetings.write( |
|
|
|
|
|
# dict([(field, vals[field]) for field in agenda_fields & vals.keys()]) |
|
|
|
|
|
# ) |
|
|
return res |
|
|
return res |