feat: inherit product.template and product.product to enforce multi-company context during archival operations
This commit is contained in:
parent
07125cdc43
commit
48fa2d0dd7
@ -2,3 +2,4 @@ from . import hr_employee
|
|||||||
from . import pos_config
|
from . import pos_config
|
||||||
from . import pos_session
|
from . import pos_session
|
||||||
from . import res_users
|
from . import res_users
|
||||||
|
from . import product
|
||||||
|
|||||||
Binary file not shown.
44
models/product.py
Normal file
44
models/product.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
class ProductTemplate(models.Model):
|
||||||
|
_inherit = 'product.template'
|
||||||
|
|
||||||
|
def action_archive(self):
|
||||||
|
if not self.env.su:
|
||||||
|
if hasattr(self.env.user, '_get_company_ids'):
|
||||||
|
allowed_companies = list(self.env.user._get_company_ids())
|
||||||
|
else:
|
||||||
|
allowed_companies = self.env.user.company_ids.filtered('active').ids
|
||||||
|
self = self.with_context(allowed_company_ids=allowed_companies)
|
||||||
|
return super().action_archive()
|
||||||
|
|
||||||
|
def write(self, vals):
|
||||||
|
if not self.env.su and 'active' in vals and not vals['active']:
|
||||||
|
if hasattr(self.env.user, '_get_company_ids'):
|
||||||
|
allowed_companies = list(self.env.user._get_company_ids())
|
||||||
|
else:
|
||||||
|
allowed_companies = self.env.user.company_ids.filtered('active').ids
|
||||||
|
self = self.with_context(allowed_company_ids=allowed_companies)
|
||||||
|
return super().write(vals)
|
||||||
|
|
||||||
|
class ProductProduct(models.Model):
|
||||||
|
_inherit = 'product.product'
|
||||||
|
|
||||||
|
def action_archive(self):
|
||||||
|
if not self.env.su:
|
||||||
|
if hasattr(self.env.user, '_get_company_ids'):
|
||||||
|
allowed_companies = list(self.env.user._get_company_ids())
|
||||||
|
else:
|
||||||
|
allowed_companies = self.env.user.company_ids.filtered('active').ids
|
||||||
|
self = self.with_context(allowed_company_ids=allowed_companies)
|
||||||
|
return super().action_archive()
|
||||||
|
|
||||||
|
def write(self, vals):
|
||||||
|
if not self.env.su and 'active' in vals and not vals['active']:
|
||||||
|
if hasattr(self.env.user, '_get_company_ids'):
|
||||||
|
allowed_companies = list(self.env.user._get_company_ids())
|
||||||
|
else:
|
||||||
|
allowed_companies = self.env.user.company_ids.filtered('active').ids
|
||||||
|
self = self.with_context(allowed_company_ids=allowed_companies)
|
||||||
|
return super().write(vals)
|
||||||
Loading…
Reference in New Issue
Block a user