Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

PDF filename is always 'account.report_invoice' in ODOO 8

Odebírat

Get notified when there's activity on this post

This question has been flagged
pdffilenamenameodooV8odoo8.0
10 Odpovědi
9900 Zobrazení
Avatar
Juan Muñoz

Hi all, 

I'm trying to change code from /addons/web/controllers/main.py

(line: file_name = '%s.%s' % (file_name, report_struct['format'])

and also trying to edit code from /addons/account/account_report.xml

(<report> tags, lines: name="Invoice" file="account.report_invoice")

BUT nothing. The generated pdf name is always the same.

I install the module 'report_custom_filename' and in the invoice reports i set 'Download filename' to (object.number)+'.pdf' just to prove.

BUT NOTHING!! All what i see gloogling is useless. Only solutions to old versions of OpenERP.

Please if anyone knows how to solve this, help me with Odoo8 :( 

Thanks so much in advance.

Juan.

1
Avatar
Zrušit
Avatar
Temur
Nejlepší odpověď

try following:

do not change anything in original source code, then:

1. go to "Settings/Technical/Actions/Reports" page

2. find an action record that generates the PDF you're interested in.

3. As you find correct record, change it's "Save as Attachment Prefix" field as you like. 

UPDATE:

- above solution applies to pdf attachment that's saved in the database but does not apply for the pdf you download immediately after click on "Print" button in the invoice form. As it's noted in comments, you can download this invoice pdf with a preconfigured name from attachments.

What it concerns name of file that's immediately downloaded after click on the "Print" button in invoice form, most probably it requires customization.

- Python tip (take look of report's controller):


### fseudo import: import report as re 
### see: how-to-import-odoo-module-in-another-module


class ReportController(re.controllers.main.ReportController):

@route(['/report/download'])
def report_download(self, data, token):
response = super(ReportController, self).report_download(data,token) file_download_name = "Whatever you like" if "you have to handle this case(response != None, request type == 'qweb-pdf' etc...)": response.headers.set('Content-Disposition', 'attachment; filename=%s.pdf;' % file_download_name)
return response

this will cause downloaded file to have name: "Whatever you like.pdf"

actually it's not a complete solution, of course you'll need to somehow generate meaningful filename (the variable file_download_name in the code above), also it's possible that there is better place for this kind of intervention than report_download function...  good luck


2
Avatar
Zrušit
Juan Muñoz
Autor

Hi Temur, thanks for your reply. I've already tried. I have this: ((object.partner_id)['name'])+'_'+(object.number)+'_'+((object.date_invoice).split('-')[1])+'.pdf' But this field only generates the attachment file stored in Settings/Database/Attachments. I want the first time you click 'Print', the generated PDF file has a name that I want. I know i can go to Settings/Database/Attachments and download the generated file with the correct name, but what I want is possible? Thanks Temur.

Temur

I'm afraid to disappoint you, but AFAIK that's not possible through configuration...

Juan Muñoz
Autor

And through .py files? I glooged about it but i only see solutions to OpenERP7 or v6.1. If anyone have the same issue pls report here.

Juan Muñoz
Autor

And through .py files? I glooged about it but i only see solutions to OpenERP7 or v6.1. If anyone have the same issue pls report here.

Temur

yes, through customisation it should be possible.. you tried to get worked the "report_custom_filename" module that you mention in the question?

Juan Muñoz
Autor

Yes. I installed it and changed the 'Download filename' field in Settings/ Reports/ Invoices, and nothing. Later also i go to /addons/report_custom_filename/controllers/reports.py and modified some lines. Because i read that this module only runs with old report actions (ir.actions.report.xml), so i added a condition -> elif(http.request.session.model('ir.actions.act_window')): #the other action type. But nothitng :(

Temur

updated answer with a python tip

Avatar
Slim BHIRI
Nejlepší odpověď

I just found an OCA module that does that for all reports.

https://github.com/OCA/reporting-engine/tree/9.0/report_custom_filename

You need to download all the project here :

https://github.com/OCA/reporting-engine

and don't forget to choose your Odoo version from repository branch.

0
Avatar
Zrušit
Avatar
PY
Nejlepší odpověď

Here you go:

# -*- coding: utf-8 -*-

from openerp.addons.report.controllers.main import ReportController
from openerp.http import request, route

import simplejson



class Main(ReportController):

    def get_custom_filename(self, model, res_id):
        """Default behavior will be to get the name of the generated attachment.
        If no attachment is found, for watever reason, this method will generate 
        the filename based on the res_model.
        
        Feel free to override it if needed.
        """
        
        args = [('res_model', '=', model), ('res_id', '=', res_id)]
        attachment = request.env['ir.attachment'].search(args)

        if attachment.exists():
            return attachment.name

        record = request.env[res_model].browse(res_id)
        if record.exists():
            return '{}-{}'.format(record._table, record.name)

    @route()
    def report_download(self, data, token):
        """Attempt to generate proper filenames for qweb-pdf."""
        res = super(Main, self).report_download(data, token)
        
        data = simplejson.loads(data)
        url, report_type = data

        if report_type != 'qweb-pdf':
            return res

        report_name, res_id = url.split('/report/pdf/')[1].split('/')
        
        args = [('report_name', '=', report_name)]
        act_report = request.env['ir.actions.report.xml'].search(args)
        
        if not act_report.exists():
            return res

        filename = self.get_custom_filename(act_report.model, int(res_id))
        if not(filename):
            return res

        if not filename.endswith('.pdf'):
            filename = '{}.pdf'.format(filename)

        content_disposition = 'attachment; filename={}'.format(filename)
        res.headers.set('Content-Disposition', content_disposition)

        return res


Just put that in a module python file and install it.

0
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
"Save as Attachment Prefix" for printed invoices PDF names ignored ?
pdf printing reports name odooV8
Avatar
Avatar
1
bře 15
6611
Using with_context in super call turns into infinite call in odoo Vyřešeno
odooV8 odoo8.0
Avatar
Avatar
Avatar
2
led 20
16254
Edit inherited field definition in odoo 8 Vyřešeno
odooV8 odoo8.0
Avatar
Avatar
Avatar
Avatar
Avatar
16
srp 19
11599
display field depending the value of another field in the view (odoo 8) Vyřešeno
odooV8 odoo8.0
Avatar
Avatar
1
led 19
6161
Hide print in menu bar
odooV8 odoo8.0
Avatar
Avatar
5
čvn 18
11690
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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