Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
1343 Переглядів
_inherit = "product.template"
_description = "Product"

branch_ids = fields.Many2many('res.branch', string='Branch', help="Branch associated with this product template")

@api.onchange('categ_id')
def _onchange_categ_id(self):
"""Sets branch_ids based on the selected category's branch_ids"""
if self.categ_id:
self.branch_ids = self.categ_id.branch_ids
else:
self.branch_ids = [(5, 0, 0)] # Clears the branch_ids field

i want to passed the value but dont want auto fetch the data user will select it on their choice based on associted with category in form of dropdown how i will do that 

Аватар
Відмінити
Найкраща відповідь

Hi,

Please refer to the code:

from odoo import api, fields, models

class ProductTemplate(models.Model):
_inherit = "product.template"

allowed_branch_ids = fields.Many2many(
'res.branch',
string="Allowed Branches",
compute="_compute_allowed_branch_ids",
)
branch_ids = fields.Many2many(
'res.branch',
string='Branch',
domain="[('id', 'in', rec.allowed_branch_ids.ids)]",
help="Branches associated with this product template"
)


@api.depends('categ_id')
def _compute_allowed_branch_ids(self):
"""Compute allowed branches from category"""
for rec in self:
if rec.categ_id:
rec.allowed_branch_ids = rec.categ_id.branch_ids
else:
rec.allowed_branch_ids = [(5, 0, 0)] # clear

Hope it helps.

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
лист. 24
1259
0
лист. 24
15
10
черв. 16
33437
1
жовт. 15
9586
4
серп. 15
3879