I am now creating a customize module for a lab test purpose in OpenERP 7. The users will require to enter their lab test components and result here.
Now i having a field which called "Reason For Changes". I would like to know the method how i can log the input of this content as a "log a note" message to display at the bottom through mail.thread?
The step would be:
Reason For Changes (ROC) as a required field
Any changes in my others fields will calling my onchange method to clearing the content of ROC field.
If the user changed something without enter a text to the ROC field, then click save, a error message "Please Enter Reason For Change" will pop up. This will disable the user from saving this.
If the user changed something and enter a text to ROC field, then save, the ROC field content will create as a message at the bottom (such as "log a note") as a reference and history log record.
My question would be how could i achieve the step 3 and 4? Deeply appreciate for your help
There are two possiblities, but the used model has to inherit email.thread
! But i guess it is inheriting, because you wrote something about the chatter messages.:
roc = fields.Char(string="Reason For Changes", track_visibility="on_change")
_columns = {
roc: fields.char(string="Reason For Changes", track_visibility="on_change"),
}
email.thread
is coming with some simple yet useful methods. One of them is message_post(). Override the write() of the model, like the following (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