Merge PR #934 into 12.0

Signed-off-by simahawk
This commit is contained in:
OCA-git-bot
2020-07-20 11:05:36 +00:00
20 changed files with 327 additions and 0 deletions

View File

@@ -0,0 +1 @@
../../../../stock_picking_type_user_restriction

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,28 @@
# Copyright 2020 Lorenzo Battistini @ TAKOBI
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Stock picking type - Restrict users",
"summary": "Restrict some users to see and use only certain picking types",
"version": "12.0.1.0.0",
"development_status": "Beta",
"category": "Warehouse",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "TAKOBI, Odoo Community Association (OCA)",
"maintainers": ["eLBati"],
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": [
"stock",
],
"data": [
"security/stock_security.xml",
"views/stock_picking_type_views.xml",
"security/ir.model.access.csv",
"views/stock_menu_views.xml",
"views/product_views.xml",
"views/stock_inventory_views.xml",
"views/stock_picking_views.xml",
"views/stock_warehouse_views.xml",
],
}

View File

@@ -0,0 +1,42 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_picking_type_user_restriction
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-07-07 04:53+0000\n"
"PO-Revision-Date: 2020-07-07 04:53+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: stock_picking_type_user_restriction
#: model:ir.model.fields,field_description:stock_picking_type_user_restriction.field_stock_picking_type__assigned_user_ids
msgid "Assigned users"
msgstr "Utenti assegnati"
#. module: stock_picking_type_user_restriction
#: model:ir.model,name:stock_picking_type_user_restriction.model_stock_picking_type
msgid "Picking Type"
msgstr "Tipo di prelievo"
#. module: stock_picking_type_user_restriction
#: model:ir.model.fields,help:stock_picking_type_user_restriction.field_stock_picking_type__assigned_user_ids
msgid "Restrict some users to only access their assigned operation types. In order to apply the restriction, the user needs the 'User: Assigned Operation Types Only' group"
msgstr "Limitare alcuni utenti ad accedere solamente ai loro tipi di operazioni assegnati. Per applicare la restrizione, l'utente necessita il gruppo 'Utente: solamente tipi di operazioni assegnati'"
#. module: stock_picking_type_user_restriction
#: model:res.groups,comment:stock_picking_type_user_restriction.group_assigned_picking_types_user
msgid "The user will have access to her assigned operation types."
msgstr "L'utente avrà accesso ai propri tipi di operazioni assegnati."
#. module: stock_picking_type_user_restriction
#: model:res.groups,name:stock_picking_type_user_restriction.group_assigned_picking_types_user
msgid "User: Assigned Operation Types Only"
msgstr "Utente: solamente tipi di operazioni assegnati"

View File

@@ -0,0 +1 @@
from . import stock_picking_type

View File

@@ -0,0 +1,10 @@
from odoo import models, fields
class PickingType(models.Model):
_inherit = 'stock.picking.type'
assigned_user_ids = fields.Many2many(
"res.users", string="Assigned users",
help="Restrict some users to only access their assigned operation types. "
"In order to apply the restriction, the user needs the "
"'User: Assigned Operation Types Only' group")

View File

@@ -0,0 +1,3 @@
With a Stock Manager, open an operation type (picking type) and set "Assigned users" field.
Then, assign "User: Assigned Operation Types Only" group to users who should be able to access to their assigned operation types only.

View File

