[MERGE] crm_profiling: convert wizard to osv_memory
bzr revid: rco@openerp.com-20111213110120-1ft3qibvw54s9rkh
This commit is contained in:
commit
6d2b354577
|
@ -39,7 +39,7 @@ It also has been merged with the earlier CRM & SRM segmentation tool because the
|
|||
'website': 'http://www.openerp.com',
|
||||
'depends': ['base', 'crm'],
|
||||
'init_xml': [],
|
||||
'update_xml': ['security/ir.model.access.csv', 'crm_profiling_view.xml'],
|
||||
'update_xml': ['security/ir.model.access.csv', 'wizard/open_questionnaire_view.xml', 'crm_profiling_view.xml'],
|
||||
'demo_xml': ['crm_profiling_demo.xml'],
|
||||
'test': [
|
||||
#'test/process/profiling.yml', #TODO:It's not debuging because problem to write data for open.questionnaire from partner section.
|
||||
|
|
|
@ -159,30 +159,6 @@ class questionnaire(osv.osv):
|
|||
_name="crm_profiling.questionnaire"
|
||||
_description= "Questionnaire"
|
||||
|
||||
def build_form(self, cr, uid, data, context=None):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param data: Get Data
|
||||
@param context: A standard dictionary for contextual values """
|
||||
|
||||
query = """
|
||||
select name, id
|
||||
from crm_profiling_question
|
||||
where id in ( select question from profile_questionnaire_quest_rel where questionnaire = %s)"""
|
||||
res = cr.execute(query, (data['form']['questionnaire_name'],))
|
||||
result = cr.fetchall()
|
||||
quest_fields={}
|
||||
quest_form='''<?xml version="1.0"?>
|
||||
<form string="%s">''' % _('Questionnaire')
|
||||
for name, oid in result:
|
||||
quest_form = quest_form + '<field name="quest_form%d"/><newline/>' % (oid,)
|
||||
quest_fields['quest_form%d' % (oid,)] = {'string': name, 'type': 'many2one', \
|
||||
'relation': 'crm_profiling.answer', 'domain': [('question_id','=',oid)] }
|
||||
quest_form = quest_form + '''</form>'''
|
||||
return quest_form, quest_fields
|
||||
|
||||
_columns = {
|
||||
'name': fields.char("Questionnaire",size=128, required=True),
|
||||
'description':fields.text("Description", required=True),
|
||||
|
@ -210,25 +186,19 @@ class partner(osv.osv):
|
|||
"partner","answer","Answers"),
|
||||
}
|
||||
|
||||
def _questionnaire_compute(self, cr, uid, data, context=None):
|
||||
def _questionnaire_compute(self, cr, uid, answers, context=None):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param data: Get Data
|
||||
@param context: A standard dictionary for contextual values """
|
||||
|
||||
temp = []
|
||||
for x in data['form']:
|
||||
if x.startswith("quest_form") and data['form'][x] != 0 :
|
||||
temp.append(data['form'][x])
|
||||
|
||||
partner_id = context.get('active_id')
|
||||
query = "select answer from partner_question_rel where partner=%s"
|
||||
cr.execute(query, (data['id'],))
|
||||
cr.execute(query, (partner_id,))
|
||||
for x in cr.fetchall():
|
||||
temp.append(x[0])
|
||||
|
||||
self.write(cr, uid, [data['id']], {'answers_ids':[[6, 0, temp]]}, context=context)
|
||||
answers.append(x[0])
|
||||
self.write(cr, uid, [partner_id], {'answers_ids': [[6, 0, answers]]}, context=context)
|
||||
return {}
|
||||
|
||||
|
||||
|
|
|
@ -2,13 +2,6 @@
|
|||
<openerp>
|
||||
<data>
|
||||
|
||||
<wizard
|
||||
string="Using a questionnaire"
|
||||
model="crm_profiling.questionnaire"
|
||||
name="open_questionnaire"
|
||||
menu="False"
|
||||
id="wizard_open_questionnaire"/>
|
||||
|
||||
<record model="ir.actions.act_window" id="open_questionnaires">
|
||||
<field name="name">Questionnaires</field>
|
||||
<field name="res_model">crm_profiling.questionnaire</field>
|
||||
|
@ -140,7 +133,7 @@
|
|||
<notebook position="inside">
|
||||
<page string="Profiling">
|
||||
<button string="Use a questionnaire"
|
||||
name="%(wizard_open_questionnaire)d" type="action" colspan="1"
|
||||
name="%(action_open_questionnaire)d" type="action" colspan="1"
|
||||
icon="gtk-justify-fill" />
|
||||
<newline/>
|
||||
<field name="answers_ids" colspan="4" nolabel="1"/>
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
</data>
|
||||
</openerp>
|
|
@ -1,10 +1,69 @@
|
|||
- |
|
||||
I check segmentation which allows users to perform segmentation within partners.
|
||||
-
|
||||
I check segmentation which allows users to perform segmentation within partners
|
||||
and set the category according to question, so first compute questions(answers)
|
||||
scenario with parther and check that category set according to questions.
|
||||
I create a crm profiling question record.
|
||||
-
|
||||
!record {model: crm_profiling.question, id: crm_profiling_question_openerppartner0}:
|
||||
answers_ids:
|
||||
- name: 'no'
|
||||
name: OpenERP partner?
|
||||
-
|
||||
I create a crm profiling answer record.
|
||||
-
|
||||
!record {model: crm_profiling.answer, id: crm_profiling_answer_openerppartner0}:
|
||||
name: 'yes'
|
||||
question_id: crm_profiling_question_openerppartner0
|
||||
-
|
||||
I create Partner category Customers.
|
||||
-
|
||||
!record {model: res.partner.category, id: res_partner_category_customers0}:
|
||||
name: Customers
|
||||
- |
|
||||
I'm creating new partner "John" with his email "info@mycustomer.com".
|
||||
-
|
||||
!record {model: res.partner, id: res_partner_john0}:
|
||||
address:
|
||||
- city: Bruxelles
|
||||
country_id: base.be
|
||||
street: Rue des Palais 51, bte 33
|
||||
type: default
|
||||
zip: '1000'
|
||||
email: 'info@mycustomer.com'
|
||||
name: John
|
||||
category_id:
|
||||
- res_partner_category_customers0
|
||||
|
||||
-
|
||||
Define the answers and category to partner.
|
||||
-
|
||||
!python {model: res.partner}: |
|
||||
data ={'form': {'quest_form3': ref("partner_quality3"), 'quest_form2': ref("nb_employees2"),'quest_form1': ref("sector1"),'questionnaire_name': ref('questionnaire1')}, 'ids': [ref('base.res_partner_ericdubois0')], 'report_type': 'pdf', 'model': 'res.partner', 'id': ref('base.res_partner_ericdubois0')}
|
||||
data = self._questionnaire_compute(cr, uid, data, context)
|
||||
partner = self.browse(cr, uid, ref('base.res_partner_ericdubois0'))
|
||||
assert partner.category_id[0].id == ref("base.res_partner_category_17"), "Category not assign properly"
|
||||
data ={'form': {'questionnaire_name': ref('res_partner_john0')}, 'ids': [ref('res_partner_john0')], 'report_type': 'pdf', 'model': 'res.partner', 'id': ref('res_partner_john0')}
|
||||
context['active_id'] = ref('res_partner_john0')
|
||||
self._questionnaire_compute(cr, uid, [ref('crm_profiling_answer_openerppartner0')], context)
|
||||
- |
|
||||
I start by creating new Questionnaire.
|
||||
-
|
||||
!record {model: crm_profiling.questionnaire, id: crm_profiling_questionnaire_basequestionnaire0}:
|
||||
description: First questionnaire.
|
||||
name: Base questionnaire
|
||||
questions_ids:
|
||||
- crm_profiling.activity_sector
|
||||
- crm_profiling.nb_employees
|
||||
- crm_profiling.partner_level
|
||||
-
|
||||
I create a segmentation record.
|
||||
-
|
||||
!record {model: crm.segmentation, id: crm_segmentation_test1}:
|
||||
answer_yes:
|
||||
- crm_profiling_answer_openerppartner0
|
||||
categ_id: res_partner_category_customers0
|
||||
name: test
|
||||
parent_id: crm_profiling.crm_segmentation0
|
||||
profiling_active: true
|
||||
som_interval: 0.0
|
||||
- |
|
||||
I continue the process of segmentation.
|
||||
-
|
||||
!python {model: crm.segmentation}: |
|
||||
self.process_continue(cr, uid, [ref('crm_segmentation_test1')], start=False)
|
||||
|
||||
|
|
|
@ -18,50 +18,72 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import pooler
|
||||
import wizard
|
||||
from tools import UpdateableStr, UpdateableDict
|
||||
|
||||
_QUEST_FORM = UpdateableStr()
|
||||
_QUEST_FIELDS=UpdateableDict()
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
class open_questionnaire(wizard.interface):
|
||||
|
||||
def _questionnaire_compute(self, cr, uid, data, context):
|
||||
pooler.get_pool(cr.dbname).get(data['model'])._questionnaire_compute(cr, uid, data, context)
|
||||
return {}
|
||||
|
||||
|
||||
def build_form(self, cr, uid, data, context):
|
||||
quest_form, quest_fields = pooler.get_pool(cr.dbname).get('crm_profiling.questionnaire').build_form(cr, uid, data, context)
|
||||
_QUEST_FORM. __init__(quest_form)
|
||||
_QUEST_FIELDS.__init__(quest_fields)
|
||||
return{}
|
||||
|
||||
_questionnaire_choice_arch = '''<?xml version="1.0"?>
|
||||
<form string="Questionnaire">
|
||||
<field name="questionnaire_name"/>
|
||||
</form>'''
|
||||
|
||||
_questionnaire_choice_fields = {
|
||||
'questionnaire_name': {'string': 'Questionnaire name', 'type': 'many2one', 'relation': 'crm_profiling.questionnaire', 'required': True },
|
||||
class open_questionnaire_line(osv.osv_memory):
|
||||
_name = 'open.questionnaire.line'
|
||||
_rec_name = 'question_id'
|
||||
_columns = {
|
||||
'question_id': fields.many2one('crm_profiling.question','Question', required=True),
|
||||
'answer_id': fields.many2one('crm_profiling.answer', 'Answer'),
|
||||
'wizard_id': fields.many2one('open.questionnaire', 'Questionnaire'),
|
||||
}
|
||||
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {'type': 'form', 'arch': _questionnaire_choice_arch, 'fields': _questionnaire_choice_fields, 'state':[('end', 'Cancel','gtk-cancel'), ('open', 'Open Questionnaire','terp-camera_test')]}
|
||||
},
|
||||
'open': {
|
||||
'actions': [build_form],
|
||||
'result': {'type': 'form', 'arch':_QUEST_FORM, 'fields': _QUEST_FIELDS, 'state':[('end', 'Cancel','gtk-cancel'), ('compute', 'Save Data','terp-stock_format-scientific')]}
|
||||
},
|
||||
'compute': {
|
||||
'actions': [],
|
||||
'result': {'type': 'action', 'action': _questionnaire_compute, 'state':'end'}
|
||||
open_questionnaire_line()
|
||||
|
||||
class open_questionnaire(osv.osv_memory):
|
||||
_name = 'open.questionnaire'
|
||||
_columns = {
|
||||
'questionnaire_id': fields.many2one('crm_profiling.questionnaire', 'Questionnaire name'),
|
||||
'question_ans_ids': fields.one2many('open.questionnaire.line', 'wizard_id', 'Question / Answers'),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
if context is None: context = {}
|
||||
res = super(open_questionnaire, self).default_get(cr, uid, fields, context=context)
|
||||
questionnaire_id = context.get('questionnaire_id', False)
|
||||
if questionnaire_id and 'question_ans_ids' in fields:
|
||||
query = """
|
||||
select question as question_id from profile_questionnaire_quest_rel where questionnaire = %s"""
|
||||
cr.execute(query, (questionnaire_id,))
|
||||
result = cr.dictfetchall()
|
||||
res.update(question_ans_ids=result)
|
||||
return res
|
||||
|
||||
def questionnaire_compute(self, cr, uid, ids, context=None):
|
||||
""" Adds selected answers in partner form """
|
||||
model = context.get('active_model')
|
||||
answers = []
|
||||
if model == 'res.partner':
|
||||
data = self.browse(cr, uid, ids[0], context=context)
|
||||
for d in data.question_ans_ids:
|
||||
if d.answer_id:
|
||||
answers.append(d.answer_id.id)
|
||||
self.pool.get(model)._questionnaire_compute(cr, uid, answers, context=context)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
|
||||
def build_form(self, cr, uid, ids, context=None):
|
||||
""" Dynamically generates form according to selected questionnaire """
|
||||
models_data = self.pool.get('ir.model.data')
|
||||
result = models_data._get_id(cr, uid, 'crm_profiling', 'open_questionnaire_form')
|
||||
res_id = models_data.browse(cr, uid, result, context=context).res_id
|
||||
datas = self.browse(cr, uid, ids[0], context=context)
|
||||
context.update({'questionnaire_id': datas.questionnaire_id.id})
|
||||
|
||||
return {
|
||||
'name': _('Questionnaire'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'open.questionnaire',
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [(res_id,'form')],
|
||||
'target': 'new',
|
||||
'context': context
|
||||
}
|
||||
}
|
||||
|
||||
open_questionnaire('open_questionnaire')
|
||||
open_questionnaire()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
<?xml version="1.0" ?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_open_questionnaire_form" model="ir.ui.view">
|
||||
<field name="name">Open Questionnaires</field>
|
||||
<field name="model">open.questionnaire</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Questionnaires">
|
||||
<field name="questionnaire_id" required="1"/>
|
||||
<newline/>
|
||||
<separator string="" colspan="4"/>
|
||||
<group col="4" colspan="4">
|
||||
<group col="2" colspan="2"/>
|
||||
<button special="cancel" icon="gtk-cancel" string="Cancel"/>
|
||||
<button name="build_form" string="Open Questionnaire" icon="terp-camera_test" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="action_open_questionnaire">
|
||||
<field name="name">Open Questionnaire</field>
|
||||
<field name="res_model">open.questionnaire</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_open_questionnaire_form"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record id="open_questionnaire_form" model="ir.ui.view">
|
||||
<field name="name">open.questionnaire.form</field>
|
||||
<field name="model">open.questionnaire</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<separator colspan="4" string="Questionnaire"/>
|
||||
<field name="question_ans_ids" colspan="4" nolabel="1" mode="tree,form" width="550" height="200"/>
|
||||
<separator string="" colspan="4" />
|
||||
<label string="" colspan="2"/>
|
||||
<group col="2" colspan="2">
|
||||
<button icon='gtk-cancel' special="cancel" string="_Cancel" />
|
||||
<button name="questionnaire_compute" string="Save Data" icon="terp-stock_format-scientific" colspan="1" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_open_questionnaire_line_tree" model="ir.ui.view">
|
||||
<field name="name">open.questionnaire.line.list</field>
|
||||
<field name="model">open.questionnaire.line</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree editable="bottom" string="Questionnaire">
|
||||
<field name="question_id"/>
|
||||
<field name="answer_id" domain="[('question_id', '=', question_id)]"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_open_questionnaire_line_form" model="ir.ui.view">
|
||||
<field name="name">open.questionnaire.line.form</field>
|
||||
<field name="model">open.questionnaire.line</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Questionnaire">
|
||||
<field name="question_id"/>
|
||||
<field name="answer_id" domain="[('question_id', '=', question_id)]"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Questionnaire form view -->
|
||||
<!--<act_window
|
||||
context="{}"
|
||||
id="act_open_questionnaire"
|
||||
name="Using a Questionnaire"
|
||||
res_model="open.questionnaire"
|
||||
src_model="crm_profiling.questionnaire"
|
||||
view_id="view_open_questionnaire_form"
|
||||
target="new"
|
||||
view_mode="form"/>-->
|
||||
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue