<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="delivery_carrier_form_view_fusion_shipping" model="ir.ui.view">
        <field name="name">delivery.carrier.form.view.fusion.shipping</field>
        <field name="model">delivery.carrier</field>
        <field name="inherit_id" ref="delivery.view_delivery_carrier_form"/>
        <field name="arch" type="xml">

            <!-- ================================================================
                 Integration Level: custom label for Fusion carriers
                 ================================================================ -->
            <xpath expr="//field[@name='integration_level']" position="attributes">
                <attribute name="invisible">delivery_type in ('fusion_canada_post', 'fusion_ups', 'fusion_ups_rest', 'fusion_fedex', 'fusion_fedex_rest', 'fusion_dhl', 'fusion_dhl_rest')</attribute>
            </xpath>
            <xpath expr="//field[@name='integration_level']" position="after">
                <field name="integration_level"
                       invisible="delivery_type not in ('fusion_canada_post', 'fusion_ups', 'fusion_ups_rest', 'fusion_fedex', 'fusion_fedex_rest', 'fusion_dhl', 'fusion_dhl_rest')"
                       widget="radio"
                       options="{'horizontal': true}"
                       help="Get Prices: only fetch shipping prices on sale orders. Get Prices and Create Shipment: also generate labels and tracking when the delivery order is validated."/>
            </xpath>

            <xpath expr="//page[@name='destination']" position="before">

                <!-- ════════════════════════════════════════════════════
                     CANADA POST Configuration
                     ════════════════════════════════════════════════════ -->
                <page string="Canada Post Configuration" name="fusion_cp_configuration"
                      invisible="delivery_type != 'fusion_canada_post'">
                    <group string="API Credentials"
                           invisible="delivery_type != 'fusion_canada_post'">
                        <group>
                            <field name="username" string="API Key"
                                   required="delivery_type == 'fusion_canada_post'"
                                   help="API key from the Canada Post Developer Program."/>
                            <field name="password" string="API Password" password="True"
                                   required="delivery_type == 'fusion_canada_post'"
                                   help="API password from the Canada Post Developer Program."/>
                            <field name="customer_number" required="delivery_type == 'fusion_canada_post'"
                                   help="Your Canada Post customer number (mailed-by number)."/>
                        </group>
                        <group>
                            <field name="fusion_cp_type" string="Account Type"
                                   required="delivery_type == 'fusion_canada_post'"/>
                            <field name="fusion_cp_contract_id" required="fusion_cp_type == 'commercial'"
                                   invisible="fusion_cp_type == 'counter'"/>
                        </group>
                    </group>
                    <group>
                        <group string="Shipping Options">
                            <field name="service_type" string="Default Service"
                                   required="delivery_type == 'fusion_canada_post'"
                                   help="Default shipping service. Users can choose a different service when adding shipping to a sale order."/>
                            <field name="option_code" string="Shipping Option"/>
                            <field name="reason_for_export"/>
                            <field name="product_packaging_id"
                                   help="Optional default package type. Dimensions will pre-fill in the shipping wizard but can be overridden per shipment."/>
                            <field name="fusion_cp_dimension_unit"
                                   required="delivery_type == 'fusion_canada_post'"
                                   help="Unit for package dimensions. Values are automatically converted to centimetres for the Canada Post API."/>
                        </group>
                        <group string="Payment &amp; Tracking">
                            <field name="fusion_cp_payment_method"
                                   string="Payment Method"
                                   required="delivery_type == 'fusion_canada_post'"/>
                            <field name="tracking_link"
                                   help="Custom tracking URL. Leave blank to use the default Canada Post tracking page."/>
                        </group>
                    </group>
                    <group string="Label Settings"
                           invisible="delivery_type != 'fusion_canada_post'">
                        <group>
                            <field name="fusion_cp_output_format"
                                   required="delivery_type == 'fusion_canada_post'"/>
                        </group>
                    </group>
                </page>

                <!-- ════════════════════════════════════════════════════
                     UPS REST Configuration
                     ════════════════════════════════════════════════════ -->
                <page string="UPS REST Configuration" name="fusion_ups_rest_configuration"
                      invisible="delivery_type != 'fusion_ups_rest'">
                    <group>
                        <group>
                            <field name="ups_shipper_number" required="delivery_type == 'fusion_ups_rest'"/>
                            <field name="ups_client_id" required="delivery_type == 'fusion_ups_rest'"/>
                            <field name="ups_client_secret" required="delivery_type == 'fusion_ups_rest'"/>
                            <field name="ups_default_service_type" required="delivery_type == 'fusion_ups_rest'"/>
                        </group>
                        <group>
                            <field name="ups_default_packaging_id" required="delivery_type == 'fusion_ups_rest'"
                                   domain="[('package_carrier_type', '=', 'fusion_ups_rest')]"/>
                            <field name="ups_package_weight_unit" string="Package Weight Unit"
                                   required="delivery_type == 'fusion_ups_rest'"/>
                            <field name="ups_package_dimension_unit"
                                   required="delivery_type == 'fusion_ups_rest'"/>
                            <field name="ups_label_file_type" string="Label Format"
                                   required="delivery_type == 'fusion_ups_rest'"/>
                        </group>
                        <group string="Options" name="ups_rest_vas" colspan="2">
                            <group>
                                <field name="ups_bill_my_account"
                                       invisible="delivery_type != 'fusion_ups_rest'"/>
                                <field name="ups_saturday_delivery" string="Saturday Delivery"
                                       required="delivery_type == 'fusion_ups_rest'"
                                       invisible="ups_default_service_type in ['03','11','13','59','12','65','08']"/>
                                <field name="allow_cash_on_delivery"
                                       required="delivery_type == 'fusion_ups_rest'"
                                       invisible="ups_default_service_type == '96'"
                                       help="This value added service enables UPS to collect the payment of the shipment from your customer."/>
                                <field name="ups_cod_funds_code"
                                       required="delivery_type == 'fusion_ups_rest'"
                                       invisible="not allow_cash_on_delivery" widget="radio"/>
                                <field name="can_generate_return" invisible="1"/>
                                <field name="return_label_on_delivery" invisible="not can_generate_return"/>
                                <field name="get_return_label_from_portal" invisible="not return_label_on_delivery"/>
                            </group>
                            <group>
                                <field name="ups_require_signature"/>
                                <field name="ups_duty_payment" string="Duties paid by"
                                       required="delivery_type == 'fusion_ups_rest'"/>
                            </group>
                        </group>
                    </group>
                </page>

                <!-- ════════════════════════════════════════════════════
                     UPS Legacy Configuration
                     ════════════════════════════════════════════════════ -->
                <page string="UPS Configuration" name="fusion_ups_configuration"
                      invisible="delivery_type != 'fusion_ups'">
                    <group>
                        <group>
                            <field name="ups_username" required="delivery_type == 'fusion_ups'"/>
                            <field name="ups_passwd" required="delivery_type == 'fusion_ups'"/>
                            <field name="ups_shipper_number" required="delivery_type == 'fusion_ups'"/>
                            <field name="ups_access_number" required="delivery_type == 'fusion_ups'"/>
                            <field name="ups_default_service_type" required="delivery_type == 'fusion_ups'"/>
                        </group>
                        <group>
                            <field name="ups_default_package_type_id" required="delivery_type == 'fusion_ups'"
                                   domain="[('package_carrier_type', '=', 'fusion_ups')]"/>
                            <field name="ups_package_weight_unit" string="Package Weight Unit"
                                   required="delivery_type == 'fusion_ups'"/>
                            <field name="ups_package_dimension_unit"
                                   required="delivery_type == 'fusion_ups'"/>
                            <field name="ups_label_file_type" string="Label Format"
                                   required="delivery_type == 'fusion_ups'"/>
                        </group>
                        <group string="Options" name="ups_legacy_vas">
                            <field name="ups_bill_my_account" invisible="delivery_type != 'fusion_ups'"/>
                            <field name="ups_saturday_delivery" string="Saturday Delivery"
                                   invisible="ups_default_service_type in ['03', '11', '13', '59', '12', '65', '08']"
                                   required="delivery_type == 'fusion_ups'"/>
                            <field name="allow_cash_on_delivery"
                                   required="delivery_type == 'fusion_ups'"
                                   invisible="ups_default_service_type == '96'"
                                   help="This value added service enables UPS to collect the payment of the shipment from your customer."/>
                            <field name="ups_cod_funds_code" invisible="not allow_cash_on_delivery"
                                   required="delivery_type == 'fusion_ups'" widget="radio"/>
                            <field name="can_generate_return" invisible="1"/>
                            <field name="return_label_on_delivery" invisible="not can_generate_return"/>
                            <field name="get_return_label_from_portal" invisible="not return_label_on_delivery"/>
                            <field name="ups_duty_payment" string="Duties paid by"
                                   required="delivery_type == 'fusion_ups'"/>
                        </group>
                    </group>
                </page>

                <!-- ════════════════════════════════════════════════════
                     FedEx REST Configuration
                     ════════════════════════════════════════════════════ -->
                <page string="FedEx REST Configuration" name="fusion_fedex_rest_configuration"
                      invisible="delivery_type != 'fusion_fedex_rest'">
                    <group>
                        <group>
                            <field name="fedex_rest_developer_key" required="delivery_type == 'fusion_fedex_rest'"/>
                            <field name="fedex_rest_developer_password" required="delivery_type == 'fusion_fedex_rest'"/>
                            <field name="fedex_rest_account_number" string="Account Number"
                                   required="delivery_type == 'fusion_fedex_rest'"/>
                            <field name="fedex_rest_service_type" required="delivery_type == 'fusion_fedex_rest'"/>
                            <field name="fedex_rest_droppoff_type" required="delivery_type == 'fusion_fedex_rest'"/>
                        </group>
                        <group>
                            <field name="fedex_rest_default_package_type_id"
                                   required="delivery_type == 'fusion_fedex_rest'"
                                   domain="[('package_carrier_type', '=', 'fusion_fedex_rest')]"/>
                            <field name="fedex_rest_weight_unit" string="Package Weight Unit"
                                   required="delivery_type == 'fusion_fedex_rest'"/>
                            <div class="o_td_label">
                                <span class="o_form_label">Package Length Unit</span>
                            </div>
                            <div class="o_field_widget">
                                <span invisible="fedex_rest_weight_unit != 'KG'">Centimeters</span>
                                <span invisible="fedex_rest_weight_unit != 'LB'">Inches</span>
                            </div>
                            <field name="fedex_rest_label_stock_type" required="delivery_type == 'fusion_fedex_rest'"/>
                            <field name="fedex_rest_label_file_type" string="Label Format"
                                   required="delivery_type == 'fusion_fedex_rest'"/>
                        </group>
                        <group string="Options">
                            <field name="return_label_on_delivery" invisible="not can_generate_return"/>
                            <field name="get_return_label_from_portal" invisible="not return_label_on_delivery"/>
                            <field name="fedex_rest_email_notifications"/>
                            <field name="fedex_rest_duty_payment" string="Duties paid by"
                                   required="delivery_type == 'fusion_fedex_rest'"/>
                            <field name="fedex_rest_residential_address"/>
                            <field name="fedex_rest_documentation_type"/>
                            <field name="fedex_rest_override_shipper_vat"/>
                        </group>
                        <group string="Extra Data" name="fedex_rest_extra_data" groups="base.group_no_one">
                            <field name="fedex_rest_extra_data_rate_request"/>
                            <field name="fedex_rest_extra_data_ship_request"/>
                            <field name="fedex_rest_extra_data_return_request"/>
                        </group>
                    </group>
                </page>

                <!-- ════════════════════════════════════════════════════
                     FedEx Legacy Configuration
                     ════════════════════════════════════════════════════ -->
                <page string="FedEx Configuration" name="fusion_fedex_configuration"
                      invisible="delivery_type != 'fusion_fedex'">
                    <group>
                        <group>
                            <field name="fedex_developer_key" required="delivery_type == 'fusion_fedex'"/>
                            <field name="fedex_developer_password" required="delivery_type == 'fusion_fedex'"/>
                            <field name="fedex_account_number" string="Account Number"
                                   required="delivery_type == 'fusion_fedex'"/>
                            <field name="fedex_meter_number" required="delivery_type == 'fusion_fedex'"/>
                            <field name="fedex_service_type" required="delivery_type == 'fusion_fedex'"/>
                            <field name="fedex_droppoff_type" required="delivery_type == 'fusion_fedex'"/>
                        </group>
                        <group>
                            <field name="fedex_default_package_type_id"
                                   required="delivery_type == 'fusion_fedex'"
                                   domain="[('package_carrier_type', '=', 'fusion_fedex')]"/>
                            <field name="fedex_weight_unit" string="Package Weight Unit"
                                   required="delivery_type == 'fusion_fedex'"/>
                            <div class="o_td_label">
                                <span class="o_form_label">Package Length Unit</span>
                            </div>
                            <div class="o_field_widget">
                                <span invisible="fedex_weight_unit != 'KG'">CM</span>
                                <span invisible="fedex_weight_unit != 'LB'">IN</span>
                            </div>
                            <field name="fedex_label_stock_type" required="delivery_type == 'fusion_fedex'"/>
                            <field name="fedex_label_file_type" string="Label Format"
                                   required="delivery_type == 'fusion_fedex'"/>
                            <field name="fedex_document_stock_type" required="delivery_type == 'fusion_fedex'"/>
                        </group>
                        <group string="Options">
                            <field name="fedex_saturday_delivery" string="Saturday Delivery"
                                   invisible="fedex_service_type not in ['INTERNATIONAL_PRIORITY', 'FEDEX_2_DAY', 'FIRST_OVERNIGHT', 'PRIORITY_OVERNIGHT']"
                                   required="delivery_type == 'fusion_fedex'"/>
                            <field name="can_generate_return" invisible="1"/>
                            <field name="return_label_on_delivery" invisible="not can_generate_return"/>
                            <field name="get_return_label_from_portal" invisible="not return_label_on_delivery"/>
                            <field name="fedex_duty_payment" string="Duties paid by"
                                   required="delivery_type == 'fusion_fedex'"/>
                        </group>
                        <group string="Extra Data" name="fedex_legacy_extra_data" groups="base.group_no_one">
                            <field name="fedex_extra_data_rate_request"/>
                            <field name="fedex_extra_data_ship_request"/>
                            <field name="fedex_extra_data_return_request"/>
                        </group>
                    </group>
                </page>

                <!-- ════════════════════════════════════════════════════
                     DHL REST Configuration
                     ════════════════════════════════════════════════════ -->
                <page string="DHL REST Configuration" name="fusion_dhl_rest_configuration"
                      invisible="delivery_type != 'fusion_dhl_rest'">
                    <group>
                        <group>
                            <field name="dhl_api_key" required="delivery_type == 'fusion_dhl_rest'"/>
                            <field name="dhl_api_secret" required="delivery_type == 'fusion_dhl_rest'"/>
                            <field name="dhl_account_number" required="delivery_type == 'fusion_dhl_rest'"/>
                            <field name="dhl_region_code" required="delivery_type == 'fusion_dhl_rest'"/>
                            <field name="dhl_product_code" required="delivery_type == 'fusion_dhl_rest'"/>
                        </group>
                        <group>
                            <field name="dhl_default_package_type_id"
                                   required="delivery_type == 'fusion_dhl_rest'"
                                   domain="[('package_carrier_type', '=', 'fusion_dhl_rest')]"/>
                            <field name="dhl_unit_system" required="delivery_type == 'fusion_dhl_rest'"/>
                            <field name="dhl_label_image_format" string="Label Format"
                                   required="delivery_type == 'fusion_dhl_rest'"/>
                            <field name="dhl_label_template" required="delivery_type == 'fusion_dhl_rest'"/>
                        </group>
                        <group string="Options">
                            <field name="return_label_on_delivery" invisible="can_generate_return == False"/>
                            <field name="get_return_label_from_portal" invisible="return_label_on_delivery == False"/>
                            <field name="dhl_dutiable"/>
                            <field name="dhl_duty_payment" string="Duties paid by"
                                   invisible="dhl_dutiable == False"
                                   required="delivery_type == 'fusion_dhl_rest'"/>
                        </group>
                    </group>
                    <group string="Custom Data" name="dhl_rest_customs" groups="base.group_no_one">
                        <field name="dhl_extra_data_rate_request" colspan="2"/>
                        <field name="dhl_extra_data_ship_request" colspan="2"/>
                        <field name="dhl_extra_data_return_request" colspan="2"/>
                    </group>
                </page>

                <!-- ════════════════════════════════════════════════════
                     DHL Legacy Configuration
                     ════════════════════════════════════════════════════ -->
                <page string="DHL Configuration" name="fusion_dhl_configuration"
                      invisible="delivery_type != 'fusion_dhl'">
                    <group>
                        <group>
                            <field name="dhl_SiteID" required="delivery_type == 'fusion_dhl'"/>
                            <field name="dhl_password" required="delivery_type == 'fusion_dhl'"/>
                            <field name="dhl_account_number" required="delivery_type == 'fusion_dhl'"/>
                            <field name="dhl_region_code" required="delivery_type == 'fusion_dhl'"/>
                            <field name="dhl_product_code" required="delivery_type == 'fusion_dhl'"/>
                        </group>
                        <group>
                            <field name="dhl_default_package_type_id"
                                   required="delivery_type == 'fusion_dhl'"
                                   domain="[('package_carrier_type', '=', 'fusion_dhl')]"/>
                            <field name="dhl_package_weight_unit" required="delivery_type == 'fusion_dhl'"/>
                            <field name="dhl_package_dimension_unit" required="delivery_type == 'fusion_dhl'"/>
                            <field name="dhl_label_image_format" string="Label Format"
                                   required="delivery_type == 'fusion_dhl'"/>
                            <field name="dhl_label_template" required="delivery_type == 'fusion_dhl'"/>
                        </group>
                        <group string="Options">
                            <field name="can_generate_return" invisible="1"/>
                            <field name="return_label_on_delivery" invisible="not can_generate_return"/>
                            <field name="get_return_label_from_portal" invisible="not return_label_on_delivery"/>
                            <field name="dhl_dutiable"/>
                            <field name="dhl_duty_payment" string="Duties paid by"
                                   invisible="not dhl_dutiable"
                                   required="delivery_type == 'fusion_dhl'"/>
                        </group>
                        <group string="Custom Data" name="dhl_legacy_customs" groups="base.group_no_one">
                            <field name="dhl_custom_data_request" nolabel="1"
                                   placeholder="'rate': {}, 'ship': {}, 'return': {}"/>
                        </group>
                    </group>
                </page>

            </xpath>
        </field>
    </record>
</odoo>
