Commit Graph
153 Commits
Author SHA1 Message Date
Gabriel de Paula Felix (gdpf) a0d4c62108 [FIX] google_calendar: do not spam while updating recurrent events
Before this task, lots of mails were sent after updating or deleting recurrent event in 'All events' or 'This and future events' update type. This was happening because updating these recurrent events was triggering patch calls event by event, when they should be handled in batch.

After this commit, updating or deleting recurrent events should trigger at most two mails for Google users.

closes odoo/odoo#137607

Task-id: 3163695
X-original-commit: ad2106babda61446bce13283d570dc723418b630
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
Signed-off-by: Gabriel de Paula Felix (gdpf) <gdpf@odoo.com>
2023-10-05 15:36:25 +00:00
amdi-odoo c2f337779b [IMP] google_calendar: add google sync helper
Add a helper method to know when the user calendar
is fully synced to Google Calendar, meaning when
API calls can correctly be performed.
The user calendar is considered fully synced if the
Google API is correctly configured in the settings
(Client ID / Secret) and the user has synced its
calendar with its Google Account.

Task-3285601

Part-of: odoo/odoo#133921
2023-09-22 11:55:51 +00:00
amdi-odoo ec073feeb4 [IMP] google_calendar: add google meet videocall url
Add a 'google_meet' value for the event videocall location
to make the difference between a custom videocall link and
a google meet one.

Task-3285601

Part-of: odoo/odoo#133921
2023-09-22 11:55:51 +00:00
amdi-odoo a3eed99161 [IMP] google_calendar: add single event synchronization
Purpose
=======
Add the possibility to only synchronize one specific event of
a user calendar instead of syncing the whole calendar.

Specification
=============
In certain cases, we do not want to synchronize the whole user
calendar with all the events and recurrences but only a specific
event. For example, in appointment, to retrieve the generated
google meet url of a specified event.

To perform the single event synchronization a synchronization
token is needed, meaning we cannot do a single event
synchronization prior to a full calendar synchronization as it
is the full sync which generates the temporary sync token.

To prevent the need of doing a full sync before a single event sync,
the permanent synchronization token is been used instead of
the temporary one when performing a single event synchronization.

Task-3285601

Part-of: odoo/odoo#133921
2023-09-22 11:55:51 +00:00
Gabriel de Paula Felix (gdpf) a14bc16647 [FIX] microsoft_calendar: traceback trying to delete recurrence
Before this commit, trying to delete a recurrent event that was already synced with Google Calendar or Microsoft Calendar was raising a traceback and not showing the User Error which forbids this action to be done.

After this commit, the traceback is not shown anymore and the User Error is correctly presented to the user while trying to delete a recurrent event (with Microsoft synchronization active).

Traceback snippet:

result = _call_kw_multi(method, model, args, kwargs)
File '/data/build/odoo/odoo/api.py', line 448, in _call_kw_multi
  result = method(recs, *args, **kwargs)
File '/data/build/odoo/addons/microsoft_calendar/models/calendar.py', line 168, in action_mass_archive
  if self._check_microsoft_sync_status() and any(self.microsoft_id):
TypeError: 'bool' object is not iterable

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error

closes odoo/odoo#134293

Issue: 3468190
Task-id: 3473180
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
Signed-off-by: Gabriel de Paula Felix (gdpf) <gdpf@odoo.com>
2023-09-06 05:53:42 +00:00
Gabriel de Paula Felix (gdpf) 9ae8f7dda3 [IMP] google_calendar: add synchronization pause button and tests
Configuration and tests added for 'pause synchronization' button (Google module).

Task-id: 3290898
Part-of: odoo/odoo#126560
2023-08-21 12:38:43 +02:00
Pedram (PEBR) ff3c554088 [FIX] google_calendar: ensure syncronization with cancelled event
This commit addresses a synchronization issue with Google Calendar,
which arose after the implementation of commit https://github.com/odoo/odoo/pull/94018/commits/d9c4043557c6460b3860216bdfd39a623a5e0795.
The mentioned commit added tracking to the pre-commit process,
inadvertently causing problems during Google Calendar synchronization.

During the synchronization of Google Calendar, a recurring event that
had one of its occurrences deleted resulted in Google sending both a
recurring event record and a cancelled single event. In Odoo's
synchronization process, it first created occurrences for the recurrent
event and then synced the single events. During this synchronization of
single events, the existing cancelled events were unlinked using the
`_cancel` function to remove the event.

The issue surfaced when the `_message_track_post_template` function was
called in the pre-commit phase. If the appointment function was
installed, the `_track_template` was overridden in this module, leading
to an attempt to access the removed event, which raised an error and
prevented calendar synchronization.

With this modification, the `_track_template` will not be called for
the created event that was cancelled in the same transaction.

opw-3418758

closes odoo/odoo#132174

X-original-commit: c1a455f6a46a8c936176e306f35651d60e39f869
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
2023-08-17 16:37:14 +02:00
Gabriel de Paula Felix (gdpf) 26f2e3b8e2 [FIX] google_calendar: events guest modification permission
Before this commit, the permission defined in Google Calendar of editing events by guests was always set in Odoo Calendar as 'True', even though there was also the 'False' option. This way, creating an event that didn't accept being edited by guests in Google and then updating it in Odoo by a guest was creating duplicates in Odoo Calendar and wrong lists of attendees.

