Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

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

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
pdffilenamenameodooV8odoo8.0
10 Odpowiedzi
9898 Widoki
Awatar
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
Awatar
Odrzuć
Awatar
Temur
Najlepsza odpowiedź

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
Awatar
Odrzuć
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

Awatar
Slim BHIRI
Najlepsza odpowiedź

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
Awatar
Odrzuć
Awatar
PY
Najlepsza odpowiedź

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
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
"Save as Attachment Prefix" for printed invoices PDF names ignored ?
pdf printing reports name odooV8
Awatar
Awatar
1
mar 15
6611
Using with_context in super call turns into infinite call in odoo Rozwiązane
odooV8 odoo8.0
Awatar
Awatar
Awatar
2
sty 20
16254
Edit inherited field definition in odoo 8 Rozwiązane
odooV8 odoo8.0
Awatar
Awatar
Awatar
Awatar
Awatar
16
sie 19
11598
display field depending the value of another field in the view (odoo 8) Rozwiązane
odooV8 odoo8.0
Awatar
Awatar
1
sty 19
6161
Hide print in menu bar
odooV8 odoo8.0
Awatar
Awatar
5
cze 18
11690
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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