Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
2763 Представления

api onchange not working on many2many - odoo 13.

Trying to update sale_line's m2m field when product is changed in form view. It's not working.

@api.onchange("product_id")
def _fetch_mf_ids(self):
    for rec in self:
        rec.mf_ids = [
            (6, 0, [x.id for x in rec.product_id.mf_ids])
        ]

Getting non-stored values for this m2m rec in sale_order_line when I print rec.mf_ids

product.mf.pgm(, )
Аватар
Отменить
Лучший ответ

1. 

Make sure that the mf_ids field is correctly defined as a Many2many field in both the product.product model and the sale.order.line model.


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'

   

    mf_ids = fields.Many2many(

        'product.mf.pgm',

        string="Manufacturing Programs",

    )

   class ProductProduct(models.Model):

    _inherit = 'product.product'

   

    mf_ids = fields.Many2many(

        'product.mf.pgm',

        string="Manufacturing Programs",

    )

Try this:

@api.onchange("product_id")

def _fetch_mf_ids(self):

    for rec in self:

        if rec.product_id:

            mf_ids = rec.product_id.mf_ids

            rec.mf_ids = [(6, 0, mf_ids.ids)]


Hope it helps

Аватар
Отменить
Related Posts Ответы Просмотры Активность
5
дек. 22
5496
1
февр. 21
3704
2
мар. 20
5147
0
февр. 19
3575
2
февр. 23
4107