[FIX] crm: avoid constraint errors when merging partners
As for the _update_foreign_keys, the _update_reference_fields method may raise an unique constraint when merging two partners.
In such case, the new record is not relevant and can be removed.
Backport of 8d23a3a86c
.
OPW 657338, closes #9705.
This commit is contained in:
parent
d117d6645e
commit
1660daf2fb
|
@ -220,7 +220,13 @@ class MergePartnerAutomatic(osv.TransientModel):
|
|||
return
|
||||
domain = [(field_model, '=', 'res.partner'), (field_id, '=', src.id)]
|
||||
ids = proxy.search(cr, openerp.SUPERUSER_ID, domain, context=context)
|
||||
return proxy.write(cr, openerp.SUPERUSER_ID, ids, {field_id: dst_partner.id}, context=context)
|
||||
try:
|
||||
with mute_logger('openerp.sql_db'), cr.savepoint():
|
||||
return proxy.write(cr, openerp.SUPERUSER_ID, ids, {field_id: dst_partner.id}, context=context)
|
||||
except psycopg2.Error:
|
||||
# updating fails, most likely due to a violated unique constraint
|
||||
# keeping record with nonexistent partner_id is useless, better delete it
|
||||
return proxy.unlink(cr, openerp.SUPERUSER_ID, ids, context=context)
|
||||
|
||||
update_records = functools.partial(update_records, context=context)
|
||||
|
||||
|
|
Loading…
Reference in New Issue