Say I have classes like this:
class First(orm.Model):
_name = 'first.class'
_columns = {
'partner_id': fields.many2one('res.partner', 'Partner'),
'res_ids': fields.one2many('second.class', 'first_id', 'Resources'),
}
class Second(orm.Model):
_name = 'second.class'
_columns = {
'partner_id': fields.many2one('res.partner', 'Partner'),
'first_id': fields.many2one('first.class', 'First'),
}
Now I want to write a method, when it is called, it will create a class entry Firstthat takes values from the class Second. But I don’t understand how to pass values to the field one2manywhen creating the class First.
For example, let's say I call create like this (this method is inside the class Second):
def some_method(cr, uid, ids, context=None):
vals = {}
for obj in self.browse(cr, uid, ids):
vals['partner_id'] = obj.partner_id and obj.partner_id.id or False
vals['res_ids'] = ??
self.pool.get('first.class').create(cr, uid, vals)
return True
There is documentation on pasting values one2manyhere:
https://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html/#osv.osv.osv.write
But this is only for the write method.
source
share