Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Send a mail with automatic attachment ofa binary field from a model

Odebírat

Get notified when there's activity on this post

This question has been flagged
wizardmailattachmenttemplatebinary
1 Odpovědět
7739 Zobrazení
Avatar
julien rey

Hi,

I have a model 'quitus.quitus' that contains a binary field 'scanned' as you can see below :

class quitus(osv.Model):
_name='quitus.quitus'
_columns={
    'order_id':fields.many2one('sale.order','Order',required=True),
    'employee_id':fields.many2one('hr.employee','Employee'),
    'description':fields.text('Description',required=True),
    'state':fields.selection([('draft','Draft'),('issued','Issued'),('confirmed','Confirmed')],'State',required=True,readonly=True), 
    'approver':fields.char('Approver',size=100,required=True),
    'scanned':fields.many2one('ir.attachment','Scanned Quitus'),
}
_defaults={
    'state':'draft',
}
def action_confirmed(self, cr, uid, ids):
    for o in self.browse(cr, uid, ids):
        if not o.employee_id:
            raise osv.except_osv(_('Error!'),_('You cannot confirm a quitus without employee'))
        if not o.scanned:
            raise osv.except_osv(_('Error!'),_('You cannot confirm a quitus without scanned doc'))  
    self.write(cr, uid, ids, { 'state' : 'confirmed' })
    return True
def action_issued(self, cr, uid, ids):
    self.write(cr, uid, ids, { 'state' : 'issued' })
    return True
def action_draft(self, cr, uid, ids):
    self.write(cr, uid, ids, { 'state' : 'draft' })
    return True
def action_send_mail(self, cr, uid, ids, context=None):
    assert len(ids) == 1, 'This option should only be used for a single id at a time.'
    ir_model_data = self.pool.get('ir.model.data')
    try:
        template_id = ir_model_data.get_object_reference(cr, uid, 'quitus', 'email_quitus_template')[1]
    except ValueError:
        template_id = False
    try:
        compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1]
    except ValueError:
        compose_form_id = False 
    ctx = dict(context)
    ctx.update({
        'default_model': 'quitus.quitus',
        'default_res_id': ids[0],
        'default_use_template': bool(template_id),
        'default_template_id': template_id,
        'default_composition_mode': 'comment',
        'mark_so_as_sent': True
    })
    return {
        'type': 'ir.actions.act_window',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'mail.compose.message',
        'views': [(compose_form_id, 'form')],
        'view_id': compose_form_id,
        'target': 'new',
        'context': ctx,

quitus()}

Then on my form view, I have added a button to send a mail :

<record model="ir.ui.view" id="view_quitus_form">
        <field name="name">view.quitus.form</field> 
        <field name="model">quitus.quitus</field> 
        <!-- types: tree,form,calendar,search,graph,gantt,kanban --> 
        <field name="type">form</field> 
        <field name="priority" eval="16"/> 
        <field name="arch" type="xml"> 
            <form string="Quitus form" version="7.0"> 
                    <header>
                        <button name="button_issued" string="Ready for Sign-off" states="draft" type="workflow"/>
                        <button name="button_confirmed" string="Confirm signed-off" states="issued" type="workflow"/>
                        <button name="action_send_mail" string="Send" states="confirmed" type="object"/>
                        <field name="state" 
                                widget="statusbar" 
                                statusbar_visible="draft,issued,confirmed" 
                                statusbar_colors="{"issued":"blue"}"/>
                    </header>
                    <sheet>
                        <h1>Quitus</h1>
                        <group> 
                            <field name="order_id" /> 
                            <field name="approver"/> 
                            <field name="description" /> 
                            <field name="employee_id"/>
                            <field name="scanned" />   
                        </group> 
                    </sheet>                        
            </form> 
        </field> 
    </record>

This button 'action_send_mail' works fine, and use the mail template below

<record id="email_quitus_template" model="email.template">
        <field name="model_id"  ref="quitus.model_quitus_quitus"></field>
        <field name="name">Send Quitus by mail</field>

        <field name="email_from"><![CDATA[${object.order_id.user_id.name} <${object.order_id.user_id.email}>]]></field>
        <field name="email_to"></field>
        <field name="subject">Copie de votre quitus</field>
        <field name="body_html">
            <![CDATA[
                <p>
                    Hello,
                </p>
                <p>
                    You'll find enclosed a copy of your quitus regarding order ${object.order_id.name} / ${object.order_id.client_order_ref}.
                </p>
                <p>
                    This quitus concerns :
                </p>
                <p>
                    ${object.description}
                </p>
                <p>
                    Best regards,
                </p>
                <div style="width: 375px; margin: 0px; padding: 0px; background-color: #8E0000; border-top-left-radius: 5px 5px; border-top-right-radius: 5px 5px; background-repeat: repeat no-repeat;">
                        <h3 style="margin: 0px; padding: 2px 14px; font-size: 12px; color: #DDD;">
                            <strong style="text-transform:uppercase;">${object.order_id.company_id.name}</strong></h3>
                </div>
                <div style="width: 347px; margin: 0px; padding: 5px 14px; line-height: 16px; background-color: #F2F2F2;">
                        <span style="color: #222; margin-bottom: 5px; display: block; ">
                        % if object.order_id.company_id.street:
                            ${object.order_id.company_id.street}<br/>
                        % endif
                        % if object.order_id.company_id.street2:
                            ${object.order_id.company_id.street2}<br/>
                        % endif
                        % if object.order_id.company_id.city or object.order_id.company_id.zip:
                            ${object.order_id.company_id.zip} ${object.order_id.company_id.city}<br/>
                        % endif
                        % if object.order_id.company_id.country_id:
                            ${object.order_id.company_id.state_id and ('%s, ' % object.order_id.company_id.state_id.name) or ''} ${object.order_id.company_id.country_id.name or ''}<br/>
                        % endif
                        </span>
                        % if object.order_id.company_id.phone:
                            <div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">
                                Tél:  ${object.order_id.company_id.phone}
                            </div>
                        % endif
                        % if object.order_id.company_id.website:
                            <div>
                                Web : <a href="${object.order_id.company_id.website}">${object.order_id.company_id.website}</a>
                            </div>
                        %endif
                        <p></p>
                    </div>
                </div>
            ]]>
        </field>
        <field name="attachment_ids">
            ${object.scanned}
        </field>
    </record>

However, I'd like to attach automatically the contents of the binary field 'scanned' to my mail ..I try this way below unsuccesfully

<field name="attachment_ids">
            ${object.scanned}
        </field>

I need some help, i'm little bit confused.

cheers

Julien

0
Avatar
Zrušit
Avatar
julien rey
Autor Nejlepší odpověď

Hi again,

I have finnaly found an acceptable solution. I share my experience for everybody.

I have updated my function send_mail in my quitus object.

def action_send_mail(self, cr, uid, ids, context=None):
    assert len(ids) == 1, 'This option should only be used for a single id at a time.'
    ir_model_data = self.pool.get('ir.model.data')
    o = self.browse(cr, uid, ids)[0]
    try:
        #get the template_id
        template_id = ir_model_data.get_object_reference(cr, uid, 'quitus', 'email_quitus_template')[1]
        email_obj = self.pool.get('email.template')  
        #get the object corresponding to template_id
        email = email_obj.browse(cr, uid, template_id)
        #get the id of the document, stored into field scanned
        attachment_id = o.scanned.id
        #write the new attachment to mail template
        email_obj.write(cr, uid, template_id, {'attachment_ids': [(6, 0, [attachment_id ])]})  
    except ValueError:
        template_id = False .......

I change the email.template object before sending mail. I added an attachement from document (ir_attachement).

I hope this could help anyone

Cheers

Julien

1
Avatar
Zrušit
sengottuvel

Hi, I have a requirement while confirm a sale order system should send the sale order copy to customer automaticlly with out any user input. Now if you click send mail button again user need to click send button. I created templete and format. How to get atttchment id for send the sale order copy. Kindly help me for complete this requirement. Thanks in advance.

Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Binary field as attachment in mail Vyřešeno
mail invoice attachment binary
Avatar
Avatar
Avatar
Avatar
Avatar
5
led 23
17923
Send a mail with fields.binary attached
mail attachment send binary
Avatar
Avatar
4
čvn 17
11160
Set default mail template in mail compose/quotations Vyřešeno
wizard mail template compose quotations
Avatar
Avatar
1
kvě 18
7357
send email with multiple attachment
mail attachment
Avatar
1
srp 24
2706
Force sender email for all platform mails Vyřešeno
mail template
Avatar
Avatar
Avatar
Avatar
Avatar
8
čvc 24
24868
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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