Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • e-learning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Conocimientos
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Cervecería
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y soporte técnico
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Explorar todos los sectores
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Servicios para partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

change printed file name in webkit report in odoo?

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
qwebreportwebkit_report
11 Respuestas
19533 Vistas
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
Mejor respuesta

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
Mejor respuesta

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)
Mejor respuesta

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
Mejor respuesta


you just have to overwrite controller method. report_download()

0
Avatar
Descartar
Avatar
Jeroen Vet
Mejor respuesta

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
Mejor respuesta

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.
Mejor respuesta

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
Mejor respuesta

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
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
odoo 16 report target new page scss
qweb report
Avatar
Avatar
1
abr 25
2317
Missing external identifier on new external layout template Resuelto
qweb report
Avatar
Avatar
2
mar 25
3029
Translate month name in t-esc Qweb report Resuelto
qweb report
Avatar
Avatar
Avatar
Avatar
Avatar
4
nov 24
8358
QWeb Report Shows Different When Edit And Print Review Resuelto
qweb report
Avatar
Avatar
1
mar 24
3087
How display the currency symbol before the subtotal value on Quotation report? Resuelto
qweb report
Avatar
Avatar
Avatar
3
sept 23
26261
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

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