From b23ce76595be5e42ccd5f6648a2aec9f1b9f092c Mon Sep 17 00:00:00 2001 From: smangukiya Date: Wed, 10 Aug 2016 17:09:58 +0530 Subject: [PATCH] IMP: support v7,v8 API and remove sql with ORM methods (#1) --- base_export_manager/models/res_users.py | 32 +++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/base_export_manager/models/res_users.py b/base_export_manager/models/res_users.py index c51534aec1a..2441dec9a9a 100644 --- a/base_export_manager/models/res_users.py +++ b/base_export_manager/models/res_users.py @@ -8,19 +8,21 @@ class ResUsers(models.Model): _inherit = 'res.users' - + + @api.v7 + def get_export_models(self, cr, uid): + return self.fetch_export_models(cr, uid) + + @api.v8 def get_export_models(self): - self.env.cr.execute("SELECT model " - "FROM ir_model " - "WHERE id IN (" - " SELECT distinct(model_id) " - " FROM ir_model_access " - " WHERE perm_export=TRUE AND group_id IN (" - " SELECT gid " - " FROM res_groups_users_rel " - " WHERE uid=%s" - " )" - ")", - (self.env.uid,)) - model_names = [r[0] for r in self.env.cr.fetchall()] - return model_names + uid = self.id or self.env.uid + return self.fetch_export_models(self.env.cr, uid) + + def fetch_export_models(self, cr, uid): + groups_id = [group.id for group in self.browse(cr, uid, uid).groups_id] + accessobj = self.pool['ir.model.access'] + accessobj_ids = accessobj.search(cr, uid, [('perm_export','=',True),('group_id','in',groups_id)]) + model_names = [access_obj.model_id.model for access_obj in accessobj.browse(cr, uid, accessobj_ids)] + #make distinct value in list + model_names = list(set(model_names)) + return model_names \ No newline at end of file