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

Add an attachment PDF to message_post (chat)

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
attachmentschattermessage_postir.attachmentodoo11
3 Antwoorden
16573 Weergaven
Avatar
cabrejua

i everyone,

I would like to add a message on the chat every time that someone use the "Generate PDF" button.


With the message I would like to have a message like "PDF Attached" and the PDF on attachment, like in this picture:


 I create the PDF on ir.attachments, and im trying to use message_post()  method in order to add the ID of the created attachment, but it does not work.

def add_chat_message(self, body_msg):    
    #Test with the created attachment
    attachment =  self.env['ir.attachment'].browse(4749)
self.message_post(body=body_msg, attachments=attachment)

How should I use this method on Odoo11?



Thank a lot you for your help.


2
Avatar
Annuleer
Avatar
cabrejua
Auteur Beste antwoord

Thanks for your reply!

But I finally got it by using attachment_ids argument on message_post, and storing the attachments in a list.

# Add attachments

for pdf in self.env['ir.attachment'].search([(...)]):

attachments.append(pdf.id)

and

self.message_post(body=body_msg, attachment_ids=attachments)

2
Avatar
Annuleer
Avatar
Murad PP
Beste antwoord

Hi, 

We can create message to model 'mail.compose.message' or in 'mail.mail'

attachment_id = self.env['ir.attachment'].create({
'name': self.name,
'type': 'binary',
'datas': base64.b64encode(pdf),
'datas_fname': self.name + '.pdf',
'store_fname': self.name,
'res_model': self._name,
'res_id': self.id,
'mimetype': 'application/x-pdf'
})
ctx = {
'default_model': 'your.model',
'default_res_id': self.id,
'default_use_template': bool(template_id),
'default_template_id': template_id,
'default_composition_mode': 'comment',

}
template = self.env['mail.template'].browse(template_id)
html_body = template.body_html
text = template.with_context(ctx).render_template(html_body, 'your.model', self.id)
compose = self.env['mail.mail'].with_context(ctx).create({
'subject': '%s' % mail_subject,
'body_html': text,
'attachment_ids': [(6, 0, [attachment_id.id])] or None,
})
if you need with in a specified template you can pass template id as above code.
when using model mail.compose.message we get attachment as well as the all data on template and use the function send_mail() to send by adding email_to 

Thanks

2
Avatar
Annuleer
Avatar
Silverstar
Beste antwoord

Hi,

Would be helpful, if we want to attach report with creating attachments. This would be very helpful.

def _attach_sign(self):
""" Render the delivery report in pdf and attach it to the picking in `self`. """
self.ensure_one()
report = self.env['ir.actions.report']._render_qweb_pdf("stock.action_report_delivery", self.id)
filename = "%s_signed_delivery_slip" % self.name
if self.partner_id:
message = _('Order signed by %s') % (self.partner_id.name)
else:
message = _('Order signed')
self.message_post(
attachments=[('%s.pdf' % filename, report[0])],
body=message,
)
return True

Output would be like this.


0
Avatar
Annuleer
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
changing the directory for attachments
attachments ir.attachment
Avatar
0
feb. 19
4121
Creating Attachments For account.invoice in odoo 12? Opgelost
attachments ir.attachment odoo12
Avatar
1
jan. 23
10386
How to move attachment from one model to another Opgelost
attachment attachments odoo11
Avatar
Avatar
Avatar
2
nov. 21
9065
Hide attachments button in the chatter
attachments chatter studio
Avatar
Avatar
1
okt. 21
5801
Odoo11 - Resize Existing Image attachments
attachments images odoo11
Avatar
0
mrt. 21
2925
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