Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Dynamic field HTML in Qweb report

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
fieldqwebreporthtmldynamic
7 Răspunsuri
36392 Vizualizări
Imagine profil
Juan Lopez

Hi,

I have created a new field in the model hr.contract.type, this new field called format is HTML type, the field format is filled with the contract format that must be printed in the hr.contract model form view. The idea is that the field format have inside keywords or variables that must be replaced in the report generation, like the Email templates, that the variables are replaced when the email is sent.

The QWeb view is this:

<?xml version="1.0"?> <t t-name="hr.contrato_laboral"> <t t-call="report.html_container"> <t t-foreach="docs" t-as="o"> <t t-call="report.external_layout"> <div class="page"> <span t-raw="o.type_id.format"/> </div> </t> </t> </t> </t>

I have read that i can create a custom report like this:

from openerp import api, models

class ParticularReport(models.AbstractModel):

_name = 'report.<<module.reportname>>'

@api.multi

def render_html(self, data=None):

report_obj = self.env['report']

report = report_obj._get_report_from_name('<<module.reportname>>')

docargs = { 'doc_ids': self._ids, 'doc_model': report.model, 'docs': self, }

return report_obj.render('<<module.reportname>>', docargs)

But where and how can i make the replacement of the keywords or variables?

Best regards,

Juan David López

0
Imagine profil
Abandonează
Zahin

Their is not right solution, its very panic to do so. for this odoo is not right ERP.

Rakesh Yadav

Hi Juan,

Did you solve it?

Imagine profil
PuentesDSoftware
Cel mai bun răspuns

Juan, I had the same error, this is because with some thing related with "context" and immutable property.

Try with this code (adapt it to your needs):



@api.v7
def render_html(self, cr, uid, ids, data=None, context=None):
      report_obj = self.pool['report']
      report = report_obj._get_report_from_name(cr, uid, self._template)
      docs = self.pool[report.model].browse(cr, uid, ids, context=context)
      docargs = {
          'doc_ids': ids,
          'doc_model': report.model,
          'docs': docs,
      }
      return report_obj.render(cr, uid, [], report.report_name, docargs, context=context)

0
Imagine profil
Abandonează
Imagine profil
yom
Cel mai bun răspuns

Hola Juan, te funciono la plantilla?

 puedo mostrar la plantilla pero no consigo que rellene los datos de los tags 

0
Imagine profil
Abandonează
Imagine profil
Zbik
Cel mai bun răspuns

You create parser like this (see method currency_text):

<span t-if="o.currency_id" t-esc="currency_text(o.amount_total, o.currency_id.name, o.partner_id.lang or 'pl_PL')"/>

class report_invoice(models.AbstractModel):
    _name = 'report.account.report_invoice'
    _template = 'account__pl.report_invoice_pl'

    def currency_text(self, sum, currency, language):
        return currency_to_text(sum, currency, language)

    @api.multi
    def render_html(self, data=None):
                                                                     
        report_obj = self.env['report']
        report = report_obj._get_report_from_name(self._template)        
       
        docargs = {
            'currency_text': self.currency_text,        
            'doc_ids': self._ids,
            'doc_model': report.model,
            'docs': self,
        }

        return report_obj.render(self._template, docargs)

 

UPDATE:

In my test system, your code works for me without any problem. Code:

        <report
            id = "contrato_laboral"
            string = "Contrato laboral"
            model = "hr.contract"
            report_type = "qweb-pdf"
            file = "hr.contrato_laboral"
            name = "hr.contrato_laboral"/>

        <template id="hr.contrato_laboral">
            <t t-call="report.html_container">
                <t t-foreach="docs" t-as="o">
                    <t t-call="report.external_layout">
                        <div class="page">
                            <span t-esc="get_formato()"/>
                        </div>
                    </t>
                </t>
            </t>
        </template>

class hr_contract_type(orm.Model):
    _name = "hr.contract.type"
    _description = "Contract Type"
    _inherit = "hr.contract.type"
    _columns = {
        'format': fields.html('Formato contrato', help="Campo HTML para definir el formato del contrato"),
    }
hr_contract_type()

class report_contrato_laboral(models.AbstractModel):
    _name = 'report.hr.contrato_laboral'
    _template = 'hr.contrato_laboral'
    
    def get_formato(self):
        return 'Hola Mundo!!!'
    
    @api.multi
    def render_html(self, data=None):
        report_obj = self.env['report']
        report = report_obj._get_report_from_name(self._template)

        docargs = {
            'get_formato':self.get_formato,
            'doc_ids': self._ids,
            'doc_model': report.model,
            'docs': self,
        }
        
        return report_obj.render(self._template, docargs)
report_contrato_laboral()

 

 

 

 

 

0
Imagine profil
Abandonează
Imagine profil
Juan Lopez
Autor Cel mai bun răspuns

Hi zbik, thanks for your answer, i tried this:

Class to add field and define custom render for report:

from openerp.osv import fields, osv
from openerp import api, models

class hr_contract_type(osv.osv):
    _name = "hr.contract.type"
    _description = "Contract Type"
    _inherit = "hr.contract.type"
    _columns = {
        'format': fields.html('Formato contrato', help="Campo HTML para definir el formato del contrato"),
    }
hr_contract_type()

class report_contrato_laboral(osv.AbstractModel):
    _name = 'report.hr.contrato_laboral'
    _template = 'hr.contrato_laboral'
    _wrapped_report_class = None
    
    def get_formato(self):
        return 'Hola Mundo!!!'
    
    def render_html(self, data=None):
        report_obj = self.env['report']
        report = report_obj._get_report_from_name(self._template)

        docargs = {
            'get_formato':self.get_formato,
            'doc_ids': self._ids,
            'doc_model': report.model,
            'docs': self,
        }
        
        return report_obj.render(self._template, docargs)
report_contrato_laboral()

XML to define report:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <report
            id = "contrato_laboral"
            string = "Contrato laboral"
            model = "hr.contract"
            report_type = "qweb-pdf"
            file = "hr.contrato_laboral"
            name = "hr.contrato_laboral"/>
    </data>
</openerp>

XML to define template

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="hr.contrato_laboral">
    <t t-call="report.html_container">
        <t t-foreach="docs" t-as="o">
            <t t-call="report.external_layout">
                <div class="page">
                    <span t-esc="get_formato()"/>
                </div>
            </t>
        </t>
    </t>
</template>
</data>
</openerp>

This is the error that is shown when i clic the print option "Contrato laboral": Uncaught SyntaxError: Unexpected end of input

Do you see an error in the code?

Best regards,

Juan David López

 

0
Imagine profil
Abandonează
Zbik

In my suggestion other inherited model is used: models.AbstractModel

Juan Lopez
Autor

Hi Zbik, I have changed this: class report_contrato_laboral(osv.AbstractModel):, for class report_contrato_laboral(models.AbstractModel): The result is the same. Any other suggestion? Best regards. Juan David López

Zbik

See UPDATE in my answer.

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

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Save HTML Qweb report as an attachment
attachment qweb report html odooV9
Imagine profil
Imagine profil
1
oct. 16
5458
[Error] Called computed field API v8 in Qweb Report if store = False
v8 field qweb api report
Imagine profil
1
mar. 15
4863
Edit the HTML reports templates Rezolvat
qweb reporting webkit report html
Imagine profil
Imagine profil
Imagine profil
Imagine profil
4
dec. 23
44232
odoo 16 report target new page scss
qweb report
Imagine profil
Imagine profil
1
apr. 25
2288
Missing external identifier on new external layout template Rezolvat
qweb report
Imagine profil
Imagine profil
2
mar. 25
2938
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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