تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
16917 أدوات العرض

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

الصورة الرمزية
إهمال
أفضل إجابة

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.

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