RemiFr82
1 year ago
6 changed files with 284 additions and 0 deletions
-
1event_to_calendar/__init__.py
-
39event_to_calendar/__manifest__.py
-
75event_to_calendar/i18n/fr.po
-
1event_to_calendar/models/__init__.py
-
122event_to_calendar/models/event_event.py
-
46event_to_calendar/views/event_event.xml
@ -0,0 +1 @@ |
|||
from . import models |
@ -0,0 +1,39 @@ |
|||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
|||
{ |
|||
"name": "Event to Calendar", |
|||
"version": "1.0.0", |
|||
"summary": """ |
|||
Add/remove an event in your odoo calendar. |
|||
""", |
|||
"description": """ |
|||
TO WRITE |
|||
""", |
|||
"author": "RemiFr82", |
|||
"contributors": "", |
|||
"website": "https://remifr82.me", |
|||
"license": "LGPL-3", |
|||
"category": "Events", |
|||
# "price": 0, |
|||
# "currency": "EUR", |
|||
"application": False, |
|||
"installable": True, |
|||
"auto_install": False, |
|||
"pre_init_hook": "", |
|||
"post_init_hook": "", |
|||
"uninstall_hook": "", |
|||
"excludes": [], |
|||
"external_dependencies": [], |
|||
"depends": [ |
|||
"calendar", |
|||
"event", |
|||
], |
|||
"data": [ |
|||
"views/event_event.xml", |
|||
], |
|||
"css": [], |
|||
"images": [], |
|||
"js": [], |
|||
"test": [], |
|||
"demo": [], |
|||
"maintainer": "RemiFr82", |
|||
} |
@ -0,0 +1,75 @@ |
|||
# Translation of Odoo Server. |
|||
# This file contains the translation of the following modules: |
|||
# * event_to_calendar |
|||
# |
|||
msgid "" |
|||
msgstr "" |
|||
"Project-Id-Version: Odoo Server 16.0+e-20230613\n" |
|||
"Report-Msgid-Bugs-To: \n" |
|||
"POT-Creation-Date: 2023-10-16 22:26+0000\n" |
|||
"PO-Revision-Date: 2023-10-16 22:26+0000\n" |
|||
"Last-Translator: \n" |
|||
"Language-Team: \n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=UTF-8\n" |
|||
"Content-Transfer-Encoding: \n" |
|||
"Plural-Forms: \n" |
|||
|
|||
#. module: event_to_calendar |
|||
#. odoo-python |
|||
#: code:addons/event_to_calendar/models/event_event.py:0 |
|||
#, python-format |
|||
msgid "" |
|||
"<p>Organizer: {}{}<br/>Note:\n" |
|||
"</p>" |
|||
msgstr "" |
|||
"<p>Organisateur : {}{}<br/>Note :\n" |
|||
"</p>" |
|||
|
|||
#. module: event_to_calendar |
|||
#: model:ir.actions.server,name:event_to_calendar.event_add_to_agenda_action_server |
|||
msgid "Add to agenda" |
|||
msgstr "Ajouter à l'agenda" |
|||
|
|||
#. module: event_to_calendar |
|||
#: model_terms:ir.ui.view,arch_db:event_to_calendar.view_event_form_inherit_event_to_calendar |
|||
msgid "Add to my agenda" |
|||
msgstr "Ajouter à mon agenda" |
|||
|
|||
#. module: event_to_calendar |
|||
#: model:ir.model,name:event_to_calendar.model_event_event |
|||
msgid "Event" |
|||
msgstr "Événement" |
|||
|
|||
#. module: event_to_calendar |
|||
#: model:ir.model.fields,field_description:event_to_calendar.field_event_event__in_user_agenda |
|||
msgid "In User agenda" |
|||
msgstr "Dans l'agenda de l'utilisateur" |
|||
|
|||
#. module: event_to_calendar |
|||
#: model:ir.model.fields,field_description:event_to_calendar.field_event_event__meeting_ids |
|||
msgid "Linked meetings" |
|||
msgstr "RDV associés" |
|||
|
|||
#. module: event_to_calendar |
|||
#: model:ir.model.fields,field_description:event_to_calendar.field_event_event__meeting_count |
|||
msgid "Meeting count" |
|||
msgstr "Nombre de RDV" |
|||
|
|||
#. module: event_to_calendar |
|||
#. odoo-python |
|||
#: code:addons/event_to_calendar/models/event_event.py:0 |
|||
#: model_terms:ir.ui.view,arch_db:event_to_calendar.view_event_form_inherit_event_to_calendar |
|||
#, python-format |
|||
msgid "Meetings" |
|||
msgstr "RDV d'Agenda" |
|||
|
|||
#. module: event_to_calendar |
|||
#: model:ir.actions.server,name:event_to_calendar.event_remove_from_agenda_action_server |
|||
msgid "Remove from agenda" |
|||
msgstr "Retirer de l'agenda" |
|||
|
|||
#. module: event_to_calendar |
|||
#: model_terms:ir.ui.view,arch_db:event_to_calendar.view_event_form_inherit_event_to_calendar |
|||
msgid "Remove from my agenda" |
|||
msgstr "Retirer de mon agenda" |
@ -0,0 +1 @@ |
|||
from . import event_event |
@ -0,0 +1,122 @@ |
|||
import pytz |
|||
from datetime import timedelta |
|||
from odoo import models, fields, api, _ |
|||
|
|||
|
|||
class EventEvent(models.Model): |
|||
_inherit = "event.event" |
|||
|
|||
meeting_ids = fields.One2many( |
|||
comodel_name="calendar.event", |
|||
inverse_name="res_id", |
|||
string="Linked meetings", |
|||
) |
|||
meeting_count = fields.Integer( |
|||
string="Meeting count", |
|||
compute="_count_meetings", |
|||
) |
|||
in_user_agenda = fields.Boolean( |
|||
"In User agenda", |
|||
compute="_get_in_user_agenda", |
|||
) |
|||
|
|||
def _count_meetings(self): |
|||
for event in self: |
|||
event.meeting_count = len(event.meeting_ids) |
|||
|
|||
def _get_in_user_agenda(self): |
|||
uid = self.env.uid |
|||
for event in self: |
|||
event.in_user_agenda = uid in event.meeting_ids.mapped("user_id").ids |
|||
|
|||
def add_to_agenda(self, user_id=False): |
|||
vals_list = [] |
|||
self_model_id = self.env["ir.model"]._get_id(self._name) |
|||
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 = {} |
|||
for tag in event.tag_ids: |
|||
categ = tag.category_id.name |
|||
if categ in groupped_tags: |
|||
groupped_tags[categ] += ", {}".format(tag.name) |
|||
else: |
|||
groupped_tags[categ] = tag.name |
|||
event_tz = pytz.timezone(event.date_tz) |
|||
vals_list.append( |
|||
{ |
|||
"name": event.name + " (event Odoo)", |
|||
"description": _("<p>Organizer: {}{}<br/>Note:\n</p>").format( |
|||
event.organizer_id.display_name, |
|||
"".join( |
|||
[ |
|||
"<br/>{} : {}".format(tag_group[0], tag_group[1]) |
|||
for tag_group in groupped_tags.items() |
|||
] |
|||
), |
|||
event.note, |
|||
), |
|||
"user_id": uid, |
|||
"location": event.address_inline, |
|||
"start": event_tz.localize(event.date_begin) |
|||
.astimezone(pytz.timezone(self.env.user.tz)) |
|||
.replace(tzinfo=None), |
|||
"stop": event_tz.localize(event.date_end) |
|||
.astimezone(pytz.timezone(self.env.user.tz)) |
|||
.replace(tzinfo=None), |
|||
"res_id": event.id, |
|||
"res_model_id": self_model_id, |
|||
# "event_tz": event.date_tz, |
|||
} |
|||
) |
|||
if vals_list: |
|||
self.env["calendar.event"].create(vals_list) |
|||
|
|||
def remove_from_agenda(self, user_id=False): |
|||
to_unlink = self.mapped("meeting_ids").filtered( |
|||
lambda meeting: meeting.user_id.id == user_id or self.env.uid |
|||
) |
|||
if to_unlink: |
|||
to_unlink.unlink() |
|||
|
|||
def display_meetings(self): |
|||
self.ensure_one() |
|||
date_begin = self.date_begin.date() |
|||
return { |
|||
"name": _("Meetings"), |
|||
"type": "ir.actions.act_window", |
|||
"res_model": "calendar.event", |
|||
"views": [(False, "tree"), (False, "calendar"), (False, "form")], |
|||
"domain": [("res_id", "=", self.id), ("res_model", "=", self._name)], |
|||
"context": { |
|||
"calendar_mode": "week", |
|||
"initial_date": fields.Date.to_string( |
|||
date_begin - timedelta(days=-date_begin.weekday()) |
|||
), |
|||
}, |
|||
} |
|||
|
|||
@api.model |
|||
def agenda_fields(self): |
|||
return [ |
|||
"name", |
|||
"date_begin_located", |
|||
"date_end_located", |
|||
"date_tz", |
|||
"tag_ids", |
|||
"organizer_id", |
|||
"adress_inline", |
|||
"note", |
|||
] |
|||
|
|||
def write(self, vals): |
|||
res = super().write(vals) |
|||
agenda_fields = self.agenda_fields() |
|||
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()]) |
|||
) |
|||
return res |
@ -0,0 +1,46 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
|
|||
<record id="view_event_form_inherit_event_to_calendar" model="ir.ui.view"> |
|||
<field name="name">event.event.view.form.inherit</field> |
|||
<field name="model">event.event</field> |
|||
<field name="inherit_id" ref="event.view_event_form" /> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//header/*[1]" position="before"> |
|||
<button type="object" name="add_to_agenda" string="Add to my agenda" class="oe_highlight" |
|||
icon="fa-calendar-plus-o" attrs="{'invisible':[('in_user_agenda','=',True)]}" /> |
|||
<button type="object" name="remove_from_agenda" string="Remove from my agenda" class="btn btn-secondary" |
|||
icon="fa-calendar-minus-o" attrs="{'invisible':[('in_user_agenda','!=',True)]}" /> |
|||
</xpath> |
|||
<xpath expr="//div[hasclass('oe_button_box')]" position="inside"> |
|||
<button type="object" name="display_meetings" class="oe_stat_button" icon="fa-calendar"> |
|||
<field name="meeting_count" widget="statinfo" string="Meetings" /> |
|||
</button> |
|||
</xpath> |
|||
<field name="date_tz" position="after"> |
|||
<field name="in_user_agenda" invisible="1" /> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
<record id="event_add_to_agenda_action_server" model="ir.actions.server"> |
|||
<field name="name">Add to agenda</field> |
|||
<field name="model_id" ref="event.model_event_event" /> |
|||
<field name="binding_model_id" ref="event.model_event_event" /> |
|||
<field name="state">code</field> |
|||
<field name="code">if records: |
|||
records.add_to_agenda() |
|||
</field> |
|||
</record> |
|||
|
|||
<record id="event_remove_from_agenda_action_server" model="ir.actions.server"> |
|||
<field name="name">Remove from agenda</field> |
|||
<field name="model_id" ref="event.model_event_event" /> |
|||
<field name="binding_model_id" ref="event.model_event_event" /> |
|||
<field name="state">code</field> |
|||
<field name="code">if records: |
|||
records.remove_from_agenda() |
|||
</field> |
|||
</record> |
|||
|
|||
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue