Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Restauration & Hôtellerie
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brasserie
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Commerce
    • Bricoleur
    • Matériel informatique & support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Parcourir toutes les industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services pour partenaires
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

How to send a attached file through email

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
4 Réponses
26922 Vues
Avatar
Priya K

I have a kept a binary field for attachment file. If I click on the confirm button, mail should be send along with attachment file.


I have tried this code,


class Test(models.Model)

_name = 'test'


soft_copy = fields.Binary(string="Soft Copy")

file_name = fields.Char(string="File Name") 


def action_confirm(self):

  self.ensure_one()

  self.state = 'confirm'

  email_template = self.env.ref('module1.test_email_template')

  email_template.send_mail(self.id, raise_exception=False, force_send=True)



Email Template,


<record id="test_email_template" model="mail.template">

            <field name="name">Test</field>

            <field name="subject">Checking Test</field>

            <field name="email_from">xyz@gmail.com</field>

            <field name="email_to">$employee_id.work_mail}</field>

            <field name="model_id" ref="module1.model_test"/>

            <field name="report_template" ref="module1.test_reports"/>

            <field name="report_name">Test</field>

            <field name="auto_delete" eval="True"/>

            <field name="body_html"><![CDATA[ -----Content---

            ]]></field>

0
Avatar
Ignorer
Nesrine Essaies

https://apps.odoo.com/apps/modules/12.0/send_an_email_with_pdf_attachmentv/

Avatar
Hilar Andikkadavath
Meilleure réponse

First you have to find the ir.attachment records of [soft_copy],  with your model, res_id and so on from ir_attachment table, After update attachment list of email_template as email_template.attachment_ids = [(4, ids)] else ''. here ids are the fetched record id.

1
Avatar
Ignorer
Priya K
Auteur

First time it work correctly, that is if I click on confirm button and one soft copy is sent to mail. But second time if i click on confirm button 1st soft copy is also coming in the second mail. i should get current datas soft copy only

Hilar Andikkadavath

Please check the one2many flags here, hope you can solve your problem,

https://hilarlive.wordpress.com/2017/04/22/one2many-or-many2many-flags/

Priya K
Auteur

Hi Hilar,

Thanks. It works correctly after sending mail I used email_template.attachment_ids = [(3, ids)] to unlink the attachment.

Hilar Andikkadavath

Fine, upvote the given answer so others can identify which one is solution,

Avatar
Nesrine Essaies
Meilleure réponse

https://apps.odoo.com/apps/modules/12.0/send_an_email_with_pdf_attachmentv/

0
Avatar
Ignorer
Avatar
Youssef Salama
Meilleure réponse

This way more clean :)

id = self.env['ir.attachment'].create(attachment)

                email_template.attachment_ids = [(6, 0, id)]

               email_template.send_mail(self.id, raise_exception=False, force_send=True)

0
Avatar
Ignorer
Avatar
Priya K
Auteur Meilleure réponse

I made it with this code to send a attachment mail through mail


def send_mail_func(self)

    email_template = self.env.ref('module1.test_email_template')

     attachment = {

               'name': str(self.file_name),

               'datas': self.binary_field_name

          datas_fname': self.file_name,

               'res_model': 'model_name',

               'type': 'binary'

           }
         
             id = self.env['ir.attachment'].create(attachment)

                email_template.attachment_ids = [(4, ir_id.id)]

               email_template.send_mail(self.id, raise_exception=False, force_send=True)

               email_template.attachment_ids = [(3, ir_id.id)]


0
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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