Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

How to download multiple attachment files on button click action?

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
attachmentodoo10.0
3 Replies
13889 Tampilan
Avatar
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
Avatar
Buang
Avatar
Enric Julià
Jawaban Terbai

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
Avatar
Buang
Girija Subramaniyan
Penulis

@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
Penulis

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

Avatar
Nikul Chaudhary
Jawaban Terbai

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
Avatar
Buang
Avatar
paidy kumar
Jawaban Terbai

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
Avatar
Buang
Girija Subramaniyan
Penulis

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

Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
How to solve os.getcwd() error while convert file to zip?
attachment download odoo10.0
Avatar
0
Jun 19
4083
count number of records based on condition Diselesaikan
odoo10.0
Avatar
Avatar
1
Nov 24
21049
How to install odoo 10 in ubuntu 20.04? Diselesaikan
odoo10.0
Avatar
Avatar
1
Sep 23
3883
Question about action_confirm
odoo10.0
Avatar
Avatar
Avatar
3
Mei 23
6455
View attachment within the browser
attachment
Avatar
Avatar
Avatar
5
Mei 23
16302
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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