Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Add an attachment PDF to message_post (chat)

Subscribe

Get notified when there's activity on this post

This question has been flagged
attachmentschattermessage_postir.attachmentodoo11
3 Replies
16565 Views
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
Discard
Avatar
cabrejua
Author Best Answer

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
Discard
Avatar
Murad PP
Best Answer

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
Discard
Avatar
Silverstar
Best Answer

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
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
changing the directory for attachments
attachments ir.attachment
Avatar
0
Feb 19
4119
Creating Attachments For account.invoice in odoo 12? Solved
attachments ir.attachment odoo12
Avatar
1
Jan 23
10377
How to move attachment from one model to another Solved
attachment attachments odoo11
Avatar
Avatar
Avatar
2
Nov 21
9057
Hide attachments button in the chatter
attachments chatter studio
Avatar
Avatar
1
Oct 21
5792
Odoo11 - Resize Existing Image attachments
attachments images odoo11
Avatar
0
Mar 21
2918
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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