Skip to content

Commit c83e4f5

Browse files
smangukiyajcadhoc
smangukiya
authored andcommitted
IMP: support v7,v8 API and remove sql with ORM methods (#1)
1 parent 57583fb commit c83e4f5

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

base_export_manager/models/res_users.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@
88

99
class ResUsers(models.Model):
1010
_inherit = 'res.users'
11-
11+
12+
@api.v7
13+
def get_export_models(self, cr, uid):
14+
return self.fetch_export_models(cr, uid)
15+
16+
@api.v8
1217
def get_export_models(self):
13-
self.env.cr.execute("SELECT model "
14-
"FROM ir_model "
15-
"WHERE id IN ("
16-
" SELECT distinct(model_id) "
17-
" FROM ir_model_access "
18-
" WHERE perm_export=TRUE AND group_id IN ("
19-
" SELECT gid "
20-
" FROM res_groups_users_rel "
21-
" WHERE uid=%s"
22-
" )"
23-
")",
24-
(self.env.uid,))
25-
model_names = [r[0] for r in self.env.cr.fetchall()]
26-
return model_names
18+
uid = self.id or self.env.uid
19+
return self.fetch_export_models(self.env.cr, uid)
20+
21+
def fetch_export_models(self, cr, uid):
22+
groups_id = [group.id for group in self.browse(cr, uid, uid).groups_id]
23+
accessobj = self.pool['ir.model.access']
24+
accessobj_ids = accessobj.search(cr, uid, [('perm_export','=',True),('group_id','in',groups_id)])
25+
model_names = [access_obj.model_id.model for access_obj in accessobj.browse(cr, uid, accessobj_ids)]
26+
#make distinct value in list
27+
model_names = list(set(model_names))
28+
return model_names

0 commit comments

Comments
 (0)