[ADD/IMP] New Field to Survey and Improved Survey / User can see only those Survey for which user in invited
bzr revid: jam@tinyerp.com-20101015070230-y7yujyil6mkii3vk
This commit is contained in:
@@ -68,6 +68,7 @@ class survey(osv.osv):
|
||||
'users': fields.many2many('res.users', 'survey_users_rel', 'sid', 'uid', 'Users'),
|
||||
'send_response': fields.boolean('E-mail Notification on Answer'),
|
||||
'type': fields.many2one('survey.type', 'Type'),
|
||||
'invited_user_ids': fields.many2many('res.users', 'survey_invited_user_rel', 'sid', 'uid', 'Invited User'),
|
||||
}
|
||||
_defaults = {
|
||||
'state': lambda * a: "draft",
|
||||
|
||||
@@ -206,6 +206,9 @@
|
||||
<separator colspan="4" string="Survey Details"/>
|
||||
<field name="note" colspan="4" nolabel="1"/>
|
||||
</page>
|
||||
<page string="Invited User">
|
||||
<field name="invited_user_ids" nolabel="1" readonly="1"/>
|
||||
</page>
|
||||
<page string="History">
|
||||
<field name="date_open" select="1"/>
|
||||
<field name="date_close"/>
|
||||
|
||||
@@ -62,9 +62,20 @@ class survey_name_wiz(osv.osv_memory):
|
||||
for sur in surv_obj.browse(cr, uid, [context.get('survey_id',False)]):
|
||||
result.append((sur.id, sur.title))
|
||||
return result
|
||||
survey_user_group_id = self.pool.get('res.groups').search(cr, uid, [('name', '=', 'Survey / User')])
|
||||
group_id = self.pool.get('res.groups').search(cr, uid, [('name', 'in', ('Tools / Manager','Tools / User','Survey / User'))])
|
||||
user_obj = self.pool.get('res.users')
|
||||
user_rec = user_obj.read(cr, uid, uid)
|
||||
if survey_user_group_id:
|
||||
if survey_user_group_id == user_rec['groups_id']:
|
||||
for sur in surv_obj.browse(cr, uid, surv_obj.search(cr, uid, [])):
|
||||
if sur.state == 'open':
|
||||
u_list = []
|
||||
for use in sur.invited_user_ids:
|
||||
u_list.append(use.id)
|
||||
if uid in u_list:
|
||||
result.append((sur.id, sur.title))
|
||||
return result
|
||||
for sur in surv_obj.browse(cr, uid, surv_obj.search(cr, uid, [])):
|
||||
if sur.state == 'open':
|
||||
res = False
|
||||
|
||||
@@ -113,7 +113,13 @@ class survey_send_invitation(osv.osv_memory):
|
||||
error = ""
|
||||
res_user = ""
|
||||
user_exists = False
|
||||
new_user = []
|
||||
attachments = []
|
||||
current_sur = survey_ref.browse(cr, uid, context.get('active_id'), context=context)
|
||||
exist_user = current_sur.invited_user_ids
|
||||
if exist_user:
|
||||
for use in exist_user:
|
||||
new_user.append(use.id)
|
||||
for id in survey_ref.browse(cr, uid, survey_ids):
|
||||
report = self.create_report(cr, uid, [id.id], 'report.survey.form', id.title)
|
||||
file = open(tools.config['addons_path'] + '/survey/report/' + id.title +".pdf")
|
||||
@@ -134,6 +140,8 @@ class survey_send_invitation(osv.osv_memory):
|
||||
continue
|
||||
user = user_ref.search(cr, uid, [('login', "=", addr.email)])
|
||||
if user:
|
||||
if user[0] not in new_user:
|
||||
new_user.append(user[0])
|
||||
user = user_ref.browse(cr, uid, user[0])
|
||||
user_ref.write(cr, uid, user.id, {'survey_id':[[6, 0, survey_ids]]})
|
||||
mail = record['mail']%{'login':addr.email, 'passwd':user.password, \
|
||||
@@ -172,11 +180,17 @@ class survey_send_invitation(osv.osv_memory):
|
||||
'survey_id': [[6, 0, survey_ids]]
|
||||
}
|
||||
user = user_ref.create(cr, uid, res_data)
|
||||
if user not in new_user:
|
||||
new_user.append(user)
|
||||
created+= "- %s (Login: %s, Password: %s)\n" % (addr.name or 'Unknown',\
|
||||
addr.email, passwd)
|
||||
else:
|
||||
error+= "- %s (Login: %s, Password: %s)\n" % (addr.name or 'Unknown',\
|
||||
addr.email, passwd)
|
||||
|
||||
new_vals = {}
|
||||
new_vals.update({'invited_user_ids':[[6,0,new_user]]})
|
||||
survey_ref.write(cr, uid, context.get('active_id'),new_vals)
|
||||
note= ""
|
||||
if created:
|
||||
note += 'Created users:\n%s\n\n' % (created)
|
||||
|
||||
Reference in New Issue
Block a user