summaryrefslogtreecommitdiff
path: root/doc/reference/javascript_reference.rst
diff options
context:
space:
mode:
authorOdoo's Mergebot <xmo+roboto@odoo.com>2020-04-09 11:45:55 +0200
committerGitHub <noreply@github.com>2020-04-09 11:45:55 +0200
commitc608ae527a834615ba4b2d81c7b29a9409da2baf (patch)
tree4b15cf163db35606347ab44da88240cdb7a76146 /doc/reference/javascript_reference.rst
parentf5e2c3cff861d859d4b8058f205f670cb4dc04c7 (diff)
parent39aef65f37a8ae969527b31a680eb27fddbc5710 (diff)
[MERGE] calendar, google_calendar: Refactoring
1/ Recurring Events ============== TL;DR A bit of magic and ... Pouf ... all virtual events are now real records. ## Purpose The current implementation of recurring events uses "virtual events" to represents all events in the recurrence. Only one event is stored in the database. All other events are dynamically built and sent to the web client which sees them as real records. This implementation is old, difficult to read (6 years of changes and bug fixes) and has become more and more difficult to maintain. A fresh start would be welcome. ## Specification When creating a recurring event, a `calendar.recurrence.rule` record should be created. This model holds the rrule configuration and is responsible to manage events that result from the rrule. When a new recurrence is created, all resulting events are also created (stored in the database). No more virtual events. To avoid an explosion of events, a maximum of 720 events is created. With 720 events, a daily recurrence lasts for 2 years and a weekly recurrence lasts for 15 years. This strategy is used by Google Calendar and seems acceptable in most cases. A cron job could eventually be introduced to generated more events as the end comes. This allows to introduce an new rrule end type: 'Forever'. This is actually a shortcut to create a recurrence running for 720 events. Inspired by Google Calendar, new possibilities are introduced when modifying a recurring event (e.g. change the name, add an attendee): - Modify only this particular event (the event is still part of the recurrence) - Modify this and following events (events are still in the same recurrence) - Modify all events In a similar way, when updating the rrule of an event (e.g. from every Monday to every Tuesday), the user can choose to: - Modify this and following events: the recurrence is split. The first part remains unchanged but now ends when the second recurrence begins. The second parts is the updated rrule. - Modify only this particular event. - Modify all events: Forbidden (same as Google Calendar) Note: when events are "moved" because the rrule changed, the events are not actually moved. They are unlinked and new events are created (See "Some design choices explained" section). ## Some design choices explained ### Where to store the rrule? Two options were considered. 1) Store the rrule on an event, each event of the recurrence having a Many2one to the parent_id, aka the Master Event of the recurrence. 2) Store the rrule on another model: `calendar.recurrence.rule`. Each event in the recurrence having a Many2one to the recurrence record. Both options have pros & cons. But there is no clear winner. However the actual business logic of handling the recurrence creation/update would be the same. Where the rrule configuration is stored is the only main difference between both options. And this is probably the easiest part of implementing recurring events. With that in mind, option 2) is chosen. It allows to clearly separate recurrence logic from the events themselves. It is also the "correct" way of modeling data to avoid many empty columns for most records. ### Reusing events on rrule update When an rrule is modified, events should also be updated. In most cases, current events are unlinked and new events are created from scratch. Only events exactly at the same time before and after the rrule update are kept. Trying to reuse other events would require an obscure and arbitrary heuristic. (Imagine an rrule every Monday that is changed to every Tuesday and every Friday. What would you do?). This implies that any change to a specific event (name change, attendee added, chatter messages) is lost. This tradeoff seems acceptable as updating an rrule should not be that frequent. Moreover, Google Calendar also works that way so why not Odoo? ### Reusing events on events shifts On the calendar view, drag and drop an event to shift the entire recurrence. One way to handle the recurrence shift is to apply the same timedelta to all events. Now events are correctly positioned... except for events that were specifically moved. Those outliers needs special handling. This also introduces some behavior inconsistencies: when an rrule is directly modified, events are not reused, but when the rrule is modified by drag & dropping an event, events are reused. This option needs more code to handle the shift and the behaviors are not consistent. The chosen option is to find the rrule configuration from the dragged event (this is easy) and update the recurrence with those new rrule values. This brings us back to an rrule update (see above): code reusability yeah; one behavior to rule them all yeah. One downside is that outliers are lost (but Google Calendar also works that way). 2/ Synchronization with Google Calendar ============== This commit refactors calendar synchronization between Odoo and Google after the main calendar application refactoring. This refactoring takes advantage of two new features from the Google API: - New way of synchronizing resources efficiently[1] Incremental sync is performed repeatedly and updates Odoo with all the changes that happened ever since the previous sync. Each time, Odoo provides the previous sync token it obtained from Google and stores the new sync token from the response. - Event metadata[2] Ability to set hidden key-value pairs with an event, called extended properties. These extended properties are used to store the related odoo event id and the Odoo owner id (see known limitations) ### Known limitations - Let A and B be two new users (no tokens available). A creates an event in Odoo and invites B. A is the owner of the event (user_id). Now B authenticates to his Google Calendar account and synchronizes his calendar. We cannot send the event to A's calendar since we don't have any access to his Google Calendar. Hence the event his sent to B's calendar. This leads to data de-synchronisation: The owner is A in Odoo but B in Google. The "real" owner (user A) is stored in the Google event's metadata to be able to reconcile the owner for following synchronizations. - Let A and B be two users of Odoo and Google Calendar. And let the Google Calendar of B be private (e.g. if A creates an event in Google Calendar and invites B, B won't see the event in his calendar). If A creates an event in Odoo and invites B. The event is synced to Google Calendar of A. Now B can see the event in Odoo but he can't see it in his Google Calendar. Task 2126717 PR #42031 PR Enterprise https://github.com/odoo/enterprise/pull/8006 [1] https://developers.google.com/calendar/v3/sync [2] https://developers.google.com/calendar/extended-properties -- I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'doc/reference/javascript_reference.rst')
0 files changed, 0 insertions, 0 deletions