<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <record model="ir.module.category" id="module_category_subscription_management">
        <field name="name">Subscriptions</field>
        <field name="description">Helps you handle subscriptions and recurring invoicing.</field>
        <field name="sequence">3</field>
    </record>

    <record id="group_sale_subscription_view" model="res.groups">
        <field name="name">See Subscriptions</field>
        <field name="category_id" ref="base.module_category_odex25_sales_subscriptions"/>
        <field name="comment">The user will have read access to subscriptions.</field>
    </record>

    <record id="group_sale_subscription_manager" model="res.groups">
        <field name="name">Administrator</field>
        <field name="category_id" ref="base.module_category_odex25_sales_subscriptions"/>
        <field name="comment">The user will have write access to Subscriptions.</field>
        <field name="implied_ids" eval="[(4, ref('odex25_sale_subscription.group_sale_subscription_view'))]"/>
        <field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
    </record>

    <record id="sales_team.group_sale_salesman" model="res.groups">
        <field name="implied_ids" eval="[(4, ref('odex25_sale_subscription.group_sale_subscription_view'))]"/>
    </record>

    <data noupdate="1">

    <!-- Multi-company -->
    <record model="ir.rule" id="sale_subscription_multicompany">
        <field name="name">Subscription multi-company</field>
        <field name="model_id" ref="model_sale_subscription"/>
        <field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
    </record>

    <record model="ir.rule" id="sale_subscription_template_multicompany">
        <field name="name">Subscription template multi-company</field>
        <field name="model_id" ref="model_sale_subscription_template"/>
        <field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
    </record>

    <record model="ir.rule" id="sale_subscription_line_multicompany">
        <field name="name">Subscription line multi-company</field>
        <field name="model_id" ref="model_sale_subscription_line"/>
        <field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
    </record>

    <record model="ir.rule" id="sale_subscription_log_multicompany">
        <field name="name">Subscription log multi-company</field>
        <field name="model_id" ref="model_sale_subscription_log"/>
        <field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
    </record>


    <!-- Reporting -->
    <record model="ir.rule" id="sale_subscription_report_comp_rule">
        <field name="name">Subscription Analysis multi-company</field>
        <field name="model_id" ref="model_sale_subscription_report"/>
        <field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
    </record>

    <record id="sale_subscription_report_personal_rule" model="ir.rule">
        <field name="name">Personal Subscription Analysis</field>
        <field ref="model_sale_subscription_report" name="model_id"/>
        <field name="domain_force">['|',('user_id','=',user.id),('user_id','=',False)]</field>
        <field name="groups" eval="[(4, ref('sales_team.group_sale_salesman'))]"/>
    </record>

    <record id="sale_order_report_see_all" model="ir.rule">
        <field name="name">All Orders Analysis</field>
        <field ref="model_sale_subscription_report" name="model_id"/>
        <field name="domain_force">[(1,'=',1)]</field>
        <field name="groups" eval="[(4, ref('sales_team.group_sale_salesman_all_leads'))]"/>
    </record>

        <record id="base.default_user" model="res.users">
            <field name="groups_id" eval="[(4,ref('odex25_sale_subscription.group_sale_subscription_manager'))]"/>
        </record>

        <!-- Portal -->
        <record id="subscription_portal" model="ir.rule">
            <field name="name">Subscription portal access</field>
            <field name="model_id" ref="odex25_sale_subscription.model_sale_subscription"/>
            <field name="domain_force">[('partner_id','in',[user.partner_id.id,user.commercial_partner_id.id])]</field>
            <field name="groups" eval="[(4, ref('base.group_portal'))]"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="True"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_unlink" eval="False"/>
        </record>
        <record id="inv_line_portal" model="ir.rule">
            <field name="name">Invoice line portal access</field>
            <field name="model_id" ref="odex25_sale_subscription.model_sale_subscription_line"/>
            <field name="domain_force">[('analytic_account_id.partner_id','in',[user.partner_id.id,user.commercial_partner_id.id])]</field>
            <field name="groups" eval="[(4, ref('base.group_portal'))]"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="False"/>
            <field name="perm_create" eval="False"/>
            <field name="perm_unlink" eval="False"/>
        </record>
    </data>
</odoo>
