Search code examples
odooopenerp-7

Can't confirm sale orders after applying record rule


In odoo 9, I have added a record rule on the model mrp.production as:

['|', ('user_id', '=', user.id), ('user_id', '=', False)]

This will show users only the MOs that belongs to them. Now when I am trying to confirm the sale order which will then create a MO for the lines in that sale order I am getting an access error as:

The requested operation cannot be completed due to security restrictions. Please contact your system administrator.

(Document type: mrp.production, Operation: read) 

Diagnosing more I found that it is causing due to the missing_ids. Take a look at this.

Before that I have used the same solution in openerp 7 and it is still working perfect without any access error while confirming SO.


Solution

  • Finally I found the reason of this issue.

    In opernep/addons/mrp/procurement.py there is line

    production_obj.create(cr, SUPERUSER_ID, vals, context=dict(context, force_company=procurement.company_id.id))
    

    which is using SUPERUSER_ID to create the production order from the procurement.

    I don't know why they changed it to use SUPERUSER_ID. May be to enable non mrp users or external users to create mrp orders even if they have not rights. BTW I have not such requirement and I have solved my problem by replacing this SUPERUSER_ID with uid.