Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Issue with a new Product Label Template (102x102) in Odoo V17

Naroči se

Get notified when there's activity on this post

This question has been flagged
developmentpythonqweb
1768 Prikazi
Avatar
Quentin Roland

Hi everyone,

I’m encountering an issue with a custom product label template I created in Odoo based on the standard implementation. The template is supposed to display products with specific dimensions (102x102), but the following problems occur:

  1. No products are displayed at all: The table seems empty, and none of the data I’m passing appears to render correctly.
  2. H1 tag stops iterating: Inside the loop for testing, the <h1> tags only display up to the third iteration and do not proceed further.

Here’s the relevant portion of my code:


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

<odoo>

<data>

<!-- Template principal -->

<template id="template_producttemplatelabel102x102">

<t t-call="web.basic_layout">

<div class="page">

<t t-set="columns" t-value="102"/>

<t t-set="rows" t-value="102"/>

<t t-call="happy_rabbits_custo.report_productlabel_102x102"/>

<t t-log="quantity"/>

<t t-log="current_data"/>

<t t-log="product"/>

<t t-log="barcode"/>


</div>

</t>

</template>


<!-- Template de gestion des labels -->

<template id="report_productlabel_102x102">

<t t-call="web.html_container">

<t t-esc='columns'/>

<t t-esc='rows'/>

<t t-if="columns and rows">

<t t-if="columns == 102 and rows == 102">

<t t-set="padding_page" t-value="'padding: 0mm'"/>

<t t-set="report_to_call" t-value="'102x102'"/>

</t>

<t t-set="page_numbers" t-value="1"/>

<h1>lalalallalalaal3 </h1>

<t t-foreach="range(page_numbers)" t-as="page">

<h1>lalalallalalaal3 </h1>


<div class="o_label_sheet" t-att-style="padding_page">

<table class="my-0 table table-sm table-borderless">

<t t-foreach="range(rows)" t-as="row">

<tr>

<t t-foreach="range(columns)" t-as="column">

<t t-if="not current_quantity and quantity and not (current_data and current_data[1])">

<h1>lalalallalalaal5 </h1>

<t t-set="current_data" t-value="quantity.popitem()"/>

<t t-set="product" t-value="current_data[0]"/>

<h1>lalalallalalaal6 </h1>


<t t-set="barcode_and_qty" t-value="current_data[1].pop()"/>

<t t-set="barcode" t-value="barcode_and_qty[0]"/>

<t t-set="current_quantity" t-value="barcode_and_qty[1]"/>

</t>

<t t-if="current_quantity">

<t t-set="make_invisible" t-value="False"/>

<t t-set="current_quantity" t-value="current_quantity - 1"/>

</t>

<t t-else="">

<t t-set="make_invisible" t-value="True"/>

</t>

</t>

<t t-if="report_to_call == '102x102'">

<t t-call="happy_rabbits_custo.report_simple_label102x102"/>

</t>

</tr>

</t>

</table>

</div>

</t>

</t>

</t>

</template>


<template id="report_simple_label102x102">

<t t-set="barcode_size" t-value="'width:80mm;height:80mm'"/>

<t t-set="table_style" t-value="'width:102mm;height:102mm;'"/>

<td t-att-style="make_invisible and 'visibility:hidden;'">

<div class="o_label_full" t-att-style="table_style">

<div class="o_label_name">

<t t-if="quantity">

<p>Quantity: <t t-esc="quantity"/></p>

</t>

<t t-if="product">

<p>Product: <t t-esc="product.display_name"/></p>

</t>

<t t-else="">

<p>No product data available.</p>

</t>


</div>

</div>

</td>

</template>


<record id="happy_rabbits_custo.report_product_template_label_102x102" model="ir.actions.report">

<field name="name">Product Label 102x102</field>

<field name="model">product.template</field>

<field name="report_type">qweb-pdf</field>

<field name="report_name">happy_rabbits_custo.template_producttemplatelabel102x102</field>

<field name="report_file">happy_rabbits_custo.template_producttemplatelabel102x102</field>

<field name="print_report_name">'Products Labels - %s' % (object.name)</field>

</record>


</data>

</odoo>

And the python model : 

from odoo import models, fields

import logging


_logger = logging.getLogger(__name__)


class ProductLabelLayout(models.TransientModel):

_inherit = 'product.label.layout'


print_format = fields.Selection(

selection_add=[('102x102xprice', '102x102')],

ondelete={'102x102xprice': 'set default'}, # Définir une politique pour la valeur ajoutée

)


def _prepare_report_data(self):

xml_id, data = super()._prepare_report_data()

if self.print_format in ['102x102xprice']:

if 'product.' in xml_id:

xml_id = xml_id.replace('product.', 'happy_rabbits_custo.')

active_model = ''

if self.product_tmpl_ids:

products = self.product_tmpl_ids.ids

active_model = 'product.template'

_logger.info('products: %s', products)

elif self.product_ids:

products = self.product_ids.ids

active_model = 'product.product'

_logger.info('products: %s', products)

else:

raise UserError(_("No product to print, if the product is archived please unarchive it before printing its label."))


_logger.info('products: %s', products)

data.update({

'active_model': active_model,

'quantity_by_product': {p: self.custom_quantity for p in products},

'layout_wizard': self.id,

'price_included': 'xprice' in self.print_format,

})



return xml_id, data



def _prepare_data(env, docids, data):

_logger.info("Starting _prepare_data with data: %s", data)


layout_wizard = env['product.label.layout'].browse(data.get('layout_wizard'))

if not layout_wizard:

_logger.error("Layout wizard is missing.")

return {}


if layout_wizard.print_format == '102x102xprice':

quantity = data.get('quantity_by_product', {})

_logger.info("Quantity by Product: %s", quantity)


if not quantity:

_logger.error("Quantity by product is empty.")

return {}


total = sum(quantity.values())

rows = layout_wizard.rows or 1

columns = layout_wizard.columns or 1

page_numbers = (total - 1) // (rows * columns) + 1


products = env['product.template'].browse(list(quantity.keys()))

_logger.info("Products loaded: %s", products)


return {

'quantity': {p.id: quantity[str(p.id)] for p in products}, # Correct format

'page_numbers': page_numbers,

'price_included': data.get('price_included'),

'extra_html': layout_wizard.extra_html,

'pricelist': layout_wizard.pricelist_id,

}



class ReportHappyRabbitsProductTemplateLabel102x102(models.AbstractModel):

_name = 'report.happy_rabbits_custo.report_producttemplatelabel102x102'

_description = 'Product Label Report 102x102'


def _get_report_values(self, docids, data):

return ProductLabelLayout._prepare_data(self.env, docids, data)


Questions:

  1. Why might the data not display in the template like my products name or other? Could there be an issue with the t-set assignments?

Any insights or suggestions would be greatly appreciated! Thanks in advance for your help.

0
Avatar
Opusti
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
TypeError str and datetime Solved
development python
Avatar
Avatar
Avatar
2
avg. 24
2299
Duplicate Orders in POS When Clicking Order Button (Odoo 18)
development python Point Of Sale
Avatar
Avatar
2
feb. 25
2408
Email template - list of followers
python qweb email
Avatar
Avatar
Avatar
2
jun. 23
3169
Best practices for code reuse in Odoo addon development ?
development python methodology
Avatar
Avatar
1
apr. 23
6075
My custom report is changing when user Configured the Document Layout Solved
python qweb v14
Avatar
Avatar
1
jan. 23
3351
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now