Odoo Help

Welcome!

This community 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.

0

Delete records in one2many relationship

By
Trai Doan
on 11/27/14, 9:47 AM 1,569 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--
2385
| 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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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