Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
wizardmailattachmenttemplatebinary
1 Odpoveď
7757 Zobrazenia
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šiť
Avatar
julien rey
Autor Best Answer

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šiť
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!

Registrácia
Related Posts Replies Zobrazenia Aktivita
Binary field as attachment in mail Solved
mail invoice attachment binary
Avatar
Avatar
Avatar
Avatar
Avatar
5
jan 23
17937
Send a mail with fields.binary attached
mail attachment send binary
Avatar
Avatar
4
jún 17
11168
Set default mail template in mail compose/quotations Solved
wizard mail template compose quotations
Avatar
Avatar
1
máj 18
7359
send email with multiple attachment
mail attachment
Avatar
1
aug 24
2711
Force sender email for all platform mails Solved
mail template
Avatar
Avatar
Avatar
Avatar
Avatar
8
júl 24
24872
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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