Odoo Help


Delete records in one2many relationship

Trai Doan
on 11/27/14, 9:47 AM 3,340 views

class a(osv.osv):

class b(osv.osv):

In class a i create 2 button create and delete . I can create new records and insert into class b but i don't know how to delete all records in class b with same fields'connect' depend on class a. Please help me to solve it.

Sorry for bad English :((




| 5 4 6
Zagreb | Karlovac, Croatia

there is only 10 kind of people the ones that understand binary ... and others

On 11/27/14, 11:35 AM

there is two ways to delete them.. 
1. in class a you can :
      self.write(cr, uid, ids[0], {'connect': [(2, c.id) for c in list  ]  
         #write list of tuples (2, c.id ) for every c in list wich calls orm unlink method on those records

or simply:

cr.execute("delete from b where connect = a.id")    #where a.id is id of recors in model a for wich you want items deleted....

Hope it helps.. 

may the source be with you

Just adding that the first method is more preferable as the 2nd one bypasses security checks and did not create any audit trail if you turned on audit trail.

on 11/28/14, 4:55 AM

Yes i agree, and i'm well aware of pros and cons for both methods... But the question was how to do it.. not what's batter way to do it ;)

on 11/29/14, 4:49 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/27/14, 9:47 AM
Seen: 3340 times
Last updated: 3/16/15, 8:10 AM