Odoo - Mixins and Useful Classes

Odoo 提供了一些 classed 和 mixins,用以幫助你輕鬆的建立一些常用的功能。

Messaging features

Messaging integration

Basic messaging system

將 messaging feature 整合到你自己的 model 中將是非常的容易。僅需要在你的 model 的定義中添加繼承 mail.thread,以及在你的 form view 中添加對應的字段和 widgets,就可以了。

class BusinessTrip(models.Model):
    _name = 'business.trip'
    _inherit = ['mail.thread']
    _description = 'Business Trip'

    name = fields.Char()
    partner_id = fields.Many2one('res.partner', 'Responsible')
    guest_ids = fields.Many2many('res.partner', 'Participants')

form view 中 添加

<record id="businness_trip_form" model="ir.ui.view">
    <field name="name">business.trip.form</field>
    <field name="model">business.trip</field>
    <field name="arch" type="xml">
        <form string="Business Trip">
            <!-- Your usual form view goes here
            ...
            Then comes chatter integration -->
            <div class="oe_chatter">
                <field name="message_follower_ids" widget="mail_followers"/>
                <field name="message_ids" widget="mail_thread"/>
            </div>
        </form>
    </field>
</record>

一旦你在 model 中添加了 chatter support,用戶就可以非常方便的在這個 model 的任意 record 上,添加 message。這些修改或留言,也會自動的發給這個 record 的 followers ,當然前提是,系統的 email 配置都是正確的。

Posting messages

  • message_post(self,body='',subject=None,message_type='notification',subtype=None,parent_id=False,attachments=None,content_subtype='html',**kwargs)
    提交一個新的 message 到 existing thread,並返回這個 message 的 ID。
- -
Parameters: body(str) – message的內容,如果是html將會被轉意
message_type(str) – see mail_message.type field
content_subtype(str) – 如果是普通文本數據,convert body into html
parent_id(int) – 用來回復之前的 message,主要是私人對話
attachments(list(tuple(str,str))) – list of tuple, tuple是 (name, content), content 不是 base64 encoded
**kwargs – extra keyword arguments will be used as default column values for the new mail.message record
Returns: id of newly created mail.message
Return Type: int

- message_post_with_view(views_or_xmlid, **kwargs)
用來 send email 或者 post a message,使用 ir.qweb 引擎來渲染這個 view_id。This method is stand alone, because there is nothing in template and composer that allows to handle views in batch. This method will probably disappear when templates handle ir ui views.

- -
Parameters: ir.ui.view record(str) – external id or record of the view that should be sent

message_post_with_template(template_id, **kwargs)
通過指定 template 來發送 message。

- -
Parameters: template_id – 使用模板的 id
**kwargs – 用來創建 mail.compose.message wizard的參數,繼承自 mail.message

Receiving messages

下述方法都是當 mail gateway 收到新的郵件時,纔會被調用。這些 email 可以被當前的 thread 自動回覆,或者一個新的 thread。重寫下面幾個方法,將會使得你可以根據 email 中的一些特定值,再返回不同的郵件(i.e. 修改時間,以及根據 email-address,修改 CC address, etc.)。

  • message_new(msg_dict, custom_values=None)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章