Commit Graph
56 Commits
Author SHA1 Message Date
Loan (LSE) a71bfd5306 [FIX] website: delete visitors by batch in cron
Before this commit:
The scheduled action will repeatedly time out if the number of visitors
to remove is too high. In the case of the client, he has ~ 4 millions
inactive visitors to remove. This might happen after a bot spam attack.

After this commit:
The visitors are removed by batch of 1000, reducing the number of old
visitors with time

opw-3256349

closes odoo/odoo#119757

X-original-commit: b69917ec0e508f8354d831525c5c48ee79b5967a
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2023-04-27 00:52:15 +02:00
Rémy Voet (ryv) 234db70d86 [IMP] *: Use the new API of _read_group for backend use
Part-of: odoo/odoo#110737
2023-04-19 21:58:27 +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
Thibault Delavallée 1a1acabd7b [REF] mail: cleanup mono/multi record composer behavior
RATIONALE

Improve usage of composer in comment or email mode: support batch-posting in
comment, support more configuration from templates, improve global model.

SPECIFICATIONS

Support a real res_ids field on mail.compose.message model. Instead of relying
on active_ids from context, store it once for all at composer level and use
it in code. Active_ids usage is still done at default_get level, using it to
populate the field.

Improve usage of domain, renamed to res_domain to match other document related
fields naming. Add support of a res_domain_user_id field allowing to set the
user from which the domain should be evaluated.

Composer now runs on a list of IDs. Mass mail mode and comment mode are now
distinct from running on a singleton or on more records. Rendered or raw
mode is not triggered by

  * mass mailing mode: always display raw mode, whatever the number of records;
  * comment mode: display rendered mode when having a single record (like the
    previous comment mode). Display raw mode when having either no records
    either at least two records.

Task-3035101 (Mail: Support batch-posting from composer)

Part-of: odoo/odoo#99482
2023-01-17 20:58:39 +01:00
Romain Derie 8850e98233 [FIX] website: prevent upsert crash if GEOIP country not found in odoo
It was reported the following error:
```
psycopg2.errors.DatatypeMismatch: column "country_id" is of type integer
                                  but expression is of type boolean
LINE 9:                 false, 1, NULL, 4, 4,
```

The root cause is unknown, it's not yet sure how this is happening
exactly.
This commit is then fixing naively the consequence.

Somehow, GEOIP is returning a country code which does not exists in Odoo
for this error to appear. It's normally not possible.

There is multiple possible cases that would lead to this error:
- The user modified the `code` field of a country in his DB (unlikely)
- The user deleted a country in his DB (unlikely)
- The GEOIP database is returning a country which does not exists in
  Odoo. This is the most probably case, even if the latest up to date
  `GeoLite 2 City` seems to have the exact same country code list as in
  Odoo 16.0 (250 exact same ones).

Moving the country_id search directly in the query will prevent the
issue and is better anyway to avoid an useless query everytime when
GEOIP is enabled.
Perf wise, it doesn't seems to alter at all the query speed.

closes odoo/odoo#108232

X-original-commit: 42fe2540620b7529d9a848c4570290cbf64a4f48
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-12-18 22:27:46 +01:00
Nasreddin Boulif (bon) 156e2f1fc3 [FIX] website: get right access token for public visitor user
Current Behavior:

When we get the access token for a website visitor, we check if the
`self.env.user` is a public user. If it is, we return his id.

Expected behavior:

We should check the `request.env.user` instead since the visitor can
only be created through the frontend.

opw-2956186

Part-of: odoo/odoo#99181
2022-09-02 19:13:53 +02:00
Raphael Collet fa49e347e9 [FIX] website: don't browse() a string
Part-of: odoo/odoo#95325
2022-07-14 22:45:44 +02:00
Romain Derie d348bed1ad [IMP] website, *: use upsert to improve visitor perf
* im_livechat, test_event_full, website_blog, website_crm,
  website_event, website_event_track, website_event_track_quiz,
  webite_livechat, website_sale

There is 6 main changes in this commit:

