<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!--  Achievement Report RECORD RULE-->
<record id="sos_sales_achievement_report_own_records_rule" model="ir.rule">
    <field name="name">Sos Achievement Report: Own Records - Read Access</field>
    <field name="model_id" ref="model_sos_sales_achievement_report"/>
    <field name="domain_force">[(1, '=', 1)]</field>
    <field name="groups" eval="[
        (4, ref('sos_inventory.sos_management_user')),
        (4, ref('sos_inventory.sos_finance_user')),
        (4, ref('sos_inventory.sos_sales_reviewer'))
    ]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="0"/>
</record>
 <record id="sos_sales_achievement_report_all_records_rule" model="ir.rule">
    <field name="name">Sos Achievement Report: All Records - Read Access</field>
    <field name="model_id" ref="model_sos_sales_achievement_report"/>
    <field name="domain_force">[
    '|',
    ('create_uid', '=', user.id),
    ('sales_person', '=', user.id)
]</field>
    <field name="groups" eval="[(4, ref('base.group_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="0"/>
    <field name="perm_unlink" eval="0"/>
</record>
<!--  Sales Target RECORD RULE-->
<record id="sos_sales_plan_target_own_records_rule" model="ir.rule">
    <field name="name">Sos Sales Target: Own Records - Read Access</field>
    <field name="model_id" ref="model_sos_sales_plan_target"/>
    <field name="domain_force">[(1, '=', 1)]</field>
    <field name="groups" eval="[
        (4, ref('sos_inventory.sos_management_user')),
        (4, ref('sos_inventory.sos_finance_user')),
        (4, ref('sos_inventory.sos_sales_reviewer'))
    ]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="0"/>
</record>
 <record id="sos_sales_plan_target_all_records_rule" model="ir.rule">
    <field name="name">Sos Sales Target: All Records - Read Access</field>
    <field name="model_id" ref="model_sos_sales_plan_target"/>
    <field name="domain_force">[
    '|',
    ('create_uid', '=', user.id),
    ('sales_executive', '=', user.id)
]</field>
    <field name="groups" eval="[(4, ref('base.group_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="0"/>
    <field name="perm_unlink" eval="0"/>
</record>
<!--  sales_action RECORD RULE-->
<!-- 1) Full visibility for management/finance/sales reviewer -->
<record id="sos_sales_action_plan_full_access_rule" model="ir.rule">
    <field name="name">Sos Action Plan: Full Access (Mgmt/Finance/Reviewer)</field>
    <field name="model_id" ref="model_sos_sales_action_plan"/>
    <!-- Always true -->
    <field name="domain_force">[(1,'=',1)]</field>
    <field name="groups" eval="[
        (4, ref('sos_inventory.sos_management_user')),
        (4, ref('sos_inventory.sos_finance_user')),
        (4, ref('sos_inventory.sos_sales_reviewer'))
    ]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="0"/>
</record>

<!-- 2) Own / Team for all internal users -->
<record id="sos_sales_action_plan_restricted_rule" model="ir.rule">
    <field name="name">Sos Action Plan: Own and Team (Internal Users)</field>
    <field name="model_id" ref="model_sos_sales_action_plan"/>
    <field name="domain_force">
        [
            '|','|',
            ('create_uid', '=', user.id),
            ('sales_executive', '=', user.id),
            ('reporting_to', '=', user.id)
        ]
    </field>
    <!-- Apply to all internal users -->
    <field name="groups" eval="[(4, ref('base.group_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="0"/>
</record>

<record id="sos_sales_action_plan_ce_team_rule" model="ir.rule">
    <field name="name">Sales Action Plan: CE Team View CE Records</field>
    <field name="model_id" ref="model_sos_sales_action_plan"/>
    <field name="domain_force">[('is_ce_user_created', '=', True)]</field>
    <field name="groups" eval="[(4, ref('sos_inventory.sos_ce_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="0"/>
</record>
<record id="sos_sales_action_plan_ce_head_rule" model="ir.rule">
    <field name="name">Sales Action Plan: CE Head View CE Records</field>
    <field name="model_id" ref="model_sos_sales_action_plan"/>
    <field name="domain_force">[('is_ce_user_created', '=', True)]</field>
    <field name="groups" eval="[(4, ref('sos_inventory.sos_ce_head'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="0"/>
</record>

      <!--  customers RECORD RULE-->
<record id="sos_customers_own_records_rule" model="ir.rule">
    <field name="name">Sos customers: Own Records - Read Access</field>
    <field name="model_id" ref="model_sos_customers"/>
    <field name="domain_force">[(1, '=', 1)]</field>
    <field name="groups" eval="[
        (4, ref('sos_inventory.sos_management_user')),
        (4, ref('sos_inventory.sos_finance_user')),
        (4, ref('sos_inventory.sos_ce_head')),
        (4, ref('sos_inventory.sos_sales_reviewer'))
    ]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="0"/>
</record>
<record id="sos_customers_ce_team_rule" model="ir.rule">
    <field name="name">Customers: CE Team View CE customers Records</field>
    <field name="model_id" ref="model_sos_customers"/>
    <field name="domain_force">[('is_ce_user_created', '=', True)]</field>
    <field name="groups" eval="[(4, ref('sos_inventory.sos_ce_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="0"/>
    <field name="perm_create" eval="0"/>
    <field name="perm_unlink" eval="0"/>
