From 4b9720abe5399f5f04758b3a936a82b63166e474 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Tue, 14 May 2024 15:37:55 +0200 Subject: [PATCH] shopinvader: store last_login_time Simply store the last login timestamp when /sign_in is called. --- shopinvader/__manifest__.py | 2 +- shopinvader/migrations/14.0.5.25.0/pre-migrate.py | 11 +++++++++++ shopinvader/models/shopinvader_partner.py | 1 + shopinvader/services/customer.py | 3 ++- shopinvader/tests/test_customer.py | 2 ++ shopinvader/views/shopinvader_partner_view.xml | 13 +++++++++++++ 6 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 shopinvader/migrations/14.0.5.25.0/pre-migrate.py diff --git a/shopinvader/__manifest__.py b/shopinvader/__manifest__.py index ffb27adcc2..b4f26bd204 100644 --- a/shopinvader/__manifest__.py +++ b/shopinvader/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Shopinvader", "summary": "Shopinvader", - "version": "14.0.5.24.12", + "version": "14.0.5.25.0", "category": "e-commerce", "website": "https://github.com/shopinvader/odoo-shopinvader", "author": "Akretion", diff --git a/shopinvader/migrations/14.0.5.25.0/pre-migrate.py b/shopinvader/migrations/14.0.5.25.0/pre-migrate.py new file mode 100644 index 0000000000..40e1b944a8 --- /dev/null +++ b/shopinvader/migrations/14.0.5.25.0/pre-migrate.py @@ -0,0 +1,11 @@ +# Copyright 2022 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tools import sql + + +def migrate(cr, version): + if not version or sql.column_exists(cr, "shopinvader_partner", "last_login_time"): + return + # Pre-create new column + sql.create_column(cr, "shopinvader_partner", "last_login_time", "timestamp") diff --git a/shopinvader/models/shopinvader_partner.py b/shopinvader/models/shopinvader_partner.py index b38e15e2aa..5b91bbdca5 100644 --- a/shopinvader/models/shopinvader_partner.py +++ b/shopinvader/models/shopinvader_partner.py @@ -36,6 +36,7 @@ class ShopinvaderPartner(models.Model): # Having the same field on both models allows to use simple conditions to check. # The compute methods offers a hook to modify the behavior. is_shopinvader_active = fields.Boolean(compute="_compute_is_shopinvader_active") + last_login_time = fields.Datetime() def _compute_is_shopinvader_active_depends(self): return () diff --git a/shopinvader/services/customer.py b/shopinvader/services/customer.py index 263242e69e..81ffce7072 100644 --- a/shopinvader/services/customer.py +++ b/shopinvader/services/customer.py @@ -4,7 +4,7 @@ # Simone Orsi # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # pylint: disable=consider-merging-classes-inherited,method-required-super -from odoo import _ +from odoo import _, fields from odoo.exceptions import UserError from odoo.addons.component.core import Component @@ -56,6 +56,7 @@ def update(self, _id, **params): return self.get() def sign_in(self, **params): + self.invader_partner.last_login_time = fields.Datetime.now() return self._assign_cart_and_get_store_cache() # The following method are 'private' and should be never never NEVER call diff --git a/shopinvader/tests/test_customer.py b/shopinvader/tests/test_customer.py index 54d3c0e6c6..b630f1fcd2 100644 --- a/shopinvader/tests/test_customer.py +++ b/shopinvader/tests/test_customer.py @@ -110,8 +110,10 @@ def test_sign_in_no_create_cart(self): SaleOrder.search(sale_domain).unlink() invader_partner = partner._get_invader_partner(self.backend) + self.assertFalse(invader_partner.last_login_time) self.service._load_partner_work_context(invader_partner) self.service.sign_in() + self.assertTrue(invader_partner.last_login_time) self.assertFalse(SaleOrder.search(sale_domain)) def test_update_customer(self): diff --git a/shopinvader/views/shopinvader_partner_view.xml b/shopinvader/views/shopinvader_partner_view.xml index 6eb81aff88..93daf71b9d 100644 --- a/shopinvader/views/shopinvader_partner_view.xml +++ b/shopinvader/views/shopinvader_partner_view.xml @@ -57,6 +57,7 @@ optional="show" /> + @@ -84,6 +85,18 @@ context="{'group_by':'parent_id'}" /> + + + +