From 48fa2d0dd7ef5a3a131753232219caa0871c78b0 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Sat, 30 May 2026 18:53:20 +0700 Subject: [PATCH] feat: inherit product.template and product.product to enforce multi-company context during archival operations --- models/__init__.py | 1 + models/__pycache__/__init__.cpython-312.pyc | Bin 327 -> 358 bytes models/product.py | 44 ++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 models/product.py diff --git a/models/__init__.py b/models/__init__.py index 26e4cbc..60833c6 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -2,3 +2,4 @@ from . import hr_employee from . import pos_config from . import pos_session from . import res_users +from . import product diff --git a/models/__pycache__/__init__.cpython-312.pyc b/models/__pycache__/__init__.cpython-312.pyc index 459921e65cafb545fe3472fcc8508673df00f2eb..066e92c02714216825dbfa719d2884ade46e9c36 100644 GIT binary patch delta 109 zcmX@k^o)u3G%qg~0}yzemddK0$ScX{Fj3u9AcY}?HHRUWHHwvyp^{CLePV(gpC;oi z_JX4Pl+xr9KTWoY3&og<*e7l&P~!pWW(4A55g_q_nURt4E`#J<1_>}Jevd)42xI{O Dvo{%` delta 96 zcmaFHbexIzG%qg~0}yx$OJ=1`fuaDm&=SZ1 diff --git a/models/product.py b/models/product.py new file mode 100644 index 0000000..0d54f09 --- /dev/null +++ b/models/product.py @@ -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)