<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Tree View for Online Orders -->
    <record id="view_pos_order_online_tree" model="ir.ui.view">
        <field name="name">pos.order.online.tree</field>
        <field name="model">pos.order</field>
        <field name="arch" type="xml">
            <tree string="Online Orders" decoration-warning="online_order_status=='pending'" decoration-success="online_order_status=='confirmed'" decoration-danger="online_order_status=='rejected'">
                <field name="pos_reference"/>
                <field name="partner_id"/>
                <field name="date_order"/>
                <field name="amount_total"/>
                <field name="online_order_status" widget="badge"
                       decoration-warning="online_order_status=='pending'"
                       decoration-success="online_order_status=='confirmed'"
                       decoration-danger="online_order_status=='rejected'"/>
                <field name="sale_order_id"/>
                <field name="order_source"/>
                <field name="fulfilment_type" widget="badge"
                       decoration-info="fulfilment_type=='pickup'"
                       decoration-primary="fulfilment_type=='delivery'"
                       decoration-muted="fulfilment_type=='dine_in'"/>
                <field name="config_id"/>
            </tree>
        </field>
    </record>

    <!-- Form View extension -->
    <record id="view_pos_order_online_form" model="ir.ui.view">
        <field name="name">pos.order.online.form.inherit</field>
        <field name="model">pos.order</field>
        <field name="inherit_id" ref="point_of_sale.view_pos_pos_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='state']" position="after">
                <field name="is_online_order" invisible="not is_online_order"/>
                <field name="online_order_status" invisible="not is_online_order" widget="badge"
                       decoration-warning="online_order_status=='pending'"
                       decoration-success="online_order_status=='confirmed'"
                       decoration-danger="online_order_status=='rejected'"/>
                <field name="sale_order_id" invisible="not is_online_order"/>
                <field name="order_source" string="Source"/>
                <field name="fulfilment_type" string="Service"/>
            </xpath>
        </field>
    </record>

    <!-- Action for Online Orders -->
    <record id="action_online_orders" model="ir.actions.act_window">
        <field name="name">Online Orders</field>
        <field name="res_model">pos.order</field>
        <field name="view_mode">tree,form</field>
        <field name="domain">[('is_online_order', '=', True)]</field>
        <field name="context">{'search_default_pending': 1}</field>
    </record>

    <!-- Search View -->
    <record id="view_pos_order_online_search" model="ir.ui.view">
        <field name="name">pos.order.online.search</field>
        <field name="model">pos.order</field>
        <field name="arch" type="xml">
            <search string="Online Orders">
                <field name="pos_reference"/>
                <field name="partner_id"/>
                <field name="sale_order_id"/>
                <filter name="pending" string="Pending" domain="[('online_order_status', '=', 'pending')]"/>
                <filter name="confirmed" string="Confirmed" domain="[('online_order_status', '=', 'confirmed')]"/>
                <filter name="rejected" string="Rejected" domain="[('online_order_status', '=', 'rejected')]"/>
                <group expand="0" string="Group By">
                    <filter name="group_status" string="Status" context="{'group_by': 'online_order_status'}"/>
                    <filter name="group_date" string="Date" context="{'group_by': 'date_order'}"/>
                </group>
            </search>
        </field>
    </record>
</odoo>
