OpenERP 7 - 在 "Log a Note" 字段中创建自动日志消息作为历史日志记录

OpenERP 7 - Create auto log message in "Log a Note" field as history log record

我现在正在为 OpenERP 7 中的实验室测试目的创建一个自定义模块。用户将需要在此处输入他们的实验室测试组件和结果。

现在我有一个名为 "Reason For Changes" 的字段。我想知道如何将此内容的输入记录为 "log a note" 消息以通过 mail.thread 显示在底部的方法?

步骤为:

  1. 更改原因 (ROC) 作为必填字段

  2. 我其他字段的任何变化都会调用我的onchange方法来清除ROC字段的内容。

  3. 如果用户更改了某些内容而没有在 ROC 字段中输入文本,然后单击保存,将弹出错误消息 "Please Enter Reason For Change"。这将禁止用户保存它。

  4. 如果用户更改了一些东西,在ROC字段输入了文本,然后保存,ROC字段内容会在底部创建为消息(例如"log a note")作为参考和历史日志记录。

我的问题是如何实现第 3 步和第 4 步?非常感谢您的帮助

有两种可能,但使用的模型必须继承email.thread!但我猜它是继承的,因为你写了一些关于聊天消息的东西。:

  1. 使用 Odoo(原 OpenERP)的自动跟踪系统。您只需在字段定义中添加参数 track_visibility,例如 (new then old API)
roc = fields.Char(string="Reason For Changes", track_visibility="on_change")

_columns = {
    roc: fields.char(string="Reason For Changes", track_visibility="on_change"),
}
  1. Post自己写的留言。 email.thread 附带了一些简单而有用的方法。其中之一是 message_post()。重写模型的write(),像下面这样(new/old API):
@api.multi
def write(self, vals):
    res = super(YourModel, self).write(vals)
    if 'roc' in vals:
        for your_model_record in self:
            your_model_record.message_post(vals.get('roc'))
    return res


def write(self, cr, uid, ids, vals, context=None):
    res = super(YourModel, self).write(vals)
    if 'roc' in vals:
        for your_model_record_id in ids:
            self.message_post(cr, uid, your_model_record_id, vals.get('roc')), context=context)
    return res

希望我的问题也能对其他人有所帮助。以下是现在对我有用的完整代码示例:

  def write(self, cr, uid, ids, vals, context=None):
      res = super(test_lab, self).write(cr, uid, ids, vals, context=context)        
      if 'ROC' in vals: 
          for lab in self.browse(cr, uid, ids, context=context):               
              self.message_post(cr,uid,[lab.id],vals.get('ROC'),context=context)                
      return res   

希望这对您有所帮助。谢谢!