[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.
This commit is contained in:
parent
210a40a79f
commit
8d23a3a86c
|
@ -220,7 +220,13 @@ class MergePartnerAutomatic(osv.TransientModel):
|
||||||
return
|
return
|
||||||
domain = [(field_model, '=', 'res.partner'), (field_id, '=', src.id)]
|
domain = [(field_model, '=', 'res.partner'), (field_id, '=', src.id)]
|
||||||
ids = proxy.search(cr, openerp.SUPERUSER_ID, domain, context=context)
|
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)
|
update_records = functools.partial(update_records, context=context)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue