Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
16930 Visualizzazioni

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

Avatar
Abbandona
Risposta migliore

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

Avatar
Abbandona

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.

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