Odoo Help

0

Delete records in one2many relationship

By
Trai Doan
on 11/27/14, 9:47 AM 2,145 views

class a(osv.osv):
        _name='a.model'
        _columns={
                  'name':fields.char('Name',size=32),
                  'ten':fields.char('Ten',size=40),
                  'list':fields.one2many('b.model','connect','List'),
                  }
a()

class b(osv.osv):
        _name='b.model'
        _columns={
                  'name':fields.char('Name',size=32),
                  'ten':fields.char('Ten',size=40),
                 'connect':fields.many2one('a.model','Relatiationship'),
                  }
b()

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 :((

1

Bole

--Bole--
2405
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

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

Bole
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:

2.
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.

Ivan
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 ;)

Bole
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.

Register

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)

Stats

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