zoukankan      html  css  js  c++  java
  • Openerp 7.0消息推送

    在一个文档的state变化时,需要将变化情况告知关注用户,通过研究account.invoice的代码,发现是经过如下过程实现此功能的:
    
    1、添加一个消息阶段:
     <record id="mt_invoice_paid" model="mail.message.subtype">
                <field name="name">paid</field>
                <field name="res_model">account.invoice</field>
            </record>

    2、定义state变更时的触发函数: def confirm_paid(self, cr, uid, ids, context=None): if context is None: context = {} self.write(cr, uid, ids, {'state':'paid'}, context=context) self.confirm_paid_send_note(cr, uid, ids, context=context) return True

    3、send_note函数,注意subtype的定义,与第一步的定义相关联。
    def confirm_paid_send_note(self, cr, uid, ids, context=None): for obj in self.browse(cr, uid, ids, context=context): self.message_post(cr, uid, [obj.id], body=_("%s <b>paid</b>.") % (self._get_document_type(obj.type)), subtype="account.mt_invoice_paid", context=context)
    这样在state变化的时候,消息会通知给关注此文档的用户,同时不同的用户可以设置关注不同的消息变更。





    测试方法:

    post_vars = {'subject': "这是一个自动通知",
                         'body': "这个单据已经改变!",
                         'partner_ids': [(4, 3)],} # Where "4" adds the ID to the list
                                                   # of followers and "3" is the partner ID
    thread_pool = self.pool.get('mail.thread')
    thread_pool.message_post(
                    cr, uid, False,
                    type="notification",
                    subtype="mt_comment",
                    context=None,
                    **post_vars)  
  • 相关阅读:
    工具类---xlsx文件读写
    2021上半年第二次作业总结
    2021上半年第一次作业总结
    C语言II博客作业04
    C语言II—作业03
    C语言II博客作业02
    C语言II博客作业01
    win7开启snmp服务实现监控过程展现
    台湾某医学会sql注入漏洞
    测试面试题(持续总结中)
  • 原文地址:https://www.cnblogs.com/chjbbs/p/3504682.html
Copyright © 2011-2022 走看看