This question has been flagged
1 Reply
5341 Views

Hello,
So my problem is, I have already created some Items and lines objects, and I'd like to pass those objects from Line to Order.
I'm trying to pass values through buttons by using this:

(4, ID)                link to existing record with id = ID (adds a relationship)

but the only thing I get is an error. 

This is an example of my code:

class Item(models.Model):
	_name = 'a.a'
	
	name= fields.Integer(string = "Name")

class Line(models.Model): _name = 'b.b' item_id = fields.Many2one('a.a', string="Item")
        quantity = fields.Integer(string = "Quantity")
        
        @api.multi def addOrder(self):
            for m in self:
                result = self.env['c.c'].create( {'line_id':[(4,m.id)], }
                                               )     return result

class Order(models.Model): _name = 'c.c' line_id = fields.One2many('b.b','item_id')
Avatar
Discard
Best Answer

Hello Emm,

You need to add Many2one field in 'b.b'  and give that field name in One2many field of 'c.c'.

You can write like following.

Example:

class Line(models.Model):
_name = 'b.b'
item_id = fields.Many2one('a.a', string="Item")
quantity = fields.Integer(string = "Quantity")
order_id =fields.Many2one('c.c',string="order")


class Order(models.Model):
_name = 'c.c'
line_id = fields.One2many('b.b','order_id')

Thanks,

Avatar
Discard