<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="view_order_form_fusion_cp" model="ir.ui.view">
        <field name="name">sale.order.form.fusion.cp</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="xml">
            <xpath expr="//div[@name='button_box']" position="inside">
                <button name="action_view_fusion_cp_shipments" type="object"
                        class="oe_stat_button" icon="fa-plane"
                        invisible="fusion_cp_shipment_count == 0">
                    <field name="fusion_cp_shipment_count" widget="statinfo"
                           string="CP Shipments"/>
                </button>
            </xpath>

            <!-- Show CP package details on the sale order -->
            <xpath expr="//group[@name='note_group']" position="before">
                <group string="Canada Post Packages"
                       invisible="not fusion_cp_package_ids"
                       colspan="6">
                    <field name="fusion_cp_package_ids" nolabel="1"
                           colspan="6" readonly="1">
                        <list create="0" delete="0" no_open="1">
                            <field name="package_type_id" string="Box Type"
                                   optional="show"/>
                            <field name="package_length" string="Length"/>
                            <field name="package_width" string="Width"/>
                            <field name="package_height" string="Height"/>
                            <field name="weight" string="Weight"/>
                            <field name="service_name" string="Service"/>
                            <field name="price" string="Cost"
                                   widget="monetary"
                                   options="{'currency_field': 'currency_id'}"/>
                            <field name="currency_id" column_invisible="1"/>
                        </list>
                    </field>
                </group>
            </xpath>
        </field>
    </record>
</odoo>
