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

    <!-- Form View -->
    <record id="seasonal_service_form_view" model="ir.ui.view">
        <field name="name">seasonal.service.form</field>
        <field name="model">seasonal.service</field>
        <field name="arch" type="xml">
            <form string="Seasonal Service">
                <header>
                    <button name="action_calculate" type="object"
                            string="Calculate" class="btn btn-info" groups="odex_benefit.group_family_services_manager"
                            attrs="{'invisible': [('state', '!=', 'draft')]}"/>

                    <button name="action_first_approval" type="object"
                            string="Approve" class="oe_highlight"
                            groups="odex_benefit.group_family_services_manager"
                            attrs="{'invisible': [('state', '!=', 'calculated')]}"/>
                    <button string="Withdraw" type="object" name="action_reset_to_draft" class="btn btn-danger"
                            groups="odex_benefit.group_family_services_manager"
                            states="calculated"/>
                    <button name="action_recalculate" string="Recalculate" class="btn btn-info"
                            groups="odex_benefit.group_family_services_manager"
                            type="object" states="calculated"/>

                    <button name="action_approval_of_gm_assistant" type="object"
                            string="Approve" class="oe_highlight"
                            groups="odex_benefit.group_benefit_manager,odex_benefit.group_family_services_manager"
                            attrs="{'invisible': [('state', '!=', 'gm_assistant')]}"/>

                    <button name="action_reset_to_calculated" type="object"
                            string="Reset"
                            class="btn btn-danger"
                            groups="odex_benefit.group_family_services_manager"
                            attrs="{'invisible': [('state', 'not in', ['gm_assistant','accounting_approve'])]}"
                    />

                    <button name="action_done" type="object"
                            string="Done"
                            class="oe_highlight"
                            groups="odex_benefit.group_family_services_manager"
                            attrs="{'invisible': [('state', '!=', 'waiting_receive')]}"
                    />

                    <field name="state" widget="statusbar"
                           statusbar_visible="draft,calculated,accounting_approve,waiting_receive,done"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button name="action_open_payment_orders"
                                type="object"
                                class="oe_stat_button"
                                icon="fa-money"
                                attrs="{'invisible': [('payment_order_count', '=', 0)]}">
                            <field name="payment_order_count" widget="statinfo" string="Payment Orders"/>
                        </button>
                        <button name="action_open_related_move_records"
                                class="oe_stat_button"
                                icon="fa-file-text-o"
                                type="object" attrs="{'invisible': [('total_moves', '=', 0)]}">
                            <field name="total_moves" widget="statinfo" string="Total Moves"/>
                        </button>
                    </div>
                    <field name="is_payment_order_done" invisible="1"/>
                    <field name="payment_order_state" invisible="1"/>
                    <widget name="web_ribbon" title="Payment Done" bg_color="bg-success"
                            attrs="{'invisible': [('payment_order_state', '!=', 'done')]}"/>
                    <widget name="web_ribbon" title="Payment Waiting" bg_color="bg-warning"
                            attrs="{'invisible': [('payment_order_state', '!=', 'waiting')]}"/>
                    <group>
                        <group>
                            <field name="name" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
                            <field name="date" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
                            <field name="service_type_id"
                                   attrs="{'readonly': [('state', '!=', 'draft')]}"/>
                            <field name="service_delivery_method"
                                   attrs="{'required':[('is_in_kind','!=',False)],'invisible':[('is_in_kind','=',False)],'readonly': [('state', '!=', 'draft')]}"/>
                            <field name="is_in_kind" invisible="1"/>
                            <field name="branch_ids" widget="many2many_tags"
                                   attrs="{'readonly': [('state', '!=', 'draft')]}"/>
                            <field name="family_category_ids" attrs="{'readonly': [('state', '!=', 'draft')]}"
                                   widget="many2many_tags"/>
                            <field name="allowed_service_categories" invisible="1" widget="many2many_tags"
                                   readonly="1"/>
                            <field name="family_domain_ids" widget="many2many_tags" invisible="1"/>
                            <field name="payment_order_id" readonly="1" invisible="1"
                                   attrs="{
                                       'invisible': [('payment_order_id', '=', False)],
                                       'readonly': [('state', '!=', 'draft')]}"/>
                            <field name="vendor_bill" invisible="1" readonly="1"
                                   attrs="{
                                       'invisible': [('vendor_bill', '=', False)],
                                       'readonly': [('state', '!=', 'draft')]}"
                            />

                        </group>
                        <group>
                            <field name="aid_amount" attrs="{'readonly': [('service_delivery_method', '=', 'cash')]}"/>
                            <field name="benefit_type" invisible="1"/>
                            <field name="currency_id" invisible="1"/>
                            <field name="company_id" invisible="1"/>
                            <field name="allowed_member_ids" widget="many2many_tags" invisible="1"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Services Requests" attrs="{'invisible': [('state', '=', 'draft')]}">
                            <div class="row mb-2">
                                <!-- Family Count -->
                                <div class="col-4">
                                    <div class="d-flex flex-column align-items-center"
                                         style="background-color: #e3f2fd; padding: 8px; border-radius: 8px;">
                                        <i class="fa fa-home text-primary"
                                           style="font-size: 20px; margin-bottom: 4px;"/>
                                        <span style="font-size: 12px; color: #555;">Family Count</span>
                                        <span class="badge badge-primary"
                                              style="font-size: 14px; padding: 4px 8px; margin-top: 3px; border-radius: 8px;">
                                            <field name="family_count" readonly="1"/>
                                        </span>
                                    </div>
                                </div>

                                <!-- Benefit Member Count -->
                                <div class="col-4">
                                    <div class="d-flex flex-column align-items-center"
                                         style="background-color: #e0f7fa; padding: 8px; border-radius: 8px;">
                                        <i class="fa fa-users text-info" style="font-size: 20px; margin-bottom: 4px;"/>
                                        <span style="font-size: 12px; color: #555;">Benefit Member Count</span>
                                        <span class="badge badge-info"
                                              style="font-size: 14px; padding: 4px 8px; margin-top: 3px; border-radius: 8px;">
                                            <field name="benefit_member_count" readonly="1"/>
                                        </span>
                                    </div>
                                </div>

                                <!-- Total Disbursement -->
                                <div class="col-4">
                                    <div class="d-flex flex-column align-items-center"
                                         style="background-color: #e8f5e9; padding: 8px; border-radius: 8px;">
                                        <i class="fa fa-money text-success"
                                           style="font-size: 20px; margin-bottom: 4px;"/>
                                        <span style="font-size: 12px; color: #555;">Total Disbursement</span>
                                        <span class="badge badge-success"
                                              style="font-size: 14px; padding: 4px 8px; margin-top: 3px; border-radius: 8px;">
                                            <field name="family_disbursement_total_amount" readonly="1"
                                                   widget="monetary"
                                                   options="{'currency_field': 'currency_id'}"/>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <field name="service_requests_ids" readonly="1">
                                <tree>
                                    <field name="family_id"/>
                                    <field name="member_id"
                                           attrs="{'column_invisible':[('parent.benefit_type','=','family')]}"/>
                                    <field name="branch_custom_id" optional="hidden"/>
                                    <field name="researcher_id" optional="hidden"/>
                                    <field name="family_category"/>
                                    <field name="benefit_member_count"/>
                                    <field name="service_benefit_count"/>
                                    <field name="service_qty"
                                           attrs="{'column_invisible':[('parent.service_delivery_method','=','cash')]}"/>
                                    <field name="requested_service_amount"
                                           attrs="{'column_invisible':[('parent.service_delivery_method','!=','cash')]}"/>
                                    <field name="state" widget="badge" decoration-success="state in ['gm_assistant']"
                                           decoration-muted="state == 'draft'"
                                           decoration-danger="state in ['refused']"
                                           decoration-info="state in ['first_approve','waiting_approve']"
                                           decoration-warning="state in ['researcher']"/>
                                </tree>
                            </field>
                        </page>
                        <page string="Families">
                            <field name="benefit_ids" attrs="{'readonly': [('state', '!=', 'draft')]}"
                                   domain="[('id', 'in', family_domain_ids)]">
                                <tree>
                                    <field name="code" decoration-bf="1"/>
                                    <field name="benefit_partner_name"/>
                                    <field name="benefit_category_id"/>
                                    <field name="create_date" optional="hide"/>
                                    <field name="meal_card"/>
                                    <field name="father_id_number" optional="hide"/>
                                    <field name="sms_phone"/>
                                    <field name="benefit_member_count"/>
                                    <field name="non_member_count" optional="hide"/>
                                    <field name="researcher_id"/>
                                    <field name="branch_custom_id"/>
                                    <field name="district_id"/>
                                    <field name="last_visit_date" optional="hide"/>
                                    <field name="acc_number" optional="hide"/>
                                    <field name="family_member_id" optional="hide"/>
                                    <field name="acc_holder_name" optional="hide"/>
                                    <field name="state" widget="badge"
                                           decoration-success="state in ['first_approve', 'second_approve']"
                                           decoration-muted="state in ['draft','new']"
                                           decoration-danger="state in ['refused','suspended_second_approve']"
                                           decoration-warning="state in ['first_refusal','waiting_approve']"
                                           decoration-info="state not in ('waiting_approve','draft','new','first_approve', 'second_approve','first_refusal','refused','suspended_second_approve')"/>
                                </tree>
                            </field>
                        </page>
                        <page string="Members" attrs="{'invisible': [('benefit_type', '!=', 'member')]}">
                            <field name="member_ids" attrs="{'readonly': [('state', '!=', 'draft')]}"
                                   domain="[('id', 'in', allowed_member_ids)]"/>
                        </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers"
                           groups="base.group_user"/>
                    <field name="activity_ids"/>
                    <field name="message_ids" widget="mail_thread"/>
                </div>
            </form>
        </field>
    </record>

    <!-- Tree View -->
    <record id="seasonal_service_tree_view" model="ir.ui.view">
        <field name="name">seasonal.service.tree</field>
        <field name="model">seasonal.service</field>
        <field name="arch" type="xml">
            <tree string="Seasonal Services">
                <field name="name"/>
                <field name="date"/>
                <field name="service_type_id"/>
                <field name="service_delivery_method"/>
                <field name="aid_amount"/>
                <field name="family_count"/>
                <field name="benefit_member_count"/>
                <field name="family_disbursement_total_amount"/>
                <field name="state"
                       widget="badge"
                       decoration-info="state == 'draft'"
                       decoration-warning="state not in ['draft','done']"
                       decoration-success="state == 'done'"
                />
                <field name="payment_order_state"
                       widget="badge"
                       decoration-info="payment_order_state == 'none'"
                       decoration-warning="payment_order_state == 'waiting'"
                       decoration-success="payment_order_state == 'done'"
                />
            </tree>
        </field>
    </record>


    <!-- Action -->
    <record id="seasonal_service_action" model="ir.actions.act_window">
        <field name="name">Seasonal Services</field>
        <field name="res_model">seasonal.service</field>
        <field name="view_mode">tree,form</field>
    </record>


</odoo>