|
@ -27,21 +27,15 @@ class ProductTemplate(models.Model): |
|
|
"""inherited product""" |
|
|
"""inherited product""" |
|
|
_inherit = 'product.template' |
|
|
_inherit = 'product.template' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
branch_id = fields.Many2one("res.branch", string='Branch', store=True, |
|
|
branch_id = fields.Many2one("res.branch", string='Branch', store=True, |
|
|
readonly=False, |
|
|
help='Leave this field empty if this product is' |
|
|
compute="_compute_branch") |
|
|
' shared between all branches' |
|
|
|
|
|
) |
|
|
|
|
|
allowed_branch_ids = fields.Many2many('res.branch', store=True, |
|
|
|
|
|
string="Allowed Branches", |
|
|
|
|
|
compute='_compute_allowed_branch_ids') |
|
|
|
|
|
|
|
|
@api.depends('company_id') |
|
|
@api.depends('company_id') |
|
|
def _compute_branch(self): |
|
|
def _compute_allowed_branch_ids(self): |
|
|
for order in self: |
|
|
for po in self: |
|
|
company = self.env.company |
|
|
po.allowed_branch_ids = self.env.user.branch_ids.ids |
|
|
so_company = order.company_id if order.company_id else self.env.company |
|
|
|
|
|
branch_ids = self.env.user.branch_ids |
|
|
|
|
|
branch = branch_ids.filtered( |
|
|
|
|
|
lambda branch: branch.company_id == so_company) |
|
|
|
|
|
if branch: |
|
|
|
|
|
order.branch_id = branch.ids[0] |
|
|
|
|
|
else: |
|
|
|
|
|
order.branch_id = False |
|
|
|
|
|