mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
152
base_ical/README.rst
Normal file
152
base_ical/README.rst
Normal file
@@ -0,0 +1,152 @@
|
||||
================================
|
||||
Readonly publishing of calendars
|
||||
================================
|
||||
|
||||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
|
||||
:target: https://odoo-community.org/page/development-status
|
||||
:alt: Alpha
|
||||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github
|
||||
:target: https://github.com/OCA/server-backend/tree/15.0/base_ical
|
||||
:alt: OCA/server-backend
|
||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||
:target: https://translation.odoo-community.org/projects/server-backend-15-0/server-backend-15-0-base_ical
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
|
||||
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/server-backend&target_branch=15.0
|
||||
:alt: Try me on Runboat
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
This module allows administrators to configure iCalendars based on an arbitrary selection on arbitrary models.
|
||||
|
||||
Users can selectively subscribe to them by enabling them in their profile form.
|
||||
|
||||
This is useful for exposing Odoo data to calendaring application like Nextcloud.
|
||||
|
||||
.. IMPORTANT::
|
||||
This is an alpha version, the data model and design can change at any time without warning.
|
||||
Only for development or testing purpose, do not use in production.
|
||||
`More details on development status <https://odoo-community.org/page/development-status>`_
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
To configure this module, you need to:
|
||||
|
||||
#. Go to Settings/Technical/iCalendars
|
||||
#. Create a iCalendar, fill in the model you want to expose and possibly a domain to restrict records. You can use the ``user`` variable to restrict things relative to the user using the iCalendar
|
||||
#. A iCalendar is only available to the allowed users. Use the `Allow automatically` to make the iCalendar available to all users
|
||||
#. See the examples below for a start
|
||||
|
||||
Examples
|
||||
~~~~~~~~
|
||||
|
||||
Simple example, for model ``calendar.event``, you'd fill in ``record.allday and record.start_date or record.start`` as `DTSTART` and ``record.allday and record.stop_date or record.stop`` as `DTEND`.
|
||||
|
||||
Advanced example, for model ``calendar.event``, you'd use ``calendar = record._get_ics_file()`` in the code.
|
||||
|
||||
Advanced example, for model ``hr.leave``, you can use the following code and ``[("employee_id.user_id", "=", user.id)]`` in the `domain` to export the own time offs. This is a bit more complex because of the way Odoo handles the begin and end times of leaves, and you'll want the extra day as most clients interpret the end date as non-inclusive.:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
confirmed = ("validate", "validate1")
|
||||
if record.request_unit_half or record.request_unit_hours:
|
||||
event = {
|
||||
"dtstart": event["dtstart"].date(),
|
||||
"dtend": event["dtend"].date() + timedelta(days=1),
|
||||
}
|
||||
else:
|
||||
event = {
|
||||
"dtstart": record.date_from,
|
||||
"dtend": record.date_to,
|
||||
}
|
||||
|
||||
event["summary"] = record.name
|
||||
event["status"] = "CONFIRMED" if record.state in confirmed else "TENTATIVE"
|
||||
|
||||
Advanced example, for model ``mail.activity``, you can use the following code and ``[("user_id", "=", user.id)]`` and `domain` to export all user activities.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
todo = {
|
||||
"summary": record.display_name,
|
||||
"due": record.date_deadline,
|
||||
"description": html2plaintext(record.note) if record.note else ""
|
||||
}
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
To use this module, you need to:
|
||||
|
||||
#. Go to your profile form
|
||||
#. Click `Enable` on one of the calendars listed in tab `Calendars`
|
||||
#. Copy the URL to the application you use
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
|
||||
* support all of https://datatracker.ietf.org/doc/html/rfc5545#section-3.8
|
||||
* allow users to define their own calendars
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-backend/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
`feedback <https://github.com/OCA/server-backend/issues/new?body=module:%20base_ical%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Do not contact contributors directly about support or help with technical issues.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Authors
|
||||
~~~~~~~
|
||||
|
||||
* Hunki Enterprises BV
|
||||
|
||||
Contributors
|
||||
~~~~~~~~~~~~
|
||||
|
||||
* Holger Brunn <mail@hunki-enterprises.com> (https://hunki-enterprises.com)
|
||||
* Florian Kantelberg <florian.kantelberg@initos.com> (https://www.initos.com)
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: https://odoo-community.org
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px
|
||||
:target: https://github.com/hbrunn
|
||||
:alt: hbrunn
|
||||
|
||||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|
||||
|
||||
|maintainer-hbrunn|
|
||||
|
||||
This module is part of the `OCA/server-backend <https://github.com/OCA/server-backend/tree/15.0/base_ical>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
2
base_ical/__init__.py
Normal file
2
base_ical/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import models
|
||||
from . import controllers
|
||||
28
base_ical/__manifest__.py
Normal file
28
base_ical/__manifest__.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# Copyright 2023 Hunki Enterprises BV
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
|
||||
|
||||
{
|
||||
"name": "Readonly publishing of calendars",
|
||||
"summary": "Provide (readonly) .ics URLs to calendar-like models",
|
||||
"version": "15.0.1.0.0",
|
||||
"development_status": "Alpha",
|
||||
"category": "Tools",
|
||||
"website": "https://github.com/OCA/server-backend",
|
||||
"author": "Hunki Enterprises BV, Odoo Community Association (OCA)",
|
||||
"maintainers": ["hbrunn"],
|
||||
"license": "AGPL-3",
|
||||
"external_dependencies": {
|
||||
"python": ["vobject"],
|
||||
},
|
||||
"depends": [
|
||||
"web",
|
||||
],
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"views/base_ical.xml",
|
||||
"views/res_users.xml",
|
||||
],
|
||||
"demo": [
|
||||
"demo/base_ical.xml",
|
||||
],
|
||||
}
|
||||
1
base_ical/controllers/__init__.py
Normal file
1
base_ical/controllers/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import main
|
||||
54
base_ical/controllers/main.py
Normal file
54
base_ical/controllers/main.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# Copyright 2023 Hunki Enterprises BV
|
||||
# Copyright 2024 initOS GmbH
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
|
||||
|
||||
import logging
|
||||
|
||||
import werkzeug.wrappers
|
||||
from werkzeug.exceptions import Unauthorized
|
||||
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ICalController(http.Controller):
|
||||
@http.route(
|
||||
"/base_ical/<int:calendar_id>",
|
||||
auth="none",
|
||||
csrf=False,
|
||||
methods=["GET"],
|
||||
type="http",
|
||||
)
|
||||
def get_ical(self, calendar_id, access_token=None):
|
||||
if not access_token:
|
||||
raise Unauthorized()
|
||||
|
||||
user_id = request.env["res.users.apikeys"]._check_credentials(
|
||||
scope=f"odoo.plugin.ical.{calendar_id}",
|
||||
key=access_token,
|
||||
)
|
||||
if not user_id:
|
||||
raise Unauthorized()
|
||||
|
||||
calendar = (
|
||||
http.request.env["base.ical"]
|
||||
.with_user(user_id)
|
||||
.search([("id", "=", calendar_id)])
|
||||
)
|
||||
if not calendar:
|
||||
return request.not_found()
|
||||
|
||||
records = calendar._get_items()
|
||||
response = werkzeug.wrappers.Response()
|
||||
if records:
|
||||
response.last_modified = max(records.mapped("write_date"))
|
||||
|
||||
response.make_conditional(request.httprequest)
|
||||
if response.status_code == 304:
|
||||
return response
|
||||
|
||||
response.mimetype = "text/calendar"
|
||||
response.data = calendar._get_ical(records)
|
||||
return response
|
||||
12
base_ical/demo/base_ical.xml
Normal file
12
base_ical/demo/base_ical.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2023 Hunki Enterprises BV
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
|
||||
<data>
|
||||
<record id="demo_calendar" model="base.ical">
|
||||
<field name="name">Demo calendar</field>
|
||||
<field name="model_id" ref="base.model_res_users" />
|
||||
<field name="expression_uid">str(record.id)</field>
|
||||
<field name="expression_dtstart">record.create_date</field>
|
||||
<field name="expression_dtend">record.write_date</field>
|
||||
</record>
|
||||
</data>
|
||||
0
base_ical/i18n/.empty
Normal file
0
base_ical/i18n/.empty
Normal file
1
base_ical/models/__init__.py
Normal file
1
base_ical/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import base_ical, base_ical_url_description, base_ical_url_show, res_users
|
||||
308
base_ical/models/base_ical.py
Normal file
308
base_ical/models/base_ical.py
Normal file
@@ -0,0 +1,308 @@
|
||||
# Copyright 2023 Hunki Enterprises BV
|
||||
# Copyright 2024 initOS GmbH
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import pytz
|
||||
import vobject
|
||||
from dateutil import relativedelta
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.tools import html2plaintext
|
||||
from odoo.tools.safe_eval import safe_eval, wrap_module
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
vobject_wrapped = wrap_module(__import__("vobject"), ["iCalendar", "readOne"])
|
||||
|
||||
|
||||
class BaseIcal(models.Model):
|
||||
_name = "base.ical"
|
||||
_description = "Definition of an iCal export"
|
||||
|
||||
def _get_operating_modes(self):
|
||||
return [
|
||||
("simple", _("Simple")),
|
||||
("advanced", _("Advanced")),
|
||||
]
|
||||
|
||||
active = fields.Boolean(default=True)
|
||||
name = fields.Char(required=True, translate=True)
|
||||
mode = fields.Selection("_get_operating_modes", required=True, default="simple")
|
||||
model_id = fields.Many2one("ir.model", required=True, ondelete="cascade")
|
||||
model = fields.Char("Model Name", related="model_id.model")
|
||||
domain = fields.Char(
|
||||
required=True, default="[]", help="You can use variables `env` and `user` here"
|
||||
)
|
||||
preview = fields.Text(compute="_compute_preview")
|
||||
code = fields.Text()
|
||||
expression_dtstamp = fields.Char(
|
||||
vevent_field="dtstamp",
|
||||
string="DTSTAMP",
|
||||
help="You can use variables `record` and `user` here",
|
||||
default="record.write_date",
|
||||
)
|
||||
expression_uid = fields.Char(
|
||||
vevent_field="uid",
|
||||
string="UID",
|
||||
help="You can use variables `record` and `user` here",
|
||||
)
|
||||
expression_dtstart = fields.Char(
|
||||
vevent_field="dtstart",
|
||||
string="DTSTART",
|
||||
help="You can use variables `record` and `user` here",
|
||||
)
|
||||
expression_dtend = fields.Char(
|
||||
vevent_field="dtend",
|
||||
string="DTEND",
|
||||
help="You can use variables `record` and `user` here",
|
||||
)
|
||||
expression_summary = fields.Char(
|
||||
vevent_field="summary",
|
||||
string="SUMMARY",
|
||||
help="You can use variables `record` and `user` here",
|
||||
default="record.display_name",
|
||||
)
|
||||
allowed_users_ids = fields.Many2many("res.users")
|
||||
auto = fields.Boolean(
|
||||
"Allow automatically",
|
||||
copy=False,
|
||||
help="If you check this, the calendar will be enabled for all current and "
|
||||
"future users. Not that unchecking this will not disable existing calendar "
|
||||
"subscriptions",
|
||||
)
|
||||
help_text = fields.Html(compute="_compute_help")
|
||||
|
||||
def _valid_field_parameter(self, field, name):
|
||||
return super()._valid_field_parameter(field, name) or name == "vevent_field"
|
||||
|
||||
@api.depends(
|
||||
"model_id",
|
||||
"domain",
|
||||
"expression_dtstamp",
|
||||
"expression_uid",
|
||||
"expression_dtstart",
|
||||
"expression_dtend",
|
||||
"expression_summary",
|
||||
"code",
|
||||
"mode",
|
||||
)
|
||||
def _compute_preview(self):
|
||||
for this in self:
|
||||
this.preview = this._get_ical(limit=5)
|
||||
|
||||
@api.depends("mode")
|
||||
def _compute_help(self):
|
||||
for this in self:
|
||||
variables = this.default_variables()
|
||||
lines = []
|
||||
for var, desc in sorted(variables.items()):
|
||||
var = (f"<code>{v.strip()}</code>" for v in var.split(","))
|
||||
lines.append(f"<li>{', '.join(sorted(var))}: {desc}</li>")
|
||||
|
||||
this.help_text = "<ul>" + "\n".join(lines) + "</ul>"
|
||||
|
||||
@api.onchange("model_id")
|
||||
def _onchange_model_id(self):
|
||||
for field_name, field in self._fields.items():
|
||||
if hasattr(field, "vevent_field"):
|
||||
self[field_name] = False
|
||||
self.update(
|
||||
self.default_get(["domain", "expression_dtstamp", "expression_summary"])
|
||||
)
|
||||
base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url")
|
||||
self.expression_uid = "'%%s-%s@%s' %% record.id" % (
|
||||
self.env.cr.dbname,
|
||||
urlparse(base_url).hostname,
|
||||
)
|
||||
|
||||
@api.constrains(
|
||||
"domain",
|
||||
"expression_dtstamp",
|
||||
"expression_uid",
|
||||
"expression_dtstart",
|
||||
"expression_dtend",
|
||||
"expression_summary",
|
||||
"code",
|
||||
"mode",
|
||||
)
|
||||
def _check_domain(self):
|
||||
for this in self:
|
||||
this._get_ical()
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
"""Enable calendar for all users if auto flag is checked"""
|
||||
result = super().create(vals_list)
|
||||
result.filtered("auto")._enable_all_users()
|
||||
return result
|
||||
|
||||
def write(self, vals):
|
||||
"""Enable calendar for all users if auto flag is checked"""
|
||||
result = super().write(vals)
|
||||
if vals.get("auto"):
|
||||
self._enable_all_users()
|
||||
return result
|
||||
|
||||
def default_variables(self):
|
||||
self.ensure_one()
|
||||
variables = {
|
||||
"datetime, relativedelta, time, timedelta": "useful Python libraries",
|
||||
"record": "Record to export",
|
||||
"user": "Current user record",
|
||||
}
|
||||
if self.mode == "advanced":
|
||||
variables.update(
|
||||
{
|
||||
"calendar": "Output: Calendar e.g. from `_get_ics_file`",
|
||||
"dict2ical": "Function to add the key-values of dict to ical component",
|
||||
"event": "Output: Dictionary of an VEVENT",
|
||||
"todo": "Output: Dictionary of an VTODO",
|
||||
"vobject": "vobject python library",
|
||||
"html2plaintext": "Converts HTML to plain text",
|
||||
}
|
||||
)
|
||||
return variables
|
||||
|
||||
def _get_eval_expression_context(self):
|
||||
"""Return the evaluation context for expression evaluation"""
|
||||
return {
|
||||
"datetime": datetime.datetime,
|
||||
"date": datetime.date,
|
||||
"relativedelta": relativedelta.relativedelta,
|
||||
"timedelta": datetime.timedelta,
|
||||
"user": self.env.user,
|
||||
}
|
||||
|
||||
def _get_eval_domain_context(self):
|
||||
"""Return the evaluation context for domain evaluation"""
|
||||
return {
|
||||
"user": self.env.user,
|
||||
"env": self.env,
|
||||
}
|
||||
|
||||
def _get_items(self, limit=None):
|
||||
"""Return events based on model_id and domain"""
|
||||
self.ensure_one()
|
||||
return self.env[self.model_id.sudo().model].search(
|
||||
safe_eval(self.domain, self._get_eval_domain_context()),
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
def _get_ical(self, records=None, limit=None):
|
||||
"""Return the vcalendar as text"""
|
||||
if self.mode == "simple":
|
||||
return self._get_ical_simple(records=records, limit=limit)
|
||||
|
||||
return self._get_ical_advanced(records=records, limit=limit)
|
||||
|
||||
def _get_ical_simple(self, records=None, limit=None):
|
||||
if not all(
|
||||
self[field_name]
|
||||
for field_name, field in self._fields.items()
|
||||
if hasattr(field, "vevent_field")
|
||||
):
|
||||
return ""
|
||||
|
||||
calendar = vobject.iCalendar()
|
||||
for record in records or self._get_items(limit):
|
||||
event = calendar.add("vevent")
|
||||
for field_name, field in self._fields.items():
|
||||
if not hasattr(field, "vevent_field"):
|
||||
continue
|
||||
|
||||
if not self[field_name]:
|
||||
continue
|
||||
|
||||
ctx = self._get_eval_expression_context()
|
||||
ctx["record"] = record
|
||||
|
||||
value = safe_eval(self[field_name], ctx)
|
||||
event.add(field.vevent_field).value = self._format_ical_value(
|
||||
value, field=field
|
||||
)
|
||||
return calendar.serialize()
|
||||
|
||||
def _get_ical_advanced(self, records=None, limit=None):
|
||||
if not self.code:
|
||||
return ""
|
||||
|
||||
context = self._get_eval_expression_context()
|
||||
context.update(
|
||||
{
|
||||
"dict2ical": self._dict_to_ical_component,
|
||||
"html2plaintext": html2plaintext,
|
||||
"vobject": vobject_wrapped,
|
||||
}
|
||||
)
|
||||
|
||||
calendar = vobject.iCalendar()
|
||||
tz = pytz.timezone(self.env.user.tz or "UTC")
|
||||
calendar.add(vobject.icalendar.TimezoneComponent(tz))
|
||||
for record in records or self._get_items(limit):
|
||||
context.update(
|
||||
{"record": record, "calendar": None, "event": None, "todo": None}
|
||||
)
|
||||
safe_eval(self.code, context, mode="exec", nocopy=True)
|
||||
|
||||
cal = context.get("calendar")
|
||||
if cal:
|
||||
# Support for `_get_ics_file`
|
||||
if isinstance(cal, dict) and record.id in cal:
|
||||
cal = cal[record.id]
|
||||
|
||||
if isinstance(cal, bytes):
|
||||
cal = cal.decode()
|
||||
|
||||
if isinstance(cal, str):
|
||||
cal = vobject.readOne(cal)
|
||||
|
||||
self._copy_ical_calendar(calendar, cal)
|
||||
|
||||
event, todo = map(context.get, ("event", "todo"))
|
||||
if event:
|
||||
self._dict_to_ical_component(calendar.add("vevent"), event)
|
||||
|
||||
if todo:
|
||||
self._dict_to_ical_component(calendar.add("vtodo"), todo)
|
||||
|
||||
return calendar.serialize()
|
||||
|
||||
def _dict_to_ical_component(self, component, data):
|
||||
for key, value in data.items():
|
||||
component.add(key).value = self._format_ical_value(value)
|
||||
|
||||
def _copy_ical_calendar(self, dst_calendar, src_calendar):
|
||||
for item in src_calendar.getChildren():
|
||||
if item.name.lower() in ("vevent", "vtodo"):
|
||||
dst_calendar.add(item)
|
||||
|
||||
def _format_ical_value(self, value, field=None):
|
||||
"""Add timezone to datetime values"""
|
||||
if isinstance(value, datetime.datetime):
|
||||
return pytz.utc.localize(value).astimezone(
|
||||
pytz.timezone(self.env.user.tz or "UTC")
|
||||
)
|
||||
return value
|
||||
|
||||
def _enable_all_users(self, users=None):
|
||||
"""Enable calendar for all users"""
|
||||
users = users or self.env.ref("base.group_user").users
|
||||
self.write({"allowed_users_ids": users})
|
||||
|
||||
def action_new_url(self):
|
||||
"""Create or activate current user's token"""
|
||||
|
||||
return {
|
||||
"type": "ir.actions.act_window",
|
||||
"res_model": "base.ical.url.description",
|
||||
"name": "iCalendar URL",
|
||||
"views": [(False, "form")],
|
||||
"target": "new",
|
||||
"context": {
|
||||
"default_calendar_id": self.id,
|
||||
},
|
||||
}
|
||||
47
base_ical/models/base_ical_url_description.py
Normal file
47
base_ical/models/base_ical_url_description.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# Copyright 2024 initOS GmbH
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
|
||||
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
|
||||
from odoo import _, fields, models
|
||||
from odoo.exceptions import AccessError
|
||||
|
||||
from odoo.addons.base.models.res_users import check_identity
|
||||
|
||||
|
||||
class BaseIcalUrlDescription(models.TransientModel):
|
||||
_name = "base.ical.url.description"
|
||||
_description = "Description for iCalendar"
|
||||
|
||||
calendar_id = fields.Many2one("base.ical", required=True)
|
||||
name = fields.Char("Description", required=True)
|
||||
|
||||
def _make_url(self):
|
||||
if not self.user_has_groups("base.group_user"):
|
||||
raise AccessError(_("Only internal users can create API keys"))
|
||||
|
||||
scope = f"odoo.plugin.ical.{self.calendar_id.id}"
|
||||
|
||||
token = self.env["res.users.apikeys"]._generate(scope, f"Calendar: {self.name}")
|
||||
|
||||
base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url")
|
||||
return urlunparse(
|
||||
urlparse(base_url)._replace(
|
||||
path=f"/base_ical/{self.calendar_id.id}",
|
||||
query=f"access_token={token}",
|
||||
)
|
||||
)
|
||||
|
||||
@check_identity
|
||||
def make_url(self):
|
||||
url = self._make_url()
|
||||
return {
|
||||
"type": "ir.actions.act_window",
|
||||
"res_model": "base.ical.url.show",
|
||||
"name": "iCalendar URL",
|
||||
"views": [(False, "form")],
|
||||
"target": "new",
|
||||
"context": {
|
||||
"default_url": url,
|
||||
},
|
||||
}
|
||||
12
base_ical/models/base_ical_url_show.py
Normal file
12
base_ical/models/base_ical_url_show.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright 2024 initOS GmbH
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class BaseIcalUrlShow(models.AbstractModel):
|
||||
_name = "base.ical.url.show"
|
||||
_description = "Show URL for iCalendar"
|
||||
|
||||
id = fields.Id()
|
||||
url = fields.Char(readonly=True)
|
||||
26
base_ical/models/res_users.py
Normal file
26
base_ical/models/res_users.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Copyright 2023 Hunki Enterprises BV
|
||||
# Copyright 2024 initOS GmbH
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
_inherit = "res.users"
|
||||
|
||||
ical_ids = fields.One2many("base.ical", compute="_compute_ical_ids")
|
||||
|
||||
def _compute_ical_ids(self):
|
||||
domain = [("allowed_users_ids", "=", self.env.uid)]
|
||||
self.write({"ical_ids": self.env["base.ical"].search(domain)})
|
||||
|
||||
@property
|
||||
def SELF_READABLE_FIELDS(self):
|
||||
return super().SELF_READABLE_FIELDS + ["ical_ids"]
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
result = super().create(vals_list)
|
||||
calendars = self.env["base.ical"].search([("auto", "=", True)])
|
||||
calendars.sudo().write({"allowed_users_ids": [(4, result.id)]})
|
||||
return result
|
||||
42
base_ical/readme/CONFIGURE.rst
Normal file
42
base_ical/readme/CONFIGURE.rst
Normal file
@@ -0,0 +1,42 @@
|
||||
To configure this module, you need to:
|
||||
|
||||
#. Go to Settings/Technical/iCalendars
|
||||
#. Create a iCalendar, fill in the model you want to expose and possibly a domain to restrict records. You can use the ``user`` variable to restrict things relative to the user using the iCalendar
|
||||
#. A iCalendar is only available to the allowed users. Use the `Allow automatically` to make the iCalendar available to all users
|
||||
#. See the examples below for a start
|
||||
|
||||
Examples
|
||||
~~~~~~~~
|
||||
|
||||
Simple example, for model ``calendar.event``, you'd fill in ``record.allday and record.start_date or record.start`` as `DTSTART` and ``record.allday and record.stop_date or record.stop`` as `DTEND`.
|
||||
|
||||
Advanced example, for model ``calendar.event``, you'd use ``calendar = record._get_ics_file()`` in the code.
|
||||
|
||||
Advanced example, for model ``hr.leave``, you can use the following code and ``[("employee_id.user_id", "=", user.id)]`` in the `domain` to export the own time offs. This is a bit more complex because of the way Odoo handles the begin and end times of leaves, and you'll want the extra day as most clients interpret the end date as non-inclusive.:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
confirmed = ("validate", "validate1")
|
||||
if record.request_unit_half or record.request_unit_hours:
|
||||
event = {
|
||||
"dtstart": event["dtstart"].date(),
|
||||
"dtend": event["dtend"].date() + timedelta(days=1),
|
||||
}
|
||||
else:
|
||||
event = {
|
||||
"dtstart": record.date_from,
|
||||
"dtend": record.date_to,
|
||||
}
|
||||
|
||||
event["summary"] = record.name
|
||||
event["status"] = "CONFIRMED" if record.state in confirmed else "TENTATIVE"
|
||||
|
||||
Advanced example, for model ``mail.activity``, you can use the following code and ``[("user_id", "=", user.id)]`` and `domain` to export all user activities.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
todo = {
|
||||
"summary": record.display_name,
|
||||
"due": record.date_deadline,
|
||||
"description": html2plaintext(record.note) if record.note else ""
|
||||
}
|
||||
2
base_ical/readme/CONTRIBUTORS.rst
Normal file
2
base_ical/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
* Holger Brunn <mail@hunki-enterprises.com> (https://hunki-enterprises.com)
|
||||
* Florian Kantelberg <florian.kantelberg@initos.com> (https://www.initos.com)
|
||||
5
base_ical/readme/DESCRIPTION.rst
Normal file
5
base_ical/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
This module allows administrators to configure iCalendars based on an arbitrary selection on arbitrary models.
|
||||
|
||||
Users can selectively subscribe to them by enabling them in their profile form.
|
||||
|
||||
This is useful for exposing Odoo data to calendaring application like Nextcloud.
|
||||
2
base_ical/readme/ROADMAP.rst
Normal file
2
base_ical/readme/ROADMAP.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
* support all of https://datatracker.ietf.org/doc/html/rfc5545#section-3.8
|
||||
* allow users to define their own calendars
|
||||
5
base_ical/readme/USAGE.rst
Normal file
5
base_ical/readme/USAGE.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
To use this module, you need to:
|
||||
|
||||
#. Go to your profile form
|
||||
#. Click `Enable` on one of the calendars listed in tab `Calendars`
|
||||
#. Copy the URL to the application you use
|
||||
5
base_ical/security/ir.model.access.csv
Normal file
5
base_ical/security/ir.model.access.csv
Normal file
@@ -0,0 +1,5 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_base_ical,access_base_ical,model_base_ical,base.group_user,1,0,0,0
|
||||
modify_base_ical,modify_base_ical,model_base_ical,base.group_system,1,1,1,1
|
||||
access_base_ical_url_description,access_base_ical_url_description,model_base_ical_url_description,base.group_user,1,0,1,0
|
||||
access_base_ical_url_show,access_base_ical_url_show,model_base_ical_url_show,base.group_user,1,0,1,0
|
||||
|
BIN
base_ical/static/description/icon.png
Normal file
BIN
base_ical/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
475
base_ical/static/description/index.html
Normal file
475
base_ical/static/description/index.html
Normal file
@@ -0,0 +1,475 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
|
||||
<title>Readonly publishing of calendars</title>
|
||||
<style type="text/css">
|
||||
|
||||
/*
|
||||
:Author: David Goodger (goodger@python.org)
|
||||
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
|
||||
:Copyright: This stylesheet has been placed in the public domain.
|
||||
|
||||
Default cascading style sheet for the HTML output of Docutils.
|
||||
|
||||
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
|
||||
customize this style sheet.
|
||||
*/
|
||||
|
||||
/* used to remove borders from tables and images */
|
||||
.borderless, table.borderless td, table.borderless th {
|
||||
border: 0 }
|
||||
|
||||
table.borderless td, table.borderless th {
|
||||
/* Override padding for "table.docutils td" with "! important".
|
||||
The right padding separates the table cells. */
|
||||
padding: 0 0.5em 0 0 ! important }
|
||||
|
||||
.first {
|
||||
/* Override more specific margin styles with "! important". */
|
||||
margin-top: 0 ! important }
|
||||
|
||||
.last, .with-subtitle {
|
||||
margin-bottom: 0 ! important }
|
||||
|
||||
.hidden {
|
||||
display: none }
|
||||
|
||||
.subscript {
|
||||
vertical-align: sub;
|
||||
font-size: smaller }
|
||||
|
||||
.superscript {
|
||||
vertical-align: super;
|
||||
font-size: smaller }
|
||||
|
||||
a.toc-backref {
|
||||
text-decoration: none ;
|
||||
color: black }
|
||||
|
||||
blockquote.epigraph {
|
||||
margin: 2em 5em ; }
|
||||
|
||||
dl.docutils dd {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Uncomment (and remove this text!) to get bold-faced definition list terms
|
||||
dl.docutils dt {
|
||||
font-weight: bold }
|
||||
*/
|
||||
|
||||
div.abstract {
|
||||
margin: 2em 5em }
|
||||
|
||||
div.abstract p.topic-title {
|
||||
font-weight: bold ;
|
||||
text-align: center }
|
||||
|
||||
div.admonition, div.attention, div.caution, div.danger, div.error,
|
||||
div.hint, div.important, div.note, div.tip, div.warning {
|
||||
margin: 2em ;
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.admonition p.admonition-title, div.hint p.admonition-title,
|
||||
div.important p.admonition-title, div.note p.admonition-title,
|
||||
div.tip p.admonition-title {
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
div.attention p.admonition-title, div.caution p.admonition-title,
|
||||
div.danger p.admonition-title, div.error p.admonition-title,
|
||||
div.warning p.admonition-title, .code .error {
|
||||
color: red ;
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
/* Uncomment (and remove this text!) to get reduced vertical space in
|
||||
compound paragraphs.
|
||||
div.compound .compound-first, div.compound .compound-middle {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
div.compound .compound-last, div.compound .compound-middle {
|
||||
margin-top: 0.5em }
|
||||
*/
|
||||
|
||||
div.dedication {
|
||||
margin: 2em 5em ;
|
||||
text-align: center ;
|
||||
font-style: italic }
|
||||
|
||||
div.dedication p.topic-title {
|
||||
font-weight: bold ;
|
||||
font-style: normal }
|
||||
|
||||
div.figure {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
div.footer, div.header {
|
||||
clear: both;
|
||||
font-size: smaller }
|
||||
|
||||
div.line-block {
|
||||
display: block ;
|
||||
margin-top: 1em ;
|
||||
margin-bottom: 1em }
|
||||
|
||||
div.line-block div.line-block {
|
||||
margin-top: 0 ;
|
||||
margin-bottom: 0 ;
|
||||
margin-left: 1.5em }
|
||||
|
||||
div.sidebar {
|
||||
margin: 0 0 0.5em 1em ;
|
||||
border: medium outset ;
|
||||
padding: 1em ;
|
||||
background-color: #ffffee ;
|
||||
width: 40% ;
|
||||
float: right ;
|
||||
clear: right }
|
||||
|
||||
div.sidebar p.rubric {
|
||||
font-family: sans-serif ;
|
||||
font-size: medium }
|
||||
|
||||
div.system-messages {
|
||||
margin: 5em }
|
||||
|
||||
div.system-messages h1 {
|
||||
color: red }
|
||||
|
||||
div.system-message {
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.system-message p.system-message-title {
|
||||
color: red ;
|
||||
font-weight: bold }
|
||||
|
||||
div.topic {
|
||||
margin: 2em }
|
||||
|
||||
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
||||
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
||||
margin-top: 0.4em }
|
||||
|
||||
h1.title {
|
||||
text-align: center }
|
||||
|
||||
h2.subtitle {
|
||||
text-align: center }
|
||||
|
||||
hr.docutils {
|
||||
width: 75% }
|
||||
|
||||
img.align-left, .figure.align-left, object.align-left, table.align-left {
|
||||
clear: left ;
|
||||
float: left ;
|
||||
margin-right: 1em }
|
||||
|
||||
img.align-right, .figure.align-right, object.align-right, table.align-right {
|
||||
clear: right ;
|
||||
float: right ;
|
||||
margin-left: 1em }
|
||||
|
||||
img.align-center, .figure.align-center, object.align-center {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
table.align-center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.align-left {
|
||||
text-align: left }
|
||||
|
||||
.align-center {
|
||||
clear: both ;
|
||||
text-align: center }
|
||||
|
||||
.align-right {
|
||||
text-align: right }
|
||||
|
||||
/* reset inner alignment in figures */
|
||||
div.align-right {
|
||||
text-align: inherit }
|
||||
|
||||
/* div.align-center * { */
|
||||
/* text-align: left } */
|
||||
|
||||
.align-top {
|
||||
vertical-align: top }
|
||||
|
||||
.align-middle {
|
||||
vertical-align: middle }
|
||||
|
||||
.align-bottom {
|
||||
vertical-align: bottom }
|
||||
|
||||
ol.simple, ul.simple {
|
||||
margin-bottom: 1em }
|
||||
|
||||
ol.arabic {
|
||||
list-style: decimal }
|
||||
|
||||
ol.loweralpha {
|
||||
list-style: lower-alpha }
|
||||
|
||||
ol.upperalpha {
|
||||
list-style: upper-alpha }
|
||||
|
||||
ol.lowerroman {
|
||||
list-style: lower-roman }
|
||||
|
||||
ol.upperroman {
|
||||
list-style: upper-roman }
|
||||
|
||||
p.attribution {
|
||||
text-align: right ;
|
||||
margin-left: 50% }
|
||||
|
||||
p.caption {
|
||||
font-style: italic }
|
||||
|
||||
p.credits {
|
||||
font-style: italic ;
|
||||
font-size: smaller }
|
||||
|
||||
p.label {
|
||||
white-space: nowrap }
|
||||
|
||||
p.rubric {
|
||||
font-weight: bold ;
|
||||
font-size: larger ;
|
||||
color: maroon ;
|
||||
text-align: center }
|
||||
|
||||
p.sidebar-title {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold ;
|
||||
font-size: larger }
|
||||
|
||||
p.sidebar-subtitle {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
p.topic-title {
|
||||
font-weight: bold }
|
||||
|
||||
pre.address {
|
||||
margin-bottom: 0 ;
|
||||
margin-top: 0 ;
|
||||
font: inherit }
|
||||
|
||||
pre.literal-block, pre.doctest-block, pre.math, pre.code {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
pre.code .ln { color: grey; } /* line numbers */
|
||||
pre.code, code { background-color: #eeeeee }
|
||||
pre.code .comment, code .comment { color: #5C6576 }
|
||||
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
|
||||
pre.code .literal.string, code .literal.string { color: #0C5404 }
|
||||
pre.code .name.builtin, code .name.builtin { color: #352B84 }
|
||||
pre.code .deleted, code .deleted { background-color: #DEB0A1}
|
||||
pre.code .inserted, code .inserted { background-color: #A3D289}
|
||||
|
||||
span.classifier {
|
||||
font-family: sans-serif ;
|
||||
font-style: oblique }
|
||||
|
||||
span.classifier-delimiter {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
span.interpreted {
|
||||
font-family: sans-serif }
|
||||
|
||||
span.option {
|
||||
white-space: nowrap }
|
||||
|
||||
span.pre {
|
||||
white-space: pre }
|
||||
|
||||
span.problematic {
|
||||
color: red }
|
||||
|
||||
span.section-subtitle {
|
||||
/* font-size relative to parent (h1..h6 element) */
|
||||
font-size: 80% }
|
||||
|
||||
table.citation {
|
||||
border-left: solid 1px gray;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docinfo {
|
||||
margin: 2em 4em }
|
||||
|
||||
table.docutils {
|
||||
margin-top: 0.5em ;
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
table.footnote {
|
||||
border-left: solid 1px black;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docutils td, table.docutils th,
|
||||
table.docinfo td, table.docinfo th {
|
||||
padding-left: 0.5em ;
|
||||
padding-right: 0.5em ;
|
||||
vertical-align: top }
|
||||
|
||||
table.docutils th.field-name, table.docinfo th.docinfo-name {
|
||||
font-weight: bold ;
|
||||
text-align: left ;
|
||||
white-space: nowrap ;
|
||||
padding-left: 0 }
|
||||
|
||||
/* "booktabs" style (no vertical lines) */
|
||||
table.docutils.booktabs {
|
||||
border: 0px;
|
||||
border-top: 2px solid;
|
||||
border-bottom: 2px solid;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table.docutils.booktabs * {
|
||||
border: 0px;
|
||||
}
|
||||
table.docutils.booktabs th {
|
||||
border-bottom: thin solid;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
||||
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
||||
font-size: 100% }
|
||||
|
||||
ul.auto-toc {
|
||||
list-style-type: none }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="readonly-publishing-of-calendars">
|
||||
<h1 class="title">Readonly publishing of calendars</h1>
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! source digest: sha256:08b4b5a2737a01f894ac4e4e5382694dcd87bf6e5ac5bb46ca91df22d8d8e51a
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-backend/tree/15.0/base_ical"><img alt="OCA/server-backend" src="https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-backend-15-0/server-backend-15-0-base_ical"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/builds?repo=OCA/server-backend&target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
|
||||
<p>This module allows administrators to configure iCalendars based on an arbitrary selection on arbitrary models.</p>
|
||||
<p>Users can selectively subscribe to them by enabling them in their profile form.</p>
|
||||
<p>This is useful for exposing Odoo data to calendaring application like Nextcloud.</p>
|
||||
<div class="admonition important">
|
||||
<p class="first admonition-title">Important</p>
|
||||
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
|
||||
Only for development or testing purpose, do not use in production.
|
||||
<a class="reference external" href="https://odoo-community.org/page/development-status">More details on development status</a></p>
|
||||
</div>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
|
||||
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
|
||||
<li><a class="reference internal" href="#known-issues-roadmap" id="id3">Known issues / Roadmap</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id4">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id5">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id6">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id7">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#other-credits" id="id8">Other credits</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id9">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="configuration">
|
||||
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
|
||||
<p>To configure this module, you need to:</p>
|
||||
<ol class="arabic">
|
||||
<li><p class="first">Go to Settings/Technical/iCalendars</p>
|
||||
</li>
|
||||
<li><p class="first">Create a calendar, fill in the model you want to expose and possibly a domain to restrict records. You can use the <tt class="docutils literal">user</tt> variable to restrict things relative to the user using the calendar</p>
|
||||
</li>
|
||||
<li><p class="first">A few iCalendar-fields have defaults that should work for any model, you’ll have to fill in expressions manually though for the start and end date of the records.</p>
|
||||
<p>For example, for model <tt class="docutils literal">calendar.event</tt>, you’d fill in <tt class="docutils literal">record.allday and record.start_date or record.start</tt> as <cite>DTSTART</cite> and <tt class="docutils literal">record.allday and record.stop_date or record.stop</tt> as <cite>DTEND</cite>.</p>
|
||||
<p>For model <tt class="docutils literal">hr.leave</tt>, you’d write <tt class="docutils literal">(record.request_unit_half or record.request_unit_hours) and record.date_from or record.date_from.date()</tt> for <cite>DTSTART</cite> and <tt class="docutils literal">(record.request_unit_half or record.request_unit_hours) and record.date_to or (record.date_to.date() + timedelta(days=1))</tt> for <cite>DTEND</cite> - this is a bit more complex because of the way Odoo handles the begin and end times of leaves, and you’ll want the extra day as most clients interpret the end date as non-inclusive.</p>
|
||||
</li>
|
||||
<li><p class="first">Existing calendars are available for users in the tab <cite>Calendars</cite> of their profile form, where they can enable them to obtain a link they can paste into whatever client they are going to use</p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="usage">
|
||||
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
|
||||
<p>To use this module, you need to:</p>
|
||||
<ol class="arabic simple">
|
||||
<li>Go to your profile form</li>
|
||||
<li>Click <cite>Enable</cite> on one of the calendars listed in tab <cite>Calendars</cite></li>
|
||||
<li>Copy the URL to the application you use</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="known-issues-roadmap">
|
||||
<h1><a class="toc-backref" href="#id3">Known issues / Roadmap</a></h1>
|
||||
<ul class="simple">
|
||||
<li>support all of <a class="reference external" href="https://datatracker.ietf.org/doc/html/rfc5545#section-3.8">https://datatracker.ietf.org/doc/html/rfc5545#section-3.8</a></li>
|
||||
<li>allow users to define their own calendars</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-backend/issues">GitHub Issues</a>.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us to smash it by providing a detailed and welcomed
|
||||
<a class="reference external" href="https://github.com/OCA/server-backend/issues/new?body=module:%20base_ical%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
<h1><a class="toc-backref" href="#id5">Credits</a></h1>
|
||||
<div class="section" id="authors">
|
||||
<h2><a class="toc-backref" href="#id6">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Hunki Enterprises BV</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
<h2><a class="toc-backref" href="#id7">Contributors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Holger Brunn <<a class="reference external" href="mailto:mail@hunki-enterprises.com">mail@hunki-enterprises.com</a>> (<a class="reference external" href="https://hunki-enterprises.com">https://hunki-enterprises.com</a>)</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="other-credits">
|
||||
<h2><a class="toc-backref" href="#id8">Other credits</a></h2>
|
||||
<p>The development of this module has been financially supported by:</p>
|
||||
<ul class="simple">
|
||||
<li>Company 1 name</li>
|
||||
<li>Company 2 name</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#id9">Maintainers</a></h2>
|
||||
<p>This module is maintained by the OCA.</p>
|
||||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.</p>
|
||||
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
|
||||
<p><a class="reference external" href="https://github.com/hbrunn"><img alt="hbrunn" src="https://github.com/hbrunn.png?size=40px" /></a></p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-backend/tree/15.0/base_ical">OCA/server-backend</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
1
base_ical/tests/__init__.py
Normal file
1
base_ical/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_base_ical
|
||||
125
base_ical/tests/test_base_ical.py
Normal file
125
base_ical/tests/test_base_ical.py
Normal file
@@ -0,0 +1,125 @@
|
||||
# Copyright 2023 Hunki Enterprises BV
|
||||
# Copyright 2024 initOS GmbH
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
|
||||
|
||||
import logging
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
|
||||
import vobject
|
||||
|
||||
from odoo.tests.common import Form, TransactionCase
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestBaseIcal(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.calendar = cls.env.ref("base_ical.demo_calendar")
|
||||
cls.user = cls.env.ref("base.user_demo")
|
||||
|
||||
def test_profile(self):
|
||||
"""Test url generation"""
|
||||
desc = (
|
||||
self.env["base.ical.url.description"]
|
||||
.with_user(self.user)
|
||||
.create({"calendar_id": self.calendar.id, "name": "Testing"})
|
||||
)
|
||||
|
||||
url = desc._make_url()
|
||||
self.assertTrue(url)
|
||||
parsed = urlparse(url)
|
||||
params = parse_qs(parsed.query)
|
||||
access_token = params.get("access_token")[0]
|
||||
self.assertTrue(access_token)
|
||||
|
||||
user_id = self.env["res.users.apikeys"]._check_credentials(
|
||||
scope=f"odoo.plugin.ical.{self.calendar.id}",
|
||||
key=access_token,
|
||||
)
|
||||
self.assertEqual(user_id, self.user.id)
|
||||
|
||||
def test_config_simple(self):
|
||||
"""Configure a simple calendar"""
|
||||
with Form(self.calendar) as calendar_form:
|
||||
calendar_form.mode = "simple"
|
||||
calendar_form.model_id = self.env.ref("base.model_res_partner")
|
||||
self.assertFalse(calendar_form.expression_dtstart)
|
||||
self.assertFalse(calendar_form.preview)
|
||||
|
||||
calendar_form.expression_dtstart = "record.create_date"
|
||||
calendar_form.expression_dtend = "record.write_date"
|
||||
self.assertTrue(calendar_form.preview)
|
||||
self.assertTrue(vobject.readOne(calendar_form.preview))
|
||||
|
||||
def test_config_advanced_event(self):
|
||||
with Form(self.calendar) as calendar_form:
|
||||
calendar_form.mode = "advanced"
|
||||
calendar_form.model_id = self.env.ref("base.model_res_partner")
|
||||
self.assertFalse(calendar_form.preview)
|
||||
|
||||
calendar_form.code = (
|
||||
"event = {"
|
||||
"'dtstart':record.create_date,"
|
||||
"'dtend':record.write_date,"
|
||||
"'summary':record.name,"
|
||||
"}"
|
||||
)
|
||||
self.assertTrue(calendar_form.preview)
|
||||
cal = vobject.readOne(calendar_form.preview)
|
||||
self.assertTrue(cal)
|
||||
self.assertTrue(
|
||||
any(item.name.lower() == "vevent" for item in cal.getChildren())
|
||||
)
|
||||
|
||||
def test_config_advanced_todo(self):
|
||||
with Form(self.calendar) as calendar_form:
|
||||
calendar_form.mode = "advanced"
|
||||
calendar_form.model_id = self.env.ref("base.model_res_partner")
|
||||
self.assertFalse(calendar_form.preview)
|
||||
calendar_form.code = (
|
||||
"todo = {'due':record.write_date,'summary':record.name}"
|
||||
)
|
||||
self.assertTrue(calendar_form.preview)
|
||||
cal = vobject.readOne(calendar_form.preview)
|
||||
self.assertTrue(cal)
|
||||
self.assertTrue(
|
||||
any(item.name.lower() == "vtodo" for item in cal.getChildren())
|
||||
)
|
||||
|
||||
def test_config_advanced_calendar(self):
|
||||
code = (
|
||||
"cal = vobject.iCalendar()\n"
|
||||
"dict2ical(cal.add('vevent'),{"
|
||||
"'summary':record.name,"
|
||||
"'dtstart':record.create_date,"
|
||||
"'dtend':record.write_date})\n"
|
||||
)
|
||||
with Form(self.calendar) as calendar_form:
|
||||
calendar_form.mode = "advanced"
|
||||
calendar_form.model_id = self.env.ref("base.model_res_partner")
|
||||
self.assertFalse(calendar_form.preview)
|
||||
calendar_form.code = (
|
||||
code + "calendar = {record.id:cal.serialize().encode()}"
|
||||
)
|
||||
self.assertTrue(calendar_form.preview)
|
||||
cal = vobject.readOne(calendar_form.preview)
|
||||
self.assertTrue(cal)
|
||||
|
||||
def test_auto_flag(self):
|
||||
"""Test the auto flag is honored"""
|
||||
self.assertFalse(self.calendar.allowed_users_ids)
|
||||
|
||||
self.calendar.auto = True
|
||||
self.assertTrue(self.calendar.allowed_users_ids)
|
||||
new_calendar = self.calendar.copy()
|
||||
self.assertIn(self.user, new_calendar.allowed_users_ids)
|
||||
|
||||
self.calendar.auto = False
|
||||
new_user = self.user.copy()
|
||||
self.assertNotIn(new_user, self.calendar.allowed_users_ids)
|
||||
|
||||
self.calendar.auto = True
|
||||
new_user = new_user.copy()
|
||||
self.assertIn(new_user, self.calendar.allowed_users_ids)
|
||||
148
base_ical/views/base_ical.xml
Normal file
148
base_ical/views/base_ical.xml
Normal file
@@ -0,0 +1,148 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2023 Hunki Enterprises BV
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
|
||||
<data>
|
||||
<record id="view_icalendar_url_show_form" model="ir.ui.view">
|
||||
<field name="name">iCalendar: Show Url</field>
|
||||
<field name="model">base.ical.url.show</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<p>
|
||||
Here is your new URL to the calendar.
|
||||
</p>
|
||||
<p><code><field name="url" readonly="True" /></code></p>
|
||||
<p class="alert alert-warning" role="alert">
|
||||
<strong>Important:</strong>
|
||||
The url cannot be retrieved later and provides.
|
||||
</p>
|
||||
<footer>
|
||||
<button special="cancel" data-hotkey="z" string="Done!" />
|
||||
</footer>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_icalendar_url_description_form" model="ir.ui.view">
|
||||
<field name="name">iCalendar: Show Url</field>
|
||||
<field name="model">base.ical.url.description</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="calendar_id" invisible="1" />
|
||||
<field name="name" />
|
||||
</group>
|
||||
<footer>
|
||||
<button
|
||||
name="make_url"
|
||||
type="object"
|
||||
string="Generate url"
|
||||
class="btn-primary"
|
||||
data-hotkey="q"
|
||||
/>
|
||||
<button
|
||||
special="cancel"
|
||||
data-hotkey="z"
|
||||
string="Cancel"
|
||||
class="btn-secondary"
|
||||
/>
|
||||
</footer>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_base_ical_form" model="ir.ui.view">
|
||||
<field name="model">base.ical</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<label class="oe_edit_only" for="name" />
|
||||
<h1><field name="name" /></h1>
|
||||
<group>
|
||||
<group name="main">
|
||||
<field name="mode" />
|
||||
<field name="model_id" />
|
||||
<field name="model" invisible="True" />
|
||||
<field
|
||||
name="domain"
|
||||
placeholder="[('user_id', '=', user.id)]"
|
||||
/>
|
||||
<field name="allowed_users_ids" widget="many2many_tags" />
|
||||
<field name="auto" />
|
||||
</group>
|
||||
<group
|
||||
name="fields"
|
||||
string="Simple Configuration"
|
||||
attrs="{'invisible': [('mode', '!=', 'simple')]}"
|
||||
>
|
||||
|
||||
<field
|
||||
name="expression_dtstamp"
|
||||
attrs="{'required': [('mode', '=', 'simple')]}"
|
||||
/>
|
||||
<field
|
||||
name="expression_uid"
|
||||
attrs="{'required': [('mode', '=', 'simple')]}"
|
||||
/>
|
||||
<field
|
||||
name="expression_dtstart"
|
||||
attrs="{'required': [('mode', '=', 'simple')]}"
|
||||
/>
|
||||
<field
|
||||
name="expression_dtend"
|
||||
attrs="{'required': [('mode', '=', 'simple')]}"
|
||||
/>
|
||||
<field
|
||||
name="expression_summary"
|
||||
attrs="{'required': [('mode', '=', 'simple')]}"
|
||||
/>
|
||||
</group>
|
||||
<group
|
||||
name="advanced"
|
||||
string="Advanced Configuration"
|
||||
attrs="{'invisible': [('mode', '!=', 'advanced')]}"
|
||||
>
|
||||
<field
|
||||
name="code"
|
||||
nolabel="1"
|
||||
widget="ace"
|
||||
options="{'mode': 'python'}"
|
||||
/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Help">
|
||||
<field name="help_text" />
|
||||
</page>
|
||||
<page string="Preview" groups="base.group_no_one">
|
||||
<field name="preview" widget="ace" />
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_base_ical_tree" model="ir.ui.view">
|
||||
<field name="model">base.ical</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="name" />
|
||||
<field name="model_id" />
|
||||
<field name="domain" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_base_ical" model="ir.actions.act_window">
|
||||
<field name="name">iCalendars</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">base.ical</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_ical" parent="base.menu_custom" action="action_base_ical" />
|
||||
</data>
|
||||
43
base_ical/views/res_users.xml
Normal file
43
base_ical/views/res_users.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2023 Hunki Enterprises BV
|
||||
Copyright 2024 initOS GmbH
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
|
||||
<data>
|
||||
<record id="view_res_users_form" model="ir.ui.view">
|
||||
<field name="model">res.users</field>
|
||||
<field name="inherit_id" ref="base.view_users_form_simple_modif" />
|
||||
<field name="arch" type="xml">
|
||||
<notebook position="inside">
|
||||
<page name="base_ical" string="Calendars">
|
||||
<label for="ical_ids" string="Calendars" />
|
||||
<field name="ical_ids">
|
||||
<tree>
|
||||
<button
|
||||
type="object"
|
||||
name="action_new_url"
|
||||
string="New URL"
|
||||
/>
|
||||
<field name="name" />
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
<!-- TODO: Re-evaluate after migration to 16.0 -->
|
||||
<label for="api_key_ids" string="Existing Access" />
|
||||
<field
|
||||
name="api_key_ids"
|
||||
domain="[('scope', '=like', 'odoo.plugin.ical.%')]"
|
||||
nolabel="1"
|
||||
readonly="1"
|
||||
>
|
||||
<tree create="false">
|
||||
<field name="name" />
|
||||
<field name="scope" />
|
||||
<field name="create_date" />
|
||||
<button type="object" name="remove" icon="fa-trash" />
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
@@ -4,3 +4,4 @@ mysqlclient
|
||||
pymssql<=2.2.5
|
||||
sqlalchemy
|
||||
sqlalchemy-hana
|
||||
vobject
|
||||
|
||||
1
setup/base_ical/odoo/addons/base_ical
Symbolic link
1
setup/base_ical/odoo/addons/base_ical
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../base_ical
|
||||
6
setup/base_ical/setup.py
Normal file
6
setup/base_ical/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
Reference in New Issue
Block a user