summaryrefslogtreecommitdiff
path: root/addons/website/models/res_users.py
diff options
context:
space:
mode:
authorOdoo's Mergebot <robodoo@odoo.com>2020-07-22 11:45:03 +0200
committerGitHub <noreply@github.com>2020-07-22 11:45:03 +0200
commitaffa40bc21db5bc077ff41244f4db649cdb147a2 (patch)
tree843e55bbc91f45aa0c7f0f90868e50231d484f00 /addons/website/models/res_users.py
parent3beb4545c4599469eff77a247db12b630cace754 (diff)
parent8ae4544b76665beb23db60b58b9a1cd4a4d9c5fc (diff)
[FW][MERGE] website: improve visitor synchronization and tests
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. Make tests independent from existing database data, notably existing visitors. Currently if any visitor is present in db tests crash as they are badly designed. 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. Add anchor methods to somehow merge visitors and update partner linked to visitors and their sub records. 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. 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. See sub commits for more details 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 odoo/odoo#54036 closes odoo/odoo#54078 Forward-port-of: odoo/odoo#54036 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/website/models/res_users.py')
-rw-r--r--addons/website/models/res_users.py37
1 files changed, 22 insertions, 15 deletions
diff --git a/addons/website/models/res_users.py b/addons/website/models/res_users.py
index 060d5e7cc14..d64f94db6b4 100644
--- a/addons/website/models/res_users.py
+++ b/addons/website/models/res_users.py
@@ -68,26 +68,33 @@ class ResUsers(models.Model):
@classmethod
def authenticate(cls, db, login, password, user_agent_env):
- """ Override to link the logged in user's res.partner to website.visitor """
+ """ Override to link the logged in user's res.partner to website.visitor.
+ If both a request-based visitor and a user-based visitor exist we try
+ to update them (have same partner_id), and move sub records to the main
+ visitor (user one). Purpose is to try to keep a main visitor with as
+ much sub-records (tracked pages, leads, ...) as possible. """
uid = super(ResUsers, cls).authenticate(db, login, password, user_agent_env)
if uid:
with cls.pool.cursor() as cr:
env = api.Environment(cr, uid, {})
visitor_sudo = env['website.visitor']._get_visitor_from_request()
if visitor_sudo:
- partner = env.user.partner_id
- partner_visitor = env['website.visitor'].with_context(active_test=False).sudo().search([('partner_id', '=', partner.id)])
- if partner_visitor and partner_visitor.id != visitor_sudo.id:
- # Link history to older Visitor and delete the newest
- visitor_sudo.website_track_ids.write({'visitor_id': partner_visitor.id})
- visitor_sudo.unlink()
- # If archived (most likely by the cron for inactivity reasons), reactivate the partner's visitor
- if not partner_visitor.active:
- partner_visitor.write({'active': True})
+ user_partner = env.user.partner_id
+ other_user_visitor_sudo = env['website.visitor'].with_context(active_test=False).sudo().search(
+ [('partner_id', '=', user_partner.id), ('id', '!=', visitor_sudo.id)],
+ order='last_connection_datetime DESC',
+ ) # current 13.3 state: 1 result max as unique visitor / partner
+ if other_user_visitor_sudo:
+ visitor_main = other_user_visitor_sudo[0]
+ other_visitors = other_user_visitor_sudo[1:] # normally void
+ (visitor_sudo + other_visitors)._link_to_visitor(visitor_main, keep_unique=True)
+ visitor_main.name = user_partner.name
+ visitor_main.active = True
+ visitor_main._update_visitor_last_visit()
else:
- vals = {
- 'partner_id': partner.id,
- 'name': partner.name
- }
- visitor_sudo.write(vals)
+ if visitor_sudo.partner_id != user_partner:
+ visitor_sudo._link_to_partner(
+ user_partner,
+ update_values={'partner_id': user_partner.id})
+ visitor_sudo._update_visitor_last_visit()
return uid