[IMP] survey: wizard and template for survey.mail.compose.message; change user_id into partner_id
bzr revid: chm@openerp.com-20130213130926-1g014ib4w0bz0dqm
This commit is contained in:
@@ -34,7 +34,7 @@ question and according to that survey is done. Partners are also sent mails with
|
||||
user name and password for the invitation of the survey.
|
||||
""",
|
||||
'author': 'OpenERP SA',
|
||||
'depends': ['mail'],
|
||||
'depends': ['email_template'],
|
||||
'data': [
|
||||
'survey_report.xml',
|
||||
'survey_data.xml',
|
||||
@@ -47,7 +47,7 @@ user name and password for the invitation of the survey.
|
||||
'wizard/survey_print_answer.xml',
|
||||
'wizard/survey_browse_answer.xml',
|
||||
'wizard/survey_print.xml',
|
||||
'survey_send_invitation.xml'
|
||||
'wizard/survey_email_compose_message.xml',
|
||||
],
|
||||
'demo': ['survey_demo.xml'],
|
||||
'test': [
|
||||
|
||||
+23
-25
@@ -28,7 +28,6 @@ import os
|
||||
from openerp import netsvc, tools
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.translate import _
|
||||
import uuid # token = uuid.uuid4()
|
||||
|
||||
class survey_type(osv.osv):
|
||||
_name = 'survey.type'
|
||||
@@ -56,26 +55,26 @@ class survey(osv.osv):
|
||||
'date_close': fields.datetime('Survey Close Date', readonly=1),
|
||||
'max_response_limit': fields.integer('Maximum Answer Limit',
|
||||
help="Set to one if survey is answerable only once"),
|
||||
'response_user': fields.integer('Maximum Answer per User',
|
||||
help="Set to one if you require only one Answer per user"),
|
||||
'response_partner': fields.integer('Maximum Answer per partner',
|
||||
help="Set to one if you require only one Answer per partner"),
|
||||
'state': fields.selection([('open', 'Open'), ('cancel', 'Cancelled'),('close', 'Closed') ], 'Status', readonly=True),
|
||||
'responsible_id': fields.many2one('res.users', 'Responsible', help="User responsible for survey"),
|
||||
'tot_start_survey': fields.integer("Total Started Survey", readonly=1),
|
||||
'tot_comp_survey': fields.integer("Total Completed Survey", readonly=1),
|
||||
'note': fields.text('Description', size=128),
|
||||
'history': fields.one2many('survey.history', 'survey_id', 'History Lines', readonly=True),
|
||||
'users': fields.many2many('res.users', 'survey_users_rel', 'sid', 'uid', 'Users'),
|
||||
'partner_id': fields.many2many('res.partner', 'survey_partner_rel', 'sid', 'uid', 'Partners'),
|
||||
'send_response': fields.boolean('Email Notification on Answer'),
|
||||
'type': fields.many2one('survey.type', 'Type'),
|
||||
'color': fields.integer('Color Index'),
|
||||
'invited_user_ids': fields.many2many('res.users', 'survey_invited_user_rel', 'sid', 'uid', 'Invited User'),
|
||||
'invited_partner_ids': fields.many2many('res.partner', 'survey_invited_partner_rel', 'sid', 'uid', 'Invited User'),
|
||||
}
|
||||
_defaults = {
|
||||
'state': lambda * a: "open",
|
||||
'tot_start_survey': lambda * a: 0,
|
||||
'tot_comp_survey': lambda * a: 0,
|
||||
'send_response': lambda * a: 1,
|
||||
'response_user': lambda * a:1,
|
||||
'response_partner': lambda * a:1,
|
||||
'date_open': fields.datetime.now,
|
||||
}
|
||||
|
||||
@@ -244,7 +243,7 @@ class survey_history(osv.osv):
|
||||
_rec_name = 'date'
|
||||
_columns = {
|
||||
'survey_id': fields.many2one('survey', 'Survey'),
|
||||
'user_id': fields.many2one('res.users', 'User', readonly=True),
|
||||
'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
|
||||
'date': fields.datetime('Date started', readonly=1),
|
||||
}
|
||||
_defaults = {
|
||||
@@ -657,9 +656,9 @@ class survey_answer(osv.osv):
|
||||
'in_visible_answer_type': fields.boolean('Is Answer Type Invisible??')
|
||||
}
|
||||
_defaults = {
|
||||
# 'sequence' : lambda * a: 1,
|
||||
'type' : lambda * a: 'char',
|
||||
'in_visible_answer_type':_get_in_visible_answer_type,
|
||||
# 'sequence' : lambda * a: 1,
|
||||
'type' : lambda * a: 'char',
|
||||
'in_visible_answer_type':_get_in_visible_answer_type,
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
@@ -676,7 +675,7 @@ class survey_response(osv.osv):
|
||||
_columns = {
|
||||
'survey_id' : fields.many2one('survey', 'Survey', required=1, ondelete='cascade'),
|
||||
'date_create' : fields.datetime('Create Date', required=1),
|
||||
'user_id' : fields.many2one('res.users', 'User'),
|
||||
'partner_id' : fields.many2one('res.partner', 'Partner'),
|
||||
'response_type' : fields.selection([('manually', 'Manually'), ('link', 'Link')], \
|
||||
'Answer Type', required=1, readonly=1),
|
||||
'question_ids' : fields.one2many('survey.response.line', 'response_id', 'Answer'),
|
||||
@@ -691,10 +690,10 @@ class survey_response(osv.osv):
|
||||
def name_get(self, cr, uid, ids, context=None):
|
||||
if not len(ids):
|
||||
return []
|
||||
reads = self.read(cr, uid, ids, ['user_id','date_create'], context=context)
|
||||
reads = self.read(cr, uid, ids, ['partner_id','date_create'], context=context)
|
||||
res = []
|
||||
for record in reads:
|
||||
name = (record['user_id'] and record['user_id'][1] or '' )+ ' (' + record['date_create'].split('.')[0] + ')'
|
||||
name = (record['partner_id'] and record['partner_id'][1] or '' )+ ' (' + record['date_create'].split('.')[0] + ')'
|
||||
res.append((record['id'], name))
|
||||
return res
|
||||
|
||||
@@ -755,14 +754,13 @@ class survey_response_answer(osv.osv):
|
||||
|
||||
survey_response_answer()
|
||||
|
||||
class res_users(osv.osv):
|
||||
_inherit = "res.users"
|
||||
_name = "res.users"
|
||||
class res_partner(osv.osv):
|
||||
_inherit = "res.partner"
|
||||
_name = "res.partner"
|
||||
_columns = {
|
||||
'survey_id': fields.many2many('survey', 'survey_users_rel', 'uid', 'sid', 'Groups'),
|
||||
'survey_id': fields.many2many('survey', 'survey_partner_rel', 'uid', 'sid', 'Groups'),
|
||||
}
|
||||
|
||||
res_users()
|
||||
res_partner()
|
||||
|
||||
class survey_request(osv.osv):
|
||||
_name = "survey.request"
|
||||
@@ -770,7 +768,7 @@ class survey_request(osv.osv):
|
||||
_rec_name = 'date_deadline'
|
||||
_columns = {
|
||||
'date_deadline': fields.date("Deadline date"),
|
||||
'user_id': fields.many2one("res.users", "User"),
|
||||
'partner_id': fields.many2one("res.partner", "Partner"),
|
||||
'email': fields.char("Email", size=64),
|
||||
'survey_id': fields.many2one("survey", "Survey", required=1, ondelete='cascade'),
|
||||
'response': fields.many2one('survey.response', 'Answer'),
|
||||
@@ -796,11 +794,11 @@ class survey_request(osv.osv):
|
||||
self.write(cr, uid, ids, { 'state' : 'cancel'})
|
||||
return True
|
||||
|
||||
def on_change_user(self, cr, uid, ids, user_id, context=None):
|
||||
if user_id:
|
||||
user_obj = self.pool.get('res.users')
|
||||
user = user_obj.browse(cr, uid, user_id, context=context)
|
||||
return {'value': {'email': user.email}}
|
||||
def on_change_partner(self, cr, uid, ids, partner_id, context=None):
|
||||
if partner_id:
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
partner = partner_obj.browse(cr, uid, partner_id, context=context)
|
||||
return {'value': {'email': partner.email}}
|
||||
return {}
|
||||
|
||||
survey_request()
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
</group>
|
||||
<group>
|
||||
<field name="max_response_limit" attrs="{'readonly':[('state','=','close')]}"/>
|
||||
<field name="response_user" attrs="{'readonly':[('state','=','close')]}"/>
|
||||
<field name="response_partner" attrs="{'readonly':[('state','=','close')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook>
|
||||
@@ -215,7 +215,7 @@
|
||||
<field name="note" placeholder="Survey description..." attrs="{'readonly':[('state','=','close')]}"/>
|
||||
</page>
|
||||
<page string="Invited User">
|
||||
<field name="invited_user_ids" readonly="1"/>
|
||||
<field name="invited_partner_ids" readonly="1"/>
|
||||
</page>
|
||||
<page string="History">
|
||||
<group>
|
||||
@@ -231,11 +231,11 @@
|
||||
<field name="history" colspan="4">
|
||||
<tree string="History">
|
||||
<field name="date"/>
|
||||
<field name="user_id"/>
|
||||
<field name="partner_id"/>
|
||||
</tree>
|
||||
<form string="History">
|
||||
<field name="date"/>
|
||||
<field name="user_id"/>
|
||||
<field name="partner_id"/>
|
||||
</form>
|
||||
</field>
|
||||
</page>
|
||||
@@ -1016,7 +1016,7 @@
|
||||
<form string="Survey Answer">
|
||||
<field name="survey_id"/>
|
||||
<field name="date_create"/>
|
||||
<field name="user_id"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="response_type"/>
|
||||
<field name="question_ids" nolabel="1" colspan="4" />
|
||||
<field name="state"/>
|
||||
@@ -1031,7 +1031,7 @@
|
||||
<tree string="Survey Answer">
|
||||
<field name="survey_id"/>
|
||||
<field name="date_create"/>
|
||||
<field name="user_id"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="response_type"/>
|
||||
<field name="state"/>
|
||||
</tree>
|
||||
@@ -1110,7 +1110,7 @@
|
||||
<group class="oe_header">
|
||||
<field name="date_deadline"/>
|
||||
<field name="survey_id"/>
|
||||
<field name="user_id" on_change="on_change_user(user_id)"/>
|
||||
<field name="partner_id" on_change="on_change_partner(partner_id)"/>
|
||||
<field name="email"/>
|
||||
<field name="response" readonly="1"/>
|
||||
</group>
|
||||
@@ -1125,7 +1125,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Evaluation Plan Phase" colors="red:date_deadline<current_date">
|
||||
<field name="date_deadline"/>
|
||||
<field name="user_id"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="email"/>
|
||||
<field name="survey_id"/>
|
||||
<field name="response" />
|
||||
@@ -1144,11 +1144,11 @@
|
||||
<separator/>
|
||||
<filter icon="terp-emblem-important" string="Late" domain="[('date_deadline','<',current_date)]"/>
|
||||
<separator/>
|
||||
<filter string="My Survey(s)" icon="terp-personal" domain="[('user_id','=',uid)]"/>
|
||||
<filter string="My Survey(s)" icon="terp-personal" domain="[('partner_id','=',uid)]"/>
|
||||
<field name="survey_id" widget="selection"/>
|
||||
<field name="user_id"/>
|
||||
<field name="partner_id"/>
|
||||
<group expand="0" string="Group By...">
|
||||
<filter string="User" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
|
||||
<filter string="User" icon="terp-personal" domain="[]" context="{'group_by':'partner_id'}"/>
|
||||
<filter string="Survey" icon="terp-stock_align_left_24" domain="[]" context="{'group_by':'survey_id'}"/>
|
||||
<filter string="Status" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
|
||||
</group>
|
||||
@@ -1161,7 +1161,7 @@
|
||||
<field name="res_model">survey.request</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="domain">[('user_id','=',uid)]</field>
|
||||
<field name="domain">[('partner_id','=',uid)]</field>
|
||||
<field name="view_id" ref="survey_request_tree"></field>
|
||||
<field name="search_view_id" ref="survey_request_search"/>
|
||||
</record>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import survey_email_compose_message
|
||||
import survey_print_statistics
|
||||
import survey_print_answer
|
||||
import survey_browse_answer
|
||||
|
||||
@@ -41,19 +41,21 @@ class survey_question_wiz(osv.osv_memory):
|
||||
"""
|
||||
Fields View Get method :- generate the new view and display the survey pages of selected survey.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
print ""
|
||||
print ""
|
||||
print view_id, view_type, context, toolbar, submenu
|
||||
print view_id
|
||||
print view_type
|
||||
print context.get("survey_id", None)
|
||||
print context.get("survey_token", None)
|
||||
print ""
|
||||
print ""
|
||||
|
||||
if not view_id and not context.get('survey_id', None) and context.get('default_survey_id', None):
|
||||
context['survey_id'] = context['active_id'] = context.get('default_survey_id')
|
||||
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
|
||||
|
||||
surv_name_wiz = self.pool.get('survey.name.wiz')
|
||||
@@ -64,6 +66,7 @@ class survey_question_wiz(osv.osv_memory):
|
||||
sur_response_obj = self.pool.get('survey.response')
|
||||
que_col_head = self.pool.get('survey.question.column.heading')
|
||||
user_obj = self.pool.get('res.users')
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
mail_message = self.pool.get('mail.message')
|
||||
|
||||
if view_type in ['form']:
|
||||
@@ -125,13 +128,13 @@ class survey_question_wiz(osv.osv_memory):
|
||||
or not context.has_key('active')) and not sur_name_rec.page_no + 1:
|
||||
if sur_rec.state != "open" :
|
||||
raise osv.except_osv(_('Warning!'),_("You cannot answer because the survey is not open."))
|
||||
cr.execute('select count(id) from survey_history where user_id=%s\
|
||||
cr.execute('select count(id) from survey_history where partner_id=%s\
|
||||
and survey_id=%s', (uid,survey_id))
|
||||
res = cr.fetchone()[0]
|
||||
user_limit = survey_obj.browse(cr, uid, survey_id)
|
||||
user_limit = user_limit.response_user
|
||||
if user_limit and res >= user_limit:
|
||||
raise osv.except_osv(_('Warning!'),_("You cannot answer this survey more than %s times.") % (user_limit))
|
||||
partner_limit = survey_obj.browse(cr, uid, survey_id)
|
||||
partner_limit = partner_limit.response_partner
|
||||
if partner_limit and res >= partner_limit:
|
||||
raise osv.except_osv(_('Warning!'),_("You cannot answer this survey more than %s times.") % (partner_limit))
|
||||
|
||||
if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey and not sur_name_rec.page_no + 1:
|
||||
survey_obj.write(cr, uid, survey_id, {'state':'close', 'date_close':strftime("%Y-%m-%d %H:%M:%S")})
|
||||
@@ -181,7 +184,7 @@ class survey_question_wiz(osv.osv_memory):
|
||||
# TODO: l10n, cleanup this code to make it readable. Or template?
|
||||
xml_group = etree.SubElement(xml_form, 'group', {'col': '40', 'colspan': '4'})
|
||||
record = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']])
|
||||
etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr('Answer Of :- ' + record.user_id.name + ', Date :- ' + record.date_create.split('.')[0] )), 'align':"0.0"})
|
||||
etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr('Answer Of :- ' + record.partner_id.name + ', Date :- ' + record.date_create.split('.')[0] )), 'align':"0.0"})
|
||||
etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(" Answer :- " + str(context.get('response_no',0) + 1) +"/" + str(len(context.get('response_id',0))) )), 'align':"0.0"})
|
||||
if context.get('response_no',0) > 0:
|
||||
etree.SubElement(xml_group, 'button', {'colspan':"1",'icon':"gtk-go-back",'name':"action_forward_previous",'string': tools.ustr("Previous Answer"),'type':"object"})
|
||||
@@ -421,17 +424,17 @@ class survey_question_wiz(osv.osv_memory):
|
||||
file.close()
|
||||
os.remove(addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf")
|
||||
context.update({'response_id':response_id})
|
||||
user_email = user_obj.browse(cr, uid, uid, context).email
|
||||
partner_email = user_obj.browse(cr, uid, uid, context).partner_email.email
|
||||
resp_email = survey_data.responsible_id and survey_data.responsible_id.email or False
|
||||
|
||||
if user_email and resp_email:
|
||||
user_name = user_obj.browse(cr, uid, uid, context=context).name
|
||||
mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(user_name) + " has given the Response Of " + survey_data.title + " Survey.\nThe Response has been attached herewith.\n\n Thanks."
|
||||
if partner_email and resp_email:
|
||||
partner_name = partner_obj.browse(cr, uid, uid, context=context).name
|
||||
mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(partner_name) + " has given the Response Of " + survey_data.title + " Survey.\nThe Response has been attached herewith.\n\n Thanks."
|
||||
vals = {'state': 'outgoing',
|
||||
'subject': "Survey Answer Of " + user_name,
|
||||
'subject': "Survey Answer Of " + partner_name,
|
||||
'body_html': '<pre>%s</pre>' % mail,
|
||||
'email_to': [resp_email],
|
||||
'email_from': user_email}
|
||||
'email_from': partner_email}
|
||||
if attachments:
|
||||
vals['attachment_ids'] = [(0,0,{'name': a_name,
|
||||
'datas_fname': a_name,
|
||||
@@ -585,21 +588,22 @@ class survey_question_wiz(osv.osv_memory):
|
||||
res_ans_obj = self.pool.get('survey.response.answer')
|
||||
que_obj = self.pool.get('survey.question')
|
||||
sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False), [])
|
||||
partner_id = self.pool.get('res.users').browse(cr, uid, uid, context).partner_email.id
|
||||
response_id = 0
|
||||
|
||||
if not sur_name_read['response']:
|
||||
response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'user_id':uid, 'date_create':datetime.datetime.now(), 'survey_id' : context['survey_id']})
|
||||
response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'partner_id':partner_id, 'date_create':datetime.datetime.now(), 'survey_id' : context['survey_id']})
|
||||
surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'response' : tools.ustr(response_id)})
|
||||
else:
|
||||
response_id = int(sur_name_read['response'])
|
||||
|
||||
if response_id not in surv_all_resp_obj.search(cr, uid, []):
|
||||
response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'user_id':uid, 'date_create':datetime.datetime.now(), 'survey_id' : context.get('survey_id',False)})
|
||||
response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'partner_id':partner_id, 'date_create':datetime.datetime.now(), 'survey_id' : context.get('survey_id',False)})
|
||||
surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'response' : tools.ustr(response_id)})
|
||||
|
||||
#click first time on next button then increemnet on total start suvey
|
||||
if not safe_eval(sur_name_read['store_ans']):
|
||||
his_id = self.pool.get('survey.history').create(cr, uid, {'user_id': uid, \
|
||||
his_id = self.pool.get('survey.history').create(cr, uid, {'partner_id': partner_id, \
|
||||
'date': strftime('%Y-%m-%d %H:%M:%S'), 'survey_id': sur_name_read['survey_id'][0]})
|
||||
survey_id = sur_name_read['survey_id'][0]
|
||||
sur_rec = survey_obj.read(cr, uid, survey_id)
|
||||
|
||||
@@ -49,7 +49,7 @@ class survey_name_wiz(osv.osv_memory):
|
||||
res = super(survey_name_wiz, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False)
|
||||
if uid != 1:
|
||||
survey_obj = self.pool.get('survey')
|
||||
line_ids = survey_obj.search(cr, uid, [('invited_user_ids','in',uid)], context=context)
|
||||
line_ids = survey_obj.search(cr, uid, [('invited_partner_ids','in',uid)], context=context)
|
||||
domain = str([('id', 'in', line_ids)])
|
||||
doc = etree.XML(res['arch'])
|
||||
nodes = doc.xpath("//field[@name='survey_id']")
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" ?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!--Survey send invitation Email template -->
|
||||
<record id="email_template_survey" model="email.template">
|
||||
<field name="name">Survey - Send by Email</field>
|
||||
<field name="email_from">${object.responsible_id and object.responsible_id.company_id and object.responsible_id.company_id.email or object.responsible_id.email or ''}</field>
|
||||
<field name="subject">${object.title}</field>
|
||||
<field name="lang">${object.lang}</field>
|
||||
<field name="model_id" ref="model_survey"/>
|
||||
<field name="auto_delete" eval="True"/>
|
||||
<field name="body_html"><![CDATA[
|
||||
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
|
||||
<p>Hello,</p>
|
||||
<p>
|
||||
Would you please spent some of your time to fill-in our survey:
|
||||
<a href="#action=survey.action_answer_survey&active_id=${object.id}&token=__TOKEN__">${object.title}</a>
|
||||
</p>
|
||||
% if object.responsible_id:
|
||||
<p>Thank you for choosing ${object.responsible_id.company_id.name or 'us'}!</p>
|
||||
% endif
|
||||
<br/>
|
||||
</div>
|
||||
]]></field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user