# -*- coding: utf-8 -*-
from odoo import api, fields, models
from odoo.addons.product.report.product_label_report import _prepare_data

class ProductLabelLayout(models.TransientModel):
    _inherit = 'product.label.layout'

    print_format = fields.Selection(selection_add=[
        ('thermal2x1', 'Etiqueta Térmica 2x1 (51x25mm)')
    ], ondelete={'thermal2x1': 'set default'})

    @api.depends('print_format')
    def _compute_dimensions(self):
        for wizard in self:
            if wizard.print_format == 'thermal2x1':
                wizard.columns, wizard.rows = 1, 1
            else:
                # Re-implement super logic to avoid ValueError on 'thermal2x1'
                if wizard.print_format and 'x' in wizard.print_format:
                    columns, rows = wizard.print_format.split('x')[:2]
                    wizard.columns = int(columns)
                    wizard.rows = int(rows)
                else:
                    wizard.columns, wizard.rows = 1, 1

    def _prepare_report_data(self):
        xml_id, data = super(ProductLabelLayout, self)._prepare_report_data()
        
        if self.print_format == 'thermal2x1':
            xml_id = 'hazard_shopify.report_product_template_label_thermal2x1'
            
        return xml_id, data

class ReportProductTemplateLabelThermal2x1(models.AbstractModel):
    _name = 'report.hazard_shopify.report_producttemplatelabel_thermal2x1'
    _description = 'Product Label Report (Thermal 2x1)'

    def _get_report_values(self, docids, data):
        return _prepare_data(self.env, data)