After this commit, the permission of guests modifying the event is taken into account in Odoo Calendar. If a guest updates an event that doesn't allow updates, a warning is shown forbidding the update and the reason explained.

closes odoo/odoo#127397

Task-id: 3276829
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
2023-08-11 13:06:58 +02:00
Thibault Delavallée 700a84edc9 [FIX] google_calendar: avoid browse(False) instead of void records
If no partner is found for a given email after calling '_mail_search_on_user'
and '_mail_find_partner_from_emails' the returned result is a void recordset
for the email.

When rebrowsing partners afterwards, browsing p.id for each partner leads
to potentially browsing False, which gives a different recordset from a
void recordset. This further causes a crash in '_write_from_google' as
he considers [False] as not being void.

This commit fixes that by correctly filtering out void partners. This is
globally a followup of odoo/odoo#99330.

Task-3453577 (TestMail: Update Alias/Gateway tests for MC)
Prepares Task-36879 (Mail: Support MultiCompany Aliases)

Part-of: odoo/odoo#130768
2023-08-03 21:56:56 +02:00
Xavier-Do 595aa24843 [IMP] registry: multiple ormcache
One of the main issue with ormcache is that the invalidation clears
everything, meaning that some value, slow to compute but with a long
lifetime, can be removed from the cache because an easy to invalidate
value is cleared, like after writting or creating a product has an
example.

Most example in the code will try to invalidate the cache of the models
doing something like `env['ir.qweb'].clear_caches()` but it is
finally equivalent to `env.registry.clear_cache()`, and cross worker.

The idea is to have multiple cache, maybe with specific sizes for a
specific purpose.

Having one per model is maybe a bad idea because it will be difficult
to size the LRU correcly, and it is too dynamic. Checking invalidation
may be expensive.

The proposed solution is closed allow a limited number of named caches,
using onse sequence per cache. This is actually close to the
cache_longterm.

We want to discourage using a specific cache for one use case in
the buisness code. Adding a cache shouldn't be something easy, doable
in stable.

Note that we could also change the invalisation mecanism using an
insert only table. We an check the sequence of this table, but also
fetch all invalidation messages.
Another possible improvement, especially if we have more than x cache is
to have a global sequence, checking signaling would mean to check the
main sequence, and only the other ones if the main one changed.

Note that this poc is inspired from the long term cache but not all
use case where applie yet.

Part-of: odoo/odoo#119813
2023-07-18 11:42:26 +02:00
Yannick Tivisse b1f7e56f79 [IMP] base: Remove private res.partner type
- Improve performances, as the ir.rule restricting private partners
  visibility is also applied on res.users by inheritance, on each
  prefetch.
- Solve the issue of partners set as followers on records (eg: application
  form) and then made private, making them impossible to contact via the
  chatter.
- Solve the multiple access issues when trying to access the bank
  account, or the private address for non HR people like the accountants
  forcing the usage of sudo in the business code.

TaskID: 3101400
2023-07-05 14:21:28 +02:00
Thomas Lefebvre (thle) 61ba5037dc [FIX] google_calendar: edit schedule of recurring event
Steps to reproduce:
-------------------
We google calendar, create a recurring event with
three occurrences.
We obtain 3 events in chronological order:
- A
- B
- C
Change the title of the event B and apply the changes
to the following events.
We get:
- A: First title
- B: Second title
- C: Second title
Modify the schedule of event C and apply the changes
only to this event.
We get:
- A: First title + First schedule
- B: Second title + First schedule
- C: Second title + Second schedule
Synchronize Google calendar with Odoo.

Issue:
------
Event C is "duplicated".
Event C will exist with the first schedule
and the second schedule.

Cause:
------
A recurrent event with `google_id` is equal to
`ID_RANGE_TIMESTAMP` can be rescheduled.
If this is the case, its `google_id`
will be equal to `ID_TIMESTAMP`.

We do not manage the deletion of the event
that belongs to the old `google id`.

Solution:
---------
When we detect a recurring event with
a modified schedule, we have to delete the event
from the old `google_id`
(which is the event with the old schedule).

For this, it is necessary to find
the old `google_id` based on the elements contained
in the `id` and the `recurringEventId` of the event.

opw-3143680

closes odoo/odoo#121825

X-original-commit: 3f145af00307383e2d0a0891d05b8db59b13662a
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
Signed-off-by: Lefebvre Thomas (thle) <thle@odoo.com>
2023-05-22 13:53:56 +02:00
pedrambiria fc002590db [FIX] google_calendar: use the event user token to send the request
Before this commit: it was possible to create an event for another user as
its organizer. But even if that user has a synchronized Google calendar, it
will be sent by the current user token, and it causes several issues.

The solution is to use the event's organizer token if it exists.

opw-3076595

closes odoo/odoo#120368

