Skip to Content
Menu
This question has been flagged

Dear master,

I new learn on odoo and python, I found the module to restricted user for some module, this addons give effect for all warehouse for all module for example for PO, SO and Internal transfer. I will modified this addons given only effect on warehouse for internal transfer on inventory module not all module. Where code will modify?


this is security xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="stock_restrictions_group" model="res.groups">
<field name="name">Warehouse Restrictions</field>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
<field name="category_id" ref="base.module_category_theme_hidden"/>
</record>

<record id="filter_user_stock_picking_type_allowed" model="ir.rule">
<field name="name">Warehouse Restrictions Picking Types</field>
<field name="model_id" search="[('model','=','stock.picking.type')]" model="ir.model"/>
<field name="groups"
eval="[(4, ref('dvit_warehouse_stock_restrictions.stock_restrictions_group'))]"/>
<field name="domain_force">[('id','in', user.default_picking_type_ids.ids)]</field>
</record>

<record id="filter_user_stock_picking_allowed" model="ir.rule">
<field name="name">Warehouse Restrictions Pickings</field>
<field name="model_id" search="[('model','=','stock.picking')]" model="ir.model"/>
<field name="groups" eval="[(4, ref('dvit_warehouse_stock_restrictions.stock_restrictions_group'))]"/>
<field name="domain_force">
[('picking_type_id','in', user.default_picking_type_ids.ids),
'|','|','|',
('location_id','in', user.stock_location_ids.ids),
('location_dest_id','in', user.stock_location_ids.ids),
('location_id.location_id','in', user.stock_location_ids.ids),
('location_dest_id.location_id','in', user.stock_location_ids.ids)]
</field>
</record>

<record id="filter_user_stock_location_allowed" model="ir.rule">
<field name="name">Warehouse Restrictions locations</field>
<field name="model_id" search="[('model','=','stock.location')]" model="ir.model"/>
<field name="groups" eval="[(4, ref('dvit_warehouse_stock_restrictions.stock_restrictions_group'))]"/>
<field name="domain_force">
['|',
('id','in', user.stock_location_ids.ids),
('location_id','in', user.stock_location_ids.ids),
]
</field>
</record>

</data>
</odoo>


this is model stock.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
from odoo.exceptions import Warning


class ResUsers(models.Model):
_inherit = 'res.users'

restrict_locations = fields.Boolean('Restrict Locations', readonly="1")

stock_location_ids = fields.Many2many(
'stock.location',
'location_security_stock_location_users',
'user_id',
'location_id',
'Stock Locations')

default_picking_type_ids = fields.Many2many(
'stock.picking.type', 'stock_picking_type_users_rel',
'user_id', 'picking_type_id', string='Warehouse Operations')


@api.constrains('default_picking_type_ids')
def update_restrict(self):
restrict_group = self.env.ref('dvit_warehouse_stock_restrictions.stock_restrictions_group')
current_group = restrict_group
if self.stock_location_ids:
current_group.write({'users': [(3, self.id)]})
self.groups_id =[(3, restrict_group.id)]
self.restrict_locations = 0
##
current_group.write({'users': [(4, self.id)]})
self.groups_id =[(4, restrict_group.id)]
self.restrict_locations = 1

@api.constrains('stock_location_ids')
def tgl_restrict(self):
# self.restrict_locations = not self.restrict_locations
# res_groups = self.env['res.groups']
restrict_group = self.env.ref('dvit_warehouse_stock_restrictions.stock_restrictions_group')
current_group = restrict_group
if self.stock_location_ids:
# Due to strange behaviuor, we must remove the user from the group then
# re-add him again to get restrictions applied
current_group.write({'users': [(3, self.id)]})
self.groups_id =[(3, restrict_group.id)]
self.default_picking_type_ids = False
self.restrict_locations = 0
## re-add
# by default select all oprtations related to the selected location or its parent
pick_types = self.env['stock.picking.type'].sudo().search(['|','|','|',
('default_location_src_id','in',[l.id for l in self.stock_location_ids]),
('default_location_src_id.location_id','in',[l.id for l in self.stock_location_ids]),
('default_location_dest_id','in',[l.id for l in self.stock_location_ids]),
('default_location_dest_id.location_id','in',[l.id for l in self.stock_location_ids]),
])
current_group.write({'users': [(4, self.id)]})
self.groups_id =[(4, restrict_group.id)]
self.default_picking_type_ids += pick_types
self.restrict_locations = 1

else:
current_group.write({'users': [(3, self.id)]})
self.groups_id =[(3, restrict_group.id)]
self.default_picking_type_ids = False
self.restrict_locations = 0


and this is for view user.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_users_form" model="ir.ui.view">
<field name="name">usability.default_warehouse.res.users.form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<group name="preferences" position="after">
<group string="Warehouse Restrictions" attrs="{'invisible': [('id','=', 1)]}">
<field name="stock_location_ids" widget="many2many_tags"/>
<field name="default_picking_type_ids" widget="many2many_tags"
attrs="{'invisible': [('restrict_locations','=', False)]}"/>
<field name="restrict_locations" string="Restriction status"/>
</group>
</group>
</field>
</record>
</odoo>


many thanks for your help.


regards

nanang

Avatar
Discard
Related Posts Replies Views Activity
1
May 24
568
2
Dec 22
12032
5
Sep 20
30003
5
Apr 20
3814
0
Apr 18
2911