</record>
  <record id="sos_customers_all_records_rule" model="ir.rule">
    <field name="name">Sos customers: All Records - Read Access</field>
    <field name="model_id" ref="model_sos_customers"/>
     <field name="domain_force">[
           '|', '|',
            ('create_uid', '=', user.id),
            ('reporting_to', '=', user.id),
            ('responsible', '=', user.id)
        ]</field>
    <field name="groups" eval="[(4, ref('base.group_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="0"/>
    <field name="perm_unlink" eval="0"/>
</record>

<record id="sos_case_diary_ce_team_rule" model="ir.rule">
    <field name="name">Case Diary: CE Team View CE Records</field>
    <field name="model_id" ref="model_sos_case_diary"/>
    <field name="domain_force">[('is_ce_user_created', '=', True)]</field>
    <field name="groups" eval="[(4, ref('sos_inventory.sos_ce_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="0"/>
    <field name="perm_create" eval="0"/>
    <field name="perm_unlink" eval="0"/>
</record>

<record id="sos_case_diary_ce_head_rule" model="ir.rule">
    <field name="name">Case Diary: CE Head View CE Records</field>
    <field name="model_id" ref="model_sos_case_diary"/>
    <field name="domain_force">[('is_ce_user_created', '=', True)]</field>
    <field name="groups" eval="[(4, ref('sos_inventory.sos_ce_head'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="0"/>
    <field name="perm_create" eval="0"/>
    <field name="perm_unlink" eval="0"/>
</record>

       <!--  Case Diary Report RECORD RULE-->
<!-- 1) Full visibility for management/finance/sales reviewer -->
<record id="sos_case_diary_full_access_rule" model="ir.rule">
    <field name="name">Sos Case Diary: Full Access (Mgmt/Finance/Reviewer)</field>
    <field name="model_id" ref="model_sos_case_diary"/>
    <!-- Always true -->
    <field name="domain_force">[(1,'=',1)]</field>
    <field name="groups" eval="[
        (4, ref('sos_inventory.sos_management_user')),
        (4, ref('sos_inventory.sos_finance_user')),
        (4, ref('sos_inventory.sos_sales_reviewer'))
    ]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="0"/>
</record>

<!-- 2) Own / Team for all internal users -->
<record id="sos_case_diary_restricted_rule" model="ir.rule">
    <field name="name">Sos Case Diary: Own and Team (Internal Users)</field>
    <field name="model_id" ref="model_sos_case_diary"/>
    <field name="domain_force">
        [
            '|','|',
            ('create_uid', '=', user.id),
            ('reporting_to', '=', user.id),
            ('sales_person', '=', user.id)
        ]
    </field>
    <!-- Apply to all internal users -->
    <field name="groups" eval="[(4, ref('base.group_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="0"/>
</record>

      <!--  Leads RECORD RULE-->
<record id="sos_sales_leads_own_records_rule" model="ir.rule">
    <field name="name">Sos Leads: Own Records - Read Access</field>
    <field name="model_id" ref="model_sos_sales_leads"/>
    <field name="domain_force">[(1, '=', 1)]</field>
    <field name="groups" eval="[
        (4, ref('sos_inventory.sos_management_user')),
        (4, ref('sos_inventory.sos_finance_user'))
    ]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="0"/>
</record>

  <record id="sos_sales_leads_all_records_rule" model="ir.rule">
    <field name="name">Sos Leads: All Records - Read Access</field>
    <field name="model_id" ref="model_sos_sales_leads"/>
     <field name="domain_force">[
            '|','|',
            ('create_uid', '=', user.id),
            ('lead_generated_by', '=', user.id),
            ('responsible_sales_persons', 'in', [user.id])
        ]</field>
    <field name="groups" eval="[(4, ref('base.group_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="0"/>
    <field name="perm_unlink" eval="0"/>
</record>
  <record id="sos_proposal_boq_all_records_rule" model="ir.rule">
    <field name="name">Sos Proposal BOQ: All Records - Read Access</field>
    <field name="model_id" ref="model_sos_proposal_boq"/>
    <field name="domain_force">[
     '|',
            ('create_uid', '=', user.id),
            ('sales_executive', '=', user.id)
        ]</field>
    
    <field name="groups" eval="[(4, ref('base.group_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="1"/>
</record>
  <record id="sos_proposal_builder_all_records_rule" model="ir.rule">
    <field name="name">Sos Proposal Builder: All Records - Read Access</field>
    <field name="model_id" ref="model_sos_proposal_builder"/>
    <field name="domain_force">[
     '|',
            ('create_uid', '=', user.id),
            ('sales_executive', '=', user.id)
        ]</field>
    
    <field name="groups" eval="[(4, ref('base.group_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="1"/>
</record>
  <record id="sos_proposal_customer_requirement_all_records_rule" model="ir.rule">
    <field name="name">Sos Proposal Requirement: All Records - Read Access</field>
    <field name="model_id" ref="model_sos_proposal_customer_requirement"/>
      <field name="domain_force">[
            ('create_uid', '=', user.id)
        ]</field>
    <field name="groups" eval="[(4, ref('base.group_user'))]"/>
    <field name="perm_read" eval="1"/>
    <field name="perm_write" eval="1"/>
    <field name="perm_create" eval="1"/>
    <field name="perm_unlink" eval="1"/>
</record>
</odoo>
