diff --git a/fusion_plating/fusion_plating_shopfloor/models/res_users.py b/fusion_plating/fusion_plating_shopfloor/models/res_users.py index 61182f95..352f6ce3 100644 --- a/fusion_plating/fusion_plating_shopfloor/models/res_users.py +++ b/fusion_plating/fusion_plating_shopfloor/models/res_users.py @@ -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. diff --git a/fusion_plating/fusion_plating_shopfloor/views/res_users_views.xml b/fusion_plating/fusion_plating_shopfloor/views/res_users_views.xml index f5200f05..8543a071 100644 --- a/fusion_plating/fusion_plating_shopfloor/views/res_users_views.xml +++ b/fusion_plating/fusion_plating_shopfloor/views/res_users_views.xml @@ -55,4 +55,30 @@ + + + res.users.form.tablet.event.smart.button + res.users + + + + + + + +