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

    <record id="print_product_label_view_form" model="ir.ui.view">
        <field name="name">print.product.label.view.form</field>
        <field name="model">print.product.label</field>
        <field name="arch" type="xml">
            <form create="false" string="Print Product Labels">
                <header>
                    <button name="action_print"
                            string="Print"
                            help="Print product labels"
                            type="object"
                            icon="fa-print"
                            class="btn-primary mr8"/>
                    <button name="action_print"
                            string="Preview"
                            context="{'print_mode': 'html'}"
                            help="Preview product labels"
                            type="object"
                            icon="fa-search"
                            class="border btn-light mr8"/>
                    <field name="label_type_id" widget="selection_badge" invisible="1"/>  <!-- Technical field to specify the label type -->
                </header>
                <div class="oe_button_box" name="button_box"/>
                <field name="mode" invisible="1"/>  <!-- Technical field to specify the mode of the label printing wizard -->
                <field name="is_template_report" invisible="1"/>  <!-- Technical field to specify if the custom label template is selected -->
                <div class="alert alert-info text-center mb-3" invisible="not message" role="alert">
                    <field name="message"/>
                </div>
                <group col="6" colspan="2" name="top_group">
                    <group name="output_format" col="2" colspan="1">
                        <field name="output" widget="badge"/>
                    </group>
                    <group name="label_report" col="2" colspan="2">
                        <field name="report_id" string="Label" widget="radio" />
                    </group>
                    <group name="label_template" col="2" colspan="2" invisible="not is_template_report">
                        <label for="report_id" string="Template"/>
                        <div class="o_row">
                            <a name="label_builder_link" invisible="not is_template_report" href="https://garazd.biz/r/kb3" title="How to get Product Label Builder" target="_blank" rel="noopener noreferrer">
                                <span>Get the Label Builder to create your own labels</span>
                            </a>
                        </div>
                    </group>
                </group>
                <div name="extra_action" class="oe_row">
                    <button name="action_sort_by_product" title="Sort labels by a product" icon="fa-sort-amount-desc" type="object" class="btn-xs btn-light"/>
                    <span class="text-muted px-3">|</span>
                    <field name="qty_per_product" class="mr-2 mt-1 text-right" help="Label quantity per product" style="width: 40px !important;"/>
                    <button name="action_set_qty" string="Set quantity" help="Set a certain quantity for each line." type="object" class="btn-xs btn-light mr-2"/>
                    <button name="action_restore_initial_qty" title="Restore initial quantity" help="Restore initial quantity" icon="fa-undo" type="object" class="btn-xs btn-light"/>
                </div>
                <notebook>
                    <page string="Labels" name="labels">
                        <field name="label_ids" mode="list">
                            <list editable="top" decoration-muted="qty==0">
                                <field name="sequence" widget="handle" width="0.5"/>
                                <field name="selected" widget="boolean_toggle"/>
                                <field name="partner_id" optional="hide"/>
                                <field name="product_id"/>
                                <field name="barcode" optional="show"/>
                                <field name="custom_value" optional="hide"/>
                                <field name="company_id" groups="base.group_multi_company" optional="hide"/>
                                <button name="action_minus_qty" type="object" title="Decrease Qty" icon="fa-minus" class="btn-light"/>
                                <field name="qty" sum="Total" width="0.6" class="text-center font-weight-bold"/>
                                <button name="action_plus_qty" type="object" title="Increase Qty" icon="fa-plus" class="btn-light"/>
                            </list>
                        </field>
                    </page>
                    <page string="Options" name="options">
                        <group name="general_options" class="o_label_nowrap">
                            <group>
                                <field name="lang" widget="radio" options="{'horizontal': true}"/>
                                <field name="humanreadable" widget="boolean_toggle" />
                                <field name="border_width" />
                            </group>
                            <group>
                                <field name="company_id" widget="radio" groups="base.group_multi_company"/>
                            </group>
                        </group>
                    </page>
                </notebook>
            </form>
        </field>
    </record>

    <record id="action_print_label_from_template" model="ir.actions.act_window">
        <field name="name">Custom Product Labels</field>
        <field name="res_model">print.product.label</field>
        <field name="view_mode">form</field>
        <field name="target">current</field>
        <field name="context">{'default_product_template_ids': context.get('active_ids', [])}</field>
        <field name="binding_model_id" ref="product.model_product_template"/>
        <field name="binding_type">report</field>
    </record>

    <record id="action_print_label_from_product" model="ir.actions.act_window">
        <field name="name">Custom Product Labels</field>
        <field name="res_model">print.product.label</field>
        <field name="view_mode">form</field>
        <field name="target">current</field>
        <field name="context">{'default_product_product_ids': context.get('active_ids', [])}</field>
        <field name="binding_model_id" ref="product.model_product_product"/>
        <field name="binding_type">report</field>
    </record>

</odoo>
