From ae4012ec513d61329e5875fbf6344197f31ab25a Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Fri, 23 Jan 2026 15:33:44 +0700 Subject: [PATCH] first commit --- __init__.py | 1 + __manifest__.py | 20 +++++++++++ __pycache__/__init__.cpython-312.pyc | Bin 0 -> 216 bytes models/__init__.py | 2 ++ models/__pycache__/__init__.cpython-312.pyc | Bin 0 -> 264 bytes .../mrp_production.cpython-312.pyc | Bin 0 -> 2275 bytes models/__pycache__/res_users.cpython-312.pyc | Bin 0 -> 804 bytes models/mrp_production.py | 34 ++++++++++++++++++ models/res_users.py | 13 +++++++ views/mrp_production_views.xml | 16 +++++++++ views/res_users_views.xml | 17 +++++++++ 11 files changed, 103 insertions(+) create mode 100644 __init__.py create mode 100644 __manifest__.py create mode 100644 __pycache__/__init__.cpython-312.pyc create mode 100644 models/__init__.py create mode 100644 models/__pycache__/__init__.cpython-312.pyc create mode 100644 models/__pycache__/mrp_production.cpython-312.pyc create mode 100644 models/__pycache__/res_users.cpython-312.pyc create mode 100644 models/mrp_production.py create mode 100644 models/res_users.py create mode 100644 views/mrp_production_views.xml create mode 100644 views/res_users_views.xml diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/__manifest__.py b/__manifest__.py new file mode 100644 index 0000000..92d146b --- /dev/null +++ b/__manifest__.py @@ -0,0 +1,20 @@ +{ + 'name': 'MRP User Product Restriction', + 'version': '17.0.1.0.0', + 'category': 'Manufacturing/Manufacturing', + 'summary': 'Restrict products in Manufacturing Orders based on user settings', + 'description': """ + This module adds a new tab in the User settings form to define allowed products for Manufacturing Orders. + If a user has products defined, they can only create MOs for those products. + If no products are defined, they cannot create any MOs. + """, + 'author': 'Antigravity', + 'depends': ['mrp'], + 'data': [ + 'views/res_users_views.xml', + 'views/mrp_production_views.xml', + ], + 'installable': True, + 'application': False, + 'license': 'LGPL-3', +} diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f92d416b7986696d5df8cb827c6a408b55b69024 GIT binary patch literal 216 zcmXwzF$%&!5Jh(q2qFY5^bV$Rv9b}5AT~BOi)0tFkj;eI-6ALP27+ht1}SW;?1Xey zPC$P%?|)|abIv;nzyJUM literal 0 HcmV?d00001 diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..71a5e6b --- /dev/null +++ b/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_users +from . import mrp_production diff --git a/models/__pycache__/__init__.cpython-312.pyc b/models/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0ae1fef7bf3cb74df60803f41f89dbeac4b31727 GIT binary patch literal 264 zcmXv|F-`+P47Beeg@8hvCJ*46tSAr-;t7a4inKzvE8R-B=aao#+)H=^1ux+Tk)WZX ziXuaP^xYPb!#JQ?}a$GBU1qTj$h`2>8yi#6mD}8RyJlt= zVk>D=8mU1-0#4z`flEXsuKgc+iLok2BdQ|x)LTO6g;VFP*9l22)T%4%?VFi5Z{B?G zdvEFMBb8Zr?;t5L?D)nv(E##DmV@|Q?-=f4WIbJy9 z16@?JKavh9#j9xyk$b+(!6$Y$s6nQ}!8+Sh4d6FTFB#lUXG7u)da@m=6$-fEnX zL37B?B3e)N-kZBKcW>d&LL)U+OO351$F=~XYASZ!N`ZLS&ikcu7|^|kM}R0I5ig5G z9HdY~m+VR#q%2C?*HVGBT|iey5L&?hFM;#e2Cva`*V0f0v3+u2X$;8CxeAyHT`sO zb+BPg)vT%I@n5@!H&s|=P*kFGhg!Svk{zds*HOu{7_a63hS!2Jue2jQ?+bti(GzsE zG=f|8*?Ql`^SBW8z?Mz(&GFsw_ABkryNTrvyX~1u>#X+v+I6U^M5eXtHinE_>O^(& zD?c4-2EU$%*1^i70JX61NEg>&OA7?a`wU5X`Jv&*H`c6g z>m%RE@=u>vHV`^+UU`u^*hrc6l=*0?F?6anbn0i)I5%B8H~nmA`g#A*V`uHdtM%b) zYtHqC!)gv|IJau@H+-w!KeyI1w|NN8jW|AGb&I5J!@X@=blSFTbYT(nF5A8lI>mS; zX}g~6qHe(6kxC13b3)#Y+wAXC*jCjz1i342;$WM%R;v*LyPSJttlzv?Iov zc4(su8HX1q8+y8?rym}y>&G?~MZbc#RAiVNkt*Rd`W7dDy!QRI`xoo_dz(s^UWp9e zZ>r5uAb<(0Lul}AV36|YmeH*uiii}fWawO;mf=gtBlZaW68sB@;%7s!3tC5XvDeA5 sCYtA%CFkIq#7!wSRE+WOXrzutenZD!X-9Dd-ydJO_~7DS2=vIq-&(*Hc>n+a literal 0 HcmV?d00001 diff --git a/models/__pycache__/res_users.cpython-312.pyc b/models/__pycache__/res_users.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4670ea5922d6f42a1181eff82802be0c72385eed GIT binary patch literal 804 zcmYjPziSjh6rS1J+uJ)lf*R0>kcGg>LA*tavyq^cT3if*2#Yc-`{uk2yF2I1uChl8 zixk>unbua~e`1x&Wf}!5JK~32m^T^UXf4X?RxN9rmRCjEd)i zaBcZVHm6O#BbB}DcJQEFz9#+L|rllf5{u}PTBC=XL^D!pV^G0gAA%E-;SHBnwe zdiCxQ#8jp_C{fE753%AUN6>e z7yXx~{mw1x#N6UnoATXZTbh~?*Nv*zwkLYTsw=MO(=vNqp)>n_CD;zXrd&1fNL*Lu aZwq7m6K$TFJ#2k=`}yGG!9S#6S@|F4%jLKL literal 0 HcmV?d00001 diff --git a/models/mrp_production.py b/models/mrp_production.py new file mode 100644 index 0000000..7d83d89 --- /dev/null +++ b/models/mrp_production.py @@ -0,0 +1,34 @@ +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + +class MrpProduction(models.Model): + _inherit = 'mrp.production' + + def _get_default_allowed_products(self): + return self.env.user.allowed_manufacture_product_ids + + allowed_product_ids = fields.Many2many( + 'product.product', + compute='_compute_allowed_product_ids', + default=_get_default_allowed_products + ) + + @api.depends_context('uid') + def _compute_allowed_product_ids(self): + for record in self: + record.allowed_product_ids = self.env.user.allowed_manufacture_product_ids + + @api.constrains('product_id') + def _check_allowed_product(self): + for record in self: + # Use sudo() isn't necessary for checking self.env.user, but if we were checking record.user_id it might be. + # self.env.user is the current logged in user performing the write/create. + user = self.env.user + + # Check if user has any allowed products + # If allowed_manufacture_product_ids is empty, NO products are allowed. + if not user.allowed_manufacture_product_ids: + raise ValidationError(_("You are not allowed to manufacture any products. Please contact your administrator.")) + + if record.product_id and record.product_id not in user.allowed_manufacture_product_ids: + raise ValidationError(_("You are not allowed to manufacture this product: %s") % record.product_id.name) diff --git a/models/res_users.py b/models/res_users.py new file mode 100644 index 0000000..f01886d --- /dev/null +++ b/models/res_users.py @@ -0,0 +1,13 @@ +from odoo import models, fields + +class ResUsers(models.Model): + _inherit = 'res.users' + + allowed_manufacture_product_ids = fields.Many2many( + 'product.product', + 'res_users_product_mrp_rel', + 'user_id', + 'product_id', + string="Allowed Products Manufacture", + help="Allowed products for Manufacturing Orders. If empty, no products are allowed." + ) diff --git a/views/mrp_production_views.xml b/views/mrp_production_views.xml new file mode 100644 index 0000000..767e97c --- /dev/null +++ b/views/mrp_production_views.xml @@ -0,0 +1,16 @@ + + + + mrp.production.form.view.inherit.restriction + mrp.production + + + + + + + [('id', 'in', allowed_product_ids)] + + + + diff --git a/views/res_users_views.xml b/views/res_users_views.xml new file mode 100644 index 0000000..bbb5265 --- /dev/null +++ b/views/res_users_views.xml @@ -0,0 +1,17 @@ + + + + res.users.form.mrp.restriction + res.users + + + + + + + + + + + +