[FIX] base: delete parent partner reset use_parent_address
authorAndrius Preimantas <andrius@versada.lt>
Fri, 28 Nov 2014 10:39:36 +0000 (11:39 +0100)
committerMartin Trigaux <mat@odoo.com>
Fri, 28 Nov 2014 11:03:42 +0000 (12:03 +0100)
When deleting a partner with some contacts, if the contacts had selected
the "use parent address" checkbox, the address of the contacts was stucked in
readonly mode (no checkbox to disable it).
Disable use_parent_address for orphan partners.

Fixes #3611 #3613

openerp/addons/base/res/res_partner.py

index 22cd4a8..7d357ed 100644 (file)
@@ -508,6 +508,14 @@ class res_partner(osv.osv, format_address):
             if not parent.is_company:
                 parent.write({'is_company': True})
 
+    def unlink(self, cr, uid, ids, context=None):
+        orphan_contact_ids = self.search(cr, uid,
+            [('parent_id', 'in', ids), ('id', 'not in', ids), ('use_parent_address', '=', True)], context=context)
+        if orphan_contact_ids:
+            # no longer have a parent address
+            self.write(cr, uid, orphan_contact_ids, {'use_parent_address': False}, context=context)
+        return super(res_partner, self).unlink(cr, uid, ids, context=context)
+
     def write(self, cr, uid, ids, vals, context=None):
         if isinstance(ids, (int, long)):
             ids = [ids]