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

how to download all records attachments of sale.order model using button v12

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
attachmentsodoo12
7 Antwoorden
7708 Weergaven
Avatar
paidy kumar

when clicking on button in tree view i am getting blank. please somebody help me.


<record model = "ir.ui.view" id = "view_order_form_dbt_task" > 
<field
name = "name" > sale.order.inherit </field>
<field
name = "model" > sale.order </field>
< field
name = "inherit_id" ref = "sale.view_order_form" />
<field
name = "arch" type = "xml" >
<field
name = "payment_term_id"position = "after" >
<field
name ="attachment_ids" />
</field>
</field>
</record>
<record
id = "view_order_tree_dbt_task" model = "ir.ui.view" >
<field
name = "name" > sale.order.tree </field>
<field
name = "model" > sale.order </field>
<field
name = "inherit_id" ref = "sale.view_order_tree" />
<field
name = "arch" type = "xml" >
<field
name = "invoice_status " position = " after " >
<button
name = "action_attachment_down" type = "object" string = "Download" />
</field>
</field>
</record>


in python file
class dbt_task (models.Model): 
    _inherit = 'sale.order'
    attachment_ids = fields.Binary ( 'Attachment' , attachment = True )

    @ api.multi
    def action_attachment_down ( self ):
        for rec in self :
        with io.BytesIO (base64 .b64decode (rec.attachment_ids)) as output:
            result = output.read ()
            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" , 'datas_fname' : 'name.file_ext' , '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': 'new',
            }
    
0
Avatar
Annuleer
Sehrish

Get an idea to download file: https://learnopenerp.blogspot.com/2020/06/write-binary-data-nto-zip-file-and-downlaod-it-on-button-click-in-odoo.html

Avatar
Hilar Andikkadavath
Beste antwoord

Here you are doing .b64decode(rec.attachment_ids) and attachments_ids will be a pool of records but you need a Base64 encoded bytes-like object or ASCII string.

for eg: I am doing like this

content = base64.b64decode(attachment.datas)
headers.append(('Content-Length', len(content)))
response = request.make_response(content, headers)
return response
0
Avatar
Annuleer
paidy kumar
Auteur

thanks for your response

using below code i am getting only last attachment of my model how do i get all attachments in single pdf. note(all attachments here in pdf format)

my code:

def action_attachment_down(self):

sale_orders = self.env['sale.order'].search([])

result = b' '

for rec in sale_orders:

if rec.attachment_ids:

result.write(rec.attachment_ids)

_logger = logging.info("record id Here.........................")

_logger = logging.info(rec.id)

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", 'datas_fname': 'sale_attachments.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': 'new',

}

Hilar Andikkadavath
Great, please check the http route defined for making this download response in class binary, that is web, controllers, main.py, class binary. 
You will get more detailed view here

On Wed, 12 Aug 2020, 4:52 pm paidy kumar, <mpaidykumar@gmail.com> wrote:

thanks for your response

using below code i am getting only last attachment of my model how do i get all attachments in single pdf. note(all attachments here in pdf format)

my code:

def action_attachment_down(self):

sale_orders = self.env['sale.order'].search([])

result = b' '

for rec in sale_orders:

if rec.attachment_ids:

result.write(rec.attachment_ids)

_logger = logging.info("record id Here.........................")

_logger = logging.info(rec.id)

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", 'datas_fname': 'sale_attachments.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': 'new',

}

Envoyé par Odoo S.A. utilisant Odoo.

paidy kumar
Auteur

for this i need to merge all attachments in single byte array.

but i am not able to do this do you have any idea to do this

Hilar Andikkadavath

Sorry, I can't check right now, but you can do one thing, zip all attachments and pass zip file in response. I will test tomorrow for other methods and will give you the feedback.

paidy kumar
Auteur

Thanks hilar thankyou so much.

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
Creating Attachments For account.invoice in odoo 12? Opgelost
attachments ir.attachment odoo12
Avatar
1
jan. 23
10254
Attach documents to products in website in odoo 12? Opgelost
attachments website odoo12
Avatar
Avatar
1
nov. 19
3642
Can't affect attachments to specific records of a custom module through XML-RPC
xmlrpc attachments odoo12
Avatar
0
apr. 19
4101
Attachements
attachments
Avatar
0
dec. 24
2262
Odoo Mail Sending Limit Opgelost
odoo12
Avatar
Avatar
Avatar
2
dec. 23
16327
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