[5.0] crm_configuration crashes on partenr's creation with duplicate key

Bug #330171 reported by Claude Brulé
2
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Undecided
Unassigned

Bug Description

When using "Leads" CRM case, first you put prospect name and prospect's contact name.
Then you can convert him to a partner.

If you put the same name twice, it causes IntegrityError: une clé dupliquée rompt la contrainte unique « res_partner_name_uniq »

the create method should be in a try/catch block and raising specific message in that case.

Revision history for this message
Claude Brulé (claude-brule-syleam) wrote :

One solution that works (may be it's not optimistic) :

=== modified file 'crm_configuration/wizard/wizard_partner_create.py'
--- crm_configuration/wizard/wizard_partner_create.py 2009-01-04 22:12:50 +0000
+++ crm_configuration/wizard/wizard_partner_create.py 2009-02-16 04:37:06 +0000
@@ -56,18 +56,26 @@
         partner_obj = pool.get('res.partner')
         contact_obj = pool.get('res.partner.address')
         for case in case_obj.browse(cr, uid, data['ids']):
- partner_id = partner_obj.create(cr, uid, {
- 'name': case.partner_name or case.name,
- 'user_id': case.user_id.id,
- 'comment': case.note,
- })
- contact_id = contact_obj.create(cr, uid, {
- 'partner_id': partner_id,
- 'name': case.partner_name2,
- 'phone': case.partner_phone,
- 'mobile': case.partner_mobile,
- 'email': case.email_from
- })
+
+ partner_id = partner_obj.search(cr, uid, [('name', '=', case.partner_name or case.name)])
+ print repr(partner_id)
+
+ if partner_id:
+ raise wizard.except_wizard("Warning !",
+ _('A partner is already existing with the same name.'))
+ else:
+ partner_id = partner_obj.create(cr, uid, {
+ 'name': case.partner_name or case.name,
+ 'user_id': case.user_id.id,
+ 'comment': case.note,
+ })
+ contact_id = contact_obj.create(cr, uid, {
+ 'partner_id': partner_id,
+ 'name': case.partner_name2,
+ 'phone': case.partner_phone,
+ 'mobile': case.partner_mobile,
+ 'email': case.email_from
+ })

         case_obj.write(cr, uid, data['ids'], {

Revision history for this message
Husen Daudi (husendaudi) wrote :

Thanks for patch claude.
Applied on trunk.

Changed in openobject-addons:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.