diff --git a/addons/crm_profiling/__openerp__.py b/addons/crm_profiling/__openerp__.py
index 19f5615ee78..fdc85ba3d4d 100644
--- a/addons/crm_profiling/__openerp__.py
+++ b/addons/crm_profiling/__openerp__.py
@@ -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.
diff --git a/addons/crm_profiling/crm_profiling.py b/addons/crm_profiling/crm_profiling.py
index 59137966da0..587ddbe0b52 100644
--- a/addons/crm_profiling/crm_profiling.py
+++ b/addons/crm_profiling/crm_profiling.py
@@ -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='''
-
'''
- 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 {}
diff --git a/addons/crm_profiling/crm_profiling_view.xml b/addons/crm_profiling/crm_profiling_view.xml
index 258de2e4e2d..a54d3d4b0a9 100644
--- a/addons/crm_profiling/crm_profiling_view.xml
+++ b/addons/crm_profiling/crm_profiling_view.xml
@@ -2,13 +2,6 @@
-
-
Questionnairescrm_profiling.questionnaire
@@ -140,7 +133,7 @@
diff --git a/addons/crm_profiling/crm_profiling_wizard.xml b/addons/crm_profiling/crm_profiling_wizard.xml
deleted file mode 100644
index 39d436a6bd9..00000000000
--- a/addons/crm_profiling/crm_profiling_wizard.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/addons/crm_profiling/test/process/profiling.yml b/addons/crm_profiling/test/process/profiling.yml
index 91c48410f8d..99fe2da1733 100644
--- a/addons/crm_profiling/test/process/profiling.yml
+++ b/addons/crm_profiling/test/process/profiling.yml
@@ -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)
+
diff --git a/addons/crm_profiling/wizard/open_questionnaire.py b/addons/crm_profiling/wizard/open_questionnaire.py
index 91b82a02d1a..b13c67640fc 100644
--- a/addons/crm_profiling/wizard/open_questionnaire.py
+++ b/addons/crm_profiling/wizard/open_questionnaire.py
@@ -18,50 +18,72 @@
# along with this program. If not, see .
#
##############################################################################
-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 = '''
- '''
-
- _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:
diff --git a/addons/crm_profiling/wizard/open_questionnaire_view.xml b/addons/crm_profiling/wizard/open_questionnaire_view.xml
new file mode 100644
index 00000000000..88955f43af4
--- /dev/null
+++ b/addons/crm_profiling/wizard/open_questionnaire_view.xml
@@ -0,0 +1,86 @@
+
+
+
+
+
+ Open Questionnaires
+ open.questionnaire
+ form
+
+
+
+
+
+
+ Open Questionnaire
+ open.questionnaire
+ form
+ form
+
+ new
+
+
+
+ open.questionnaire.form
+ open.questionnaire
+ form
+
+
+
+
+
+
+ open.questionnaire.line.list
+ open.questionnaire.line
+ tree
+
+
+
+
+
+
+
+
+
+ open.questionnaire.line.form
+ open.questionnaire.line
+ form
+
+
+
+
+
+
+
+
+
+