1. Using raw SQL Upsert instead of the ORM methods. While raw SQL should
generally be avoided, it makes sense for such a low level behavior which
is impacting every flows.
Indeed, tracking visitors is a generic behavior done on all pages and
controllers. It is important to optimize it to reduce processing time
and SQL Queries.
Benchmark of that change alone:
> Rendering a tracked page improves from ~19.5ms to ~17ms (using `ab`
  with 1000 loop) and the requests involved in the tracking process are
  reduced from 8 SQL Queries to 3:
  - 1 request to upsert the visitor
  - 1 request to fetch the visitor data
  - 1 request to add the tracking record

2. Adding in that upsert query the `visitor.track` insert, creating both
records in one go, bringing the query count from 3 to 2.

3. Refactoring of the `parent_id` behavior that was introduced in stable
with [1]. The purpose was to keep track of multiple visitor linked to a
same user to merge the tracking together. Especially useful for tracking
a same visitor on different devices (when logged in).
Only one visitor was kept as active, others would be archived and their
tracks would be set/moved to the main partner.
Removing those duplicate visitor was not possible because those archived
duplicated visitor were holding the devices notification push token.
Since [2], those token were moved to their own table, all related to the
main visitor.
We can then now safely remove those duplicate visitors after merging
their track to the main visitor. Thus, the `parent_id` field is no more
useful. Removing it removes a layer of complexity.
Note that thanks to this part, the `active` field can also be removed.

4. Deeper functionnal change, inspired from Plausible: The access_token
is no more stored in a cookie but is the result of a hashing method
based on <IP Adress, User Agent>.
The reason behind that change is that, in an upcoming refactoring,
sessions won't be stored anymore unless absolutely needed (login, add to
cart..). It will also ship a no cookies policy, trying to get rid of all
cookies.
This change is bringing some functional changes:
- Since the IP is included in the hash to generate the token, it means
  that:
  A. If an anonymous user switch IP (eg from 4G to wifi), it is
     considered as a new visitor.
  B. If 2 anonymous users with the exact same user agent (same browser,
     same browser version, same exact os or phone) are on the same IP,
     those will be considered as the same visitor.
- Since the request host is not included in the hash, it means that
  visiting a DB from 2 differents URLs (domain and/or ip) on the same
  device and same browser will result in a shared visitor.
  It shouldn't imply any issue as this is A. not wrong and B. mostly
  used for tests.
As all this is only related to non logged in user, it shouldn't be a
real issue as anonymous visitors are not supposed to be meant to be
business critical, even if we use them for "a bit more" than simple
analytics data.

5. The access_token is now replaced by the partner_id once the user logs
in, so:
- We don't need to either search on the partner_id field or the
access_token field (depending if the user is logged in or not), we can
only use the access_token row/field to do both.
- On logout, everything works out of the box as the access_token will be
regenerated since there is no partner_id anymore.
- On login, if an access_token matches the user's partner_id, that
visitor is returned.
If there is no such token, a new visitor is created for that partner_id.
In both 2 cases, tracks are moved to that visitor and the anonymous
visitor is removed.
- We can remove the code that was in charge of checking if the
access_token / visitor cookie was wrong (coming from another user eg,
different user login on same device). Indeed, such collision is not
possible anymore as the access_token automatically match the logged in
user.
- We can remove the code that was in charge of checking if the
access_token / visitor cookie was wrong (coming from a logged in user
while the current visitor is not loggedin). Such collision is not
possible anymore as the access_token is (re)generated as an anonymous
token (hash) when not logged in.

6. There is no more check to prevent a track to be created if there was
already a track for that URL in the last 30 minutes.
While this can easily be re-introduced (one CTE on the upsert), it was
adding ~100ms (from ~20 to ~110ms) to the request on a big database as
Odoo where there is ~100 millions tracks and ~100 millions visitors.
It has been validated that it was not a real issue as it is not
fundamentally wrong. If a visitor visited 20 times a product or a
specific page in that short amount of time, you might want to know that
because the user is most likely interested by it.

Changes (1+2), 3, (4+5) and 6 are all independant from each other and
could have existed on their own.

[1]: https://github.com/odoo/odoo/commit/c6b8a44b970a46dcd87a4e2cb1ad52fa340b209f
[2]: https://github.com/odoo/enterprise/pull/16781/commits/f75090fe8b42484e89e933976e8441d2f5eb9415

task-2867045

closes odoo/odoo#87857

Related: odoo/enterprise#28004
Related: odoo/upgrade#3566
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-06-07 16:31:20 +02:00
Romain Derie 92feb6a67f [FIX] website: ensure request.env and env.uid are set
Some cases might lead to undefined `env` on request or undefined `uid`
on request.env:
1. Mobile app: no uid is set on the jsonRequest env
2. Multi db: _env is None on request, and request.env unbound

1. Was checked with [1]
2. Was checked with [2] but by doing so, it actually broke the check
   done for 1.

[1]: https://github.com/odoo/odoo/commit/245ef4b0fddc7e5da3ebe841438c2d2902933f14
[2]: https://github.com/odoo/odoo/commit/3a7033463ea98def2e3fb85333c4f00f7c7d6925

task-2867045

Part-of: odoo/odoo#87857
2022-06-07 16:31:19 +02:00
Ivan Yelizariev 08605c506e [FIX] website: make search by "Visited Pages" work again
Field `website.visitor::page_ids` was storable initially [1], but then it was
refactored [2] and hence the search by "Visited Pages" [3] became broken.

Fix it by adding `search=` attribute

[1]: https://github.com/odoo/odoo/commit/6bec0e4d29e6b33b74962b2893a7a405667ef58c
[2]: https://github.com/odoo/odoo/commit/e33172e83210a5e0044a6fb92e315b84deefc440
[3]: https://github.com/odoo/odoo/blob/c6c7605cdae803aca4f441ef4e622a1b79f17019/addons/website/views/website_visitor_views.xml#L248-L257

opw-2622141

closes odoo/odoo#91829

X-original-commit: 792e07b8ff43ecb0499f4add27f5465c28e716cf
Signed-off-by: Ivan Elizaryev (iel) <iel@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-05-19 19:04:55 +02:00
Julien Castiaux c46f4b908a [IMP] *: request.session.geoip -> request.geoip
Commit "[IMP] core: don't save visitor default session" moved the geoip
from the session to the request with a deprecation warning. This commit
adapts the remaining modules to use `request.geoip` instead of
`request.session.geoip`.

Geoip is always set on the request but it can be an empty dictionnary in
case the geolocalization failed.

closes odoo/odoo#86015

Task: 2789035
Related: odoo/enterprise#25192
Signed-off-by: Julien Castiaux <juc@odoo.com>
2022-04-05 14:13:54 +02:00
Vincent Schippefilt 05fc9a6733 [IMP] *: use _read_group instead of read_group
This commit modifies most of the usages of read_group and uses
_read_group instead. _read_group doesn't join automatically on the
many2one fields when no order_by is specified, making it more performant
when the "name" of the many2one is not relevant, which is the case for
most back-end cases

closes odoo/odoo#84908

Task-id: 2479334
Related: odoo/enterprise#24877
Signed-off-by: Raphael Collet <rco@odoo.com>
2022-03-02 17:10:48 +00:00
Aurélien Warnon a0d33b1c29 [IMP] website[_event|_crm]: unlink visitors when inactive & enforce linked visitors
PURPOSE

Visitors are useful in terms of marketing analysis but they can bloat the
database really quickly if you have a lot of traffic on your website.
This commit aims to relieve the database by fully deleting inactive visitors.

SPECS

On an active website, you can easily reach hundreds or even thousands of
visitors per day.
While active visitors are useful for marketing purposes, inactive ones were
archived after a period of inactivity (i.e: not connected for X days in a row,
where X is configurable as a parameter and 30 by default).

But archiving visitors is not really useful either.
We don't see any specific cases where you would want to restore some visitors.
That means we are better off unlinking the visitors completely to save database
storage space.

We want to make exceptions and avoid deletion of inactive visitors in some
cases:
- When they are linked to a partner (meaning most likely linked to a
  registered user)
- When they are linked to leads
- When they are registered to events

Several tests were added to ensure that leads matching these conditions are not
unlinked.

We also took this opportunity to enforce the "_link_to_visitor" rules in those
tests to make sure that:
- When visitors are linked, the leads are merged into the main visitor
- When visitors are linked, the event tickets are merged into the main visitor
- When visitors are linked, the wishlisted tracks are merged into the main
  visitor

This is also preliminary work for a commit that will move the push_token of
website.visitors to a separate table.
That will in turn allow us to link the push_tokens within the
"_link_to_visitor" method and delete the linked visitor instead of archiving
it.

LINKS

Task-2410217

