Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] shopinvader: store last_login_time #1539

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shopinvader/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Shopinvader",
"summary": "Shopinvader",
"version": "14.0.5.24.13",
"version": "14.0.5.25.0",
"category": "e-commerce",
"website": "https://github.com/shopinvader/odoo-shopinvader",
"author": "Akretion",
Expand Down
11 changes: 11 additions & 0 deletions shopinvader/migrations/14.0.5.25.0/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2022 ACSONE SA/NV (<http://acsone.eu>)
# 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")
1 change: 1 addition & 0 deletions shopinvader/models/shopinvader_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(readonly=True)

def _compute_is_shopinvader_active_depends(self):
return ()
Expand Down
3 changes: 2 additions & 1 deletion shopinvader/services/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Simone Orsi <[email protected]>
# 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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions shopinvader/tests/test_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions shopinvader/views/shopinvader_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
groups="base.group_multi_company"
/>
<field name="create_date" readonly="1" />
<field name="last_login_time" />
<field name="sync_date" />
</group>
<group name="record">
Expand Down Expand Up @@ -50,6 +51,7 @@
<field name="backend_id" />
<field name="external_id" />
<field name="create_date" readonly="1" />
<field name="last_login_time" />
<field
name="company_id"
widget="selection"
Expand Down Expand Up @@ -84,6 +86,18 @@
context="{'group_by':'parent_id'}"
/>
</group>
<group string="Login time">
<filter
name="filter_login_never"
string="Never logged-in"
domain="[('last_login_time', '=', False)]"
/>
<filter
name="filter_login_last_month"
string="No login in a month"
domain="[('last_login_time', '&lt;=', (context_today() + relativedelta(months=-1)).strftime('%Y-%m-%d'))]"
/>
</group>
</search>
</field>
</record>
Expand Down
Loading