Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Dynamic field HTML in Qweb report

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
fieldqwebreporthtmldynamic
7 Réponses
36387 Vues
Avatar
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
Avatar
Ignorer
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?

Avatar
PuentesDSoftware
Meilleure réponse

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
Avatar
Ignorer
Avatar
yom
Meilleure réponse

Hola Juan, te funciono la plantilla?

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

0
Avatar
Ignorer
Avatar
Zbik
Meilleure réponse

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
Avatar
Ignorer
Avatar
Juan Lopez
Auteur Meilleure réponse

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
Avatar
Ignorer
Zbik

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

Juan Lopez
Auteur

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.

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Save HTML Qweb report as an attachment
attachment qweb report html odooV9
Avatar
Avatar
1
oct. 16
5457
[Error] Called computed field API v8 in Qweb Report if store = False
v8 field qweb api report
Avatar
1
mars 15
4863
Edit the HTML reports templates Résolu
qweb reporting webkit report html
Avatar
Avatar
Avatar
Avatar
4
déc. 23
44232
odoo 16 report target new page scss
qweb report
Avatar
Avatar
1
avr. 25
2287
Missing external identifier on new external layout template Résolu
qweb report
Avatar
Avatar
2
mars 25
2937
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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