Merge lp:~openerp-dev/openobject-server/6.0-opw-586600-rgo into lp:openobject-server/6.0

Proposed by Ravi Gohil (OpenERP)
Status: Merged
Approved by: Xavier ALT
Approved revision: 3657
Merged at revision: 3659
Proposed branch: lp:~openerp-dev/openobject-server/6.0-opw-586600-rgo
Merge into: lp:openobject-server/6.0
Diff against target: 25 lines (+8/-2)
1 file modified
bin/osv/orm.py (+8/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.0-opw-586600-rgo
Reviewer Review Type Date Requested Status
Naresh(OpenERP) Pending
Review via email: mp+149753@code.launchpad.net

Description of the change

Steps to reproduce issue:
1) Create 2 new accounts, one of type=receivable and one of type=payable,
2) Create a new partner and set these accounts in the field account receivable, account payable,
3) Select the one of the account you've created and click on delete,
You will have the warning message: You cannot remove/deactivate an account which is set as a property to any Partner.

4) Delete the partner you've created an retry to delete the account.
You will still have the same error message.

The reason for this is that the constraint wont allow to delete the account if it is referring to properties, but the properties are no longer needed as the resource itself was deleted.

This fix will remove the properties at the time of deletion of resource record.

Kindly review the fix.

Thanks.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/osv/orm.py'
2--- bin/osv/orm.py 2012-10-03 13:00:55 +0000
3+++ bin/osv/orm.py 2013-02-21 07:31:20 +0000
4@@ -3256,13 +3256,19 @@
5
6 self.pool.get('ir.model.access').check(cr, uid, self._name, 'unlink', context=context)
7
8- properties = self.pool.get('ir.property')
9+ ir_property = self.pool.get('ir.property')
10+
11+ # Check if the records are used as default properties.
12 domain = [('res_id', '=', False),
13 ('value_reference', 'in', ['%s,%s' % (self._name, i) for i in ids]),
14 ]
15- if properties.search(cr, uid, domain, context=context):
16+ if ir_property.search(cr, uid, domain, context=context):
17 raise except_orm(_('Error'), _('Unable to delete this document because it is used as a default property'))
18
19+ # Delete the records' properties.
20+ property_ids = ir_property.search(cr, uid, [('res_id', 'in', ['%s,%s' % (self._name, i) for i in ids])], context=context)
21+ ir_property.unlink(cr, uid, property_ids, context=context)
22+
23 wf_service = netsvc.LocalService("workflow")
24 for oid in ids:
25 wf_service.trg_delete(uid, self._name, oid, cr)