Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
6665 Переглядів

I added another page in MO form and also added the One2many fields. I'm trying to add values in my one2many field onchange. I tried using the [(0,0, {values})] but nothing happened. Any idea on how to implement it?


custom_line_ids = fields.One2many('mrp.production', 'product_id', 'Custom Line')   
@api.onchange('product_id')
    def add_custom_line_ids(self):
        vals = {
                'sequence': self.sequence,
                'name': self.name,
                'product_id': self.product_id,
                'date_planned_start': self.date_planned_start,
                'state': self.state,
            }
        self.update({'custom_line_ids':[(0, 0, vals)]})


Аватар
Відмінити
Автор

@Odoo Mates,
Hello, yes I was looking at your tutorial also but gave me a valueError.

for record in self:
lines = []
for line in self.product_id.product_variant_ids:
vals = {
'sequence': self.sequence,
'name': self.name,
'product_id': self.product_id,
'date_planned_start': self.date_planned_start,
'state': self.state,
}
lines.append((0,0,vals))
record.custom_line_ids = lines

Найкраща відповідь

Hello 

Try this

custom_line_ids = fields.One2many('mrp.production', 'product_id', 'Custom Line')
@api.onchange('product_id')
def add_custom_line_ids(self):
vals = {
'sequence': self.sequence,
'name': self.name,
'product_id': self.product_id,
'date_planned_start': self.date_planned_start,
'state': self.state,
}
self.custom_line_ids = [(0, 0, vals)]



Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
лип. 19
7717
1
бер. 21
2231
0
вер. 20
2822
1
лип. 19
14591
0
квіт. 16
3174