Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Send eMail template through code

Naroči se

Get notified when there's activity on this post

This question has been flagged
button
3 Odgovori
57362 Prikazi
Avatar
Atchuthan
Hi friendz,

          When sending the mail by clicking button "send by Email" in "addition" module,  the following error comes:
          AttributeError: 'addition' object has no attribute 'message_post'

__openerp__.py:

{
    "name": "addition",
    "version": "7.0",
    "summary" : "addition of 2 nos",
    "depends": ["base","mail","email_template"],
    "author": "atchuthan",
    "category": "Others",
    "description": """
    This module provide : summation of 2 integer numbers  
    """,
     'data' : ['addition_view.xml','addition_action_data.xml'],
    'demo_xml': [],
    'installable': True,
    'auto-install' : True,
    'active': False
}

addition.py:

from osv import osv, fields
from openerp.tools.translate import _

class addition(osv.osv):
    _name = 'addition' 
    _rec_name = 'result'  
    _columns = {
            'number1': fields.integer('number 1', required=True),
            'number2' : fields.integer('number 2', required=True),
            'result' : fields.integer('Result'),
                    }

    def action_addition_send(self, cr, uid, ids, context=None):
            '''
            This function opens a window to compose an email, with the edi sale template message loaded by default
            '''
            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, 'addition', 'email_template_edi_addition')[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': 'addition',
                '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,
            }

class mail_compose_message(osv.Model):
    _inherit = 'mail.compose.message'

    def send_mail(self, cr, uid, ids, context=None):
        context = context or {}
        if context.get('default_model') == 'addition' and context.get('default_res_id') and context.get('mark_so_as_sent'):
            context = dict(context, mail_post_autofollow=True)
        return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)

addition_view.xml:

<?xml version="1.0" encoding="utf-8" ?>
<openerp>
    <data>
        <record model="ir.ui.view" id="addition_tree_view">
            <field name="name">addition.tree</field>
            <field name="model">addition</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="addition_tree">
                    <field name="number1" />
                    <field name="number2" />
                    <field name="result" />
                </tree>
            </field>
        </record>
        <record model="ir.ui.view" id="addition_form_view">
            <field name="name">addition.form</field>
            <field name="model">addition</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="addition_form" version="7.0">
                    <header>
                        <button name="action_addition_send" string="Send by Email"
                            type="object" class="oe_highlight" />
                    </header>
                    <sheet>
                        <group>
                            <field name="number1" onchange="onchange_addition(number1, number2)" />
                            <field name="number2" onchange="onchange_addition(number1, number2)" />
                            <field name="result" />  <!-- onchange_addition(number1, number2) -->
                        </group>
                    </sheet>
                </form>
            </field>
        </record>
        <record model="ir.actions.act_window" id="action_addition_form">
            <field name="name">addition</field>
            <field name="res_model">addition</field>
        </record>
        <menuitem name="Parent" icon="terp-project" id="parent_id" />
        <menuitem name="Son" parent="parent_id" id="son_id" />
        <menuitem name="Addition" parent="son_id" id="addition_id"
            action="action_addition_form" />
    </data>
</openerp>

addition_action_data.xml:

<?xml version="1.0" ?>
<openerp>
    <data>
        <!-- EDI related Email Templates menu -->
        <record model="ir.actions.act_window" id="action_email_templates">
            <field name="name">Email Templates</field>
            <field name="res_model">email.template</field>
            <field name="view_type">form</field>
            <field name="view_mode">form,tree</field>
            <field name="view_id" ref="email_template.email_template_tree" />
            <field name="search_view_id" ref="email_template.view_email_template_search" />
            <field name="context"
                eval="{'search_default_model_id': ref('model_addition')}" />
        </record>
    </data>

    <!-- Mail template are declared in a NOUPDATE block so users can freely 
        customize/delete them -->
    <data noupdate="1">
        <!--Email template -->
        <record id="email_template_edi_addition" model="email.template">
            <field name="name">Addition 2 nos - Send by mail</field>
            <field name="email_from">bms@openerp.com</field>
            <field name="subject">addition</field>
            <field name="email_to">atchuthantu@yahoo.com</field>
            <field name="auto_delete" eval="True" />
            <field name="model_id" ref="model_addition" />
            <field name="body_html"><![CDATA[
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">

    <p>Hello,</p>

    <p>Addition successful</p>

</div>
            ]]></field>
        </record>
    </data>
</openerp>

traceback:

2013-06-18 12:56:43,251 3505 INFO bms werkzeug: 127.0.0.1 - - [18/Jun/2013 12:56:43] "POST /web/dataset/call_kw/mail.compose.message:create HTTP/1.1" 200 -
2013-06-18 12:56:43,314 3505 INFO bms werkzeug: 127.0.0.1 - - [18/Jun/2013 12:56:43] "POST /web/dataset/call_kw/mail.compose.message:read HTTP/1.1" 200 -
2013-06-18 12:56:43,392 3505 INFO bms werkzeug: 127.0.0.1 - - [18/Jun/2013 12:56:43] "POST /web/dataset/call_kw/res.partner:name_get HTTP/1.1" 200 -
2013-06-18 12:56:43,418 3505 ERROR bms openerp.osv.osv: Uncaught exception
Traceback (most recent call last):
  File "/var/app/openerp/server/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/var/app/openerp/server/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/var/app/openerp/server/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/var/app/openerp/addons/bms/bms.py", line 304, in send_mail
    return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
  File "/var/app/openerp/addons/addition/addition.py", line 55, in send_mail
    return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
  File "/var/app/openerp/addons/email_template/wizard/mail_compose_message.py", line 80, in send_mail
    return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
  File "/var/app/openerp/addons/mail/wizard/mail_compose_message.py", line 259, in send_mail
    msg_id = active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values)
AttributeError: 'addition' object has no attribute 'message_post'
2013-06-18 12:56:43,430 3505 ERROR bms openerp.netsvc: 'addition' object has no attribute 'message_post'
Traceback (most recent call last):
  File "/var/app/openerp/server/openerp/netsvc.py", line 293, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/var/app/openerp/server/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/var/app/openerp/server/openerp/osv/osv.py", line 188, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/var/app/openerp/server/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/var/app/openerp/server/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/var/app/openerp/server/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/var/app/openerp/addons/bms/bms.py", line 304, in send_mail
    return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
  File "/var/app/openerp/addons/addition/addition.py", line 55, in send_mail
    return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
  File "/var/app/openerp/addons/email_template/wizard/mail_compose_message.py", line 80, in send_mail
    return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
  File "/var/app/openerp/addons/mail/wizard/mail_compose_message.py", line 259, in send_mail
    msg_id = active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values)
AttributeError: 'addition' object has no attribute 'message_post'
2013-06-18 12:56:43,432 3505 INFO bms werkzeug: 127.0.0.1 - - [18/Jun/2013 12:56:43] "POST /web/dataset/call_button HTTP/1.1" 200 -
3
Avatar
Opusti
Enjoying the discussion? Don't just read, join in!

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Opening new window with button in OpenERP Solved
button
Avatar
Avatar
1
jan. 24
15143
button in systray
button
Avatar
Avatar
2
mar. 18
5780
how can i restict auto data saving while clicking on custom button in odoo10?
button
Avatar
0
jan. 18
4023
Modify / override button action in header of form ?
button
Avatar
Avatar
2
feb. 24
26764
Why can't I make a button in tree
button
Avatar
Avatar
Avatar
3
sep. 15
8301
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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