X-original-commit: 966943168dc9da0622485a46b0786ed5765eaf77
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
2023-05-22 11:42:55 +02:00
Nasreddin Boulif (bon) df187c4cc2 [FIX] google_calendar: sync the right description
Steps to reproduce:

  - Install 'CRM' module (for test purpose)
  - Configure the google calendar credentials on Odoo
  - Go to CRM -> Configuration -> Activity Types and create a new one
  - Set 'Meeting' as Action
  - As default note, add some bullet points:
    ```
    Hello :
      - First point
      - Second point
      - Third point
    ```
  - Open any Opportunity and create a new Activity (in the chatter)
  - Select 'Meeting' as activity type and open the calendar
  - Add a new event (description should be field with the default note)
  - Open the event (on Odoo and/or Google Calendar)

Issue:

  The description of the event is broken (bullet points missing).

Cause:

  When syncing the event from Odoo to Google Calendar, the description
  is converted to plain text (using `html2plaintext` function).
  Then, when syncing the event from Google Calendar to Odoo,
  the description is also updated locally with the remote one.

Solution:

  Don't convert the description to plain text but use
  `tools.html_sanitize` on the html content instead to sanitize it.

opw-3105194

closes odoo/odoo#119695

X-original-commit: 21f3f9aa31a44840077b80d27aaee8160b391308
Signed-off-by: Nasreddin Boulif (bon) <bon@odoo.com>
2023-04-28 11:18:26 +02:00
Achraf 20e4bd9bb3 [FIX] google_calendar: Change logger type from error to exception
In sentry we receive like 2k syncing issue from google_calendar.

This commit converts `_logger.error` to `_logger.warning` because we don't
need an erro for that

sentry-4121123364
https://online.sentry.io/issues/4121123364

closes odoo/odoo#119742

X-original-commit: e797712561113f098edc1346995cecd7e96ad362
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Achraf <abz@odoo.com>
2023-04-26 17:06:28 +02:00
Martin Trigaux 69f911d994 [IMP] *: enforce usage of Markup in mail
When using message_post, the body format must be explicitly specified.
If html is expected, a Markup object should be used.
If text is given, the content will be escaped.

Before this PR:
message_post was unaware if the content of a message was HTML or
text. This lead to multiple situation where the content was
incorrectly considered as HTML and led to display errors.
In
  self.message_post(body="Hello %s!" % self.name)
if the name contained HTML, it would be evaluated.

In
  self.message_post(body="Contact Raoul <raoul@caramail.be>")
the email would not be displayed as considered as unknown HTML and
discarded by the sanitizer

Now each call must explict the type of content.
Use the escape() helper to properly combine Markup and translations.
It would also be acceptable to use Markup() to wrap a static
translation but escape is better as one can not guarantee the content
of a translation.

closes odoo/odoo#111850

Related: odoo/documentation#3612
Related: odoo/enterprise#36728
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-04-13 16:39:48 +02:00
Arnaud Joset abdf22c9dc [FIX] google_calendar: keep partner order according to email order
Before this commit, when an event was synced with internal and external users,
the corresponding partners were merged like this:
1) partner corresponding to internal users
2) regular partner

If the list of emails provided by google was in another order: regular partners
then internal, there were an issue:

```
emails = [a.get('email') for a in google_attendees] # sorted by google, external then internal for example
partners = self._get_sync_partner(emails) # always internal then external partners
for attendee in zip(emails, partners, google_attendees):
    # we are associating the external email with internal partner
    # the external attendee is skipped because we take the user partner
```

This commit makes sure to return the partner is the order of the mails in _get_sync_partner.

closes odoo/odoo#118355

X-original-commit: ae442c20878277da93feb8761f5ed556c0c735b2
Signed-off-by: Kevin Baptiste <kba@odoo.com>
Signed-off-by: Arnaud Joset <arj@odoo.com>
2023-04-13 05:07:41 +02:00
Louis Wicket (wil) 9afe7c74c9 [IMP] *: remove "French spacing" 👺
According to Wiktionary, French spacing is "the archaic practice (though
still current in French) of inserting a space around colons, semicolons,
question marks, and exclamation marks". This is not standard practice in
English and most languages of the world.

The purpose of this commit is to start purging the code from this typo,
as it may reflect poorly on the software for some people.

closes odoo/odoo#114533

Related: odoo/enterprise#37853
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2023-03-14 15:52:10 +01:00
Pierre Masereel 0b7d9d5263 [FIX] google_calendar: do not always generate meet link
Since we create a google meet link when we create an event, we get an
issue with the appoitments that generate their own videocall links. That
lead to send a Odoo discuss link to the customer, and then set the
google meet link in the sales person calendar.

As the insert of google event is done post commit of the transaction,
and there is no way to generate a google meet link before the creation
of an event, there is no trivial fix to generate the google mette link
at the right moment. We just don't generate the google link when a Odoo
discuss link is already there.

closes odoo/odoo#113192

X-original-commit: 1a1a8e48995cfe37a0c8536bbcfc3341d76499ef
Signed-off-by: Masereel Pierre <pim@odoo.com>
2023-02-20 23:21:49 +01:00
pedrambiria 31f91e6a58 [FIX] google_calendar: avoiding return of recordset when using ormcache
Before this commit: In some cases where some events won't sync to
Odoo properly you got the "Unable to use a closed cursor." error. The
problem is that `_from_google_ids` function returns a recordset, and the
underlying cursor may be closed.