Part-of: odoo/odoo#65113
2022-02-17 17:37:40 +00:00
Aurélien Warnon 0641cb20e8 [REF] website_event: move website.visitor's parent_id to website
The concept of 'parent_id' on website.visitors was introduced in the saas-13.3
stable while implementing the "event online" feature:
However, it should have been part of the website module from the start since
it's a 'global' concept that does not depend on events at all.
See #53540 for more details.

This commit aims to clean the code by moving the field to the website module,
which allows a nice cleaning of associated overridden methods as well.

Along with that, we move the website.visitor demo data from the event module to
the website module, allowing a fresh install of website to showcase some of our
visitors feature.

We also took this opportunity to do some minor improvements in the visitors
kanban view in order to make relevant information more visible.

Task-2429652

Part-of: odoo/odoo#65113
2022-02-17 17:37:40 +00:00
Raphael Collet a1904aa6f6 [IMP] core: field index names
The possible index names have been renamed "btree", "btree_not_null"
(instead of "not null") and "trigram" (instead of "gin").

Task 2742526

Part-of: odoo/odoo#83274
2022-01-28 14:10:01 +00:00
Fabien Pinckaers eedf37d6e2 [IMP] Better handling of indexes
Three supported types:
- btree (default for index=True)
- btree not null (when >90% of the data are null)
- gin trigram search (for char fields)

Review of indexes on all objects.

closes odoo/odoo#83015

Signed-off-by: Fabien Pinckaers <fp@odoo.com>
2022-01-19 16:52:23 +00:00
Louis Wicket (wil) 80d74e7ee0 [IMP] mail, web, *: add support for guest users
* = crm_livechat, hr, hr_holidays, im_livechat, mail_bot, purchase, sms,
    snailmail, survey, test_discuss_full, test_mail, web_editor, website,
    website_livechat

 - Create new model `mail.guest` for guests.
 - Rewrite some RPCs to target routes rather than model methods so that
   guests are able to use them.
 - Patch JS and python models to support guests.
 - Create a stand-alone page and boot the channel in it.

task-2494829

closes odoo/odoo#75496

Related: odoo/enterprise#20417
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2021-09-02 00:43:34 +00:00
Florent de Labarre 1e764eb2b2 [FIX] website : prevent bad query
In database with front end, there are lot of bad query like this:
bad query: UPDATE "website_visitor" SET "timezone"='Europe/Paris',"write_uid"=116,"write_date"=(now() at time zone 'UTC') WHERE id IN (15414)

closes odoo/odoo#70709

Error: Could not serialize access due to concurrent update
X-original-commit: d0db984990679a63714ca62e6b605d94af7d5c28
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-05-12 07:25:22 +00:00
Nicolas Lempereur 1f14a6b8ed [FIX] website{,_livechat}: 'Website Visitor' translated
Make translation works for "Website Visitor" that was appearing when a
logged-out user open a livechat session.

note: list comprehension has to be removed since translation only search
language in direct calling method closure.

opw-2504461

closes odoo/odoo#70146

X-original-commit: 7d28f32d9be1590764883f4621df04e04c4e1f12
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
2021-04-30 08:45:00 +00:00
David Beguin 14167ea884 [FIX] website_livechat: hide visited website.page for non website_designer
When opening the visitor view, if user is not website designer, there was an
access error as only website editor can read website.page model.

This commit applies the website_designer group to page_ids field to avoid crash.
There are no viable solution to show the visited page in stable without changing
the model definition. Hide the info is then the better solution.

Task ID-2301261
PR odoo/odoo#60549

X-original-commit: 69cc2911b52fd17b37fb71544574f63cf09dd17e
2021-03-29 11:17:47 +00:00
Jeremy Kersten 70eb143b2f [IMP] website: use correct groups on field access_token
Previously, since the group name was wrong, nobody can access this.
Now we let group_website_publisher read it...
Change is not critical, since previous typo make it unreadable for
all.

closes odoo/odoo#66061

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2021-02-12 12:10:22 +00:00
Aurélien Warnon 1adf67423e [IMP] website_*: improve various website.visitor views
PURPOSE

Make various changes to the website.visitor views to improve readability and
ease marketing analysis.

SPECS

