Search code examples
odooodoo-10qweb

Custom (width and height) to print Product Labels on Odoo - QWEB


Right now the system is printing the Product Labels and work fine but in wrong dimensions.

I need set width to 7cm and height to 4cm on QWEB report.

Where I can change the dimensions to print QWEB report?

I can't change the format to the print preferences because in a sheet can be many Products Labels.

This is my QWEB:

<?xml version="1.0"?>
<t t-name="product.report_productlabel">
<t t-call="report.html_container">
<div class="page">
  <style>

  </style>

  <t t-foreach="docs" t-as="template">
    <t t-foreach="template.product_variant_ids" t-as="product">

      <div class="col-xs-6" style="padding:0;">
        <table style="border-spacing:0;margin-bottom:0;height: 110px;border: 2px solid black;" class="table">
          <thead>
            <tr style="width: 3in;">
              <td style="width: 2.63in;text-align: center;background-color: #fff;" colspan="2" class="col-xs-8 danger">
                <strong style="text-transform: uppercase;">
                  <t t-esc="product.name"/>
                </strong>
              </td>
            </tr>
          </thead>
          <tbody>
            <tr style="width: 1in;">
              <td style="text-align: center; border-top: 0px solid #fff; padding: 0px 5px 0px 5px;" class="col-xs-5">
                <h4 style="border: 4px solid #ff4040;border-radius: 9px;background-color: #ffff00;padding: 10px 12px 10px 12px;font-size: 26px;margin-top: 0px;margin-bottom: 0px;">
                  <strong t-field="product.list_price" />

                  <strong>
                    <t t-esc="product.company_id.currency_id.symbol"/>
                  </strong>
                </h4>
              </td>
              <td style="text-align: center;border-top: 0px solid #fff;padding: 0px 5px 0px 5px;" class="col-xs-7">
                <img class="img-responsive"
                     t-att-src="'data:image/png;base64,%s' % res_company.logo"
                     style="background-color: #fff;margin-left: auto;margin-right: auto;width: auto;height: 16px;margin-bottom: 8px;"/>
                <img class="img-responsive" t-if="product.barcode"
                     t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', product.barcode, 650, 200)"
                     style="height: 20px;width: 100%;"/>
                <span style="">
                  <t t-esc="product.barcode"/>
                </span>
              </td>
            </tr>
          </tbody>
        </table>
      </div>

    </t>
  </t>
</div>

Solution

  • This the solution for the width of the table using the DPI of 90;

    <table style="border-spacing:0;margin-bottom:0;height: 187px; width: 319px; border: 2px solid black;" class="table">
    

    This is the QWEB template with the dimensions you need and I also scale the fonts and padding of the table elements to match the new width and height:

    <?xml version="1.0"?>
    <t t-name="product.report_productlabel">
    <t t-call="report.html_container">
        <div class="page">
            <style>
    
            </style>
    
            <t t-foreach="docs" t-as="template">
                <t t-foreach="template.product_variant_ids" t-as="product">
    
                    <div class="col-xs-6" style="padding:0;">
                        <table style="border-spacing:0;margin-bottom:0;height: 187px; width: 319px; border: 2px solid black;"
                               class="table">
                            <thead>
                                <tr style="width: 3in;">
                                    <td style="width: 2.63in; font-size: 19px; text-align: left; background-color: #fff; margin-top: 10px;"
                                        colspan="2"
                                        class="col-xs-8 danger">
                                        <strong style="text-transform: uppercase;">
                                            <t t-esc="product.name"/>
                                        </strong>
                                    </td>
                                </tr>
                            </thead>
                            <tbody>
                                <tr style="width: 1in;">
                                    <td width="50%"
                                        style="text-align: center; border-top: 0px solid #fff; padding: 5px; position: relative;">
                                        <div style="position:absolute; bottom: 20px; left: 0; padding-left: 5px; width: 100%">
                                            <h4 style="border: 4px solid #ff4040; border-radius: 9px; background-color: #ffff00; padding: 10px 6px; font-size: 21px; margin: 0px ">
                                                <strong t-field="product.list_price"/>
                                                <strong>
                                                    <t t-esc="product.company_id.currency_id.symbol"/>
                                                </strong>
                                            </h4>
                                        </div>
                                    </td>
                                    <td width="50%"
                                        style="text-align: center;border-top: 0px solid #fff;padding: 5px; position: relative;">
                                        <div style="position:absolute; bottom: 20px; padding-right: 5px;">
                                            <img class="img-responsive"
                                                 t-att-src="'data:image/png;base64,%s' % res_company.logo"
                                                 style="background-color: #fff; margin-left: auto; margin-right: auto; width: auto; height: 35px; margin-bottom: 5px;"/>
                                            <img class="img-responsive" t-if="product.barcode"
                                                 t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', product.barcode, 650, 200)"
                                                 style="height: 20px; width: 100%;"/>
                                            <span style="font-size: 14px">
                                                <t t-esc="product.barcode"/>
                                            </span>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
    
                </t>
            </t>
        </div>
    </t>