6
27
def test_prof(self, cr, uid, prof_id, pid, answers_ids):
7
28
#return True if the partner pid fetch the profile rule prof_id
8
ids_to_check = pooler.get_pool(cr.dbname).get('segmentation.profile').get_parents(cr, uid, [prof_id])
9
[yes_answers, no_answers] = pooler.get_pool(cr.dbname).get('segmentation.profile').get_answers(cr, uid, ids_to_check)
11
for y_ans in yes_answers:
12
if y_ans not in answers_ids:
16
for ans in answers_ids:
29
ids_to_check = pooler.get_pool(cr.dbname).get('segmentation.profile').get_parents(cr, uid, [prof_id])
30
[yes_answers, no_answers] = pooler.get_pool(cr.dbname).get('segmentation.profile').get_answers(cr, uid, ids_to_check)
32
for y_ans in yes_answers:
33
if y_ans not in answers_ids:
37
for ans in answers_ids:
25
46
def _recompute_profiles(self, cr, uid, pid, answers_ids):
30
from segmentation_profile
33
for prof_id in cr.fetchall():
34
if test_prof(self, cr, uid, prof_id[0], pid, answers_ids):
51
from segmentation_profile
54
for prof_id in cr.fetchall():
55
if test_prof(self, cr, uid, prof_id[0], pid, answers_ids):
38
59
class question(osv.osv):
39
_name="segmentation.question"
40
_description= "Question"
42
'name': fields.char("Question",size=128, required=True),
43
'answers_ids': fields.one2many("segmentation.answer","question_id","Avalaible answers",),
60
_name="segmentation.question"
61
_description= "Question"
63
'name': fields.char("Question",size=128, required=True),
64
'answers_ids': fields.one2many("segmentation.answer","question_id","Avalaible answers",),
48
69
class answer(osv.osv):
49
_name="segmentation.answer"
52
"name": fields.char("Answer",size=128, required=True),
53
"question_id": fields.many2one('segmentation.question',"Question"),
70
_name="segmentation.answer"
73
"name": fields.char("Answer",size=128, required=True),
74
"question_id": fields.many2one('segmentation.question',"Question"),
58
79
class questionnaire(osv.osv):
59
_name="segmentation.questionnaire"
60
_description= "Questionnaire"
62
'name': fields.char("Questionnaire",size=128, required=True),
63
'description':fields.text("Description", required=True),
64
'questions_ids': fields.many2many('segmentation.question','profile_questionnaire_quest_rel','questionnaire', 'question', "Questions"),
80
_name="segmentation.questionnaire"
81
_description= "Questionnaire"
83
'name': fields.char("Questionnaire",size=128, required=True),
84
'description':fields.text("Description", required=True),
85
'questions_ids': fields.many2many('segmentation.question','profile_questionnaire_quest_rel','questionnaire', 'question', "Questions"),
69
90
class profile(osv.osv):
71
def get_answers(self, cr, uid, ids):
73
select distinct(answer)
74
from profile_question_yes_rel
75
where profile in (%s)"""% ','.join([str(i) for i in ids ])
78
ans_yes = [x[0] for x in cr.fetchall()]
81
select distinct(answer)
82
from profile_question_no_rel
83
where profile in (%s)"""% ','.join([str(i) for i in ids ])
86
ans_no = [x[0] for x in cr.fetchall()]
88
return [ans_yes, ans_no]
90
def get_parents(self, cr, uid, ids):
93
select distinct(parent_id)
94
from segmentation_profile
95
where parent_id is not null
96
and id in (%s)""" % ','.join([str(i) for i in ids ]))
98
parent_ids = [x[0] for x in cr.fetchall()]
102
if x not in ids_to_check:
103
ids_to_check.append(x)
107
ids_to_check = pooler.get_pool(cr.dbname).get('segmentation.profile').get_parents(cr, uid, ids_to_check)
111
def process_continue(self, cr, uid, ids, state=False):
112
cr.execute('delete from partner_profile_rel where profile_id=%d', (ids[0],))
114
cr.execute('select id from res_partner order by id ')
115
partners = [x[0] for x in cr.fetchall()]
119
cr.execute('select distinct(answer) from partner_question_rel where partner=%d' % pid)
120
answers_ids = [x[0] for x in cr.fetchall()]
121
if (not test_prof(self, cr, uid, ids[0], pid, answers_ids)):
122
to_remove_list.append(pid)
124
for pid in to_remove_list:
127
for partner_id in partners:
128
cr.execute('insert into partner_profile_rel (profile_id,partner_id) values (%d,%d)', (ids[0],partner_id))
134
_name="segmentation.profile"
135
_description="Profile"
137
"name": fields.char("Description",size=128, required=True),
138
"answer_yes": fields.many2many("segmentation.answer","profile_question_yes_rel","profile","answer","Inclued Answers"),
139
"answer_no": fields.many2many("segmentation.answer","profile_question_no_rel","profile","answer","Excluded Answers"),
140
'parent_id': fields.many2one('segmentation.profile', 'Parent Profile'),
141
'child_ids': fields.one2many('segmentation.profile', 'parent_id', 'Childs Profile'),
144
(orm.orm.check_recursion, 'Error ! You can not create recursive profiles.', ['parent_id'])
92
def get_answers(self, cr, uid, ids):
94
select distinct(answer)
95
from profile_question_yes_rel
96
where profile in (%s)"""% ','.join([str(i) for i in ids ])
99
ans_yes = [x[0] for x in cr.fetchall()]
102
select distinct(answer)
103
from profile_question_no_rel
104
where profile in (%s)"""% ','.join([str(i) for i in ids ])
107
ans_no = [x[0] for x in cr.fetchall()]
109
return [ans_yes, ans_no]
111
def get_parents(self, cr, uid, ids):
114
select distinct(parent_id)
115
from segmentation_profile
116
where parent_id is not null
117
and id in (%s)""" % ','.join([str(i) for i in ids ]))
119
parent_ids = [x[0] for x in cr.fetchall()]
123
if x not in ids_to_check:
124
ids_to_check.append(x)
128
ids_to_check = pooler.get_pool(cr.dbname).get('segmentation.profile').get_parents(cr, uid, ids_to_check)
132
def process_continue(self, cr, uid, ids, state=False):
133
cr.execute('delete from partner_profile_rel where profile_id=%d', (ids[0],))
135
cr.execute('select id from res_partner order by id ')
136
partners = [x[0] for x in cr.fetchall()]
140
cr.execute('select distinct(answer) from partner_question_rel where partner=%d' % pid)
141
answers_ids = [x[0] for x in cr.fetchall()]
142
if (not test_prof(self, cr, uid, ids[0], pid, answers_ids)):
143
to_remove_list.append(pid)
145
for pid in to_remove_list:
148
for partner_id in partners:
149
cr.execute('insert into partner_profile_rel (profile_id,partner_id) values (%d,%d)', (ids[0],partner_id))
155
_name="segmentation.profile"
156
_description="Profile"
158
"name": fields.char("Description",size=128, required=True),
159
"answer_yes": fields.many2many("segmentation.answer","profile_question_yes_rel","profile","answer","Inclued Answers"),
160
"answer_no": fields.many2many("segmentation.answer","profile_question_no_rel","profile","answer","Excluded Answers"),
161
'parent_id': fields.many2one('segmentation.profile', 'Parent Profile'),
162
'child_ids': fields.one2many('segmentation.profile', 'parent_id', 'Childs Profile'),
165
(orm.orm.check_recursion, 'Error ! You can not create recursive profiles.', ['parent_id'])
149
170
class partner(osv.osv):
151
def write(self, cr, uid, ids, vals, context=None):
154
if 'answers_ids' in vals:
155
vals['profiles_ids']=[[6, 0, _recompute_profiles(self, cr, uid, ids[0],vals['answers_ids'][0][2])]]
156
return super(partner, self).write(cr, uid, ids, vals, context=context)
172
def write(self, cr, uid, ids, vals, context=None):
175
if 'answers_ids' in vals:
176
vals['profiles_ids']=[[6, 0, _recompute_profiles(self, cr, uid, ids[0],vals['answers_ids'][0][2])]]
177
return super(partner, self).write(cr, uid, ids, vals, context=context)
158
_inherit="res.partner"
160
"answers_ids": fields.many2many("segmentation.answer","partner_question_rel","partner","answer","Answers"),
161
"profiles_ids":fields.many2many("segmentation.profile","partner_profile_rel","partner_id","profile_id","Matching Profiles", readonly=True, select="2"),
179
_inherit="res.partner"
181
"answers_ids": fields.many2many("segmentation.answer","partner_question_rel","partner","answer","Answers"),
182
"profiles_ids":fields.many2many("segmentation.profile","partner_profile_rel","partner_id","profile_id","Matching Profiles", readonly=True, select="2"),
185
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: