This question has been flagged

Hello All,

I Applied onchange function for product pack with domain. In this function i want that products related to product pack(One2may field) should available on the form view. My function working well and product related to product pack visible on the form. For first row of One2many type field onchange work, But when i move to second row then onchange is also work well but the previous row product show is current row product. Means is that when i work on current row then all the previous rows products seen as current row products. It's shows same products. So, anyone can give me solution for this problem.

My code is here:

Python Code:

class SaleOrderLine(models.Model):
    _inherit = "sale.order.line"

    @api.onchange('product_id')
    def _onchange_product_pack_name(self):
        print"A:", self.product_id.product_pack
        res = self.product_id.product_pack
        print "res:", res
        if res:
            return {'domain': {'pack_id': [('id', 'in', [v.id for v in res])]}}

    products_id = fields.Many2many('product.template', string='Extra products')
    pack_id = fields.Many2many('product.pack', string='Pack Products',change_default=True, default=_onchange_product_pack_name)

Avatar
Discard

waht is the need of default=_onchange_product_pack_name

Author

Hello Hilar,

When i work on current row of One2many field and after that when i seen previous rows product record then all previous rows records show same product as current row products. For example i select previous row gold pack then products are A,B. After when I select diamond pack and it's products available C,D. But when i see again 'gold pack' product, they are C,D instead of A,B.

Thanks,