Help

11

what is track_visibility?

Can you describe how track_visibility works and provide scenario where it is used.

Avatar
Discard
3 Answers
6
Avatar
joseph d'souza
Best Answer

Yes let say one scenario like you want to track the visibility of invoice related for ex : invoice is created , invoice is validated, invoice is paid etc..

You can set a mail.message.subtype that depends on an other to act through a relation field. Here is an Account-related subtypes for track visiblity

    <record id="mt_invoice_validated" model="mail.message.subtype">
        <field name="name">Validated</field>
        <field name="res_model">account.invoice</field>
        <field name="default" eval="False"/>
        <field name="description">Invoice validated</field>
    </record> 


    <record id="mt_invoice_paid" model="mail.message.subtype">
        <field name="name">Paid</field>
        <field name="res_model">account.invoice</field>
        <field name="default" eval="False"/>
        <field name="description">Invoice paid</field>
    </record>

Your object need to inherit from mail.thread. for traking the visiblity which produces the messages

If an object is inherited from 'mail.thread' then _track is used to send notifications. Therefore 'module.subtype_xml' is the related "Message Subtype". These subtypes have to be declared in XML. Here is an example:

<record id="subtype_xml" model="mail.message.subtype"> <field name="name">Relevant Fields</field> <field name="res_model">account.invoice</field> <field name="default" eval="True"/> <field name="description">some descriotion.</field> </record>

2 Comments
Avatar
Discard

thanks but I need to understand how track_visibility is used in py file

'user_id': fields.many2one('res.users', 'Salesperson', readonly=True, track_visibility='onchange', states={'draft':[('readonly',False)]}),

its available in account_invoice.py

Avatar
Vinod Kumar
-

Hello friend can i get automatically created message id i want to change that message

0
Avatar
Dinesh Kumar
Best Answer

Hi,

"track_visibility" is used to record each and every action or updates of the particular field.

For example:

'user_id': fields.many2one('res.users', 'Salesperson', readonly=True, track_visibility='onchange', states={'draft':[('readonly',False)]}),

In this example log will be recorded with from and to values, when the value of "user_id" is changed.

If you want to record a log with your own message use the below function.
    message_post(body="Your message")

Avatar
Discard
-7
Avatar
AlSayedGamal
Best Answer


To understand the logic of track_visibility="onchange" you have to see both the python and xml parts of code.

According to the code you sent track_visibility='onchange' in python means that the field attrs will be re-evaluated whenever any "onchange" function is triggered.

So if we assumed that in view we have

<field name = "nationality" /> 
<field name = "user_id" attrs="{'invisible': [('nationailty', '=', 'Egyptian')]}" />

The field user_id will only appear if the nationality field (changed) to be Egyptian.

Avatar
Discard