diff --git a/addons/crm/crm_segmentation.py b/addons/crm/crm_segmentation.py index 9cafe950410..b87d6a3b653 100644 --- a/addons/crm/crm_segmentation.py +++ b/addons/crm/crm_segmentation.py @@ -56,6 +56,7 @@ added to partners that match the segmentation criterions after computation.'), @param uid: the current user’s ID for security checks, @param ids: List of Process continue’s IDs""" + partner_obj = self.pool.get('res.partner') categs = self.read(cr, uid, ids, ['categ_id', 'exclusif', 'partner_id',\ 'sales_purchase_active', 'profiling_active']) for categ in categs: @@ -80,9 +81,11 @@ added to partners that match the segmentation criterions after computation.'), for pid in to_remove_list: partners.remove(pid) - for partner_id in partners: - cr.execute('insert into res_partner_res_partner_category_rel (category_id,partner_id) \ - values (%s,%s)', (categ['categ_id'][0], partner_id)) + for partner in partner_obj.browse(cr, uid, partners): + category_ids = [categ_id.id for categ_id in partner.category_id] + if categ['categ_id'][0] not in category_ids: + cr.execute('insert into res_partner_res_partner_category_rel (category_id,partner_id) \ + values (%s,%s)', (categ['categ_id'][0], partner.id)) self.write(cr, uid, [id], {'state':'not running', 'partner_id':0}) return True diff --git a/addons/crm_profiling/crm_profiling.py b/addons/crm_profiling/crm_profiling.py index 8f07dfcbdda..7dc72f80289 100644 --- a/addons/crm_profiling/crm_profiling.py +++ b/addons/crm_profiling/crm_profiling.py @@ -244,6 +244,7 @@ class crm_segmentation(osv.osv): @param uid: the current user’s ID for security checks, @param ids: List of crm segmentation’s IDs """ + partner_obj = self.pool.get('res.partner') categs = self.read(cr,uid,ids,['categ_id','exclusif','partner_id', \ 'sales_purchase_active', 'profiling_active']) for categ in categs: @@ -280,8 +281,10 @@ class crm_segmentation(osv.osv): for pid in to_remove_list: partners.remove(pid) - for partner_id in partners: - cr.execute('insert into res_partner_res_partner_category_rel (category_id,partner_id) values (%s,%s)', (categ['categ_id'][0],partner_id)) + for partner in partner_obj.browse(cr, uid, partners): + category_ids = [categ_id.id for categ_id in partner.category_id] + if categ['categ_id'][0] not in category_ids: + cr.execute('insert into res_partner_res_partner_category_rel (category_id,partner_id) values (%s,%s)', (categ['categ_id'][0],partner.id)) self.write(cr, uid, [id], {'state':'not running', 'partner_id':0}) return True