Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Food & Hospitality
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Guest House
    • Distributor nápojů
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Trades
    • Údržbář
    • IT hardware a podpora
    • Solar Energy Systems
    • Výrobce obuvi
    • Úklidové služby
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

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

Odebírat

Get notified when there's activity on this post

This question has been flagged
developmentpythonqweb
1754 Zobrazení
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
Zrušit
Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
TypeError str and datetime Vyřešeno
development python
Avatar
Avatar
Avatar
2
srp 24
2281
Duplicate Orders in POS When Clicking Order Button (Odoo 18)
development python Point Of Sale
Avatar
Avatar
2
úno 25
2393
Email template - list of followers
python qweb email
Avatar
Avatar
Avatar
2
čvn 23
3164
Best practices for code reuse in Odoo addon development ?
development python methodology
Avatar
Avatar
1
dub 23
6055
My custom report is changing when user Configured the Document Layout Vyřešeno
python qweb v14
Avatar
Avatar
1
led 23
3335
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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