Steps to reproduce the issue:
 1. Create user_A and user_B in Odoo
 2. Sync user_A and user_B with Google calendar
 3. Create an event with user_B on the Google calendar
 4. Run the "Google Calendar: synchronization" cron
 5. Change the created event's owner to user_A on the Google calendar
 6. Run the "Google Calendar: synchronization" cron
=> You will get this error on the log, and the event won't sync:

```
Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/api.py", line 886, in get
    return field_cache[record._ids[0]]
KeyError: 99

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/fields.py", line 1061, in __get__
    value = env.cache.get(record, self)
  File "/home/odoo/src/odoo/odoo/api.py", line 889, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'calendar.event(99,).google_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/odoo/src/odoo/addons/google_calendar/models/res_users.py", line 91, in _sync_all_google_calendar
    user.with_user(user).sudo()._sync_google_calendar(google)
  File "/home/odoo/src/odoo/addons/google_calendar/models/res_users.py", line 70, in _sync_google_calendar
    synced_events = self.env['calendar.event']._sync_google2odoo(events - recurrences, default_reminders=default_reminders)
  File "/home/odoo/src/odoo/addons/google_calendar/models/google_sync.py", line 147, in _sync_google2odoo
    existing = google_events.exists(self.env)
  File "/home/odoo/src/odoo/addons/google_calendar/utils/google_event.py", line 180, in exists
    events.odoo_ids(env)
  File "/home/odoo/src/odoo/addons/google_calendar/utils/google_event.py", line 88, in odoo_ids
    found = self._load_odoo_ids_from_db(env, model)
  File "/home/odoo/src/odoo/addons/google_calendar/utils/google_event.py", line 111, in _load_odoo_ids_from_db
    mapping = {e.google_id: e.id for e in odoo_events}  # {google_id: odoo_id}
  File "/home/odoo/src/odoo/addons/google_calendar/utils/google_event.py", line 111, in <dictcomp>
    mapping = {e.google_id: e.id for e in odoo_events}  # {google_id: odoo_id}
  File "/home/odoo/src/odoo/odoo/fields.py", line 1087, in __get__
    recs._fetch_field(self)
  File "/home/odoo/src/odoo/odoo/models.py", line 3276, in _fetch_field
    self._read(fnames)
  File "/home/odoo/src/odoo/addons/calendar/models/calendar_event.py", line 436, in _read
    super()._read(fields)
  File "/home/odoo/src/odoo/odoo/models.py", line 3343, in _read
    cr.execute(query_str, params + [sub_ids])
  File "<decorator-gen-20>", line 2, in execute
  File "/home/odoo/src/odoo/odoo/sql_db.py", line 89, in check
    raise psycopg2.OperationalError('Unable to use a closed cursor.')
```

The solution is to use ormcache on a function that returns the ids of the
events.

opw-3098799

closes odoo/odoo#112517

X-original-commit: 831e2e916541a95a1b932d9f58b3592ecee0c685
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
2023-02-13 14:05:26 +01:00
Gabriel de Paula Felix (gdpf) 94e7d25273 [IMP] google calendar: auto accept meeting when only creator is attendee
Before this commit, when an event containing only the creator was created in Google Calendar, the creator's attendee status in Odoo was marked as 'needsAction'. Now, when an event like this is created (in Google Calendar), the event is automatically accepted in Odoo.

A test was added to make sure that new events with only the creator are automatically accepted.

closes odoo/odoo#112195

Task: 2782961
Related-to: #68700
X-original-commit: 6d0ead3d73477614dc1bd97a95b695f80925fdd3
Signed-off-by: Arnaud Joset <arj@odoo.com>
2023-02-08 16:49:51 +01:00
Pierre Masereel 42afdd13df [IMP] google_calendar: generate meeting link when creating event
When we are creating an event in odoo and synchronise it with google,
the google meet link is not automatically generated. To ease the use of
the meeting, we'll auto generate the google meet link.

closes odoo/odoo#110847

Task-id: 2945998
Signed-off-by: Masereel Pierre <pim@odoo.com>
2023-01-31 16:24:45 +01:00
pedrambiria fe9e93d9e6 [FIX] google_calendar: not sending emails to existing event attendees
Before this commit: syncing with google led to sending emails to
attendees of existing future events on Odoo.

Steps to reproduce the first issue:

Install 'google_calendar' module
Integrate with Google Calendar in setting
Add an event to the Odoo calendar for future date
Add one external attendee to the event
Sync with Google
Invitation emails would be sent to the attendees of the events.
Solution

It's possible to not send emails to the attendees in api calls. So
the solution is to not send emails to the attendees for the syncing
time.
opw-2819046

closes odoo/odoo#102870

X-original-commit: 5a56e37a5f54662b1f3593930738e51c010abab7
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
2022-10-10 16:10:52 +02:00
pedrambiria c6f690f0f9 [FIX] google_calendar: sync events without an attendee's state
Before this commit: if an event's attendee didn't have a state, it couldn't
get synced with Google.

The solution is first to set a default value for it.

opw-2915661

closes odoo/odoo#102865

