<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="report_product_template_label_thermal2x1" model="ir.actions.report">
            <field name="name">Product Label (Thermal 2x1)</field>
            <field name="model">product.template</field>
            <field name="report_type">qweb-pdf</field>
            <field name="report_name">hazard_shopify.report_producttemplatelabel_thermal2x1</field>
            <field name="report_file">hazard_shopify.report_producttemplatelabel_thermal2x1</field>
            <field name="paperformat_id" ref="hazard_shopify.paperformat_label_thermal2x1"/>
            <field name="print_report_name">'Products Labels - %s' % (object.name)</field>
            <field name="binding_type">report</field>
        </record>

        <template id="report_producttemplatelabel_thermal2x1">
            <t t-call="web.html_container">
                <t t-set="barcode_size" t-value="'width: 40mm; height: 8mm;'"/>
                <t t-foreach="quantity.items()" t-as="barcode_and_qty_by_product">
                    <t t-set="product" t-value="barcode_and_qty_by_product[0]"/>
                    <t t-foreach="barcode_and_qty_by_product[1]" t-as="barcode_and_qty">
                        <t t-set="barcode" t-value="barcode_and_qty[0]"/>
                        <t t-foreach="range(barcode_and_qty[1])" t-as="qty">
                            <div class="page" style="position: relative; width: 51mm; height: 25mm; background-color: white; overflow: hidden; box-sizing: border-box; page-break-inside: avoid; page-break-after: always;">
                                
                                <!-- Top Text Section -->
                                <div style="position: absolute; top: 1mm; left: 0; width: 100%; text-align: center;">
                                    <div style="font-family: Arial, sans-serif; font-size: 10px; font-weight: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; padding: 0 1mm;" t-esc="product.name"/>
                                    
                                    <t t-if="product.is_product_variant and product.product_template_attribute_value_ids">
                                        <div style="font-family: Arial, sans-serif; font-size: 11px; font-weight: normal; margin-top: 1px;" t-esc="', '.join(product.product_template_attribute_value_ids.mapped('name'))"/>
                                    </t>
                                </div>
                                
                                <!-- Bottom Barcode Section -->
                                <div style="position: absolute; bottom: 1.5mm; left: 0; width: 100%; text-align: center;">
                                    <t t-if="barcode">
                                        <div t-out="barcode" style="padding:0; margin: 0 auto;" t-options="{'widget': 'barcode', 'symbology': 'auto', 'img_style': 'width: 44mm; height: 11mm; display: block; margin: 0 auto;'}"/>
                                        <div style="font-family: Arial, sans-serif; font-size: 11px; font-weight: normal; margin-top: 1px; line-height: 1;" t-esc="barcode"/>
                                    </t>
                                    <t t-elif="product.default_code">
                                        <div t-out="product.default_code" style="padding:0; margin: 0 auto;" t-options="{'widget': 'barcode', 'symbology': 'auto', 'img_style': 'width: 44mm; height: 11mm; display: block; margin: 0 auto;'}"/>
                                        <div style="font-family: Arial, sans-serif; font-size: 11px; font-weight: normal; margin-top: 1px; line-height: 1;" t-esc="product.default_code"/>
                                    </t>
                                    <t t-else="">
                                        <div style="font-family: Arial, sans-serif; font-size: 11px; color: grey;">Sin código</div>
                                    </t>
                                </div>

                            </div>
                        </t>
                    </t>
                </t>
            </t>
        </template>
    </data>
</odoo>
