Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
9 ตอบกลับ
28628 มุมมอง

I want to add track_visibility = 'onchange' for many fields, particularly existing fields in the product model.

These fields are written with V7 API, but I am using Odoo 8.


I know that I can override the entire field definition, like:

'name': fields.char('Name', required=True, translate=True, select=True, track_visibility='onchange'),


But this seems quite sloppy.

What if the field definition changes in an update? My minor tracking modification could break the module's functionality.


Trying to just add tracking (like below) will cause the field Name, etc. to be undefined, because it overwrites, rather than inheriting.

# Overrides instead of inheriting

'name': fields.char(track_visibility='onchange'),


Is there a way to do this more cleanly? Either in V7 or V8 API.


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

You must have to override using copy field from base file and add(append) the track_visibility='onchange' 

to the fields this is the only way.


อวตาร
ละทิ้ง
ผู้เขียน

Ok, that's what I thought. Seems like a lot of overhead to just change the tracking. There are a lot of default fields which we would like to monitor in this way. Thanks for your input, Krupesh.

most welcome.

I know this topic is bit old now but, in case someonce find it, i wanted to add a comment :

In newer versions (9.0+), as Royal Administrator said below, you DO NOT need to copy the whole field definition, you ONLY need to set the the parameter you want to override.

This ensure you respect the "override chain" (change only what you need)

Thank you @bruno PLANCHER. Today, this answers helped me to sovle my problem

คำตอบที่ดีที่สุด

I might be late to the party but i think you can use https://apps.openerp.com/apps/modules/8.0/message_post_model/ to solve your needs or you can dig deep at how they've done it by looking at the source code.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

you can override just track_visiblity attribute :

name = fields.Char(track_visibility='onchange')

อวตาร
ละทิ้ง

Works for me in Odoo 8. Thanks!

คำตอบที่ดีที่สุด

In the big comment atop class Field in fields.py, I noticed "For instance, the second class below only adds a tooltip on the field...."  I wanted to see the lead names, aka subject lines, in the lead notifications, and I was successful like this:

from openerp import models, fields

class crm_lead(models.Model):
     _inherit = 'crm.lead'
    name = fields.Char(track_visibility='onchange')

You do need the overhead of getting the datatype correct for the field.
Then the track_visibility attribute can be changed free of further overhead.

อวตาร
ละทิ้ง
ผู้เขียน

So only whatever I define in my inherited field definition will be changed? I can define only track_visibility without affecting other field attributes?

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 20
3536
1
ส.ค. 19
4920
0
ส.ค. 23
1612
0
พ.ย. 21
3333
Show log note (tracking) in odoo 11 แก้ไขแล้ว
1
มี.ค. 24
2612