Odoo Help


Adding Messages (Subtypes?) For Product Changes (v7)

Alex Gallien
on 9/21/15, 6:27 PM 1,572 views

I am looking to add messages whenever a change is made to a product record, so that we have a history of changes and who made them. However I cannot seem to figure out how to implement this. From what I can tell, it seems like I need a new message Subtype, but I couldn't figure out how to create one that worked. I set up the following:

Message Type: Product Change

Model: product.product

Default: 1

Description: null

Parent: null

Relation field: null

but this doesn't seem to do anything. Is there a place I can define this? The end goal is having a message whenever any field in a product.product record gets changed. Either in the GUI or via a custom module would be fine - but I can't seem to find any documentation or good examples on this. Cheers!

Alex Gallien
On 9/22/15, 7:38 PM

Axel's answer was great for state changes, but what I wanted was field changes. Turns out this is actually pretty simple, just inherit the fields and add the parameter track_visibility='onchange'. This will set a message every time a change to that field is made. Super easy once I figured it out.

that is another way but my way is not only for state fields, read the code that tracks fields: if visibility == 'always' or (visibility == 'onchange' and name in updated_fields) or name in self._track:

Axel Mendoza
on 9/22/15, 7:44 PM

Got it - thanks for clarifying. I appreciate your help!

Alex Gallien
on 9/23/15, 1:47 PM

Axel Mendoza

--Axel Mendoza--
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 9/21/15, 11:41 PM

You don't need to manually create messages for your field changes. There is an automatic tracking/logging system for models fields changes in OpenERP v7. like source code said at: openerp/addons/mail/mail_thread.py on the mail.thread module:

    # Automatic logging system if mail installed
# _track = {
# 'field': {
# 'module.subtype_xml': lambda self, cr, uid, obj, context=None: obj[state] == done,
# 'module.subtype_xml2': lambda self, cr, uid, obj, context=None: obj[state] != done,
# },
# 'field2': {
# ...
# },
# }
# where
# :param string field: field name
# :param module.subtype_xml: xml_id of a mail.message.subtype (i.e. mail.mt_comment)
# :param obj: is a browse_record
# :param function lambda: returns whether the tracking should record using this subtype

take as example _track properties on crm.lead and account.invoice

For crm.lead:

    _track = {
'state': {
'crm.mt_lead_create': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'new',
'crm.mt_lead_won': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'done',
'crm.mt_lead_lost': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'cancel',
'stage_id': {
'crm.mt_lead_stage': lambda self, cr, uid, obj, ctx=None: obj['state'] not in ['new', 'cancel', 'done'],

For account.invoice:

    _track = {
'type': {
'state': {
'account.mt_invoice_paid': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'paid' and obj['type'] in ('out_invoice', 'out_refund'),
'account.mt_invoice_validated': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'open' and obj['type'] in ('out_invoice', 'out_refund'),

So how would I implement this to show changes in the message section below? Adding new fields to the _track dictionary? Thanks for pointing me in the right direction.

Alex Gallien
on 9/22/15, 1:32 PM

yes, just add the needed fields to the _track dict like in the examples and you will be ok

Axel Mendoza
on 9/22/15, 1:38 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 9/21/15, 6:27 PM
Seen: 1572 times
Last updated: 9/22/15, 7:38 PM