X-original-commit: 89b53744c668183913b8a188730bd350fe778807
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
2022-10-10 15:09:44 +02:00
pedrambiria 2adf005a8b [FIX] google_calenar: remove attendees with alias emails
Before this commit: if one recurrence event in the google calendar
contains an attendee with one of the alias emails, it wouldn't get synced
and raise an error.

The solution is to remove those attendees.

opw-2963825

closes odoo/odoo#101037

X-original-commit: c9fa96604950f61c079627b88495130365d3b534
Signed-off-by: Arnaud Joset <arj@odoo.com>
2022-09-27 10:38:36 +02:00
Jeremy Kersten 75e1d93344 [IMP] google_calendar: rename google_cal[endar]_account_id
Rename from google_cal_account_id to google_calendar_account_id, to have
the complete 'service' name into the field and allow to use it from a
generic way in oauth2callback from google_account e.g.

task-2497212
pr-95744

closes odoo/odoo#95744

Related: odoo/upgrade#3673
Signed-off-by: Christophe Simonis <chs@odoo.com>
2022-08-10 14:43:02 +02:00
Jeremy Kersten 05b409f8f1 [REF] google_account, google_calendar: clean and make it overridable
This commit removes outdated method no more used since we delete oog
apps like gdrive.
This commit remove the logging of sensitive infos.
This commit allows to override easily api key.

task-2497212
pr-95744

Part-of: odoo/odoo#95744
2022-08-10 14:43:01 +02:00
pedrambiria 8b6341c1ff [REV] google_calendar: not sending emails to existing event attendees"
There was an issue with this fix.

This reverts commit 8ebb44420c3e2dcc0d990d2646486654b4b2955d.

closes odoo/odoo#96421

X-original-commit: 29f0c7635c900324631fe3562399c3ced5bc15f7
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2022-07-21 00:50:39 +02:00
pedrambiria fb36e02de5 [FIX] google_calendar: not sending emails to existing event attendees
Before this commit: syncing with google led to sending emails to
attendees of existing future events on Odoo.

Steps to reproduce the first issue:

	- Install 'google_calendar' module
	- Integrate with Google Calendar in setting
	- Add an event to the Odoo calendar for future date
	- Add one external attendee to the event
	- Sync with Google

	Invitation emails would be sent to the attendees of the events.

Solution

	It's possible to not send emails to the attendees in api calls. So
the solution is to not send emails to the attendees for the syncing
time.

opw-2819046

closes odoo/odoo#95781

X-original-commit: ac78ad6bf806ae3233ad38399771745edc8dc00d
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
2022-07-12 07:31:41 +02:00
Rémy Baranx (bar) ed02c32853 [FIX] google_calendar: allow user to reset his own tokens only
Each user should be able to reset his own google calendar token.
An admin user (from `base.group_system`) should be able to reset any tokens.

Task-2673934

closes odoo/odoo#83397

Signed-off-by: Arnaud Joset <arj@odoo.com>
2022-06-14 10:35:54 +02:00
Arnaud Joset fe2be46214 [FIX] google_calendar: remove dead code
The _sync_google_calendar method was copied in https://github.com/odoo/odoo/commit/24c2d7e9d609f02b1814be0faf82352bfeb45d96
in the google.calendar.credentials model from res.users but it was not useful
or used. This method makes more sense on res.users model.

closes odoo/odoo#92835

X-original-commit: f78431507ec9a5e2d9f1d2847d723e1f7bfeca11
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Signed-off-by: Arnaud Joset <arj@odoo.com>
2022-06-03 09:46:46 +02:00
pedrambiria 40d4679093 [FIX] google_calendar: allow to sync a private contact
Before this commit: if a user is the attendee of an event containing
a private contact, the user couldn't sync with google calendar. Because
of the "res.partner.rule.private.employee" record rule restriction.

Steps to reproduce the issue:
 1. Create users A and B
 2. Enable "Access to Private Addresses" for user A and disable it for B
 3. Login with user A
 4. Integrate with Google Calendar in setting
 5. Create a contact with private address (type = 'private')
 6. Sync with Google Calendar in the calendar module
 7. Create an event with user B and the private contact as attendees
 8. Reset account of google calendar from user A setting
 9. Login with user B
 10. Try to sync with Google Calendar

 => You will receive an access error

The solution is not to allow any user to add private contacts as an
attendee. Also, create a new contact with the same email if it wants to
match existing private contact with a google event attendee.

opw-2850552

closes odoo/odoo#92624

X-original-commit: 96ee1ef45954bd27632da9c2cef3cf9ba44caca0
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
2022-06-01 15:23:06 +02:00
thcl-odoo b6e08d662d [FIX] google_calendar: add show_as on sync
Current behavior :
When a Google Agenda event is created with "Show as" set to Available,
Show as (`show_as`) isn't set accordingly

Steps :
- Install Calendar
- setup and activate Google Calendar sync
- Create an event and set "Show as" on Available
- Refresh Odoo calendar to sync it
-> Created event "show as" is set to Busy

OPW-2805096

closes odoo/odoo#90261

