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 eMail template through code

Odoberať

Get notified when there's activity on this post

This question has been flagged
button
3 Replies
57756 Zobrazenia
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
Zrušiť
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
Opening new window with button in OpenERP Solved
button
Avatar
Avatar
1
jan 24
15280
button in systray
button
Avatar
Avatar
2
mar 18
5911
how can i restict auto data saving while clicking on custom button in odoo10?
button
Avatar
0
jan 18
4170
Modify / override button action in header of form ?
button
Avatar
Avatar
2
feb 24
26976
Why can't I make a button in tree
button
Avatar
Avatar
Avatar
3
sep 15
8414
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