Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX][15.0] base_ical: User creation and repetition rules #322

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions base_ical/models/base_ical.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
)
preview = fields.Text(compute="_compute_preview")
code = fields.Text()
remove_repetition_rule = fields.Boolean(
help="Automatically remove the repetition rules. Useful if the repetition "
"already created multiple records"
)
expression_dtstamp = fields.Char(
vevent_field="dtstamp",
string="DTSTAMP",
Expand Down Expand Up @@ -89,6 +93,7 @@
"expression_summary",
"code",
"mode",
"remove_repetition_rule",
)
def _compute_preview(self):
for this in self:
Expand Down Expand Up @@ -194,6 +199,9 @@

def _get_ical(self, records=None, limit=None):
"""Return the vcalendar as text"""
if not self.model_id:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could mark this branch as # pragma: nocover

return ""

Check warning on line 203 in base_ical/models/base_ical.py

View check run for this annotation

Codecov / codecov/patch

base_ical/models/base_ical.py#L203

Added line #L203 was not covered by tests

if self.mode == "simple":
return self._get_ical_simple(records=records, limit=limit)

Expand Down Expand Up @@ -239,6 +247,8 @@
}
)

to_remove = ["rrule"] if self.remove_repetition_rule else []

calendar = vobject.iCalendar()
tz = pytz.timezone(self.env.user.tz or "UTC")
calendar.add(vobject.icalendar.TimezoneComponent(tz))
Expand All @@ -260,7 +270,7 @@
if isinstance(cal, str):
cal = vobject.readOne(cal)

self._copy_ical_calendar(calendar, cal)
self._copy_ical_calendar(calendar, cal, to_remove=to_remove)

event, todo = map(context.get, ("event", "todo"))
if event:
Expand All @@ -275,9 +285,16 @@
for key, value in data.items():
component.add(key).value = self._format_ical_value(value)

def _copy_ical_calendar(self, dst_calendar, src_calendar):
def _copy_ical_calendar(self, dst_calendar, src_calendar, *, to_remove=None):
"""Copy all events and todos from an calendar. Optionally remove children
of the items (like rrule)"""
for item in src_calendar.getChildren():
if item.name.lower() in ("vevent", "vtodo"):
if to_remove:
for attr in list(item.getChildren()):
if attr.name.lower() in to_remove:
item.remove(attr)

Check warning on line 296 in base_ical/models/base_ical.py

View check run for this annotation

Codecov / codecov/patch

base_ical/models/base_ical.py#L296

Added line #L296 was not covered by tests

dst_calendar.add(item)

def _format_ical_value(self, value, field=None):
Expand Down
2 changes: 1 addition & 1 deletion base_ical/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ def SELF_READABLE_FIELDS(self):
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)]})
calendars.sudo().write({"allowed_users_ids": [(4, r.id) for r in result]})
return result
2 changes: 2 additions & 0 deletions base_ical/views/base_ical.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@
string="Advanced Configuration"
attrs="{'invisible': [('mode', '!=', 'advanced')]}"
>
<field name="remove_repetition_rule" />
<field
name="code"
nolabel="1"
colspan="2"
widget="ace"
options="{'mode': 'python'}"
/>
Expand Down
Loading