Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

How to download multiple attachment files on button click action?

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
attachmentodoo10.0
3 Răspunsuri
13885 Vizualizări
Imagine profil
Girija Subramaniyan

While select multiple records in tree view and click button, need to download respective attachments simultaneously. I'm working in Odoo10.0

def generate_renewal_pdf(self):
 """ Print renewal pdf"""
    attachment_ids = {}
     for mail in self:
         attachments = mail.attachment_ids
         for attach in attachments:
               attachment_ids[attach.id] = str(attach.datas_fname)
              download = True
              return {
                   'type': 'ir.actions.act_url',
                    'url': '/web/content/%s/%s/%s' % (attach.id,   # How to pass multiple id here to download multiple
                                                                                attach.datas_fname, 
                                                                                download), 
                     'target': 'self', 
                   }

Anyone have solution?

0
Imagine profil
Abandonează
Imagine profil
Enric Julià
Cel mai bun răspuns

Hello,  Girija Subramaniyan,

What's inside the method: 'download_attachments' where you pass multiples id's from files??.

It works for me if i have a single record, but i have multiples files, so i need the answer please

Thanks!

0
Imagine profil
Abandonează
Girija Subramaniyan
Autor

@api.multi
def download_attachments(self, attachment_ids):
""" Create attachment renewal tar file
@params: attachemnt_ids
"""
config_obj = self.env['ir.config_parameter']
attachment_obj = self.env['ir.attachment']

attachment_ids = attachment_ids
ids = self._ids
filestore_path = os.path.join(attachment_obj._filestore(), '')
attachment_dir = filestore_path + 'attachments'
# create directory and remove its content
if not os.path.exists(attachment_dir):
os.makedirs(attachment_dir)
else:
shutil.rmtree(attachment_dir)
os.makedirs(attachment_dir)
file_name = 'Renewal'
if isinstance(ids, int):
ids = [ids]

config_ids = config_obj.search([('key', '=', 'web.base.url')])
self.env['ir.attachment'].search([('active', '=', False)]).unlink()

if len(config_ids):
value = config_ids[0].value
active_model = 'ir.attachment'
tar_dir = os.path.join(attachment_dir, file_name)
#tFile = tarfile.open(tar_dir, 'w:gz')
with ZipFile(tar_dir,'w') as zip:

if value and active_model:
# change working directory otherwise file is tared with all its parent directories
original_dir = os.getcwd()
filter_attachments = []
for attach in attachment_obj.browse(attachment_ids):
if attach.active:
filter_attachments.append(attach.id)
if not filter_attachments:
raise UserError(_("No attachment to download"))
for attachment in attachment_obj.browse(filter_attachments):
# to get full path of file
full_path = attachment_obj._full_path(attachment.store_fname)
mail_id = self.env['mail.mail'].sudo().search(
[('attachment_ids', '=', attachment.id)])
partner_name = mail_id.customer_id.name
if partner_name:
partner_name = partner_name.replace('/','')
else:
partner_name = str(random.randint(1, 999999))
attachment_name = str(attachment.datas_fname)
new_file = os.path.join(attachment_dir,
partner_name+"-"+attachment_name)
# copying in a new directory with a new name
# shutil.copyfile(full_path, new_file)
try:
shutil.copy2(full_path, new_file)
except:
pass
#raise UserError(_("Not Proper file name to download"))
head, tail = ntpath.split(new_file)
# change working directory otherwise it tars all parent directory
os.chdir(head)
try:
zip.write(tail)
except:
_logger.error("No such file was found : %s" %tail)
# tFile.close()
os.chdir(original_dir)
values = {
'name': file_name + '.zip',
'datas_fname': file_name + '.zip',
'res_model': 'event.registration',
# 'res_id': ids[0],
'res_name': 'Renewal',
'type': 'binary',
'store_fname': 'attachments/Renewal',
'active': False,
}
# Create selected all attachment with tar file
attachment_id = self.env['ir.attachment'].create(values)
url = "%s/web/content/%s?download=true" % (value,
attachment_id.id)
return {
'type': 'ir.actions.act_url',
'url': url,
'nodestroy': False,
}

Girija Subramaniyan
Autor

In below code i have create zip file and updated attachements in that

Imagine profil
Nikul Chaudhary
Cel mai bun răspuns

Hello Girija,
Please try like this, i think it's helpful for you.
Ex.
def generate_renewal_pdf(self):
 """ Print renewal pdf"""
    attachment_ids = []
     for mail in self:
         attachments = mail.attachment_ids
         for attach in attachments:
               attachment_ids.append(attach.id)
              url = '/web/content/download_document?tab_id=%s' % attachment_ids

              return {
                   'type': 'ir.actions.act_url',
                    'url': url
                     'target': 'self', 
                   }


And please check https://apps.odoo.com/apps/modules/10.0/download_multiple_attachments/

0
Imagine profil
Abandonează
Imagine profil
paidy kumar
Cel mai bun răspuns

Hi Girija can you help me to do this .i am also struggling to do this

if you completed this please tell me.

Thanks in advance

0
Imagine profil
Abandonează
Girija Subramaniyan
Autor

Hi Paidy Kumar.

i did like this, worked for me

def generate_renewal_pdf(self):

""" Print renewal pdf"""

attachment_ids = []

for mail in self:

attachments = mail.attachment_ids

for attach in attachments:

attachment_ids.append(attach.id)

if (len(attachment_ids) > 1):

# To download multiple records attachments

download = self.download_attachments(attachment_ids)

else:

# download single record

config_obj = self.env['ir.config_parameter']

config_ids = config_obj.search([('key', '=', 'web.base.url')])

if len(config_ids):

value = config_ids[0].value

url = "%s/web/content/%s?download=true" % (value,

attachment_ids[0])

download = {

'type': 'ir.actions.act_url',

'url': url,

'target': 'self',

}

return download

Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
How to solve os.getcwd() error while convert file to zip?
attachment download odoo10.0
Imagine profil
0
iun. 19
4082
count number of records based on condition Rezolvat
odoo10.0
Imagine profil
Imagine profil
1
nov. 24
21048
How to install odoo 10 in ubuntu 20.04? Rezolvat
odoo10.0
Imagine profil
Imagine profil
1
sept. 23
3883
Question about action_confirm
odoo10.0
Imagine profil
Imagine profil
Imagine profil
3
mai 23
6453
View attachment within the browser
attachment
Imagine profil
Imagine profil
Imagine profil
5
mai 23
16302
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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