X-original-commit: ff56f8126e105f2196843fed1646a3081f25aff3
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Claude Thibault (thcl) <thcl@odoo.com>
2022-05-04 10:55:47 +02:00
thcl-odoo a784ddab33 [FIX] google_calendar: add Meeting URL on sync
Current behavior :
When a Google Agenda event is created with a meeting, the Meeting URL
(`videocall_location`) isn't set at creation.

Steps :
- Install Calendar
- setup and activate Google Calendar sync
- Create an event with a meeting via Google Calendar
- Refresh Odoo calendar to sync it
-> Created event doesn't contains a Meeting URL

OPW-2805096

X-original-commit: f85dfa2b3cb1fa03dcaa10b93fc5309b3a04eae6
Part-of: odoo/odoo#90261
2022-05-04 10:55:46 +02:00
pedrambiria f43995eab8 [FIX] google_calendar: Prevent resyncing of synced recurrence events
Before this commit: When you sync the Odoo calendar with Google for the
first time, it will resync all of the created recurrence events with
Google after fetching all of the Google events. The problem is that it
chooses the 'accepted' state by default for the current user's state.
If you were invited to events and you hadn't accepted that, it would
update your status and send an email per event for all attendees.

Steps to reproduce the issue:
 1. Create two new google accounts ( you'll bombard with emails)
 2. Create a recurrent event without ending with the first account and
choose the second account as a guest.(don't accept)
 3. Sync second account with Odoo
  => It'll send about 700 emails

The solution is to prevent synced recurrence events from syncing and.

opw-2691146

closes odoo/odoo#89633

X-original-commit: 084aeb239e85a4e3abb3e233af68c6838dfbb3d7
Signed-off-by: Arnaud Joset <arj@odoo.com>
2022-04-26 14:28:49 +02:00
Abdelouahab (abla) 6246ec0f46 [FIX] google_calendar : fix default reminder
To reproduce
============

- Sync Google Calendar to Odoo
- Create an event in GCaledar without setting a notification
In Odoo Notification reminder is set

Purpose
=======

we use default reminder given by Google which is notification 30 minutes before even if the event
doesn't have a reminder.

Specification
=============

To solve the issue we use empty reminder instead of the default given by google if no reminder is set.

opw-2792364

closes odoo/odoo#87592

X-original-commit: a25d38dd252a657ea44c822a227e415337003672
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: abla001 <abla@odoo.com>
2022-03-30 17:35:26 +02:00
Arnaud Joset a67dc7e151 [FIX] google_calendar: chose internal users when portal and internal users share the same email
Before this commit, when two users shared the same mail, they were ordered by alphabetical order.
This commit makes sure that the internal user is preferred.

closes odoo/odoo#84805

X-original-commit: 992b7a00f8eb567aed730420d0d10fa476fb9dd7
Signed-off-by: Thibault Francois <tfr@odoo.com>
Signed-off-by: Arnaud Joset <arj@odoo.com>
2022-02-17 16:41:56 +00:00
Arnaud Joset 968cd5ff33 [FIX] google_calendar: increase debug when all events in a recurrence are deleted.
Before this commit, a lot of events and mail followers would be deleted and recreated.
This PR commit aims to identify the issue and fix it.

X-original-commit: d0adfb0b269d21a2284e9608c75bd6f1afffa9a8
Part-of: odoo/odoo#84805
2022-02-17 16:41:56 +00:00
Arnaud Joset c654700291 [FIX] google_calendar: allow deletion of attendee with the same email
Before this commit, when a recurrent event would have several partners with the same email, a traceback would occurs:

```py
~/src/odoo/15.0/addons/google_calendar/models/calendar_recurrence_rule.py in _write_from_google(self, gevent, vals)
    111             if email_normalize(odoo_attendee_email) not in emails:
    112                 attendee = existing_attendees.exists().filtered(lambda att: att.email == email_normalize(odoo_attendee_email))
--> 113                 self.calendar_event_ids.write({'need_sync': False, 'partner_ids': [(3, attendee.partner_id.id)]})
    114
    115         # Update the recurrence values

~/src/odoo/15.0/odoo/fields.py in get(self, record, owner)
   4062         elif size == 1:
   4063             return ids[0]
-> 4064         raise ValueError("Expected singleton: %s" % record)
   4065
   4066     def set(self, record, value):
```

closes odoo/odoo#83040

X-original-commit: 670961cd8140143c6e5a82b37dd6030758165485
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Signed-off-by: Arnaud Joset <arj@odoo.com>
2022-01-20 08:21:58 +00:00
Arnaud Joset cbff2f508f [FIX] google_calendar: avoid cachemiss error when record has been deleted between write and patch
In some cases, the module can patch an event but if it is deleted, some write will fails.

This fix prevent the following traceback:

```py
Traceback (most recent call last):
  File "/home/odoo/src/odoo/15.0/odoo/fields.py", line 1057, in __get__
    value = env.cache.get(record, self)
  File "/home/odoo/src/odoo/15.0/odoo/api.py", line 889, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'calendar.event(30350266,).attendee_ids'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/odoo/src/odoo/15.0/odoo/api.py", line 886, in get
    return field_cache[record._ids[0]]
KeyError: 30350266

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/odoo/src/odoo/15.0/odoo/fields.py", line 1057, in __get__
    value = env.cache.get(record, self)
  File "/home/odoo/src/odoo/15.0/odoo/api.py", line 889, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'calendar.event(30350266,).show_as'

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/odoo/src/odoo/15.0/addons/google_calendar/models/google_sync.py", line 43, in called_after
    func(self.with_env(env), *args, **kwargs)
  File "/home/odoo/src/odoo/15.0/addons/google_calendar/models/google_sync.py", line 234, in _google_patch
    self.need_sync = False
  File "/home/odoo/src/odoo/15.0/odoo/fields.py", line 1217, in __set__
    records.write({self.name: write_value})
  File "/home/odoo/src/odoo/15.0/addons/google_calendar/models/calendar.py", line 55, in write
    res = super(Meeting, self.with_context(dont_notify=notify_context)).write(values)
  File "/home/odoo/src/odoo/15.0/addons/calendar/models/calendar_event.py", line 491, in write
    previous_attendees = self.attendee_ids
  File "/home/odoo/src/odoo/15.0/odoo/fields.py", line 3389, in __get__
    return super().__get__(records, owner)
  File "/home/odoo/src/odoo/15.0/odoo/fields.py", line 2603, in __get__
    return super().__get__(records, owner)
  File "/home/odoo/src/odoo/15.0/odoo/fields.py", line 1083, in __get__
    recs._fetch_field(self)
  File "/home/odoo/src/odoo/15.0/odoo/models.py", line 3276, in _fetch_field
    self._read(fnames)
  File "/home/odoo/src/odoo/15.0/odoo/models.py", line 3346, in _read
    self.check_access_rule('read')
  File "/home/odoo/src/odoo/15.0/odoo/models.py", line 3553, in check_access_rule
    invalid = self - self._filter_access_rules_python(operation)
  File "/home/odoo/src/odoo/15.0/odoo/models.py", line 3608, in _filter_access_rules_python
    return self.sudo().filtered_domain(dom or [])
  File "/home/odoo/src/odoo/15.0/odoo/models.py", line 5511, in filtered_domain
    data = rec.mapped(key)
  File "/home/odoo/src/odoo/15.0/odoo/models.py", line 5436, in mapped
    recs = recs._fields[name].mapped(recs)
  File "/home/odoo/src/odoo/15.0/odoo/fields.py", line 1176, in mapped
    self.__get__(first(remaining), type(remaining))
  File "/home/odoo/src/odoo/15.0/odoo/fields.py", line 1087, in __get__
    raise MissingError("\n".join([
odoo.exceptions.MissingError: Record does not exist or has been deleted.
(Record: calendar.event(30350266,), User: XXX)
```

X-original-commit: 2f0c9ca75de616da61e327259d03a8831b8e159b
Part-of: odoo/odoo#83040
2022-01-20 08:21:58 +00:00
Arnaud Joset 58addb377e [FIX] google_calendar: improve error handling when the record does not exists anymore.
Before this commit, the following traceback could be encountered when events were deleted:

```py
Traceback (most recent call last):
  File "/home/odoo/src/odoo/15.0/addons/google_calendar/models/google_sync.py", line 43, in called_after
    func(self.with_env(env), *args, **kwargs)
  File "/home/odoo/src/odoo/15.0/addons/google_calendar/models/google_sync.py", line 233, in _google_patch
    self._google_error_handling(e)
  File "/home/odoo/src/odoo/15.0/addons/google_calendar/models/google_sync.py", line 177, in _google_error_handling
    start = self.start and self.start.strftime('%Y-%m-%d at %H:%M') or _("undefined time")
  File "/home/odoo/src/odoo/15.0/odoo/fields.py", line 1087, in __get__
    raise MissingError("\n".join([
odoo.exceptions.MissingError: Record does not exist or has been deleted.
(Record: calendar.event(28241777,), User: XXXX)
```

X-original-commit: e77cbc639032e7f58345942330102b37e7a55971
Part-of: odoo/odoo#83040
2022-01-20 08:21:58 +00:00
Arnaud Joset 8847d391e4 [FIX] google_calendar: fix attendee deletion
When an attendee is deleted in google, we need to sync the odoo attendees and delete the ones that do not exist anymore in google.
Unfortunately, by doing so, we introduced an issue. We filtered attendees that were no longer existing when we looped on the attendee emails.

```py
odoo.exceptions.MissingError: Record does not exist or has been deleted.
(Record: calendar.attendee(YYY,), User: XXX)
```

This commit ensure that we filter only existing attendees.

X-original-commit: 0fb1002c9bb027d1694b834c52e4492a03c8a09d
Part-of: odoo/odoo#83040
2022-01-20 08:21:58 +00:00
Yolann Sabauxandandro19951 e10ae3f024 [FIX] google_calendar, microsoft_calendar: ignore no partner created
Description of the issue/feature this PR addresses: in version 15,
sometimes Google and Microsoft calendar synchronizations break with error:

Create/update: a mandatory field is not set.
Delete: another model requires the record being deleted. If possible, archive it instead.
Model: Calendar Attendee Information (calendar.attendee), Field: Contact (partner_id)

This is happening, because when Odoo is syncing an event, it will match
attendee with res.partner, if no existing partner is found, a new one
will be created unless:

- the address matches an existing mail alias ([alias_name]@[mail.catchall.domain])
- the address is invalid (eg. in outlook the email address is sometimes
  in the form /o=ExchangeLabs/ou=.../cn=Recipients/cn=...

In this case we should not try to add the attendee to the odoo event.

Current behavior before PR: Error when syncing that the customer can
only solve by removing the erroneous attendee or remove the event from
their calendar.

Desired behavior after PR is merged: if the partner cannot be created
we ignore it.

opw-2670002
opw-2683889
opw-2702661
opw-2704631
opw-2711907
opw-2720032
opw-2722028
closes #82109
fixes #78678

closes odoo/odoo#82667

X-original-commit: 1cd470c8922119d0da0b69ab7d4b4ff746533689
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Signed-off-by: yosa-odoo <yosa@odoo.com>
Co-authored-by: andro19951 <andro19951@gmail.com>
2022-01-17 08:38:45 +00:00
alt-odoo fd96a99eef [FIX] google_calendar: don't delete several times the same attendee
Small side effect of commit https://github.com/odoo/odoo/commit/b19dc634684aab239575b9a9e784c7420d110b7d

When deleting old attendees, we are removing the partner id associated with the email
from the partner_ids set on the event.

As the same partner can be set on more than one event, we need to loop only once
on each attendee email, otherwise we will face the error "Record does not exist
or has been deleted."

Also, when deleting partner_ids on an event, the attendee is already automatically
removed as well in _attendees_values method, there is no need to do it manually, as
it will raise the error a second time.

opw-2694428
opw-2695915

closes odoo/odoo#80828

X-original-commit: 766a1ad50a9dbc85ed2f9083f881781b7d5ec96c
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Alex Thuyls (alt) <alt@odoo.com>
2021-12-03 11:18:53 +00:00
Kevin Baptiste b90ee11ef3 [FIX] hr_holidays, *_calendar: disable sync on new leave
On large databases, the `postcommit` hook for Google|Microsoft Calendar
was taking up to 10% of a leave validation even if the user has the sync
disabled.

This commit disables the postcommit hook for new leaves, as the event will
be synced through the cron eventually.

closes odoo/odoo#80160

Taskid: 2693265
X-original-commit: 88884292e105eab2c36b2a334c617ac4978fa79c
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Kevin Baptiste <kba@odoo.com>
2021-11-22 11:56:46 +00:00
Raphael ColletandXavier Dollé 1595c0ee27 [REF] core: replace thread-local "envs" by cursor-bound "transaction"
Refactor the Environments object into a Transaction object, which is
bound to one cursor, and is no longer shared among several cursors.

The following methods/properties have been changed:
 - Environment.envs no longer works (because of the design change);
 - Environment.manage() is deprecated (no longer useful);
 - Environment.reset() is now an instance method;
 - env.clear_upon_failure() is deprecated in favor of cr.savepoint().

closes odoo/odoo#75598

Related: odoo/enterprise#20451
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Co-authored-by: Xavier Dollé <xdo@odoo.com>
2021-09-03 15:45:46 +00:00
Arnaud Joset b19dc63468 [IMP] calendar,google_calendar,microsoft_calendar: allow to create events with non-default attendee state
Before this commit, it was not possible to create events with defined attendee state. The default value was always set.
This was a limitation when the events were part of a recurrence and all events attendee needed to be created with a known state.

To reproduce, one would create a recurrent event, sync it with Google and in Google, 'decline' this event and the following.
The attendee state was not properly set.

closes odoo/odoo#68700

Taskid: 2484335
Related: odoo/upgrade#2537
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2021-08-26 10:21:02 +00:00
Arnaud Joset 40fd44f618 [IMP] calendar,google_calendar,microsoft_calendar: Improve UI
Before this commit, the calendar UX was not good enough. The look and feel was not modern.
This commit improves a lot of small details, remove unneeded or not mature features (like the videocall location url).

Counted recurrence now brings a better experience. When weekly or montly recurrences are created, occurences in the past are dismissed but before this commit their number was not adapted.
User would end up with less occurences than the provided number without explanations.

Taskid: 2484335
Part-of: odoo/odoo#68700
2021-08-26 10:21:02 +00:00
Arnaud Joset 24c2d7e9d6 [IMP] google_calendar: move credentials from res_user table to a dedicated table
Before this commit, several token related data were stored on the res_users table. During event sync, the table could be locked and this commit aims to move these data to a dedicated table to avoid bottleneck effets.

Taskid: 2484335
Part-of: odoo/odoo#68700
2021-08-26 10:21:01 +00:00
Arnaud Joset 80e1259fd9 [FIX] google_calendar: prevent weird behavior when partner email and user email differs.
This commit allows using different mail on the user and the partner without experiencing weird behaviors.

Before this commit, sometimes when user would set a different email on his user_id and his main partner, the sync event would not be visible as long as the event was not accepted in Google.

closes odoo/odoo#74903

X-original-commit: bca4532890432d994c0941042f4eff75485c87ce
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2021-08-10 08:44:28 +00:00