Warehouse stock restriction not working in edit mode odoo10?

187 Views Asked by At

In my custom module I use stock picking type to see the warehouse operations of the user.

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

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

I added this in user form.

In my sexurity.xml file add

<record id="filter_user_stock_picking_type" model="ir.rule">
        <field name="name">Filter Stock Picking Type</field>
        <field name="model_id" search="[('model','=','stock.picking.type')]" model="ir.model"/>
        <field name="groups" eval="[(4, ref('base.group_user'))]"/>
        <field name="domain_force">[('id','in', [ s.id for s in user.default_picking_type_ids ])]</field>
 </record>

so it is worked in when a user is created and assigns stock operation.

But when changed the stock operation to particular user, it will not affect.

How to resolve this issue??

1

There are 1 best solutions below

0
On BEST ANSWER

I think, the problem is the Odoo Cache. The old values are stored in the Cache for a long time and your change will not take any effect.

You can try it to clear the cache. It helped me to solve the similar problem.

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

    @api.multi
    def write(self, vals):
        ret = super(User, self).write(vals)

        if 'default_picking_type_ids' in vals:
            # clear default ir values when default_picking_type_ids changes
            self.env['ir.values'].get_defaults_dict.clear_cache(self.env['ir.values'])
        return ret