The changes include notably:
- Add/rename/move fields/filters elements
- Remove some unnecessary information or put it in optional="hide" in tree view
- Add website_id information (with the multi-website group)
- Slightly rework layouts (new widgets / spacing / images / buttons / ...)
- Move some technical information into the "debug mode"

LINKS

Task 2092302
ENT PR odoo/enterprise#14611
UPG PR odoo/upgrade#1902

closes odoo/odoo#61417

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-11-26 15:29:13 +00:00
SEINLET Nicolas 5a03cc64d3 [IMP] website_visitor: avoid double indexing
unique constraint create an btree unbique index:
``` # \d website_visitor [...] Indexes:     "website_visitor_pkey"
PRIMARY KEY, btree (id)     "website_visitor_access_token_unique" UNIQUE
CONSTRAINT, btree (access_token)     "website_visitor_partner_uniq"
UNIQUE CONSTRAINT, btree (partner_id) ``` removing index=True avoid this
double indexing.

closes odoo/odoo#60120

X-original-commit: efb33e783bd04d542009ef0f57eba6a4aacbca65
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Signed-off-by: Nicolas Seinlet (nse) <nse@odoo.com>
2020-10-15 15:50:31 +00:00
David Beguin 4c9e39cfbd [FIX] website: get visitor tz directly from cookie
Since tz is now (from 6eb4762fee) added to the client cookie,
visitor timezone can directly be set when creating the visitor, using the
request.

Jstz can be removed as even for module in ENT that used this lib,
we can get the timezone using Intl lib instead.

This will also reduce the number of request made only to get visitor's
timezone.

This commit reverts part of 17e8402523
Linked ENT PR: 12963

Task ID: 2333825

closes odoo/odoo#59501

X-original-commit: 3d9a2de3575777c87327691319d89f9de6b8eada
Related: odoo/enterprise#13918
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-10-08 11:45:39 +00:00
Martin Trigaux 2683184aa6 [FIX] *: fix all the typos
And other reported English mistakes in source string
Courtesy of Transifex translators

And remove leftover from gengo

closes odoo/odoo#59022

X-original-commit: 26efc84c5cac47a2cc83d7b084f8b71528fec6c7
Related: odoo/enterprise#13781
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2020-10-05 09:36:34 +00:00
Victor Feyens 2f3dcb8947 [IMP] base,website*: do not store country flags.
1) Avoid the storage of all country flags as ir_attachment (230+
ir_attachment in a new db) to reduce the filestore of databases.

The country flags are nearly static and not expected to be modified on
Odoo instances.

This change is based on the new "image_url" widget logic (see previous commits).

2) Extend the flag coverage for countries

Add the missing country flags & specify a mapping to provide flags
for overseas administrated countries/territories.
2020-09-02 16:43:45 +00:00
8ae4544b76 [REF] website: improve visitor / user synchronization at authenticate
RATIONALE

Event will soon gain a major update called Event Online, allowing to better
support full-online events. In order to prepare its merge, preparatory merge
are done to lessen the final diff and have a smooth integration in a stable
version (13.3).

PURPOSE

Purpose of this merge is to clean visitor synchronization and tests. It
prepares further improvements to visitor model linked to Event Online.

SPECIFICATIONS

Add anchor methods to somehow merge visitors and update partner linked
to visitors and their sub records.

Main idea would be to be able to

  * avoid unlinking visitors, notably because we have keys linked to them
    allowing push notifications. As a given user may be linked to several
    devices (different keys / different visitors) keeping them in database
    improves push efficiency;
  * allow to link sub-records to a main visitor, like tracked pages history,
    even if multiple visitors are linked to the same identity;

In this stable we cannot remove current unlink of duplicate visitors due
to constraint of partner_id / visitor_id. However those methods allow to
tweak behavior by override. This will be done in future tasks.

LINKS

Task ID 2290016 (improve visitor synchronization and tests)
Prepares Task ID 2252655 (main Online Event task)
Prepares Task ID 2284043 (Visitor-based track wishlist)
PR #54036

X-original-commit: 8a8d2d4412d1b58545ee4f0240cca5114e541b6a
Co-authored-by: Aurélien Warnon <awa@odoo.com>
Co-authored-by: David Beguin <dbe@odoo.com>
Co-authored-by: Thibault Delavallée <tde@odoo.com>
2020-07-22 09:02:55 +00:00
2648840624 [REF] website: allow to configure delay before archiving visitors
RATIONALE

