<?xml version="1.0" encoding="UTF-8"?>
<odoo>
        <record id="view_op_admission_tree" model="ir.ui.view">
            <field name="name">op.admission.list</field>
            <field name="model">op.admission</field>
            <field name="priority" eval="8"/>
            <field name="arch" type="xml">
                <list string="Registration">
                    <field name="application_number"/>
                    <field name="title" optional="show"/>
                    <field name="name"/>
                    <field name="admission_date"/>
                    <field name="application_date"/>
                    <field name="course_id"/>
                    <field name="batch_id" optional="hide"/>
                    <field name="state"
                           string="Status"
                           widget="badge"
                           decoration-muted="state in ('draft')"
                           decoration-success="state in ('done','confirm')"
                           decoration-primary="state in ('submit','admission','pending')"
                           decoration-danger="state in ('cancel')"

                           optional="show"/>
                    <field name="company_id" groups="base.group_multi_company"
                           optional="show"/>
                    <field name="gender" optional="hide"/>
                    <field name="birth_date" optional="hide"/>
                    <field name="email" optional="hide"/>
                </list>
            </field>
        </record>

        <record id="view_op_admission_form" model="ir.ui.view">
            <field name="name">op.admission.form</field>
            <field name="model">op.admission</field>
            <field name="priority" eval="8"/>
            <field name="arch" type="xml">
                <form string="Registration">
                    <header>
                        <button string="Submit" invisible="state != 'draft'"
                                class="oe_highlight" type="object"
                                name="submit_form"/>
                        <button name="confirm_in_progress"
                                invisible="state not in ('submit','pending')"
                                string="Confirm" type="object"
                                class="oe_highlight"/>
                        <button string="Admission Confirm" class="oe_highlight"
                                invisible="state != 'confirm'"
                                type="object"
                                name="admission_confirm"/>
                        <button name="enroll_student" invisible="state != 'admission'"
                                string="Enroll" type="object"
                                class="oe_highlight"/>
                        <button name="confirm_rejected"
                                invisible="state not in ('confirm','confirm_pending')"
                                string="Reject" type="object"/>
                        <button name="confirm_pending" invisible="state != 'submit'"
                                string="Pending" type="object"/>
                        <button name="confirm_cancel" string="Cancel" type="object"/>
                        <button name="confirm_to_draft"
                                invisible="state not in ('pending','reject','cancel')"
                                string="Set to Draft"
                                type="object"/>
                        <button name="open_student" invisible="state != 'done'"
                                string="Open Student Profile"
                                type="object"/>
                        <field name="state" widget="statusbar"
                               statusbar_visible="draft,confirm,done"/>
                    </header>
                    <sheet>
                        <field name="active" invisible="True"/>
                        <widget name="web_ribbon" title="Archived" bg_color="bg-danger"
                                invisible="active == True"/>

                        <div class="row flex-column flex-sm-row align-items-center">
                            <div class="d-md-flex">
                                <div class="o_employee_avatar ms-2 p-0 h-100 mw-25 align-self-start align-self-sm-center">
                                    <field name="image" widget='image' class="m-0" options='{"size": [128,158], "zoom": true}' />
                                </div>
                                <div class="align-self-start o_employee_form_header_info ps-md-3">
                                    <div class="oe_title ps-0 pe-2 mw-100">
                                        <h5 class="d-flex align-items-baseline mb-0">
                                            <field name="title" options="{'no_create': True}" placeholder="Title"/>
                                        </h5>
                                        <div class="d-flex student-name">
                                            <div class="">
                                                <h1 class="d-md-flex align-items-center gap-1 w-50">
                                                    <field name="name" placeholder="Name" required="1" invisible="True"/>
                                                    <field name="first_name" widget="inline_char" required="1" placeholder="First Name"/>
                                                    <field name="middle_name" widget="inline_char" placeholder="Middle Name"/>
                                                    <field name="last_name" widget="inline_char" placeholder="Last Name"/>
                                                </h1>
                                            </div>
                                        </div>
                                        <div class="d-flex align-items-baseline">
                                            <i class="fa fa-fw me-1 fa-envelope text-primary" title="Email"/>
                                            <field name="email" class="w-100" widget="email" placeholder="Email"/>
                                        </div>
                                        <div class="d-flex align-items-baseline">
                                            <i class="fa fa-fw me-1 fa-phone text-primary" title="Phone"/>
                                            <field name="phone" class="w-100" widget="phone" placeholder="Phone"/>
                                        </div>

                                    </div>
                               </div>
                            </div>
                        </div>

                        <notebook>
                            <page name="admission_detail" string="Admission Detail">
                                <group>
                                    <group>
                                        <field name="register_id"
                                               readonly="state == 'done'"
                                               domain="[('state', 'in', ['application','admission'])]"
                                               widget="selection"/>
                                        <field name="application_date"
                                               readonly="state == 'done'"/>
                                        <field name="course_ids" invisible="True"/>
                                        <field name="course_id"
                                               readonly="state == 'done'"
                                               domain="[('id', 'in', course_ids)]"
                                               options="{'no_open': True, 'no_create': True}"/>
                                        <field name="discount"/>
                                        <field name="due_date"
                                               readonly="state == 'done'"/>
                                        <field name="is_student"/>
                                        <field name="company_id"
                                               groups="base.group_multi_company"
                                               optional="show"/>
                                        <field name="fees_start_date"/>
                                    </group>
                                    <group>
                                        <field name="application_number"/>
                                        <field name="admission_date"
                                               readonly="state == 'done'"/>
                                        <field name="batch_id"
                                               context="{'course_id': course_id,'get_parent_batch':1}"
                                               readonly="state == 'done'"
                                               required="1"/>
                                        <field name="fees" readonly="state == 'done'"
                                               required="state not in ('draft', 'submit')"/>
                                        <field name="fees_term_id" required="1"
                                               readonly="state not in ('draft', 'submit', 'confirm')"/>
                                        <field name="partner_id"/>
                                        <field name="student_id" placeholder="Student"
                                               readonly="state == 'done'"
                                               options="{'no_create_edit': True}"
                                               required="is_student == True"
                                               invisible="is_student == False"/>
                                    </group>
                                </group>
                            </page>
                            <page name="educational_detail"
                                  string="Educational Detail">
                                <group>
                                    <group>
                                        <field name="prev_institute_id"
                                               readonly="state == 'done'"/>
                                        <field name="prev_result"
                                               readonly="state == 'done'"/>
                                    </group>
                                    <group>
                                        <field name="prev_course_id"
                                               readonly="state == 'done'"/>
                                    </group>
                                </group>
                            </page>
                            <page name="personal_detail" string="Personal Detail">
                                <group>
                                    <group>
                                        <field name="gender" required="1"/>

                                        <field name="birth_date"
                                               options="{'datepicker':{'warn_future': true}}"
                                               readonly="state == 'done'"/>
                                        <field name="family_income"
                                               readonly="state == 'done'"/>
                                        <field name="family_business"
                                               readonly="state == 'done'"/>

                                        <field name="nbr" invisible="True"/>
                                    </group>
                                    <group>
                                        <label for="street" string="Address"/>
                                        <div name="o_address_format">
                                            <field name="street" placeholder="Street..."/>
                                            <field name="street2" placeholder="Street2"/>
                                            <div class="address_format d-md-flex">
                                                <field name="city" placeholder="City" />
                                                <field name="state_id" class="oe_no_button" placeholder="State"
                                                         options="{&quot;no_open&quot;: True}"/>
                                                <field name="zip" placeholder="ZIP" />
                                            </div>
                                            <field name="country_id" placeholder="Country" class="oe_no_button"
                                                    options="{&quot;no_open&quot;: True}"/>
                                        </div>
                                    </group>
                                </group>
                            </page>
                        </notebook>
                    </sheet>
                    <chatter/>
                </form>
            </field>
        </record>

        <record id="view_op_admission_search" model="ir.ui.view">
            <field name="name">op.admission.search</field>
            <field name="model">op.admission</field>
            <field name="priority" eval="8"/>
            <field name="arch" type="xml">
                <search string="Registration">
                    <field name="name"/>
                    <field name="application_number"/>
                    <field name="admission_date"/>
                    <field name="application_date"/>
                    <field name="birth_date"/>
                    <field name="course_id"/>
                    <field name="batch_id"/>
                    <separator/>
                    <filter name="enrolled_student" string="Enrolled"
                            domain="[('state','=','done')]"/>
                    <group>
                        <filter string="Admission Date"
                                name="group_by_adm_admission_date"
                                domain="[]" context="{'group_by':'admission_date'}"/>
                        <filter string="Application Date"
                                name="group_by_adm_application_date"
                                domain="[]" context="{'group_by':'application_date'}"/>
                        <filter string="Course" name="group_by_adm_course_id"
                                domain="[]" context="{'group_by':'course_id'}"/>
                        <filter string="Batch" name="group_by_adm_batch_id"
                                domain="[]" context="{'group_by':'batch_id'}"/>
                        <filter string="Status" name="group_by_adm_state"
                                domain="[]" context="{'group_by':'state'}"/>
                        <filter string="Register" name="group_by_adm_register"
                                domain="[('register_id.state', 'not in', ['cancel', 'done'])]"
                                context="{'group_by':'register_id'}"/>
                        <filter string="Archived" name="inactive"
                                domain="[('active', '=', False)]"/>
                    </group>
                </search>
            </field>
        </record>

        <record model="ir.ui.view" id="view_op_admission_graph">
            <field name="name">op.admission.graph</field>
            <field name="model">op.admission</field>
            <field name="arch" type="xml">
                <graph string="Course By Admission" type="pie">
                    <field name="course_id"/>
                    <field name="nbr" operator="+"/>
                </graph>
            </field>
        </record>

        <record model="ir.ui.view" id="view_op_admission_pivot">
            <field name="name">op.admission.pivot</field>
            <field name="model">op.admission</field>
            <field name="arch" type="xml">
                <pivot string="Course By Admission">
                    <field name="title"/>
                    <field name="name"/>
                    <field name="middle_name"/>
                    <field name="last_name"/>
                    <field name="application_number"/>
                    <field name="register_id"/>
                    <field name="admission_date"/>
                    <field name="application_date"/>
                    <field name="birth_date"/>
                    <field name="course_id" type="row"/>
                    <field name="batch_id"/>
                    <field name="state"/>
                </pivot>
            </field>
        </record>

        <record model="ir.actions.act_window" id="act_open_op_admission_view">
            <field name="name">Registration</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">op.admission</field>
            <field name="path">admission</field>
            <field name="binding_view_types">form</field>
            <field name="view_mode">list,form,graph,pivot</field>
            <field name="search_view_id" ref="view_op_admission_search"/>
            <field name="domain">[]</field>
            <field name="context">{}</field>
        </record>

        <record model="ir.actions.act_window.view"
                id="act_open_op_admission_view_form">
            <field name="act_window_id" ref="act_open_op_admission_view"/>
            <field name="sequence" eval="20"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_op_admission_form"/>
        </record>

        <record model="ir.actions.act_window.view"
                id="act_open_op_admission_view_tree">
            <field name="act_window_id" ref="act_open_op_admission_view"/>
            <field name="sequence" eval="10"/>
            <field name="view_mode">list</field>
            <field name="view_id" ref="view_op_admission_tree"/>
        </record>

        <record id="view_op_student_course_form_admission_inherit" model="ir.ui.view">
            <field name="name">op.student.course.form.admission.inherit</field>
            <field name="model">op.student.course</field>
            <field name="inherit_id"
                   ref="openeducat_core.view_op_student_course_form"/>
            <field name="arch" type="xml">
                <field name="fees_term_id" position="before">
                    <field name="product_id" required="1"/>
                </field>
            </field>
        </record>

    <record id="res_config_settings_view_user" model="ir.ui.view">
        <field name="name">res.config.settings.view.form.admission</field>
        <field name="model">res.config.settings</field>
        <field name="priority" eval="40"/>
        <field name="inherit_id"
               ref="openeducat_core.res_config_settings_view_form_core"/>
        <field name="arch" type="xml">
            <xpath expr="//div[contains(@invisible, 'module_openeducat_admission')]/div[1]"
                   position="inside">
                <div class="col-12 col-md-1 col-lg-6 mb16">
                    <div class="o_setting_left_pane">
                        <field
                                name="enable_create_student_user"/>
                    </div>
                    <div class="o_setting_right_pane">
                        <label
                                for="enable_create_student_user"/>
                                <span class="fa fa-info-circle" title="Openeducat Enterprise Module"/>
                        <div class="text-muted">Enable this option to create a student
                            user
                        </div>
                    </div>
                </div>
            </xpath>
        </field>
    </record>
</odoo>
