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

File Download on menu action

Odebírat

Get notified when there's activity on this post

This question has been flagged
menufilefilesodoo
2 Odpovědi
4834 Zobrazení
Avatar
Muhammad Aadil

How can we download a static file (we will put it in /static/files folder) from menu action?

0
Avatar
Zrušit
Avatar
Muhammad Aadil
Autor Nejlepší odpověď

I have solved problem... Thanks for your code

1. Menu Action

2. Action 

Download Filefield>ir.actions.serverfield>codefield> action = model.get_stock_file()field>record>

3. Function to download

def get_stock_file(self):  url = str('/ox_fee/static/files/OurSampleFile.xlsx')
return {'type' : 'ir.actions.act_url','url': url,'target': 'self' }



0
Avatar
Zrušit
Avatar
shubham shiroya
Nejlepší odpověď

follow this way:

  1. Create a new Python controller:
from odoo import http
from odoo.http import request
import os


class FileDownloadController(http.Controller):
 
@http.route('/file/download', type='http', auth='user')
def file_download(self):
file_path = '/static/files/your_file.txt' # Update with the actual file path
 
# Get the absolute path of the file
full_path = os.path.join(request.env['ir.config_parameter'].get_param('web.base.url'), file_path)
 
# Read the file and return it as a response
with open(full_path, 'rb') as file:
file_data = file.read()
 
# Set the response headers for file download
response = request.make_response(file_data)
response.headers['Content-Disposition'] = 'attachment; filename="your_file.txt"' # Update with the desired file name
response.mimetype = 'application/octet-stream'
 
return response

  1. Create a menu action that triggers the file download:

field name="name">Download File/field>
field name="type">ir.actions.server/field>
field name="model_id" ref="model_your_model"/>
field name="state">code/field>
field name="code">
action = self.env["ir.actions.act_url"].sudo().with_context(
action_id=self.id, dialog=True).create({
"name": "File Download",
"url": "/file/download",
"target": "new",
})
return {"action": action}
/field>
/record>

  1. Add the menu action to the desired menu:
menuitem id="menu_item_file_download" name="Download File" action="menu_action_file_download"/>

With this setup, when the user selects the "Download File" menu item, the file will be downloaded through the custom controller's file_download method.


note: here i remove the XML tag like(< >) because when i edit the tag and save the answer the i didn't see the full code of XML,so please add the (<>) once you edit the XML file

1
Avatar
Zrušit
Muhammad Aadil
Autor

Thanks.. Let me try..

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
How to pass context in menuitem?
menu odoo
Avatar
Avatar
1
kvě 20
8220
current transaction is aborted, commands ignored until end of transaction block
python file odoo
Avatar
Avatar
1
led 23
7886
How to add window action menu in usermenu odoo15
menu js odoo
Avatar
0
led 22
3278
Custom menu not getting displayed on odoo portal view Vyřešeno
development menu portal odoo
Avatar
Avatar
Avatar
Avatar
Avatar
7
říj 25
8968
Broken app's images after re-buit docker containers.
image menu icons odoo
Avatar
0
led 24
2287
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