Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

How to download multiple attachment files on button click action?

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
attachmentodoo10.0
3 Replies
13880 Rodiniai
Portretas
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
Portretas
Atmesti
Portretas
Enric Julià
Best Answer

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
Portretas
Atmesti
Girija Subramaniyan
Autorius

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

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

Portretas
Nikul Chaudhary
Best Answer

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
Portretas
Atmesti
Portretas
paidy kumar
Best Answer

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
Portretas
Atmesti
Girija Subramaniyan
Autorius

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!

Registracija
Related Posts Replies Rodiniai Veikla
How to solve os.getcwd() error while convert file to zip?
attachment download odoo10.0
Portretas
0
birž. 19
4077
count number of records based on condition Solved
odoo10.0
Portretas
Portretas
1
lapkr. 24
21046
How to install odoo 10 in ubuntu 20.04? Solved
odoo10.0
Portretas
Portretas
1
rugs. 23
3882
Question about action_confirm
odoo10.0
Portretas
Portretas
Portretas
3
geg. 23
6449
View attachment within the browser
attachment
Portretas
Portretas
Portretas
5
geg. 23
16299
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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