Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
4932 Vistas

I was trying to add aditional label formats using this module code:


from collections import defaultdict
from odoo import fields, models


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

print_format = fields.Selection(selection_add=[
('2x4', '2 x 4')
], ondelete={'2x4': 'set default'})


And i thought that would do it, but it leads to an error. Any ideas ?


load could not load template
ValueError: Invalid template id: ''
Template: product.report_productlabel


Avatar
Descartar
Mejor respuesta

You need to try this code.When we create new selection field on the prin_format you must add new functions for that types and need to create new printing format

from collections import defaultdict
from odoo import fields, models,
_
from odoo.exceptions import UserError


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

print_format = fields.Selection(selection_add=[
    (
'price_card', 'Price Card'), ], ondelete={'price_card': 'set default'})

def _prepare_report_data(self):
    xml_id, data =
super()._prepare_report_data()

   
if 'price_card' in self.print_format:
        xml_id =
module_name.report_product_label_product_price_tag'

        active_model =
''
       
if self.product_tmpl_ids:
            products =
self.product_tmpl_ids.ids
            active_model =
'product.template'
        elif
self.product_ids:
            products =
self.product_ids.ids
            active_model =
'product.product'
        price = format(
self.product_tmpl_ids.list_price, ".2f")
        data = {
           
'active_model': active_model,
           
'product_tmpl_name': self.product_tmpl_ids.name,
           
'product_tmpl_price': price,
           
'product_tmpl': self.product_tmpl_ids,
           
'product_name': self.product_ids.name,
           
'product_id': self.product_ids,
        }
   
return xml_id, data

def process(self):
    action =
super(ProductLabelLayout, self).process()
   
self.ensure_one()
    xml_id, data =
self._prepare_report_data()
   
if not xml_id:
        raise UserError(
_('Unable to find report template for %s format', self.print_format))
    report_action =
self.env.ref(xml_id).report_action(None, data=data)
    report_action.update({
'close_on_report_download': True})
   
return action

Also, try to add the paper format and further details

<record id="paperformat_product_price_tag" model="report.paperformat">
    <field name="name">Price Card Label</field>
    <field name="default" eval="True"/>
    <field name="format">custom</field>
    <field name="page_height">267</field>
    <field name="page_width">175</field>
    <field name="orientation">Landscape</field>
    <field name="margin_top">0</field>
    <field name="margin_bottom">0</field>
    <field name="margin_left">0</field>
    <field name="margin_right">0</field>
    <field name="disable_shrinking" eval="True"/>
    <field name="header_line" eval="False"/>
    <field name="header_spacing">0</field>
    <field name="dpi">96</field>
</record>
<record id="report_product_label_product_price_tag" model="ir.actions.report">
 
  <field name="name">Product Price Card</field>
    <field name="model">product.template</field>
    <field name="report_type">qweb-pdf</field>
    <field name="report_name">module_name.report_product_price_tag</field>
    <field name="report_file">module_name.report_product_price_tag</field>
    <field name="binding_type">report</field>
    <field name="binding_model_id" ref="model_product_template"/>
    <field name="paperformat_id" ref="paperformat_product_price_tag"/>
</record>
<template id="report_product_price_tag">
    //content
</template>




Hope it helps

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jul 25
2765
1
abr 25
4182
2
jul 24
5789
1
abr 24
1638
3
may 24
2393