Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

Button in action menu to download all pickings attachments

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
actionpdfpickingdownload
1 Beantwoorden
5421 Weergaven
Avatar
Alexandru Gagea

Hello,


I am trying to select multiple pickings and download into a single pdf they're attachments

 ( shipping labels )


Bellow is my code which will download only one attachment.


Working on Odoo 13 CE.


def generate_awb_pdf(self):
sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', []))
pickings = self.env['stock.picking'].search([('origin', 'in', [o.name for o in sale_orders])])
attachment_ids = self.env['ir.attachment'].search(
[('res_model', '=', 'stock.picking'), ('res_id', 'in', [p.id for p in pickings])])
result = b''
for rec in attachment_ids:
result += rec.datas
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
attachment_obj = self.env['ir.attachment']
attachment_id = attachment_obj.sudo().create(
{'name': "name", 'store_fname': 'awb.pdf', 'datas': result})
download_url = '/web/content/' + str(attachment_id.id) + '?download=true'
return {
'name': 'Report',
'type': 'ir.actions.act_url',
'url': str(base_url) + str(download_url),
'target': 'self',
}



Thank you !


1
Avatar
Annuleer
Alexandru Gagea
Auteur

Hello Jainesh, 

I've changed the code as you suggested (makes sense..) , however, nothing is getting downloaded.


def generate_awb_pdf(self):

sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', []))
pickings = self.env['stock.picking'].search([('origin', 'in', [o.name for o in sale_orders])])
attachment_ids = self.env['ir.attachment'].search(
[('res_model', '=', 'stock.picking'), ('res_id', 'in', [p.id for p in pickings])])
result = b''

for rec in attachment_ids:
result += rec.datas
attachment_obj = self.env['ir.attachment']
attachment_id = attachment_obj.sudo().create(
{'name': "name", 'store_fname': 'awb.pdf', 'datas': rec.datas})
download_url = '/web/content/' + str(attachment_id.id) + '?download=true'
self.get_report(download_url)

def get_report(self, download_url):
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
return {
'name': 'Report',
'type': 'ir.actions.act_url',
'url': str(base_url) + str(download_url),
'target': 'new',
}

Avatar
Jainesh Shah(Aktiv Software)
Beste antwoord

Hello Alexandru,

The problem in your solution is that the data is being returned inside a loop, so once the data is returned the execution of loop will stop.

Please keep the return part in a separate method and call that method inside the loop so even after something is returned the main loop continues.

eg:

for rec in attachment_ids:
    #code to generate url
    self.get_report(url_of_report)

def get_report(self, url_of_report)
    return {
        'name': 'Report',
        'type': 'ir.actions.act_url',
        'url': url_of_report,
        'target': 'self',
}

Hope this solves your issue.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

0
Avatar
Annuleer
Jainesh Shah(Aktiv Software)

Hello @Alexandru

Based on your comment:

For the point:
I am trying to select multiple pickings and download into a single pdf they're attachments ( shipping labels )

- I understand you want all attachments as a single pdf file, Here you have made a few mistakes in code as:
1. In attachments you might have different file types like image, pdf, zip so creating a new attachment of pdf type directly by combining binary data is not a valid solution.

2. Also if you have only pdf attachment then you might also have user uploaded pdf or any other pdf documents related to picking.

I have made a server action which will download all pdf attachments in to a single attachment.

Please check below link for code.
-------------------------------------
https://drive.google.com/drive/folders/1gRGCd9Aet2oTxWMH8Wpsz1wFLLLMUVJi?usp=sharing
-------------------------------------

Note: Please install PyPDF2 lib if you do not have it in your system.

Please make required changes to the above code, I have tested this and it gives me a common pdf for all pdf type attachments in selected pickings.

Although the page numbers and details belong to individual pdfs you might need to find a work around for it if necessary.

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
Error on printing multiple records
action pdf
Avatar
0
feb. 25
1268
How to make downloading a pdf file Opgelost
pdf download
Avatar
Avatar
2
jan. 24
15229
Configure a link to download a PDF file
pdf download Link
Avatar
0
mei 24
2853
Picking PDF document with partial delivery
pdf picking partial
Avatar
0
dec. 15
4256
Download Pdf File On local Machine ?
pdf python download
Avatar
0
mrt. 15
5352
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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