Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie

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)

Awatar
Odrzuć

waht is the need of default=_onchange_product_pack_name

Autor

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,

Powiązane posty Odpowiedzi Widoki Czynność
1
lip 19
3853
2
paź 17
4741
2
lip 25
493
0
gru 24
1099
2
paź 24
1207