Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

change printed file name in webkit report in odoo?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
qwebreportwebkit_report
11 Respostes
19518 Vistes
Avatar
Nikunj Nakum

How to change name of resultant file name in odoo webkit report?

 

for example : now is printing --> sale.report_saleorder.pdf 

but i want in this way --> Sale Order.pdf

Thank In advance

 

 

0
Avatar
Descartar
Avatar
Laurent Destailleur
Best Answer

This is a complete code that change behaviour to force your own file name without breaking compatibility with other reports and without changing Odoo core. Check you edit value for 'nameofreporttochange' with name of report (you will find it into console because it is output into log).

Just put this into a file   myfile.py and declare this file into manifest of your module.

from openerp.addons.web.http import Controller, route, request
from openerp.addons.web.controllers.main import _serialize_exception
from openerp.osv import osv
from openerp.addons.report.controllers.main import ReportController
from openerp import http
import simplejson
import logging


# Surcharge la fonction report_download afin de pouvoir modifier le
# content assist pour forcer la valeur du 'Content-Disposition' et forcer le nom du fichier telecharge.
class SponsorReportController(ReportController):

    @route(['/report/download'], type='http', auth="user")
    def report_download(self, data, token):
        logging.info("report_download")
        requestcontent = simplejson.loads(data)
        url, type = requestcontent[0], requestcontent[1]
        
        logging.info(url)
        logging.info(type)

        response = ReportController().report_download(data, token)

        if len(url.split('/report/pdf/')) > 1 and type == 'qweb-pdf':
            reportname = url.split('/report/pdf/')[1].split('?')[0]
            reportname, docids = reportname.split('/')
            logging.info(reportname)
            assert docids
            logging.info(docids)
        
            if reportname == 'nameofreporttochange':
                filename = 'My new filename'
                if docids.isnumeric():
                    partner_obj = http.request.env['res.partner']
                    object = partner_obj.browse(int(docids))
                    filename = filename + " - " + object.name
            
            response.headers.set('Content-Disposition', 'attachment; filename=%s.pdf;' % filename)
            
        return response

1
Avatar
Descartar
Avatar
Pascal Tremblay
Best Answer

Here is our solution to include the sale order name (SO000012, SO000013, etc.) in the file name of the sale orders reports pdf via « Print » buttons.

Content of control_pt.py :

import pdb
from openerp.addons.web.http import Controller, route, request
from openerp.addons.report.controllers.main import ReportController
from openerp.osv import osv
from openerp import http
import simplejson

class PTReportController(ReportController):
    @route(['/report/download'], type='http', auth="user")
    def report_download(self, data, token):
        order_obj = http.request.env['sale.order']
        requestcontent = simplejson.loads(data)
        url, type = requestcontent[0], requestcontent[1]
# url = u'/report/pdf/sale.report_saleorder/37'
# type = u'qweb-pdf'
        assert type == 'qweb-pdf'
        reportname = url.split('/report/pdf/')[1].split('?')[0]
# reportname = u'sale.report_saleorder/37'
        reportname, docids = reportname.split('/')
# reportname = u'sale.report_saleorder'
# docids = 37
        assert docids
        object = order_obj.browse(int(docids))

        name = object.name
# name = 2014-DE000020
        filename = 'PT_' + object.name
# filename = PT_2014-DE000020

        response = ReportController().report_download(data, token)
        response.headers.set('Content-Disposition', 'attachment; filename=%s.pdf;' % filename)
        return response

0
Avatar
Descartar
Avatar
Jainesh Shah(Aktiv Software)
Best Answer

Hi Nikunj,

This code prints the report with the dynamic pdf names without affecting other reports of the same module or base :

