[MERGE] crm_profiling: convert wizard to osv_memory
bzr revid: rco@openerp.com-20111019144722-r3c1a62jp3cd5cpq
This commit is contained in:
commit
a520910bae
|
@ -39,7 +39,7 @@ It also has been merged with the earlier CRM & SRM segmentation tool because the
|
||||||
'website': 'http://www.openerp.com',
|
'website': 'http://www.openerp.com',
|
||||||
'depends': ['base', 'crm'],
|
'depends': ['base', 'crm'],
|
||||||
'init_xml': [],
|
'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'],
|
'demo_xml': ['crm_profiling_demo.xml'],
|
||||||
'test': ['test/test_crm_profiling.yml'],
|
'test': ['test/test_crm_profiling.yml'],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
|
|
|
@ -159,19 +159,19 @@ class questionnaire(osv.osv):
|
||||||
_name="crm_profiling.questionnaire"
|
_name="crm_profiling.questionnaire"
|
||||||
_description= "Questionnaire"
|
_description= "Questionnaire"
|
||||||
|
|
||||||
def build_form(self, cr, uid, data, context=None):
|
def build_form(self, cr, uid, questionnaire_id, context=None):
|
||||||
"""
|
"""
|
||||||
@param self: The object pointer
|
@param self: The object pointer
|
||||||
@param cr: the current row, from the database cursor,
|
@param cr: the current row, from the database cursor,
|
||||||
@param uid: the current user’s ID for security checks,
|
@param uid: the current user’s ID for security checks,
|
||||||
@param data: Get Data
|
@param data: Get Data
|
||||||
@param context: A standard dictionary for contextual values """
|
@param context: A standard dictionary for contextual values """
|
||||||
|
|
||||||
query = """
|
query = """
|
||||||
select name, id
|
select name, id
|
||||||
from crm_profiling_question
|
from crm_profiling_question
|
||||||
where id in ( select question from profile_questionnaire_quest_rel where questionnaire = %s)"""
|
where id in ( select question from profile_questionnaire_quest_rel where questionnaire = %s)"""
|
||||||
res = cr.execute(query, (data['form']['questionnaire_name'],))
|
res = cr.execute(query, (questionnaire_id,))
|
||||||
result = cr.fetchall()
|
result = cr.fetchall()
|
||||||
quest_fields={}
|
quest_fields={}
|
||||||
quest_form='''<?xml version="1.0"?>
|
quest_form='''<?xml version="1.0"?>
|
||||||
|
@ -180,7 +180,6 @@ class questionnaire(osv.osv):
|
||||||
quest_form = quest_form + '<field name="quest_form%d"/><newline/>' % (oid,)
|
quest_form = quest_form + '<field name="quest_form%d"/><newline/>' % (oid,)
|
||||||
quest_fields['quest_form%d' % (oid,)] = {'string': name, 'type': 'many2one', \
|
quest_fields['quest_form%d' % (oid,)] = {'string': name, 'type': 'many2one', \
|
||||||
'relation': 'crm_profiling.answer', 'domain': [('question_id','=',oid)] }
|
'relation': 'crm_profiling.answer', 'domain': [('question_id','=',oid)] }
|
||||||
quest_form = quest_form + '''</form>'''
|
|
||||||
return quest_form, quest_fields
|
return quest_form, quest_fields
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
|
@ -219,16 +218,16 @@ class partner(osv.osv):
|
||||||
@param context: A standard dictionary for contextual values """
|
@param context: A standard dictionary for contextual values """
|
||||||
|
|
||||||
temp = []
|
temp = []
|
||||||
for x in data['form']:
|
for x in context.get('fields'):
|
||||||
if x.startswith("quest_form") and data['form'][x] != 0 :
|
if x.startswith("quest_form") and data[x] != 0 :
|
||||||
temp.append(data['form'][x])
|
if data[x] and data[x][0]:
|
||||||
|
temp.append(data[x][0])
|
||||||
|
partner_id = context.get('active_id')
|
||||||
query = "select answer from partner_question_rel where partner=%s"
|
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():
|
for x in cr.fetchall():
|
||||||
temp.append(x[0])
|
temp.append(x[0])
|
||||||
|
self.write(cr, uid, [partner_id], {'answers_ids':[[6, 0, temp]]}, context=context)
|
||||||
self.write(cr, uid, [data['id']], {'answers_ids':[[6, 0, temp]]}, context=context)
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,6 @@
|
||||||
<openerp>
|
<openerp>
|
||||||
<data>
|
<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">
|
<record model="ir.actions.act_window" id="open_questionnaires">
|
||||||
<field name="name">Questionnaires</field>
|
<field name="name">Questionnaires</field>
|
||||||
<field name="res_model">crm_profiling.questionnaire</field>
|
<field name="res_model">crm_profiling.questionnaire</field>
|
||||||
|
@ -140,7 +133,7 @@
|
||||||
<notebook position="inside">
|
<notebook position="inside">
|
||||||
<page string="Profiling">
|
<page string="Profiling">
|
||||||
<button string="Use a questionnaire"
|
<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" />
|
icon="gtk-justify-fill" />
|
||||||
<newline/>
|
<newline/>
|
||||||
<field name="answers_ids" colspan="4" nolabel="1"/>
|
<field name="answers_ids" colspan="4" nolabel="1"/>
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<openerp>
|
|
||||||
<data>
|
|
||||||
</data>
|
|
||||||
</openerp>
|
|
|
@ -18,50 +18,72 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
import pooler
|
|
||||||
import wizard
|
|
||||||
from tools import UpdateableStr, UpdateableDict
|
|
||||||
|
|
||||||
_QUEST_FORM = UpdateableStr()
|
from osv import osv, fields
|
||||||
_QUEST_FIELDS=UpdateableDict()
|
from tools.translate import _
|
||||||
|
|
||||||
class open_questionnaire(wizard.interface):
|
class open_questionnaire(osv.osv_memory):
|
||||||
|
_name = 'open.questionnaire'
|
||||||
def _questionnaire_compute(self, cr, uid, data, context):
|
_columns = {
|
||||||
pooler.get_pool(cr.dbname).get(data['model'])._questionnaire_compute(cr, uid, data, context)
|
'questionnaire_id': fields.many2one('crm_profiling.questionnaire', 'Questionnaire name', required=True),
|
||||||
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 },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
states = {
|
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||||
'init': {
|
res = super(open_questionnaire, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
|
||||||
'actions': [],
|
if context.has_key('form') and context.has_key('fields'):
|
||||||
'result': {'type': 'form', 'arch': _questionnaire_choice_arch, 'fields': _questionnaire_choice_fields, 'state':[('end', 'Cancel','gtk-cancel'), ('open', 'Open Questionnaire','terp-camera_test')]}
|
field = {}
|
||||||
},
|
form = context.get('form')
|
||||||
'open': {
|
form += """
|
||||||
'actions': [build_form],
|
<newline/>
|
||||||
'result': {'type': 'form', 'arch':_QUEST_FORM, 'fields': _QUEST_FIELDS, 'state':[('end', 'Cancel','gtk-cancel'), ('compute', 'Save Data','terp-stock_format-scientific')]}
|
<separator string="" colspan="4"/>
|
||||||
},
|
<group col="4" colspan="4">
|
||||||
'compute': {
|
<group col="2" colspan="2"/>
|
||||||
'actions': [],
|
<button special="cancel" icon="gtk-cancel" string="Cancel"/>
|
||||||
'result': {'type': 'action', 'action': _questionnaire_compute, 'state':'end'}
|
<button name="questionnaire_compute" string="Save Data" icon="terp-stock_format-scientific" type="object"/>
|
||||||
|
</group>
|
||||||
|
</form>
|
||||||
|
"""
|
||||||
|
res['fields'] = context.get('fields')
|
||||||
|
for key, value in res['fields'].items():
|
||||||
|
field[key] = fields.many2one('crm_profiling.answer', value['string'])
|
||||||
|
self._columns.update(field)
|
||||||
|
res['arch'] = form
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def questionnaire_compute(self, cr, uid, ids, context=None):
|
||||||
|
""" Adds selected answers in partner form """
|
||||||
|
model = context.get('active_model')
|
||||||
|
if model == 'res.partner':
|
||||||
|
data = self.read(cr, uid, ids, context.get('fields').keys(), context=context)[0]
|
||||||
|
self.pool.get(model)._questionnaire_compute(cr, uid, data, 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')
|
||||||
|
questionnaire_id = self.browse(cr, uid, ids, context=context)[0].questionnaire_id.id
|
||||||
|
quest_form, quest_fields = self.pool.get('crm_profiling.questionnaire').build_form(cr, uid, questionnaire_id, context=context)
|
||||||
|
context.update({
|
||||||
|
'form': quest_form,
|
||||||
|
'fields': quest_fields
|
||||||
|
})
|
||||||
|
|
||||||
|
result = models_data._get_id(cr, uid, 'crm_profiling', 'view_open_questionnaire_form')
|
||||||
|
res_id = models_data.browse(cr, uid, result, context=context).res_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:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?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"/>
|
||||||
|
<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="target">new</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