Skip to Content
Odoo เมนู
  • ลงชื่อเข้าใช้
  • ทดลองใช้ฟรี
  • แอป
    การเงิน
    • ระบบบัญชี
    • ระบบการออกใบแจ้งหนี้
    • ระบบบัญชีรายจ่าย
    • ระบบการจัดการข้อมูลผ่านสเปรดชีต (BI)
    • เอกสาร
    • ระบบลงลายเซ็น
    การขาย
    • ลูกค้าสัมพันธ์
    • การขาย
    • POS ร้านค้า
    • POS ร้านอาหาร
    • ระบบสมัครสมาชิก
    • การเช่า
    การจัดการเว็บไซต์
    • เครื่องมือสร้างเว็บไซต์
    • ระบบการขายออนไลน์
    • บล็อก
    • ฟอรั่ม
    • ไลฟ์แชท
    • ระบบการอบรมออนไลน์
    ซัพพลายเชน
    • คลังสินค้า
    • ระบบการผลิต
    • PLM
    • ระบบการจัดซื้อ
    • การซ่อมบำรุง
    • ระบบจัดการคุณภาพ
    ทรัพยากรบุคคล
    • ข้อมูลพนักงาน
    • ระบบสรรหาบุคลากร
    • ระบบการลา
    • การประเมิน
    • ระบบการแนะนำพนักงาน
    • ระบบจัดการยานพาหนะ
    การตลาด
    • โซเชียลมาร์เก็ตติ้ง
    • การตลาดผ่านอีเมล
    • ระบบการตลาดผ่าน SMS
    • ระบบการจัดงานอีเวนต์
    • การตลาดแบบอัตโนมัติ
    • ระบบแบบสำรวจ
    การบริการ
    • โปรเจกต์
    • ระบบบันทึกเวลา
    • ระบบการจัดการบริการภาคสนาม
    • ระบบดูแลช่วยเหลือ
    • การวางแผน
    • การนัดหมาย
    ประสิทธิผล
    • ระบบแสดงความคิดเห็น
    • ระบบการอนุมัติ
    • ไอโอที
    • VoIP
    • คลังข้อมูล
    • WhatsApp
    แอปพลิเคชันของบุคคลที่สาม Odoo สตูดิโอ แพลตฟอร์มคลาวด์ของ Odoo
  • อุตสาหกรรม
    การค้าปลีก
    • ร้านขายหนังสือ
    • ร้านขายเสื้อผ้า
    • ร้านขายเฟอร์นิเจอร์
    • ร้านขายของชำ
    • ร้านขายฮาร์ดแวร์
    • ร้านขายของเล่น
    Food & Hospitality
    • บาร์และผับ
    • ร้านอาหาร
    • อาหารฟาสต์ฟู้ด
    • Guest House
    • ตัวแทนจำหน่ายเครื่องดื่ม
    • Hotel
    อสังหาริมทรัพย์
    • Real Estate Agency
    • บริษัทสถาปัตยกรรม
    • บริษัทรับเหมา
    • การจัดการอสังหาริมทรัพย์
    • การจัดสวน
    • สมาคมเจ้าของอสังหาริมทรัพย์
    ปรึกษา
    • สำนักงานบัญชี
    • Odoo พาร์ทเนอร์
    • เอเจนซี่การตลาด
    • สำนักงานกฎหมาย
    • บริการสรรหาบุคลากร
    • การตรวจสอบและการรับรอง
    ระบบการผลิต
    • Textile
    • เหล็ก
    • เฟอร์นิเจอร์
    • อาหาร
    • Brewery
    • ของขวัญขององค์กร
    สุขภาพ & ฟิตเนส
    • ชมรมกีฬา
    • ร้านขายแว่นตา
    • ฟิตเนส
    • ผู้ประกอบวิชาชีพด้านสุขภาพ
    • ร้านขายยา
    • ร้านทำผม
    Trades
    • ช่างซ่อม
    • ฮาร์ดแวร์และการสนับสนุนด้านไอที
    • ระบบพลังงานแสงอาทิตย์
    • ช่างทำรองเท้า
    • บริการทำความสะอาด
    • HVAC Services
    อื่น ๆ
    • Nonprofit Organization
    • สำนักงานสิ่งแวดล้อม
    • ร้านเช่าป้ายโฆษณา
    • การถ่ายภาพ
    • ร้านเช่าจักรยาน
    • ตัวแทนจำหน่ายซอฟต์แวร์
    Browse all Industries
  • คอมมูนิตี้
    ศึกษา
    • บทเรียน
    • เอกสารกำกับโปรแกรม
    • การรับรอง
    • การฝึกอบรม
    • บล็อก
    • พอดแคสต์
    เพิ่มศักยภาพให้กับการศึกษา
    • โปรแกรมการศึกษา
    • Scale Up! Business Game
    • เยี่ยมชม 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
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
ช่วยเหลือ

Send eMail template through code

ติดตาม

รับการแจ้งเตือนเมื่อมีกิจกรรมในโพสต์นี้

คำถามนี้ถูกตั้งค่าสถานะ
button
3 ตอบกลับ
57508 มุมมอง
อวตาร
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
อวตาร
ละทิ้ง
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!

สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!

ลงชื่อ
Related Posts ตอบกลับ มุมมอง กิจกรรม
Opening new window with button in OpenERP แก้ไขแล้ว
button
อวตาร
อวตาร
1
ม.ค. 24
15202
button in systray
button
อวตาร
อวตาร
2
มี.ค. 18
5838
how can i restict auto data saving while clicking on custom button in odoo10?
button
อวตาร
0
ม.ค. 18
4096
Modify / override button action in header of form ?
button
อวตาร
อวตาร
2
ก.พ. 24
26853
Why can't I make a button in tree
button
อวตาร
อวตาร
อวตาร
3
ก.ย. 15
8357
คอมมูนิตี้
  • บทเรียน
  • เอกสารกำกับโปรแกรม
  • ฟอรั่ม
โอเพนซอร์ส
  • ดาวน์โหลด
  • Github
  • Runbot
  • การแปล
บริการ
  • โฮสติ้ง odoo.sh เซิร์ฟเวอร์
  • การสนับสนุน
  • อัปเกรด
  • การพัฒนาที่กำหนดเอง
  • การศึกษา
  • ค้นหานักบัญชี
  • ค้นหาพาร์ทเนอร์
  • ร่วมเป็นพาร์ทเนอร์
เกี่ยวกับเรา
  • บริษัทของเรา
  • ทรัพย์สินในรูปของเครื่องหมายการค้า
  • ติดต่อเรา
  • งาน
  • ระบบการจัดงานอีเวนต์
  • พอดแคสต์
  • บล็อก
  • ลูกค้า
  • กฎหมาย • ความเป็นส่วนตัว
  • ความปลอดภัย
الْعَرَبيّة 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 เป็นชุดแอปธุรกิจแบบเปิดที่ครอบคลุมทุกความต้องการของบริษัทของคุณ อาธิ CRM eCommerce ระบบบัญชี ระบบสินค้าคงคลัง ระบบการขายหน้าร้าน โปรเจกต์ และ อีกมากมาย

ความเหนือกว่าอันเป็นเอกลักษณ์ของ 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