from odoo.addons.report.controllers.main import ReportController 
from odoo import http import simplejson import logging class PrintReport(ReportController):     @http.route(['/report/download'], type='http', auth="user")     def report_download(self, data, token):         logging.info("report_download")         requestcontent = simplejson.loads(data)         url, type = requestcontent[0], requestcontent[1]         logging.info(url)         logging.info(type)         response = super(PrintReport,self).report_download(data,token)         if len(url.split('/report/pdf/')) > 1 and type == 'qweb-pdf':             reportname = url.split('/report/pdf/')[1].split('?')[0]             reportname, docids = reportname.split('/')             logging.info(reportname)             assert docids             logging.info(docids)             if reportname == 'module_name.report_template_name':                 filename = 'module_template.report_template_name'                 if docids.isdigit():                     obj = http.request.env['model.name']                     object = obj.browse(int(docids))                     filename = object.field_name + " " + object.field_name                 else:                     filename = 'File_name'        ### will print multiple reports with the respective name given                 response.headers.set('Content-Disposition', 'attachment; filename=%s.pdf;' % filename)         return response

Hope this will help you.

Thanks.

0
Avatar
Descartar
Avatar
mansy gajjar
Best Answer


you just have to overwrite controller method. report_download()

0
Avatar
Descartar
Avatar
Jeroen Vet
Best Answer

You can check out my solution at stackoverflow http://stackoverflow.com/questions/30485464/how-to-set-pdf-name-in-qweb-report-odoo/32152798#32152798

0
Avatar
Descartar
Fabian Tribrunner

wrong link?

Jeroen Vet

Yes, sorry, fixed the link.

Avatar
Balvant Ramani
Best Answer

Yes... but it is sometype of hacking.... why odoo not give that because... in python if we take unicodecharacter in file name it gives parsing error...  if you want to try that fix name like "čćžšđ" and it give error... and odoo is support multi language... this is crotian character... if some one put this type of name it become problem.. so odoo not give that..

0
Avatar
Descartar
Avatar
Serpent Consulting Services Pvt. Ltd.
Best Answer

Nikunj,

The tecnical workaround is big and needs customization.

For quicker solution, go to odoo/addons/report/controllers/main.py line 123, change reortname!

Thanks.

0
Avatar
Descartar
Pascal Tremblay

It is how i'm trying to do now. But how to get the report_filename there?

Avatar
Torvald Baade Bringsvor
Best Answer

An inbetween solution can be to override the ReportController for the /report/download URL.

This is what I did:

from openerp.addons.web.http import Controller, route, request
from openerp.addons.web.controllers.main import _serialize_exception
from openerp.osv import osv
from openerp.addons.report.controllers.main import ReportController
from openerp import http
import simplejson


class SponsorReportController(ReportController):

    @route(['/report/download'], type='http', auth="user")
    def report_download(self, data, token):
        partner_obj = http.request.env['res.partner']
        requestcontent = simplejson.loads(data)
        url, type = requestcontent[0], requestcontent[1]
        assert type == 'qweb-pdf'
        reportname = url.split('/report/pdf/')[1].split('?')[0]

        reportname, docids = reportname.split('/')
        assert docids
        object = partner_obj.browse(int(docids))
        response = ReportController().report_download(data, token)
        filename = object.report_filename

        response.headers.set('Content-Disposition', 'attachment; filename=%s.pdf;' % filename)
        return response

As you can see I have copied some of the code from odoo/addons/report/controllers/main.py to get the ID of the document, then I invoke the report_filename on the object and overwrite the Content-Disposition header in the response. This is a little cleaner than messing with the core code. Hope this helps you.

 

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

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

Registrar-se
Related Posts Respostes Vistes Activitat
odoo 16 report target new page scss
qweb report
Avatar
Avatar
1
d’abr. 25
2313
Missing external identifier on new external layout template Solved
qweb report
Avatar
Avatar
2
de març 25
3022
Translate month name in t-esc Qweb report Solved
qweb report
Avatar
Avatar
Avatar
Avatar
Avatar
4
de nov. 24
8354
QWeb Report Shows Different When Edit And Print Review Solved
qweb report
Avatar
Avatar
1
de març 24
3083
How display the currency symbol before the subtotal value on Quotation report? Solved
qweb report
Avatar
Avatar
Avatar
3
de set. 23
26252
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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