commit ae4012ec513d61329e5875fbf6344197f31ab25a Author: Suherdy Yacob Date: Fri Jan 23 15:33:44 2026 +0700 first commit 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 0000000..f92d416 Binary files /dev/null and b/__pycache__/__init__.cpython-312.pyc differ 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 0000000..0ae1fef Binary files /dev/null and b/models/__pycache__/__init__.cpython-312.pyc differ diff --git a/models/__pycache__/mrp_production.cpython-312.pyc b/models/__pycache__/mrp_production.cpython-312.pyc new file mode 100644 index 0000000..7d7d03b Binary files /dev/null and b/models/__pycache__/mrp_production.cpython-312.pyc differ diff --git a/models/__pycache__/res_users.cpython-312.pyc b/models/__pycache__/res_users.cpython-312.pyc new file mode 100644 index 0000000..4670ea5 Binary files /dev/null and b/models/__pycache__/res_users.cpython-312.pyc differ 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 + + + + + + + + + + + +