Event will soon gain a major update called Event Online, allowing to better
support full-online events. In order to prepare its merge, preparatory merge
are done to lessen the final diff and have a smooth integration in a stable
version (13.3).

PURPOSE

Purpose of this merge is to clean visitor synchronization and tests. It
prepares further improvements to visitor model linked to Event Online.

SPECIFICATIONS

Introduce a new configuration parameter in website allowing to set number of
days before de-activating visitors: ``website.visitor.live.days`` . It is
set to 30 days instead of 7 as before.

Purpose of extending delay is to be able to use visitor information a bit
longer in business flows. For example one could contact visitors 2 weeks
after an event to get their feedback. Adding a bit of delay allow to keep
those visitors alive a bit longer by default. Allowing to configure it gives
more flexibility to admins and deployment.

LINKS

Task ID 2290016 (improve visitor synchronization and tests)
Prepares Task ID 2252655 (main Online Event task)
Prepares Task ID 2284043 (Visitor-based track wishlist)
PR #54036

X-original-commit: f83af1d53716499dcad94f363aff609a2f8e55d9
Co-authored-by: Aurélien Warnon <awa@odoo.com>
Co-authored-by: David Beguin <dbe@odoo.com>
Co-authored-by: Thibault Delavallée <tde@odoo.com>
2020-07-22 09:02:55 +00:00
Thibault Delavallée 150a24ad81 [IMP] website: use HttpCaseWithUserDemo for tests and clean boostrapping
RATIONALE

Event will soon gain a major update called Event Online, allowing to better
support full-online events. In order to prepare its merge, preparatory merge
are done to lessen the final diff and have a smooth integration in a stable
version (13.3).

PURPOSE

Purpose of this merge is to clean visitor synchronization and tests. It
prepares further improvements to visitor model linked to Event Online

SPECIFICATIONS

Clean existing visitor tests. Use HttpCaseWithUserDemo and clean bootstrapping
of data.

Introduce a mock for visitor from request allowing to shortcut some visitor /
user synchronization and test directly expected results without too much
boilerplate in tests.

LINKS

Task ID 2290016 (improve visitor synchronization and tests)
Prepares Task ID 2252655 (main Online Event task)
Prepares Task ID 2284043 (Visitor-based track wishlist)
PR #54036

