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

    <!-- ===== Tree View ===== -->
    <record id="woo_order_view_tree" model="ir.ui.view">
        <field name="name">woo.order.tree</field>
        <field name="model">woo.order</field>
        <field name="arch" type="xml">
            <tree>
                <field name="woo_order_number"/>
                <field name="instance_id"/>
                <field name="sale_order_id"/>
                <field name="woo_status"/>
                <field name="state" widget="badge"
                       decoration-success="state == 'completed'"
                       decoration-info="state == 'confirmed'"
                       decoration-warning="state == 'shipped'"
                       decoration-danger="state == 'cancelled'"/>
            </tree>
        </field>
    </record>

    <!-- ===== Form View ===== -->
    <record id="woo_order_view_form" model="ir.ui.view">
        <field name="name">woo.order.form</field>
        <field name="model">woo.order</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <field name="state" widget="statusbar"
                           statusbar_visible="new,confirmed,shipped,completed"/>
                </header>
                <sheet>
                    <group>
                        <group string="WooCommerce">
                            <field name="woo_order_number"/>
                            <field name="woo_order_id"/>
                            <field name="woo_status"/>
                            <field name="instance_id"/>
                        </group>
                        <group string="Odoo">
                            <field name="sale_order_id"/>
                            <field name="invoice_id"/>
                            <field name="invoice_synced"/>
                            <field name="company_id" groups="base.group_multi_company"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Shipments" name="shipments">
                            <field name="shipment_ids">
                                <tree>
                                    <field name="picking_id"/>
                                    <field name="carrier_id"/>
                                    <field name="tracking_number"/>
                                    <field name="shipped_date"/>
                                    <field name="is_backorder"/>
                                    <field name="synced_to_woo"/>
                                </tree>
                            </field>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <!-- ===== Search View ===== -->
    <record id="woo_order_view_search" model="ir.ui.view">
        <field name="name">woo.order.search</field>
        <field name="model">woo.order</field>
        <field name="arch" type="xml">
            <search>
                <field name="woo_order_number"/>
                <field name="sale_order_id"/>
                <filter name="new" string="New"
                        domain="[('state', '=', 'new')]"/>
                <filter name="confirmed" string="Confirmed"
                        domain="[('state', '=', 'confirmed')]"/>
                <filter name="shipped" string="Shipped"
                        domain="[('state', '=', 'shipped')]"/>
                <filter name="completed" string="Completed"
                        domain="[('state', '=', 'completed')]"/>
                <filter name="cancelled" string="Cancelled"
                        domain="[('state', '=', 'cancelled')]"/>
                <group expand="1" string="Group By">
                    <filter name="group_instance" string="Instance"
                            context="{'group_by': 'instance_id'}"/>
                    <filter name="group_state" string="State"
                            context="{'group_by': 'state'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- ===== Action ===== -->
    <record id="action_woo_order" model="ir.actions.act_window">
        <field name="name">WooCommerce Orders</field>
        <field name="res_model">woo.order</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="woo_order_view_search"/>
    </record>

</odoo>
