feat(shopfloor): per-user 7-day tablet event smart button

Owner-only smart button on res.users form. Click opens the audit log
filtered to that user (both user_id and attempted_user_id, so
failed unlock attempts against a tile show up too).

Compute is non-stored: search_count on the audit model per user on
demand. Sudo'd because the audit model has Owner-only ACL — the
compute fires for the form-viewing user (Owner) who would see the
results anyway via the menu.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-05-24 13:34:45 -04:00
parent b26fa13044
commit 2a93ece4ba
2 changed files with 59 additions and 0 deletions

View File

@@ -140,6 +140,39 @@ class ResUsers(models.Model):
'target': 'new',
}
x_fc_tablet_event_count_7d = fields.Integer(
string='Tablet Events (7d)',
compute='_compute_tablet_event_count_7d',
store=False,
)
def _compute_tablet_event_count_7d(self):
from datetime import timedelta
cutoff = fields.Datetime.now() - timedelta(days=7)
for user in self:
user.x_fc_tablet_event_count_7d = self.env[
'fp.tablet.session.event'
].sudo().search_count([
'|',
('user_id', '=', user.id),
('attempted_user_id', '=', user.id),
('create_date', '>=', cutoff),
])
def action_view_tablet_events(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': _('Tablet Events: %s') % self.name,
'res_model': 'fp.tablet.session.event',
'view_mode': 'list,form',
'domain': [
'|',
('user_id', '=', self.id),
('attempted_user_id', '=', self.id),
],
}
def _check_credentials(self, credential, env):
"""Custom auth manager: accept `type='fp_tablet_pin'` credential.