X-original-commit: 4e0d4e7c315b5a9d880754e02966debd6a59c728
2020-07-22 09:02:55 +00:00
Martin Trigaux ba244cef01 [IMP] *: replace to new _() syntax
Using a few regex like
\((_\(.*%s.*)(\) % )([\w\[\]][\w .\[\]\(\)'"]*)\)
($1, $3))

Old syntax is still compatible but starts the migration to the new
syntax that catches error.
2020-06-18 13:03:34 +02:00
Thibault Delavallée 52ac7f2ddb [FIX] website(_crm): fix email and phone computation of visitor
Currently there are several limitations in visitor email and phone
computation, notably phone of partner is not taken into account (only mobile)
and computation does not work in website_crm if there are no leads.

In this commit we

  * support both mobile and phone fields of partner. Indeed generally all
    SMS flows check for those two fields and not only for mobile;
  * replace the SQL by standard ORM computation. As those fields are not stored
    and displayed in list views ORM should be capable of managing them;
  * avoid crash when creating visitors through the UI (no ids -> don't go
    into raw SQL);
  * correctly keep partner-based values when no lead is linked to the visitor;

Tests are also added in order to ensure behavior.

Task ID 2196869

closes odoo/odoo#48369

X-original-commit: 02ceb42e204be2b40b334b4e554eef6dfaffd228
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-03-25 15:51:25 +00:00
fja-odoo 124c3539aa [FIX] website: perf - prefetch access token to avoid extra request
Access_token has a restricted group, so it not fetched by defaut.

In our case, we know that after the first access to partner_id, that will fill
the cache without access_token, we will access access_token (so new query).

So we access first the access_token, to have only one request that fill the
cache with the access_token, and the partner_id used later.

Related to #47257
task-2211013

X-original-commit: 7dd69d10d00d5f4a7c12ec414d63f868a10683be
2020-03-19 15:37:46 +00:00
David Beguin a37a82cbcd [IMP] website: remove dead code in visitor management
This commit cleans visitor's code:
  * remove 'response' parameter that is not used anymore
    in _handle_website_page_visit method.
  * remove 'website_track_values' parameter that was not set anywhere anymore
    in the _create_visitor method.

Task ID: 2205541
PR #46339

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-03-03 16:38:48 +00:00
fja-odoo 7a000acffd [FIX] website: fix website vistor concurent update
When requesting multiple tracked content at the same time with the same
visitor concurrent updates happen.

The best way I got to consistently reproduce the issue is to open 2
tracked pages with chrome command line:
google-chrome http://pcodoo:8069/contactus http://pcodoo:8069/

The first tracked page will update the visitor and lock it.
When the second will try to create a track which has a FK referencing
the visitor PSQL will try to SELECT FOR KEY SHARE the visitor but it is
locked => Concurrent Update Error. Using FOR NO KEY UPDATE instead of
FOR UPDATE performs a weaker lock that will not block
SELECT FOR KEY SHARE. By doing that we garantee that we will not
Update/Delete the PK while we lock the record.

closes odoo/odoo#45491

Fixes: https://github.com/odoo/odoo/pull/38372
X-original-commit: 33d0f0bc6b4c84de61ad876311690f26476c32f9
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2020-02-17 12:43:47 +00:00
Thibault Delavallée 3a7b08e5cf [REF] website(_crm): improve code about contacting visitors
Purpose of this commit is to clean mail and SMS composer calls in website_crm
and website_crm_sms by separating composer preparation (context, values) from
customer preparation (check valid data exists, creating partner).

Indeed most of message composer code is based on records having a partner_id
correctly set, unless some templates are used that dynamically creates the
partner. SMS composer is more tolerant and check for phone / mobile numbers to
use.

By the way we make the action name translatable, because why not.

LINKS

Spotted when working on task ID 2056759 (remove crm.partner.binding mixin)
Community PR odoo/odoo#44970
Enterprise PR odoo/enterprise#8307
2020-02-13 15:29:40 +00:00
David Beguin c785373db1 [FIX] website: fix visitor _compute_time_statistics
This commit fixes the visitor's time_statistics computation. When creating a
new visitor, last connection datetime is not set, so it's not retrieved in the
search_read and crash at search_read_result[visitor.id].

This fix also speeds up and simplifies the time_statistics computation.
As time_connection_datetime is always set (for already created visitor) and in
the depends, no need to read values before looping, the data is already fetched
in memory. We can then use directly the value for each visitor in self.

Task ID: 2120464
PR #40199

closes odoo/odoo#43780

X-original-commit: 1f0c9f272ea5b6b7b891fcb8d00eb81e7fe33f81
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-01-22 15:17:14 +00:00
alt-odoo 4b0fdffe59 [FIX] website: display archived website visitors
When computing time statistics, we need to look for
archived website visitors also to avoid a KeyError
if we use the default 'Archived' filter.

closes odoo/odoo#39970

X-original-commit: fe4d9bd25de45f1748ea010c51c8871bb3d14b9a
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
2019-11-07 14:36:43 +00:00
Jeremy Kersten 3a7033463e [FIX] website: allow authenticate in json multidb
Before this commit launch a server with --db-filter that match at least 2 dbs name
Try to authenticate

You will have an error request is unbound when you try to access request.env

Now we retrieve the user from self instead of the request.

New test to ensure rpc authentication is tested.

Related to commit 245ef4b1

closes odoo/odoo#38969

X-original-commit: 4b3400c430bec7539aada0619fd203978daca2d8
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-10-17 15:35:11 +00:00
Nans Lefebvre dcca8ae272 [FIX] website: fix _update_visitor_last_visit concurrency issues
Install the website, install a second language.
Switch the language on the website: error 500.

The function opened a new cursor, to update website_visitor.
It did so at the end of the query dispatch.
However when switching the language of the website, the lang is written on the
website visitor. This is done at the flush, done at the end (exit) of the query.
This is done on the cursor that was used for all the transaction.
Therefore that write would systemically fail on a
ERROR: could not serialize access due to concurrent update

opw 2080986

closes odoo/odoo#38453

X-original-commit: cc88a36744dc3c2949c47e8b163e1de98f5dbd95
Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
2019-10-11 07:33:40 +00:00
Pierre Paridans 245ef4b0fd [FIX] website: check uid on request.env
Without this commit, connection with mobile app crash
since there are no uid set on the env.

_is_public_user expecting singleton.

closes odoo/odoo#37756

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-10-02 09:32:58 +00:00
fja-odoo 950f252ba6 [FIX] website: rename user_partner_id -> partner_id
It is just a partner_id not a user related field

task-2072877

closes odoo/odoo#37102

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-10-01 19:50:00 +00:00
fja-odoo 7d6479e175 [IMP] website, website_sale: Improve website tracking
The update of visit_count now uses website_track instead of
website_visitor_lastconnection for less complex query and better
precision.

The name of a visitor is now changed only if it has no partner linked
and the # is removed

The cookie was not reset when a new partner connects or if a partner
disconnects. Now a check is performed to ensure the cookie belongs to
the partner/public user.

Now website visitors that log in will be added to the previous
website visitor of the partner. This way we have a full history and only
one visitor per partner.

Now a partner is able to delete a recently viewed product from his
recently viewed product list.

task-2072877
2019-10-01 19:50:00 +00:00
fja-odoo fe1dddb1ec [FIX] website: allow visitor sort by last visit time
A visitor needs to be sorted by last visit datetime, to do so we need to
remove the temp table and ignore concurrent updates.

task-2072877
2019-10-01 19:49:46 +00:00
Martin Trigaux ade9341212 [IMP] website: do not use a default name for visitors
See 'Webiste Visitor (date)' as display name
Remove default value as a way to easily detect if somebody has already
a name or not

Note using the id in the display name is a bad (may not be set yet)
but is used knowlingly as a short way to differentiate 2 visitors.

Linked to task id: 2073714

closes odoo/odoo#37230

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2019-09-23 08:14:43 +00:00
Martin Trigaux 33dc3bd995 [REV] website: revert commit 5b9a81a2
Comparing on translated string does not work as two people in different language
won't get the same result in the name_get
2019-09-23 06:15:09 +00:00
David Beguin 7f485c8d10 [IMP] website, website_* : improve visitor kanban view
This commit review the design of the visitor kanban view.
There is now two style for kanban card.
Ungrouped : the card takes all the width of the screen. It's simulate a nice tree view.
Grouped : Same design as before. ('normal' kanban card)

Apply visitor kanban views redesign also in :
- website_livechat
- website_crm
- website_sms

Task ID: 2073714
PR #37081

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2019-09-20 09:40:26 +00:00
David Beguin 5b9a81a2c6 [IMP] website : increment visitor name to be identifiable
This commit aims to rename the visitor that has no lead and no res.partner
to 'Website Visitor #id'.
So that the visitors can be identified when, for example,
an operator talk with multiple visitors.

Task ID: 2073714
PR #37081
2019-09-20 08:55:38 +00:00
David Beguin 17e8402523 [IMP] website : store visitor timezone
In order to be able to send push notifications using recipients timezone,
the visitor timezone is now stored in DB.

The visitor timezone is only updated once, when found_visitor_timezone
cannot be found in localstorage. Once the timezone is updated,
found_visitor_timezone is added to localstorage.

Task ID : 1936643
PR #34973
2019-09-20 14:44:56 +00:00
David Beguin 73505303f8 [IMP] website : send mail to visitor linked to res.partner
This commit allows to send an email to a visitor
directly from the visitor form view if the visitor is linked a
res.partner that a valid email address

Task ID: 2056080
PR #36290
2019-09-17 14:12:20 +00:00
David Beguin 6f5abf933b [IMP] website,livechat : apply various imp and fix on visitor views
Applies various improvements:
  - Remove welcome message if chat request usecase.
  - If a visitor is online: line is green / if offline: line is red (in the list view)
  - Visitors list view: add first / last connection fields and remove time_since_last_action
  - Avoid useless leave notification if the livechat channel is empty

Fix
  - ACLS on website_visitor_page model (for im_livechat_group_user)
  - ACLS on website_visitor and website_visitor_page model (for sales_team.group_sale_salesman)
  - Update visitor lang if visitor change the website lang.
  - Create visitor twice when translated website (due to rerouting)
  - Avatar for visitor banner in discuss. (image_64 instead of old image_small)

Task ID: 2056080
PR #36290
2019-09-17 14:12:19 +00:00