@@ -0,0 +1 @@
* Lorenzo Battistini (https://takobi.online)

View File

@@ -0,0 +1 @@
Restrict some users to only access their assigned operation types.

View File

@@ -0,0 +1,21 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_stock_picking_user,stock.picking user,stock.model_stock_picking,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,1,1,1
access_stock_picking_type_user,stock.picking.type user,stock.model_stock_picking_type,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,0,0,0
access_stock_production_lot_user,stock.production.lot user,stock.model_stock_production_lot,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,1,1,1
access_stock_move_user,stock.move user,stock.model_stock_move,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,1,1,0
access_stock_inventory_user,stock.inventory user,stock.model_stock_inventory,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,1,1,0
access_stock_inventory_line_user,stock.inventory.line user,stock.model_stock_inventory_line,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,1,1,0
access_product_product_stock_user,product_product_stock_user,product.model_product_product,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,0,0,0
access_product_template_stock_user,product.template stock user,product.model_product_template,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,0,0,0
access_stock_warehouse_orderpoint,stock.warehouse.orderpoint,stock.model_stock_warehouse_orderpoint,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,0,0,0
access_stock_quant_user,stock.quant user,stock.model_stock_quant,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,0,0,0
access_stock_quant_package_stock_user,stock.quant.package stock user,stock.model_stock_quant_package,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,1,1,1
access_stock_package_level_stock_user,stock.package_level stock user,stock.model_stock_package_level,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,1,1,1
access_stock_rule_user,stock_rule user,stock.model_stock_rule,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,0,0,0
access_stock_move_line_user,stock.move.line user,stock.model_stock_move_line,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,1,1,1
access_stock_fixed_putaway_user,stock_fixed_putaway_strat user,stock.model_stock_fixed_putaway_strat,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,0,0,0
access_product_price_history_stock_user,prices.history stock user,product.model_product_price_history,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,0,0,0
access_barcode_nomenclature_stock_user,barcode.nomenclature.stock.user,barcodes.model_barcode_nomenclature,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,0,0,0
access_barcode_rule_stock_user,barcode.rule.stock.user,barcodes.model_barcode_rule,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,0,0,0
access_stock_forecast_user,report.stock.forecast.user,stock.model_report_stock_forecast,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,0,0,0
access_stock_scrap_user,stock.scrap.user,stock.model_stock_scrap,stock_picking_type_user_restriction.group_assigned_picking_types_user,1,1,1,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_stock_picking_user stock.picking user stock.model_stock_picking stock_picking_type_user_restriction.group_assigned_picking_types_user 1 1 1 1
3 access_stock_picking_type_user stock.picking.type user stock.model_stock_picking_type stock_picking_type_user_restriction.group_assigned_picking_types_user 1 0 0 0
4 access_stock_production_lot_user stock.production.lot user stock.model_stock_production_lot stock_picking_type_user_restriction.group_assigned_picking_types_user 1 1 1 1
5 access_stock_move_user stock.move user stock.model_stock_move stock_picking_type_user_restriction.group_assigned_picking_types_user 1 1 1 0
6 access_stock_inventory_user stock.inventory user stock.model_stock_inventory stock_picking_type_user_restriction.group_assigned_picking_types_user 1 1 1 0
7 access_stock_inventory_line_user stock.inventory.line user stock.model_stock_inventory_line stock_picking_type_user_restriction.group_assigned_picking_types_user 1 1 1 0
8 access_product_product_stock_user product_product_stock_user product.model_product_product stock_picking_type_user_restriction.group_assigned_picking_types_user 1 0 0 0
9 access_product_template_stock_user product.template stock user product.model_product_template stock_picking_type_user_restriction.group_assigned_picking_types_user 1 0 0 0
10 access_stock_warehouse_orderpoint stock.warehouse.orderpoint stock.model_stock_warehouse_orderpoint stock_picking_type_user_restriction.group_assigned_picking_types_user 1 0 0 0
11 access_stock_quant_user stock.quant user stock.model_stock_quant stock_picking_type_user_restriction.group_assigned_picking_types_user 1 0 0 0
12 access_stock_quant_package_stock_user stock.quant.package stock user stock.model_stock_quant_package stock_picking_type_user_restriction.group_assigned_picking_types_user 1 1 1 1
13 access_stock_package_level_stock_user stock.package_level stock user stock.model_stock_package_level stock_picking_type_user_restriction.group_assigned_picking_types_user 1 1 1 1
14 access_stock_rule_user stock_rule user stock.model_stock_rule stock_picking_type_user_restriction.group_assigned_picking_types_user 1 0 0 0
15 access_stock_move_line_user stock.move.line user stock.model_stock_move_line stock_picking_type_user_restriction.group_assigned_picking_types_user 1 1 1 1
16 access_stock_fixed_putaway_user stock_fixed_putaway_strat user stock.model_stock_fixed_putaway_strat stock_picking_type_user_restriction.group_assigned_picking_types_user 1 0 0 0
17 access_product_price_history_stock_user prices.history stock user product.model_product_price_history stock_picking_type_user_restriction.group_assigned_picking_types_user 1 0 0 0
18 access_barcode_nomenclature_stock_user barcode.nomenclature.stock.user barcodes.model_barcode_nomenclature stock_picking_type_user_restriction.group_assigned_picking_types_user 1 0 0 0
19 access_barcode_rule_stock_user barcode.rule.stock.user barcodes.model_barcode_rule stock_picking_type_user_restriction.group_assigned_picking_types_user 1 0 0 0
20 access_stock_forecast_user report.stock.forecast.user stock.model_report_stock_forecast stock_picking_type_user_restriction.group_assigned_picking_types_user 1 0 0 0
21 access_stock_scrap_user stock.scrap.user stock.model_stock_scrap stock_picking_type_user_restriction.group_assigned_picking_types_user 1 1 1 0

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="group_assigned_picking_types_user" model="res.groups">
<field name="name">User: Assigned Operation Types Only</field>
<field name="category_id" ref="base.module_category_warehouse_management"/>
<field name="comment">The user will have access to her assigned operation types.</field>
</record>
<record id="stock.group_stock_user" model="res.groups">
<field name="implied_ids" eval="[(4, ref('group_assigned_picking_types_user'))]"/>
</record>
<data noupdate="1">
<record id="picking_type_assigned_users" model="ir.rule">
<field name="name">Assigned picking types</field>
<field ref="stock.model_stock_picking_type" name="model_id"/>
<field name="domain_force">['|',('assigned_user_ids','in',user.id),('assigned_user_ids','=',False)]</field>
<field name="groups" eval="[(4, ref('group_assigned_picking_types_user'))]"/>
</record>
<record id="picking_assigned_users" model="ir.rule">
<field name="name">Assigned pickings</field>
<field ref="stock.model_stock_picking" name="model_id"/>
<field name="domain_force">['|',('picking_type_id.assigned_user_ids','in',user.id),('picking_type_id.assigned_user_ids','=',False)]</field>
<field name="groups" eval="[(4, ref('group_assigned_picking_types_user'))]"/>
</record>
<record id="picking_type_see_all" model="ir.rule">
<field name="name">All picking types</field>
<field ref="stock.model_stock_picking_type" name="model_id"/>
<field name="domain_force">[(1,'=',1)]</field>
<field name="groups" eval="[(4, ref('stock.group_stock_user'))]"/>
</record>
<record id="picking_see_all" model="ir.rule">
<field name="name">All pickings</field>
<field ref="stock.model_stock_picking" name="model_id"/>
<field name="domain_force">[(1,'=',1)]</field>
<field name="groups" eval="[(4, ref('stock.group_stock_user'))]"/>
</record>
</data>
</odoo>

View File

@@ -0,0 +1 @@
from . import test_picking_type_user_restriction

View File

@@ -0,0 +1,60 @@
from odoo.tests.common import SavepointCase
class TestUserRestriction(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(
cls.env.context,
tracking_disable=True,
no_reset_password=True,
))
cls.stock_user = cls.env['res.users'].create({
'login': 'stock_user',
'name': 'stock_user',
'groups_id': [(6, 0, [cls.env.ref('stock.group_stock_user').id])]
})
cls.stock_user_assigned_type = cls.env['res.users'].create({
'login': 'stock_user_assigned_type',
'name': 'stock_user_assigned_type',
'groups_id': [(6, 0, [cls.env.ref(
'stock_picking_type_user_restriction.'
'group_assigned_picking_types_user'
).id])]
})
cls.picking_type_out = cls.env.ref('stock.picking_type_out')
cls.picking_type_model = cls.env['stock.picking.type']
def test_access_picking_type(self):
# assigned_user_ids is not set: both users can read
pick_types = self.picking_type_model.sudo(self.stock_user.id).search([
('name', '=', 'Delivery Orders')])
self.assertTrue(self.picking_type_out in pick_types)
pick_types = self.picking_type_model.sudo(
self.stock_user_assigned_type.id).search([
('name', '=', 'Delivery Orders')])
self.assertTrue(self.picking_type_out in pick_types)
self.picking_type_out.assigned_user_ids = [
(6, 0, [self.stock_user_assigned_type.id])]
# assigned_user_ids is set with stock_user_assigned_type: both users can read
pick_types = self.picking_type_model.sudo(self.stock_user.id).search([
('name', '=', 'Delivery Orders')])
self.assertTrue(self.picking_type_out in pick_types)
pick_types = self.picking_type_model.sudo(
self.stock_user_assigned_type.id).search([
('name', '=', 'Delivery Orders')])
self.assertTrue(self.picking_type_out in pick_types)
self.picking_type_out.assigned_user_ids = [
(6, 0, [self.stock_user.id])]
# assigned_user_ids is set with stock_user: only stock_user can read
pick_types = self.picking_type_model.sudo(self.stock_user.id).search([
('name', '=', 'Delivery Orders')])
self.assertTrue(self.picking_type_out in pick_types)
pick_types = self.picking_type_model.sudo(
self.stock_user_assigned_type.id).search([
('name', '=', 'Delivery Orders')])
self.assertFalse(self.picking_type_out in pick_types)

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_template_property_form_assigned_users" model="ir.ui.view">
<field name="name">view_template_property_form_assigned_users</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="stock.view_template_property_form"/>
<field name="arch" type="xml">
<page name="inventory" position="attributes">
<attribute name="groups">stock.group_stock_user,product.group_stock_packaging,stock_picking_type_user_restriction.group_assigned_picking_types_user</attribute>
</page>
</field>
</record>
<record model="ir.ui.view" id="stock.product_form_view_procurement_button">
<field name="groups_id" eval="[(4, ref('stock_picking_type_user_restriction.group_assigned_picking_types_user'))]"/>
</record>
<record model="ir.ui.view" id="product_form_view_procurement_button_assigned_users">
<field name="name">product_form_view_procurement_button_assigned_users</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="stock.product_form_view_procurement_button"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='%(stock.action_product_replenish)d']" position="attributes">
<attribute name="groups">stock.group_stock_user,stock_picking_type_user_restriction.group_assigned_picking_types_user</attribute>
</xpath>
<xpath expr="//button[@name='action_view_stock_move_lines']" position="attributes">
<attribute name="groups">stock.group_stock_user,stock_picking_type_user_restriction.group_assigned_picking_types_user</attribute>
</xpath>
</field>
</record>
<record model="ir.ui.view" id="stock.product_template_form_view_procurement_button">
<field name="groups_id" eval="[(4, ref('stock_picking_type_user_restriction.group_assigned_picking_types_user'))]"/>
</record>
<record model="ir.ui.view" id="product_template_form_view_procurement_button_assigned_users">
<field name="name">product_template_form_view_procurement_button_assigned_users</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="stock.product_template_form_view_procurement_button"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='%(stock.action_product_replenish)d']" position="attributes">
<attribute name="groups">stock.group_stock_user,stock_picking_type_user_restriction.group_assigned_picking_types_user</attribute>
</xpath>
<xpath expr="//button[@name='action_view_stock_move_lines']" position="attributes">
<attribute name="groups">stock.group_stock_user,stock_picking_type_user_restriction.group_assigned_picking_types_user</attribute>
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_inventory_form_assigned_users" model="ir.ui.view">
<field name="name">view_inventory_form_assigned_users</field>
<field name="model">stock.inventory</field>
<field name="inherit_id" ref="stock.view_inventory_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='action_start']" position="attributes">
<attribute name="groups">stock.group_stock_user,stock_picking_type_user_restriction.group_assigned_picking_types_user</attribute>
</xpath>
<xpath expr="//button[@name='action_reset_product_qty']" position="attributes">
<attribute name="groups">stock.group_stock_user,stock_picking_type_user_restriction.group_assigned_picking_types_user</attribute>
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="stock.menu_stock_root" model="ir.ui.menu">
<field name="groups_id" eval="[(4, ref('group_assigned_picking_types_user'))]"/>
</record>
</odoo>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="view_picking_type_form_assigned_users">
<field name="name">view_picking_type_form_assigned_users</field>
<field name="model">stock.picking.type</field>
<field name="inherit_id" ref="stock.view_picking_type_form"/>
<field name="arch" type="xml">
<field name="show_reserved" position="after">
<field name="assigned_user_ids" widget="many2many_tags" options="{'no_create': True}"
groups="stock.group_stock_manager"/>
</field>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_picking_form_assigned_users" model="ir.ui.view">
<field name="name">view_picking_form_assigned_users</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//header//button[3]" position="attributes">
<attribute name="groups">stock.group_stock_user,stock_picking_type_user_restriction.group_assigned_picking_types_user</attribute>
</xpath>
<xpath expr="//header//button[4]" position="attributes">
<attribute name="groups">stock.group_stock_user,stock_picking_type_user_restriction.group_assigned_picking_types_user</attribute>
</xpath>
<xpath expr="//header//button[5]" position="attributes">
<attribute name="groups">stock.group_stock_user,stock_picking_type_user_restriction.group_assigned_picking_types_user</attribute>
</xpath>
</field>
</record>
<record id="stock.all_picking" model="ir.ui.menu">
<field name="groups_id" eval="[(4, ref('group_assigned_picking_types_user'))]"/>
</record>
</odoo>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="stock.act_stock_warehouse_2_stock_warehouse_orderpoint" model="ir.actions.act_window">
<field name="groups_id" eval="[(4, ref('group_assigned_picking_types_user'))]"/>
</record>
</odoo>