Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • Hotel
    Real Estate
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    Consulting
    • Accounting Firm
    • Odoo पार्टनर
    • Marketing Agency
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

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

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

Send eMail template through code

Subscribe

Get notified when there's activity on this post

This question has been flagged
button
3 Replies
57321 Views
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
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
Opening new window with button in OpenERP Solved
button
Avatar
Avatar
1
जन॰ 24
15129
button in systray
button
Avatar
Avatar
2
मार्च 18
5757
how can i restict auto data saving while clicking on custom button in odoo10?
button
Avatar
0
जन॰ 18
3997
Modify / override button action in header of form ?
button
Avatar
Avatar
2
फ़र॰ 24
26733
Why can't I make a button in tree
button
Avatar
Avatar
Avatar
3
सित॰ 15
8273
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة 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, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

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