<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2018-2019 ForgeFlow, S.L.
     License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>
    <record model="ir.module.category" id="module_category_purchase_request">
        <field name="name">Purchase Request</field>
        <field name="parent_id" ref="base.module_category_purchase_management" />
        <field name="sequence">10</field>
    </record>
    <record id="group_purchase_request_user" model="res.groups">
        <field name="name">Purchase Request User</field>
        <field name="implied_ids" eval="[(4, ref('base.group_user'))]" />
        <field name="category_id" ref="module_category_purchase_request" />
    </record>
    <record id="group_purchase_request_manager" model="res.groups">
        <field name="name">Purchase Request Manager</field>
        <field
            name="implied_ids"
            eval="[(4, ref('purchase_request.group_purchase_request_user'))]"
        />
        <field name="category_id" ref="module_category_purchase_request" />
    </record>
    <record model="ir.rule" id="purchase_request_comp_rule">
        <field name="name">Purchase Request multi-company</field>
        <field name="model_id" ref="model_purchase_request" />
        <field name="global" eval="True" />
        <field name="domain_force">
            ['|',('company_id','=',False),('company_id', 'in', company_ids)]
        </field>
    </record>
    <record model="ir.rule" id="purchase_request_line_comp_rule">
        <field name="name">Purchase Request Line multi-company</field>
        <field name="model_id" ref="model_purchase_request_line" />
        <field name="global" eval="True" />
        <field name="domain_force">
            ['|',('company_id','=',False),('company_id', 'in', company_ids)]
        </field>
    </record>
    <record id="purchase_request_followers_rule" model="ir.rule">
        <field name="name">Follow Purchase Request</field>
        <field name="model_id" ref="model_purchase_request" />
        <field name="groups" eval="[(6,0, [ref('group_purchase_request_user')])]" />
        <field name="perm_read" eval="True" />
        <field name="perm_write" eval="False" />
        <field name="perm_create" eval="False" />
        <field name="perm_unlink" eval="False" />
        <field name="domain_force">
            ['|',('requested_by','=',user.id),
                                        ('message_partner_ids', 'in',
            [user.partner_id.id])]
        </field>
    </record>
    <record id="purchase_request_rule" model="ir.rule">
        <field name="name">Purchase Request User</field>
        <field name="model_id" ref="model_purchase_request" />
        <field name="groups" eval="[(6,0, [ref('group_purchase_request_user')])]" />
        <field name="perm_read" eval="True" />
        <field name="perm_write" eval="True" />
        <field name="perm_create" eval="True" />
        <field name="perm_unlink" eval="True" />
        <field name="domain_force">[('requested_by','=',user.id)]</field>
    </record>
    <record id="purchase_request_manager_rule" model="ir.rule">
        <field name="name">Purchase Request Manager</field>
        <field name="model_id" ref="model_purchase_request" />
        <field name="groups" eval="[(6,0, [ref('group_purchase_request_manager')])]" />
        <field name="perm_read" eval="True" />
        <field name="perm_write" eval="True" />
        <field name="perm_create" eval="True" />
        <field name="perm_unlink" eval="True" />
    </record>
    <record id="purchase_request_line_followers_rule" model="ir.rule">
        <field name="name">Follow Purchase Request Line</field>
        <field name="model_id" ref="model_purchase_request_line" />
        <field name="groups" eval="[(6,0, [ref('group_purchase_request_user')])]" />
        <field name="perm_read" eval="True" />
        <field name="perm_write" eval="False" />
        <field name="perm_create" eval="False" />
        <field name="perm_unlink" eval="False" />
        <field name="domain_force">
            ['|',('request_id.requested_by','=',user.id),
                                        ('request_id.message_partner_ids', 'in',
            [user.partner_id.id])]
        </field>
    </record>
    <record id="purchase_request_line_rule" model="ir.rule">
        <field name="name">Purchase Request Line User</field>
        <field name="model_id" ref="model_purchase_request_line" />
        <field name="groups" eval="[(6,0, [ref('group_purchase_request_user')])]" />
        <field name="perm_read" eval="True" />
        <field name="perm_write" eval="True" />
        <field name="perm_create" eval="True" />
        <field name="perm_unlink" eval="True" />
        <field name="domain_force">[('request_id.requested_by','=',user.id)]</field>
    </record>
    <record id="purchase_request_line_manager_rule" model="ir.rule">
        <field name="name">Purchase Request Line Manager</field>
        <field name="model_id" ref="model_purchase_request_line" />
        <field name="groups" eval="[(6,0, [ref('group_purchase_request_manager')])]" />
        <field name="perm_read" eval="True" />
        <field name="perm_write" eval="True" />
        <field name="perm_create" eval="True" />
        <field name="perm_unlink" eval="True" />
    </record>
</odoo>
