Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Dynamic field HTML in Qweb report

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
fieldqwebreporthtmldynamic
7 Replies
36385 Rodiniai
Portretas
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
Portretas
Atmesti
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?

Portretas
PuentesDSoftware
Best Answer

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
Portretas
Atmesti
Portretas
yom
Best Answer

Hola Juan, te funciono la plantilla?

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

0
Portretas
Atmesti
Portretas
Zbik
Best Answer

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
Portretas
Atmesti
Portretas
Juan Lopez
Autorius Best Answer

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
Portretas
Atmesti
Zbik

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

Juan Lopez
Autorius

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!

Registracija
Related Posts Replies Rodiniai Veikla
Save HTML Qweb report as an attachment
attachment qweb report html odooV9
Portretas
Portretas
1
spal. 16
5456
[Error] Called computed field API v8 in Qweb Report if store = False
v8 field qweb api report
Portretas
1
kov. 15
4863
Edit the HTML reports templates Solved
qweb reporting webkit report html
Portretas
Portretas
Portretas
Portretas
4
gruod. 23
44232
odoo 16 report target new page scss
qweb report
Portretas
Portretas
1
bal. 25
2287
Missing external identifier on new external layout template Solved
qweb report
Portretas
Portretas
2
kov. 25
2937
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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