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

I've added  track_visibility='onchange' on my fields and it doesn't work.

any idea ?

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

Hi

By default, One2many fields changes won't update on chatter.


To display tracking of the One2many field in chatter, please refer to the code below.


class A(models.Model):
_name = "A.A"
_inherit = ['mail.thread', 'mail.activity.mixin']

name = fields.Char("Name")
b_lines = fields.One2many('B.B', 'a_id')


class B(models.Model):
_name = "B.B"
_inherit = ['mail.thread', 'mail.activity.mixin']

a_id = fields.Many2one('A.A')
name = fields.Char("Name",tracking=True)
#To Show tracking in chatter Add tracking=True

def write(self, vals):
super().write(vals)
if set(vals) & set(self._get_tracked_fields(vals)):
self._track_changes(self.a_id)

def _track_changes(self, field_to_track):
if self.message_ids:
message_id = field_to_track.message_post(
body=f'{self._description}: {self.display_name}').id
trackings = self.env['mail.tracking.value'].sudo().search(
[('mail_message_id', '=', self.message_ids[0].id)])
for tracking in trackings:
tracking.copy({'mail_message_id': message_id})


Hope it helps,

KIran K

อวตาร
ละทิ้ง

It works !!

But you forgot to return the super() of the write method.

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

Hi, 
Please try with "tracking=True"  instead of track_visibility .
Hope it will help you.
Thanks

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Thank you Malay for your answer, but still the same problem

อวตาร
ละทิ้ง

HI,

Try to inherit "mail.thread" Model in your line model. Try to add _inherit = ['mail.thread'] line after your model description.

Just like this:

class YourCustomModel(models.Model):
_name = 'your.custom.model.name'
_inherit = ['mail.thread']
_description = 'Your Custom Model'

Hope it will help you.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 25
2274
2
ก.ค. 25
7748
2
ก.ค. 25
4166
2
ก.ค. 25
3946
2
มิ.ย. 25
2548