<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="view_empowerment_request_form" model="ir.ui.view">
        <field name="name">empowerment.request.form</field>
        <field name="model">empowerment.request</field>
        <field name="arch" type="xml">
            <form string="طلب تمكين">
                <sheet>
                    <header>
                        <!-- Draft -->
                        <button string="اعتماد الاخصائى الاجتماعى" type="object" name="action_approve_social_worker" states="draft"/>
                        <button string="رفض" type="object" name="action_reject" states="draft,social_worker,head_of_department,branch_manager,finance"/>

                        <!-- Social Worker -->
                        <button string="اعتماد" type="object" name="action_approve_head" states="social_worker"/>
                        <button string="ارجاع لمسودة" type="object" name="action_return_to_draft" states="social_worker"/>


                        <!-- Head of Department -->
                        <button string="اعتماد" type="object" name="action_approve_branch" states="head_of_department"/>
                        <button string="ارجاع للاخصائى الاجتماعى" type="object" name="action_return_to_social_worker" states="head_of_department"/>


                        <!-- Branch Manager -->
                        <button string="اعتماد" type="object" name="action_approve_finance" states="branch_manager"/>

                        <!-- Finance -->
                        <button string="اعتماد" type="object" name="action_approve_final" states="finance"/>
                        <button string="ارجاع لمسودة" type="object" name="action_return_to_draft" states="finance"/>
                        <field name="state"  widget="statusbar" />
                    </header>

                    <group string="معلومات عامة">
                        <field name="name"/>
                        <field name="request_date"/>
                        <field name="creator_id"/>
                        <field name="branch_id"/>
                    </group>

                    <group string="البيانات الشخصية">
                        <field name="familye_id"/>
                        <field name="relationship"/>
                        <field name="benefit_category_id"/>
                        <field name="identity_number"/>
                        <field name="sms_phone"/>
                        <field name="email"/>
                        <field name="nationality"/>
                        <field name="education_status"/>
                        <field name="has_car"/>
                        <field name="health_status" attrs="{'required': [('service_type', '=', 'employment')]}"/>
                    </group>

                    <group string="بيانات الخدمة">
                        <field name="service_id"/>
                        <field name="service_type"/>
                        <field name="service_item"/>

                    </group>

                    <group string="بيانات تعليمية" attrs="{'invisible': [('service_type', 'not in', [
                            'educational_care','bachelor_service','diploma_service',
                            'bachelor_intercession','diploma_intercession'])]}">

                        <field name="study_specialization"
                        />
                        <field name="university_id" attrs="{'invisible': [('study_specialization', '!=', 'bachelor')]}"
                        />
                        <field name="institute_id" attrs="{'invisible': [('study_specialization', '!=', 'diploma')]}
                                " />
                        <field name="intercession_type" />
                        <field name="request_entity_id" />
                        <field name="description" />
                    </group>

                    <group string="بيانات تدريبية" attrs="{'invisible': [('service_type', 'not in', ['training_service','training_intercession'])]}">
                        <field name="training_type" />
                        <field name="training_course_id"  context="{'default_name': ''}"/>
                        <field name="training_entity_id"  attrs="{'invisible': [('service_type', '!=', 'training_intercession')]}"/>
                        <field name="training_intercession_type"  attrs="{'invisible': [('service_type', '!=', 'training_intercession')]}"/>
                    </group>

                    <group string="بيانات تمويل" attrs="{'invisible': [('service_type', 'not in', ['funding_service','project_funding_intercession'])]}">
                        <field name="project_funding_type_id"  attrs="{'invisible': [('service_type', '!=', 'funding_service')]}"/>
                        <field name="sponsor_id"  domain="[('branch_id', '=', branch_id)]"/>
                        <field name="sponsor_mobile" readonly="1"/>
                        <!--                        commmint-->
                        <field name="sponsor_identity" readonly="1"/>
                        <field name="sponsor_email" readonly="1"/>
                        <!--                        <field name="sponsor_communication_method" readonly="1"/>-->
                        <field name="finance_request_entity_id"  context="{'default_name': ''}" attrs="{'invisible': [('service_type', '!=', 'project_funding_intercession')]}"/>
                    </group>

                    <group string="الجهة المستلمة للطلب">
                        <field name="request_receiver_id"
                               context="{'default_is_empowerment_receiver': True}"

                               options="{'no_open': False}"/>
                    </group>
                    <!--                    commint  domain="[('is_empowerment_receiver', '=', True)]"
                                                   context="{'default_is_empowerment_receiver': True}"-->

                    <group string="الإجراءات">
                        <field name="reject_reason" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
                        <field name="return_reason" attrs="{'readonly': [('state', '!=', 'draft')]}"/>

                    </group>



                    <notebook string="بيانات احصائية">

                        <page string="الدورات التدريبية">
                            <field name="employment_history_ids" >
                                <tree>
                                    <field name="name" />
                                    <field name="position" />
                                    <field name="salary" />
                                    <field name="date_from"  required="True"/>
                                    <field name="date_to"  required="True"/>
                                    <field name="country"  required="True"/>
                                </tree>
                            </field>
                        </page>
                        <page string=" الخبرات السابقة">
                            <field name="qualifiction_id"
                                   editable="bottom">
                                <tree editable="bottom">
                                    <field name="uni_name"/>
                                    <!--                                    <field name="col_name"/>-->
                                    <field name="qualification_id" />
                                    <field name="qualification_specification_id"
                                           context="{'default_type': 'qualification'}"/>
                                    <field name="qualification_degree" />
                                    <field name="comp_date"/>
                                    <field name="country_name" />
                                    <field name="attachment"  widget="binary"/>
                                </tree>
                            </field>
                        </page>


                        <page string="بيانات المستفيد">
                            <field name="member_ids" widget="one2many_list"
                                   readonly="0" edit="0" create="0">
                                <form string="Family Member">
                                    <widget name="web_ribbon" title="Non Benefit Member" bg_color="bg-danger"
                                            attrs="{'invisible': [('member_status', '!=', 'non_benefit')]}"/>
                                    <widget name="web_ribbon" title="Benefit Member" bg_color="bg-success"
                                            attrs="{'invisible': [('member_status', '!=', 'benefit')]}"/>
                                    <sheet>
                                        <group>
                                            <label for="relationn" string="Relation"/>
                                            <div>
                                                <field name="relationn" class="oe_inline" nolabel="1"
                                                       attrs="{'readonly':[('parent.state','not in',['draft','new','complete_info'])]}"
                                                       options='{"no_open": True,"no_create_edit": True}'
                                                />
                                                <field name="relation" class="oe_inline" nolabel="1" invisible="1"/>
                                            </div>
                                        </group>
                                        <group>
                                            <group>
                                                <field placeholder="Name" name="name" class="oe_inline" readonly="1"
                                                       force_save="1" invisible="1"/>
                                                <field name="is_mother" invisible="1"/>
                                                <field name="member_first_name" force_save="1"
                                                       attrs="{'invisible':[('is_mother','=',True)],'required':[('is_mother','=',False)]}"/>
                                                <field name="mother_first_name" force_save="1"
                                                       attrs="{'invisible':[('is_mother','=',False)],'required':[('is_mother','=',True)]}"/>
                                                <field name="member_third_name" force_save="1"
                                                       attrs="{'invisible':[('is_mother','=',True)],'required':[('is_mother','=',False)]}"/>
                                                <field name="mother_third_name" force_save="1"
                                                       attrs="{'invisible':[('is_mother','=',False)],'required':[('is_mother','=',True)]}"/>
                                                <field name="member_id_number" />
                                                <field name="is_dead"/>
                                                <field name="death_certificate" widget="many2many_attachment_preview"
                                                       attrs="{'invisible':[('is_dead','=',False)]}"/>
                                                <!--                                                     <field name="gender" required="1"/>-->
                                                <field name="member_location" force_save="1" invisible="1"/>
                                                <field name="relationn_type" invisible="1"/>
                                                <field name="member_location_conf" required="1" domain="[('location_type', '=', relationn_type in ['mother','replacement_mother'] and 'mother_location' or 'member')]"
                                                        options="{'no_create': True, 'no_create_edit': True}"/>
                                                <field name="is_work" attrs="{'invisible':[('age','&lt;',18)]}"/>
                                                <field name="member_income"
                                                       attrs="{'invisible':['|',('age','&lt;',18),('is_work','=',False)], 'required':[('is_work','=',True)]}"/>
                                                <field name="salary_certificate" widget="many2many_attachment_preview" attrs="{'invisible':['|',('age','&lt;',18),('is_work','=',False)]}"/>
                                                <field name="minor_siblings" readonly="1" force_save="1"/>
                                                <field name="sponsor_id"/>
                                                <field name="is_excluded_suspension" invisible="1" readonly="1" force_save="1"/>
                                                <field name="member_status" readonly="1" widget="badge"
                                                       decoration-success="member_status == 'benefit'"
                                                       decoration-danger="member_status == 'non_benefit'"/>
                                            </group>
                                            <group>
                                                <field name="member_second_name" force_save="1"
                                                       attrs="{'invisible':[('is_mother','=',True)],'required':[('is_mother','=',False)]}"/>
                                                <field name="mother_second_name" force_save="1"
                                                       attrs="{'invisible':[('is_mother','=',False)],'required':[('is_mother','=',True)]}"/>
                                                <field name="member_family_name" force_save="1"
                                                       attrs="{'invisible':[('is_mother','=',True)],'required':[('is_mother','=',False)]}"/>
                                                <field name="mother_family_name" force_save="1"
                                                       attrs="{'invisible':[('is_mother','=',False)],'required':[('is_mother','=',True)]}"/>
                                                <field name="benefit_id" invisible="1"/>
                                                <field name="member_phone"
                                                       attrs="{'invisible':[('is_mother','=',True)]}"/>
                                                <field name="birth_date" />
                                                <field name="age" />
                                                <field name="age_status"/>
                                                <field name="is_married"
                                                       attrs="{'invisible':[('is_mother','=',True)]}"/>
                                                <field name="marriage_certificate"
                                                       widget="many2many_attachment_preview"
                                                       attrs="{'invisible':['|',('is_mother','=',True),('is_married','=',False)]}"/>
                                                <field name="mother_marital_conf"
                                                       attrs="{'invisible':[('is_mother','=',False)]}"
                                                       options="{'no_create': True, 'no_create_edit': True}"
                                                       groups="!odex_benefit.group_benefit_manager"/>
                                                <field name="mother_location" invisible="1"/>
                                            </group>
                                        </group>
                                        <notebook>
                                            <page string="Hobbies">
                                                <field name="hobbies_attachment_ids" widget="one2many_list">
                                                    <tree editable="bottom">
                                                        <field name="hobbies_id" required="1"/>
                                                        <field name="name"/>
                                                        <field name="datas" widget="binary"
                                                               filename="attachment_file_name"/>
                                                        <button name="action_preview_attachment" type="object"
                                                                string="Preview Attachment"/>
                                                        <field name="expiration_date"/>
                                                        <field name="attach_status"/>
                                                        <field name="member_id" invisible="1"/>
                                                    </tree>
                                                </field>
                                            </page>
                                            <page string="Diseases">
                                                <field name="diseases_attachment_ids" widget="one2many_list">
                                                    <tree editable="bottom">
                                                        <field name="diseases_id" required="1"/>
                                                        <field name="name"/>
                                                        <field name="datas" widget="binary"
                                                               filename="attachment_file_name"/>
                                                        <button name="action_preview_attachment" type="object"
                                                                string="Preview Attachment"/>
                                                        <field name="expiration_date"/>
                                                        <field name="attach_status"/>
                                                        <field name="member_id" invisible="1"/>
                                                    </tree>
                                                </field>
                                            </page>
                                            <page string="Disabilities">
                                                <field name="disabilities_attachment_ids" widget="one2many_list">
                                                    <tree editable="bottom">
                                                        <field name="disabilities_id" required="1"/>
                                                        <field name="name"/>
                                                        <field name="datas" widget="binary"
                                                               filename="attachment_file_name"/>
                                                        <button name="action_preview_attachment" type="object"
                                                                string="Preview Attachment"/>
                                                        <field name="expiration_date"/>
                                                        <field name="attach_status"/>
                                                        <field name="member_id" invisible="1"/>
                                                    </tree>
                                                </field>
                                            </page>
                                            <page string="Education">
                                                <h3>Education Status</h3>
                                                <field name="member_education_status_ids" mode="tree,form"/>
                                            </page>
                                            <page string="Attachments">
                                                <field name="attachment_ids" widget="one2many_list">
                                                    <tree editable="bottom" delete="0">
                                                        <field name="name" string="Attachment Name"
                                                               attrs="{'readonly':[('is_default','=',True)]}"
                                                               force_save="1"/>
                                                        <field name="attach_id" invisible="1"/>
                                                        <field name="datas" widget="binary"
                                                               filename="attachment_file_name"/>
                                                        <button name="action_preview_attachment" type="object"
                                                                string="Preview Attachment"/>
                                                        <field name="expiration_date"/>
                                                        <field name="attach_status"/>
                                                        <field name="allow_days"/>
                                                        <field name="benefit_id" invisible="1"/>
                                                        <field name="is_required" invisible="1"/>
                                                        <field name="is_default" invisible="1"/>
                                                    </tree>
                                                </field>
                                                <group>
                                                    <field name="state" invisible="1"/>
                                                    <field name="required_attach"
                                                           attrs="{'required':[('state','not in',['draft','new'])]}"/>
                                                </group>
                                            </page>

                                        </notebook>
                                    </sheet>
                                </form>
                                <tree string="Family Members">
                                    <field name="name" force_save="1"/>
                                    <!--                    <field name="gender" required="1"/>-->
                                    <field name="relationn"/>
                                    <field name="member_location_conf"/>
                                    <field name="member_status" string="Is Benefit?"/>
                                    <field name="age"/>
                                    <field name="benefit_id"/>
                                    <field name="state"/>
                                </tree>
                            </field>
                        </page>



                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record id="view_empowerment_request_tree" model="ir.ui.view">
        <field name="name">empowerment.request.tree</field>
        <field name="model">empowerment.request</field>
        <field name="arch" type="xml">
            <tree string="طلبات التمكين">
                <field name="name"/>
                <field name="familye_id"/>
                <field name="service_id"/>
                <field name="state"/>
            </tree>
        </field>
    </record>

    <record id="view_empowerment_request_search" model="ir.ui.view">
        <field name="name">empowerment.request.search</field>
        <field name="model">empowerment.request</field>
        <field name="arch" type="xml">
            <search string="بحث طلبات التمكين">
                <!-- Search fields -->
                <field name="name" string="رقم الطلب"/>
                <field name="familye_id" string="المستفيد" options="{'no_create': True}"/>
                <field name="sms_phone" string="رقم الجوال"/>
                <field name="identity_number" string="رقم الهوية"/>

                <!-- Group by / Aggregation filters -->
                <filter string="نوع الخدمة" name="group_by_service_type" context="{'group_by':'service_type'}"/>
                <filter string="بند الخدمة" name="group_by_service_id" context="{'group_by':'service_id'}"/>
                <filter string="الحالة" name="group_by_state" context="{'group_by':'state'}"/>
            </search>
        </field>
    </record>



    <record id="action_empowerment_request" model="ir.actions.act_window">
        <field name="name">طلبات التمكين</field>
        <field name="res_model">empowerment.request</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="view_empowerment_request_search"/>
    </record>


    <record id="view_empowerment_return_reason_wizard_form" model="ir.ui.view">
        <field name="name">empowerment.return.reason.wizard.form</field>
        <field name="model">empowerment.return.reason.wizard</field>
        <field name="arch" type="xml">
            <form string="سبب الإرجاع">
                <sheet>
                    <group>
                        <field name="reason" />
                    </group>
                    <footer>
                        <button string="حفظ" type="object" name="action_return" class="btn-primary"/>
                        <button string="إلغاء" class="btn-secondary" special="cancel"/>
                    </footer>
                </sheet>
            </form>
        </field>
    </record>


    <menuitem id="menu_empowerment_requests" name="Empowerment Requests" parent="odex25_empowermentmanagement.menu_empowerment_root" action="action_empowerment_request"/>
</odoo>