99import json
1010import logging
1111import secrets
12+ from collections import defaultdict
1213
1314import requests
1415
@@ -54,6 +55,14 @@ class GlodoInstance(models.Model):
5455 help = "AES-256 shared secret for encrypted communication" ,
5556 )
5657
58+ partner_id = fields .Many2one (
59+ "res.partner" ,
60+ )
61+
62+ tag_ids = fields .Many2many (
63+ "glodo.instance.tag" ,
64+ )
65+
5766 database_ids = fields .One2many (
5867 "glodo.instance.database" ,
5968 "instance_id" ,
@@ -74,10 +83,16 @@ class GlodoInstance(models.Model):
7483 readonly = True ,
7584 )
7685
77- remote_user_count = fields .Integer (
86+ active_remote_user_count = fields .Integer (
87+ "Active Users" ,
88+ compute = "_compute_remote_user_count" ,
89+ store = True ,
90+ )
91+
92+ inactive_remote_user_count = fields .Integer (
93+ "Inactive Users" ,
7894 compute = "_compute_remote_user_count" ,
7995 store = True ,
80- readonly = True ,
8196 )
8297
8398 last_sync_date = fields .Datetime (
@@ -96,12 +111,29 @@ def _compute_database_count(self):
96111 for instance in self :
97112 instance .database_count = len (instance .database_ids )
98113
99- @api .depends ("database_ids.remote_user_ids" )
114+ @api .depends (
115+ "database_ids.remote_user_ids" , "database_ids.remote_user_ids.is_archived"
116+ )
100117 def _compute_remote_user_count (self ):
118+ if not self .ids :
119+ self .active_remote_user_count = self .inactive_remote_user_count = 0
120+ return
121+
122+ count_data = defaultdict (lambda : {"active" : 0 , "inactive" : 0 })
123+
124+ remote_user_data = self .env ["glodo.remote.user" ]._read_group (
125+ [("instance_id" , "in" , self .ids )],
126+ ["instance_id" , "is_archived" ],
127+ ["__count" ],
128+ )
129+
130+ for instance , is_archived , count in remote_user_data :
131+ key = "inactive" if is_archived else "active"
132+ count_data [instance .id ][key ] = count
133+
101134 for instance in self :
102- instance .remote_user_count = sum (
103- len (db .remote_user_ids ) for db in instance .database_ids
104- )
135+ instance .active_remote_user_count = count_data [instance .id ]["active" ]
136+ instance .inactive_remote_user_count = count_data [instance .id ]["inactive" ]
105137
106138 @api .model_create_multi
107139 def create (self , vals_list ):
@@ -352,6 +384,20 @@ def action_view_databases(self):
352384 "context" : {"default_instance_id" : self .id },
353385 }
354386
387+ def action_view_remote_users (self ):
388+ self .ensure_one ()
389+
390+ return {
391+ "type" : "ir.actions.act_window" ,
392+ "name" : self .env ._ ("Users - %(name)s" , name = self .name ),
393+ "res_model" : "glodo.remote.user" ,
394+ "view_mode" : "list,form" ,
395+ "domain" : [("instance_id" , "=" , self .id )],
396+ "context" : {
397+ "search_default_filter_active" : 1 ,
398+ },
399+ }
400+
355401 def action_view_action_logs (self ):
356402 """View action logs for this instance."""
357403 self .ensure_one ()
0 commit comments