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
    Real Estate
    • Real Estate Agency
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consulting
    • Accounting Firm
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Furnitures
    • Food
    • 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
    • Solar Energy Systems
    • Shoe Maker
    • Serveis de neteja
    • HVAC Services
    Others
    • 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

[10]Download a generated xlsx file by pressing a button

Subscriure's

Get notified when there's activity on this post

This question has been flagged
filedownloadxlsxodoo10
5 Respostes
16591 Vistes
Avatar
Paolo M

Hello, I associated with a button a method that allows the generation of an xlsx file, I would like to return the file just created, as for a normal file, with the Save as...

This is my code, I do not know how to write the return, I need help.

   @api.multi
    def export(self):
        workbook = xlsxwriter.Workbook('/tmp/test.xlsx')
        worksheet = workbook.add_worksheet()
        row = 0
        col = 0
        for vals in self.carrier_line_ids:
            worksheet.write(row, 0, vals.reference)
            ...
            ...
            row += 1


        workbook.close()
1
Avatar
Descartar
Avatar
Paolo M
Autor Best Answer

My solution:

@api.multi
    def export(self):
        file_name = 'temp'
        workbook = xlsxwriter.Workbook(file_name, {'in_memory': True})
        worksheet = workbook.add_worksheet()
        row = 0
        col = 0
        for e in header:
            worksheet.write(row, col, e)
            col += 1
        row += 1
        for vals in self.carrier_line_ids:
            worksheet.write(row, 0, vals.reference)
            ...
            ...
        workbook.close()
        with open(file_name, "rb") as file:
            file_base64 = base64.b64encode(file.read())
         self.carrier_xlsx_document_name = self.name + '.xlsx'
        self.write({'carrier_xlsx_document': file_base64, })

carrier_xlsx_document is a binary


view.xml

<field name="carrier_xlsx_document" widget="binary" filename="carrier_xlsx_document_name"
attrs="{'invisible':[('state','=', 'draft')]}" readonly="1"/>
<field name="carrier_xlsx_document_name" invisible="1"/>

Add to import xlsxwriter and base64

I hope this solution can help other programmers.

A request for mods: you can change the name of the thread and add SOLVED, I can't.

0
Avatar
Descartar
Simon Capriles

Hi, I am trying this solution but I get the following error message:
FileNotFoundError: [Errno 2] No such file or directory: 'Registro_Ventas_12/2021.xlsx'
Do you know why is this happening?
This is my code:
def write_xlsx(self, file_name, header_list, field_list):
workbook = xlsxwriter.Workbook(file_name, {'in_memory': True})
worksheet = workbook.add_worksheet()
row = col = 0
# Write header row
for header in header_list:
worksheet.write(row, col, header)
col += 1
row += 1
# Write value rows
n = 1
for line in self.lcv_line_ids:
line_registry = self.env['lcv.line'].browse([line.id])
worksheet.write(row, 0, n)
col = 1
for field in field_list:
if isinstance(getattr(line_registry, field), float):
value = str(round(getattr(line_registry, field), 2))
else:
value = str(getattr(line_registry, field))
worksheet.write(row, col, value)
col += 1
n += 1
row += 1
workbook.close()
with open(file_name, "wb") as file:
file_base64 = base64.b64encode(file.read())
return file_base64

Avatar
Peterc
Best Answer

I have no clue how to help you, but the forum software won't let me ask my question until I've answered other people's questions, so I'm going to go with a classic answer: paint ram's blood over your doorway.

2
Avatar
Descartar
Avatar
Anil Kesariya
Best Answer

Hi Paolo,

Go to,

Setting>>Translation>>Import/ Export>>Export Translation

The popup wizard generate the translation file and allow you to download the file.

This will give you an idea how you can make it to work with your module.

You will find the reference code inside base mdoule

I hope this will give you an idea, how you can hit the goal.

Rgds,

Anil.





0
Avatar
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

We have a written a blog about how to create XLS report in odoo 10, you can go through it: How to Create an XLS Report in Odoo ?


Thanks

0
Avatar
Descartar
Paolo M
Autor

This does not help me, I create an xlsx file and I want it to be saved, for now I create it but I can not generate the window with a direct link to the file.

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
How to download a file with button that executes a method in odoo 10? Solved
download files odoo10
Avatar
Avatar
2
d’abr. 24
22783
Upload un fichier téléchargeable par les visiteurs
upload file download
Avatar
0
de juny 23
3534
Decode file
file odoo10 decode
Avatar
0
d’oct. 20
3684
Download External File in Openerp 7.0
external file download
Avatar
3
de juny 20
9500
play and dowload mp3 from tree view
file download play
Avatar
0
d’abr. 16
6616
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