Commit Graph
38 Commits
Author SHA1 Message Date
Thibault Delavallée c68f655782 [FIX] test_mail: fix activity tests
Fix some activity tests: use real test models, try to avoid date issues
by using freezegun.

Followup of odoo/odoo@a26e6e954c and odoo/odoo@06dee038dd .

Task-2654840

closes odoo/odoo#77120

X-original-commit: 2387c2ee6272a7c260386427c108208e747b819b
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-09-24 11:09:17 +00:00
Habib (ayh) 45ee18ce5b [IMP] mail: enable inheritance in the next activity values computation
values for next activities are currently prepared inside the `mail_activity._action_done()` method which makes inheritance very difficult. This commit delegates the value computation to a sub-method and thereby improves the extensibility of the module.

required to support changes to enterprise documents odoo/enterprise#20769
Task-2627837

closes odoo/odoo#77004

X-original-commit: a26e6e954c5e6c773f37e9239138a7b94ded821f
Related: odoo/enterprise#21079
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-09-22 20:38:59 +00:00
Thibault Delavallée 5553ad50bf [MOV] mail: reorder model files
As mail grows and will continue to grow, ordering imports and having right
files naming as well as right content in them is important to understand
module organization and content.

Containing

  * reorder init file to give an overview of models;
  * move ResGroups override in its own file, outside of res_users file;
  * split file containing MailActivity model and MailActivityMixin so that
    mixin is contained in its own file, easing followup;
  * split Activity and ActivityType models into two files;

No functional change comes with this commit. This is only code move.

