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
    • Sociale 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 print all attachments to an object at once?

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
attachmentprintprintingattachments
11 Antwoorden
15913 Weergaven
Avatar
Andreas Maertens

Is there a way to print all attachments stored for a object at once? In my case I want to print all attached files (not only .pdf) of a product on printing delivery orders. I wonder if there already is a way or I need to create a new addon for.

4
Avatar
Annuleer
Avatar
Andreas Maertens
Auteur Beste antwoord

I made a new report class.

Following imports you'll need:

from osv import osv
from openerp.report.pyPdf import PdfFileWriter
from openerp.report.pyPdf import PdfFileReader
from openerp.report.interface import report_int
from cStringIO import StringIO
from openerp import pooler
from tempfile import mkstemp
import os
import base64
from openerp.report.pyPdf.utils import PdfReadError
import netsvc

Here's an outtake of the report class:

class report_attachment_merge(report_int):

I made extra methodes for several usecases. I'll give you the printing of attachments from the product:

    def create(self, cr, uid, ids, datas, context=None):    
        method = None
        if context['active_model'] == 'product.product': method = self.create_product
        if method is None:
            raise Exception(_('Not implemented Call for your Model'))
        else:
            return method(cr, uid, ids, context)


    def create_product(self, cr, uid, ids, context=None):

You'll need instances of PdfFileWriter, PdfFileReader and StringIO, the Product-Class and the Attachments

        stream = StringIO()        
        writer = PdfFileWriter()
        product_obj = pooler.get_pool(cr.dbname).get('product.product')
        attach_obj = pooler.get_pool(cr.dbname).get('ir.attachment')

You get Product ID from context and the related attachments from their:

        product = product_obj.browse(cr, uid, context['active_id'])
        # get datas from related attachments
        attachment_ids = attach_obj.search(cr, uid, [ ('res_model','=','product.product'),
                                                      ('res_id','=', product.id ),
                                                    ] )

Now the clou, write that attachments in temporary files and read them with pdfFileReader. After that, put them together through pdfFileWriter

        for attachment in attach_obj.browse(cr, uid, attachment_ids):
            # make tempfile
            fd, file_name = mkstemp()
            try:
                os.write(fd, base64.decodestring(attachment.datas))
            finally:
                os.close(fd)
            fileObject = file(file_name, 'r')
            try:
                reader = PdfFileReader(fileObject)
            except PdfReadError as e:
                _err_logger.error(_('Expected Error occured: %s' % e))
                _err_logger.error(__name__)
                _err_logger.error(_('This happens, when file to print is not a Pdf-File'))
                break

            # add datas to writer
            for pageNr in range(0,reader.numPages):
                writer.addPage(reader.getPage(pageNr))
        # write datas to stream
        if writer.getNumPages() > 0:
            writer.write(stream)
            return stream.getvalue() , 'pdf'
        else:
            raise Exception(_('No Pdf-Files to print.'))

report_attachment_merge('report.attachment_merge')

You'll get a pdf file back containing all pdfs from attachments.

You may need to call that from a wizard:

class print_product_attachments(osv.osv_memory):

    _name = "print.product.attachments.wizard"

    def print_a_pdf(self, cr, uid, ids, context=None):
        return {
            'type': 'ir.actions.report.xml',
            'report_name': 'attachment_merge',
            'context': context,
        }

    _columns= {}

print_product_attachments()

That's it.

If someone could tell me how to render pdf files from openERP already used models please don't hestitate to tell. ;) This is the weak part of that solution.

4
Avatar
Annuleer
Avatar
Francesco OpenCode
Beste antwoord

You can't do this with OpenERP naked. You must delevoled (or search if someone did it, yet) a module that does this.

2
Avatar
Annuleer
Andreas Maertens
Auteur

Right! I've done that. As I said to Laurens, you will see a solution here tomorrow. ;)

Francesco OpenCode

We found our hero,yet. :D

Laurens

That's great, Andreas! I'm looking forward to it. :)

Avatar
Wilbert Tan
Beste antwoord

Hi , is there a final solution for this ?

0
Avatar
Annuleer
Avatar
Laurens
Beste antwoord

Andreas, did you wind up finding a solution/fix for this? I'm very interested.

0
Avatar
Annuleer
Andreas Maertens
Auteur

I did! I'll give you some source tomorrow, when back @ work

Ray Carnes

Hi Andreas, did you post this already somewhere else?

Andreas Maertens
Auteur

no, there's only that scource snippets.

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
Attachment Security Issue
attachment attachments
Avatar
0
okt. 21
3640
how to store attachments files in a filesystem instead of the database - odoo 10
attachment attachments
Avatar
Avatar
2
nov. 17
8029
Is their any simple way to Print reports directly instead of saving First ? Opgelost
printer print printing
Avatar
Avatar
Avatar
Avatar
Avatar
9
dec. 25
44680
Disable upload attachment Based on specific PO state, ODOO 15
attachment attachments v15
Avatar
Avatar
1
feb. 23
3292
How to move attachment from one model to another Opgelost
attachment attachments odoo11
Avatar
Avatar
Avatar
2
nov. 21
9076
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