first commit
This commit is contained in:
commit
ae4012ec51
1
__init__.py
Normal file
1
__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from . import models
|
||||
20
__manifest__.py
Normal file
20
__manifest__.py
Normal file
@ -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',
|
||||
}
|
||||
BIN
__pycache__/__init__.cpython-312.pyc
Normal file
BIN
__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
2
models/__init__.py
Normal file
2
models/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from . import res_users
|
||||
from . import mrp_production
|
||||
BIN
models/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
models/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/mrp_production.cpython-312.pyc
Normal file
BIN
models/__pycache__/mrp_production.cpython-312.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/res_users.cpython-312.pyc
Normal file
BIN
models/__pycache__/res_users.cpython-312.pyc
Normal file
Binary file not shown.
34
models/mrp_production.py
Normal file
34
models/mrp_production.py
Normal file
@ -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)
|
||||
13
models/res_users.py
Normal file
13
models/res_users.py
Normal file
@ -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."
|
||||
)
|
||||
16
views/mrp_production_views.xml
Normal file
16
views/mrp_production_views.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="mrp_production_form_view_inherit_restriction" model="ir.ui.view">
|
||||
<field name="name">mrp.production.form.view.inherit.restriction</field>
|
||||
<field name="model">mrp.production</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_production_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="product_id" position="before">
|
||||
<field name="allowed_product_ids" invisible="1"/>
|
||||
</field>
|
||||
<field name="product_id" position="attributes">
|
||||
<attribute name="domain">[('id', 'in', allowed_product_ids)]</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
17
views/res_users_views.xml
Normal file
17
views/res_users_views.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_users_form_mrp_restriction" model="ir.ui.view">
|
||||
<field name="name">res.users.form.mrp.restriction</field>
|
||||
<field name="model">res.users</field>
|
||||
<field name="inherit_id" ref="base.view_users_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<notebook position="inside">
|
||||
<page string="Manufacturing Restrictions">
|
||||
<group>
|
||||
<field name="allowed_manufacture_product_ids" widget="many2many_tags" options="{'no_create': True}"/>
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue
Block a user