Task-2631873
PR odoo/odoo#75571
2021-08-25 13:12:11 +00:00
Ivan YelizarievandNicolas Seinlet a88a912bd4 [FIX] mail: speed up read_progress_bar
This commit fixes the performance issue in getting statistics for
``activity_state`` (colored clock icon for overdue/today/planned) in
CRM.  The query has been tested for several years on a large database
(Odoo's own production database).

Performance test on 29 K crm.lead records (activity_state):

With a filter for 10 records:

```
| measurement        | before | after |
|--------------------+--------+-------|
| number of queries  |     25 |     5 |
| query time, ms     |     12 |    95 | (*)
| remaining time, ms |     32 |     7 |
```

All records:

```
| measurement        | before | after |
|--------------------+--------+-------|
| number of queries  |   1326 |     5 |
| query time, ms     |   1739 |   129 |
| remaining time, ms |  47934 |    17 |
```

As we can see in the last results, the time went from almost 50 seconds
(not responsive at all) to 150 milliseconds (responsive).  The time
increase in (*) may be caused by imperfect measurements, which are raw
and not averaged measures.

---

opw-2346901
task-1915411

X-original-commit: 1088e73c9a897902f9d2d70df980fe2a5ed23492
Co-authored-by: Nicolas Seinlet <nse@odoo.com>
2021-07-16 11:16:34 +00:00
dht-odoo 84e3680d80 [FIX] test_mail: fix randomly failing activity test case
We have a test case 'test_my_activity_flow_employee' that checks user's
own activty for current day. However, the creation of the activities is
done with OdooBot, and 'date_deadline' is not being passed. For this
reason, the default deadline (default value = fields.Date.context_today)
is set based on the tz of OdooBot (which is Europe/Brussels) and so it
might happen that the deadline is set on the next day (when test case
is performed just before mid-night).

In such cases, when we search for today's activites for the employee
(with absolute current date in domain, which is still before midnight),
result can be misleading as we expect one activty for the employee but
none could be found (as deadlines are set for the next day).

This commit fixes the issue by using absolute current for the test case
(whlie setting 'date_dateline' and while searching records) and thus making
it more reliable.

Note: The test case was introduced with commit https://github.com/odoo/odoo/commit/6aa3dc609cb13a469492b1a39a8fd9810040f079

TaskID-2570963

closes odoo/odoo#73034

X-original-commit: 962153a062af3f611e38c0d588febfecd9755810
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-07-01 05:00:45 +00:00
bit-odoo 800f9c499a [FW][FIX] mail, various: show only my activities shown through systray
Before this commit, suppose we have a scenario like below

  Task-A:
    Activity-1:
      name: Email ( Today )
      Assigned to: User-1
  Task-B:
    Activity-1:
      name: Email ( Today )
      assigned to: User-2
    Activity-2:
      name: Call ( Due in 3 Days )
      assigned to: User-1

When User-1 goes through the systray 'Today' filter shortcut he gets both
Task-A and Task-B in the list instead of only Task-A. Indeed currently
activities are not filtered based on current user with its deadlines.

However purpose of systray is to indicate activities current user has to
perform instead of global activities.

After this commit activities will be filtered based on deadlines as well as the
current user. In order to achieve this behavior we needed to pass a domain like
[
   ('activity_ids.date_deadline','=', fields.Date.today()),
   ('activity_ids.user_id','=', 1)
]

And for that purpose we introduced a non-stored compute field with a search
method.

Task ID-2438822
COM PR odoo/odoo#72219

X-original-commit: f4eaf4d8fb2f97240201104dcd4fc7e2674bce02
2021-06-21 07:51:00 +00:00
Aurélien Warnon 6ed53df401 [IMP] mail: add mailing.activity tests based on read_group operation
This commit adds some tests on mailing.activity to ensure read grouping is only
possible when the user has access to the underlying document.

Task-2272475
2021-06-02 07:18:06 +00:00
Aurélien Warnon cbf4f50727 [IMP] mail: add mailing.activity tests based on _search operation
This commit adds some tests on mailing.activity to ensure _searching is only
possible when the user has access to the underlying document.

Query count for 'test_adv_activity_mixin' had to be slightly adapted (+1) since
calling 'action_close' in turn calls 'activity_search' that calls 'search' on
mail.activity that now runs an additional query (see '_search' override
docstring).

Task-2272475
2021-06-02 07:18:06 +00:00
Aurélien Warnon 832c3e8333 [IMP] mail: add mailing.activity tests based on read operation
This commit adds some tests on mailing.activity to ensure reading is only
possible when the user has access to the underlying document.

Task-2272475
2021-06-02 07:18:06 +00:00
std-odoo 5680d52ff8 [IMP] mail: make the "activity_state" field searchable
Purpose
=======
Make the "activity_state" searchable on the "mail.activity" mixin.
This field is not stored as it depends on the current time.

Technical
=========
To make the search, we perform a SQL query.

The "activity_state" depends on the state of each activities on the
record. And this state also depends on the timezone of the user of
the activity. That's what made things tricky and we need to make the
conversion in SQL for performance purpose (we can not fetch all records
and compute them in python).

There's a special case, where there's less than 24 hours between the
deadline and the current time but one day of difference. In that case
the state should be "planned" and not "today". This case is handle by
the function "DATE_TRUNC" (e.g. 23h 01/01/2020 & 1h 02/02/2020).

Also for performance purpose, we compute the delay only once and we use
the function "SIGN" so we can use a switch/case instead of duplicating
3 times the expressions.

Task 2354754

closes odoo/odoo#60074

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-11-06 07:31:12 +00:00
Priyanka Kakadiya 77c231219e [IMP] mail: set default activity summary only if there is any
PURPOSE

Currently, there is an on-change to set an activity summary to the default
summary of an activity type. This can be useful if types are properly
configured. The problem is, the activity summary will be updated even if there
isn't any default summary on the type. Meaning that it simply removing a
relevant custom summary the user might have already entered.

SPECIFICATIONS

When triggering the on-change on activity_type_id, only update the activity
summary to the default summary if there is a default summary defined on the
activity type.

LINKS

Task-2254825
PR #51373

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2020-06-16 10:41:37 +00:00
Raphael Collet ea3e39506a [IMP] models: use slots for BaseModel
This restricts the attributes of a BaseModel instance to `env`, `_ids`
and `_prefetch_ids`.  This way, one can only assign fields on a record;
other assignments are programming errors.

This also reduces the memory footprint of records from 168 to 64 bytes
(-62%), and makes their instanciation faster.

closes odoo/odoo#51075

Related: odoo/enterprise#10529
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-05-18 09:51:43 +00:00
jvm-odoo 06dee038dd [FIX] mail: attachments in the message when marking activity as done
Fine tuning of 1e411e3a6d
- It moves the attachment in the message when we mark an activity as
  done.
- It adds a test

OPW-2196668

closes odoo/odoo#47349

X-original-commit: 2033066426a6af6eed5f80f1bcde6e650e998f0d
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
2020-03-11 09:49:02 +00:00
Xavier-Do 8970127c03 Revert "[IMP] test_mail(_full): run tests at post_install"
This reverts commit 976e560a87.

Even if it didn't looked like a bad idea, this need some more thinking.
This new version of query count creates random failure of runbot builds.

closes odoo/odoo#43820

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-01-23 09:19:12 +00:00
Sébastien Theys 976e560a87 [IMP] test_mail(_full): run tests at post_install
- take advantage of runbot multi-build capabilities
- get similar result when running them locally during dev
- better detect when other modules add extra queries

Query counts are split in the base value (testing with just test_mail installed)
+ the extra modules overhead.

Part of task-2178641

closes odoo/odoo#43666

Pr: #43666
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2020-01-22 13:36:22 +00:00
Thibault Delavallée f926f63212 [REF] test_mail: update test message composer / message track / activity to new common
PURPOSE

Currently tools and asserts for mail tests are located inside test_mail
module. It makes difficult to re-use them in apps tests or force them to
write custom quick and dirty tools and asserts.

SPECIFICATIONS

Update tests to new tools / asserts / helpers / classes defined in mail
and test_mail. Notably

  * ``BaseFunctionalTest`` class is replaced by the new ``TestMailCommon``
    pimped one;
  * ``assertNotifications`` is replaced by ``assertSinglePostNotifications``
    (shortcut for a simple message_post) or ``assertPostNotifications``
    (complete asserts involving several messages and notifications);
  * correctly invoke ``mock_mail_gateway`` when mocking email sending;
  * replace manual check of sent emails or ``assertEmails`` by
    ``assertSentEmails``;
  * remove custom mocks / checks and replace them by now standard mocks
    and assertions (if any);

In this commit we update: test_message_composer, test_message_track and
test_mail_activity.

LINKS

Task ID 2068986
PR #38070
2019-11-20 16:00:47 +00:00
Thibault Delavallée 46241ce8a9 [REF] test_mail: lessen data created by default
PURPOSE

In order to rewrite some tests, remove low-level tests and add coverage
first step is to reorganize a bit test_mail content. Several tests cases
are spread among several files and finding back some feature coverage
tests is not easy.

SPECIFICATIONS

Quickly clean common class and lessen data creation by default. Offer some
tool methods, notably to create portal users used in some tests but not
all, or to create mail templates.

LINKS

Task 1958697
2019-09-06 13:27:59 +00:00
Raphael Collet 9920f20e4c [IMP] models: ORM speedup
This branch is the combination of several optimizations in the ORM:

* store field values once in the cache: the cache reflects more
faithfully the database, only fields that explicitly depend on the
context have an extra indirection in the cache;

* delay recomputations by default: use method `recompute` to explicitly
flush out pending recomputations;

* delay updates in method `write`: updates are stored in a data
structure that can be flushed efficiently to the database with method
`flush` (which also flush out recomputations);

* make method `modified` take advantage of inverse fields to inverse
dependencies;

* filter records by evaluating a domain on records in Python;

* a computed field with `readonly=False` behaves like a normal field
with an onchange method;

* computed fields are computed in superuser mode by default.

Work done by Toufik Ben Jaa, Raphael Collet, Denis Ledoux and Fabien
Pinckaers.

closes odoo/odoo#35659

Signed-off-by: Denis Ledoux <beledouxdenis@users.noreply.github.com>
2019-08-20 12:43:59 +00:00
Raphael Collet b7fd679a6c [FIX] *: sudo() -> with_user() 2019-07-04 11:32:22 +00:00
Thibault Delavallée 20c10fcd19 [ADD] sms, test_mail(_full): add basic SMS tests and improve test tools
Purpose of this commit is to improve and add tools, methods and data to test
mail and SMS features. We also add tests for current implementation of SMS
feature, allowing to better understand future changes.

[ADD] test_mail_full

  * have a module depending on mail sub-applications like sms or snailmail.
    Its purpose is to check that standard mail features work effectively with
    all overrides and extra behaviors activated;
  * add a new model specific for SMS gateway, with default recipient
    computation;
  * add SMS tests for SMS module adding SMS capabilities linked to mail
    feature. This commit tests SMS feature before the upcoming refactoring
    and improvement of SMS module in community: posting with SMS and sms
    composer usage;

In test_mail

  * add necessary mobile information on test partners;
  * improve assertBusNotification that was not correctly asserting all items
    in message of bus notifications;

In sms

  * add mock for SMS sending. Purpose is to mock the connection to IAP
    services by mocking the call to IAP server. It allows to perform SMS
    tests without having to contact (and pay) for this service;
  * allow some customization when calling the SMS gateway mock to simulate
    errors and test corner cases;

Related to task 1922163
Linked to PR #34516
2019-07-02 10:44:56 +00:00
XavierDo 303220f214 [FIX] mail: only notify activity assignation on user change
The current implementatipon of write on mail.activity will
send a notification to the user every time a write is made
on user_id.

To avoid to send notification / mail if the user_id is given
but doesn't change, we can simply filter the records. This
will also avoid to check assignation rights in this case.

Task: 1905086

closes odoo/odoo#30055
2019-01-10 10:14:45 +00:00
Thibault Delavallée abc212f59a [REF] mail: remove create_user_id field on activity
As activities are created using the current user there is no need anymore to
have another field to store the activity creator. We can therefore remove
create_user_id and replace its use by the magic create_uid field.

This commit is linked to task ID 1856417 and PR #27619.
2018-12-12 12:45:24 +00:00
Sébastien TheysandThibault Delavallée b9c8ba83e6 [IMP] mail: clean activities access rights
This commit improves code of access rights checks when creating or updating
activities. Several points triggers this commit

 * we would like to use _filter_access_rules and override it on activities
   model in order to be more standard;
 * we would like to get rid of sudo used in various CRUD overrides as using
   standard ORM method allows to correctly use current user;
 * we would like to get rid of create_user_id field once we can keep the
   current user as create_uid;

Access rights are a bit updated. They are now the following

 * you can create activities for documents like posting messages (using
   _mail_post_access attribute; if not defined, write access on document
   is required);
 * you can read activities for documents you can read;
 * you can write and unlink activities either following the defined access
   rule (created OR assigned), and otherwise like posting messages (
   using _mail_post_access attribute; if not defined, write access on
   document is required);

In this commit we also hide edit / mark as done / cancel buttons for
activities the current user cannot modify.

This commit is linked to task ID 1856417 and PR #27619.

Co-Authored-By: Sébastien Theys <seb@odoo.com>
Co-Authored-By: Thibault Delavallée <tde@odoo.com>
2018-12-12 12:44:03 +00:00
Thibault Delavallée 5494b0bc3e [FIX] mail: do not prevent record update due to automated activities
Currently creating activities assigned to user not having to the document
raises an Error as people should not have activities they cannot handle
directly on a document they cannot access.

In some cases activities are created through business flow, like automatic
activities creation when creating leave requests. Assigning an activity
to someone that has no access to the document should not prevent from
creating the leave request.

This commit therefore does not check assigned user access on automated
activities to avoid having blocked business flows.

This commit is linked to task ID 1903484.

closes odoo/odoo#28139
2018-10-25 09:29:10 +00:00
Thibault Delavallée a7b3d1697c [REF] test_mail: use odoo test helper method to create test users
Purpose of this commit is to use the newly introduced helper to create
test users in a quick way and reduce code duplication. A mail specific
helper tool function is defined based on the standard one defined in test
allowing to pass a custom context. It bypasses mailing features in order
to speedup the creation.

This commit is linked to task ID 1889703 and PR #27526.
2018-10-18 13:57:02 +00:00
Thibault Delavallée d5131fe976 [REF] test_mail: reorganize activity tests
Purpose is to separate tests related to access rights (low level), base
activity features and mixin itself. It eases understanding of tests and
prepare future addition of tests.

This commit is linked to task ID 1856417.
2018-10-02 16:05:17 +02:00
Prakash Prajapati 36854d3bda [IMP] mail: allow to reschedule assigned user on automated activities
Purpose of this commit is to add possibility of rescheduling the assigned
user on automated activities. Currently rescheduling is limited to updating
the deadline. In some cases we want to be able to update the assigned
user of an automated activity.

Tests are added to avoid regression.

This commit is linked to task ID 1838956 and PR #25899.
2018-08-10 15:36:04 +02:00
Thibault Delavallée 618c42575e [IMP] mail: remove activities when archiving records
When archiving records through the generic toggle_active methods we now
remove ongoing activities.

Purpose of this commit is to avoid having ongoing activities in the systray
linked to archived records. As archiving records means we won't work on
them anymore it makes no sense to keep related activities.
2018-08-01 10:24:36 +02:00
Thibault Delavallée 792efc8615 [IMP] mail: notify people when another user assigns them on an activity
When someone assigns an activity to another user it is a good idea to
notify this user a new activity has been assigned to him. This is done
using the message_notify method that sends a notification either in the
Inbox either by email depending on the user preferences.

This commits is linked to task ID 1854820. Closes PR #25265.
2018-07-27 17:22:31 +02:00
Christophe Simonis 73652a0b19 [MERGE] forward port branch saas-11.3 up to 50860317cc
Note: 1aacc96262 has been ignored and will
be forward-ported later
2018-06-15 13:27:27 +02:00
Thibault Delavallée 60614d9961 [FIX] test_mail: fix timezone issue in activity test
Due to timezone difference between two test users the state of activities
depend on the time when the test is running. Indeed if user 1 plans an
activity for tomorrow this could already be today for user 2. Test
that ensure tomorrow is correctly computed should therefore be done with
users being in the same timezone. Current behavior is correct as activities
manipulate date that cannot always be timezoned back to another timezone.

How to reproduce the issue before this fix: run the activity mixin tests
between 0:00 and 1:00 in +1 TZ (Brussels).
2018-06-07 13:59:02 +02:00
Thibault Delavallée 96a223a5f0 [IMP] mail: prevent creation of activities to users that have no access to document
This commit is related to task ID 58968 . Closes #24176.
2018-05-15 15:42:54 +02:00
Thibault Delavallée bcc6884737 [IMP] mail: limit cache invalidation when subscribing followers
Cache invalidation when subscribing people has been added at e6f038a821.
Indeed subscribing partners to a record may lead to an access right update
as some of them are based on followers. This is why a cache invalidation
is necessary to avoid access rights issues.

However subscribing people to a record should change their rights only on
the records involved in the subscription mechanism. We can therefore give
ids to the cache invalidation to limit to updated records.

Cache invalidation is also limited when writing on followers if writing
on model, res_id or partner_id fields. Indeed changing subtypes or
channel of a subscription should have no impact on cache and access rights.

Cache invalidation done manually in _message_subscribe is not necessary
as subscription create or update mail.followers records since f9c210923d.
Create and write of mail.followers records already ask for cache invalidation.
It is therefore not necessary to invalidate cache twice.

This commit allows to save a few queries on some tests, notably about
activities that deal with subscription and messages. As cache is now kept
it is not necessary to refetch some data, leading to a few query gain. We
gain about 1K queries on com runbot.

A side effect of limiting cache invalidation is that some unit tests require
a manual cache invalidation to have up to date results. Indeed record not
being up to date in cache was hidden by the invalidation we just removed.
2018-04-10 11:00:41 +02:00
Dharmang Soni 807c4c3f5e [REF] mail, note: move reminder feature from mail to note
This commit refactors f488dc58c3 that added reminder feature in activities.
After merging it was suggested specifications were not correct and it has
been decided to move the whole reminder feature in note.

Reminders are now notes instead of activities. Now when having note appµ
systray proposes to create a note / reminder. A note.note record is created
with info given by the user. If a date is given in the systray quick create
then an activity is scheduled on this note.

This means user can create records in activity systray that are not
activities but notes used as reminders. Those will use the first availableµ
note column for the user.

As reminders are now notes the support of activities not linked to any
document is removed, as well as archiving activities and tests linked to
that behavior.

This commit has been not carefully tested nor in-depth reviewied. It is
considered as too important for the upcoming freeze. This closes task ID
1833628. Closes #24129 . Many thanks to @dpr-odoo for its quick development
and good work on this task.
2018-04-09 14:35:06 +02:00
Thibault Delavallée 60b81e00b2 [IMP] mail: add tool methods to manage activities directly from the mixin
This commit adds tools methods related to activities in the mail.activity
mixin. It gives to models inheriting from the activity mixin an easy-to-use
API to schedule, unlink or mark activities as done. Purpose of those methods
is to avoid having people manually managing activities in the code to hide
the technical details of the activities model, notably access rights
or activity types.

A field is added on activity model to indicate they have been generated
automatically. This way when rescheduling or unlinking based on some
specific activity types we do not change user-created activities.

Those methods include scheduling activities, changing their dates, marking
them as done or unlinking them. Future commits will use those methods
in various addons to automatically generate activities based on workflow
we want to implement.

This commit also adds tests for the newly added code. Future commits should
probably have a look at activity security and add some tests cases to check
it is correctly taken into account. It is considered a bit out of scope for
this task.

Thanks to @jem-odoo for its in-depth review of this commit. Well thanks for
other commits also.
2018-03-27 15:00:46 +02:00
Thibault Delavallée 093dd9b512 [IMP] test_mail: clean reminder-related activity tests
It has not been done completely at f488dc58c3.
2018-03-27 15:00:36 +02:00
f488dc58c3 [IMP] mail: allow to use stand alone activities as reminders
This commit allows to create personal reminders and to manage them using
activities. It is done using activities not necessarily linked to a record
but only to a user. Reminders can be used for example as a personal todo
list.

Technically we choose to model a reminder as an activity related to no
record. This means having a void res_id and model. An activity type is
added to classify reminders in it.

Settings reminder as done is not done like classic activities. Indeed classic
activities are unlinked and a message is logged on the related document.
As there is no document for reminders those are archived instead. It means
an active field is added as well as an override of toggle_archive to update
systray counter.

Activities systray widget is improved to display reminders in activities
list. This entry leads to a kanban view of activities allowing their
management. It is also possible to create them directly from the systray
allowing a quick creation of reminders.

This commit is related to task ID 41745. Closes #22143 .

Co-authored-by: Dharmang Soni <dpr@odoo.com>
Co-authored-by: Xavier Dollé <xdo@odoo.com>
2018-03-27 13:26:41 +02:00
Thibault Delavallée d040bfde89 [MOV] (test_)mail: move tests into their dedicated module
Purpose: avoid having useless tables for test models in a
production environment.
2017-11-29 10:11:15 +01:00