Skip to Content
Menu
This question has been flagged
3 Replies
6234 Views

Dear Community,

I have the o_chatter located on the main record view to post changes to fields

<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
<field name="message_ids" widget="mail_thread">
</div>

Right now when I change char fields such as name, it will post a message on the chatter saying that 

Name: Yousef  Al-Hadhrami Ali Al-Hadhrami                       

but when I change a relational field such as employee family which is a relational field, it will only post ids instead of contents


This is the One2many field

class HrEmployeeFamily(models.Model):
_inherit = 'hr.employee'
employee_family_ids = fields.One2many(
string="Family",
comodel_name='hr.employee.family',
inverse_name='related_employee'
)

and let's say this is the family model:

class EmployeeFamily(models.Model):
_name = 'hr.employee.family'
_inherit = 'employee.record'

related_employee = fields.Many2one('hr.employee', string="Related Employee")
family_name = fields.Char(track_visibility='onchange')

instead of writing on the chatter 

Family Name:Jack Sporrow  Jack Smith       

it writes the model and ids:

Family Name:hr.employee.family,8

I'd like it to post a full detailed log on what was changed on the relational field, how can I achieve that?

Avatar
Discard

which version are you using?

Author

Version 10

Author

@Ravi, your answer kinda did something but not the thing that it should do

it only shows the record if it was updated

so lets say you had family_name + family_date_of_birth, and you modify one of those, it won't show up on the log because it only shows when a record gets linked to the employee himself.

Author

it only shows the record when it gets linked or unliked from an employee

but if you change something in the record, it won't show on the log because the link haven't changed

I think you need a related field on the model because currently family_name, family_date_of_birth are not direct model field so it does not reflect it's changing on chatter

Author

I think there is,

related_employee = fields.Many2one('hr.employee', string="Related Employee") is the related field on on Family

employee_family_ids = fields.One2many(

string="Family",

comodel_name='hr.employee.family',

inverse_name='related_employee'

) is the related field on the employee

Author

I found a way to [ost to the parent record that one of the family records is updated, deleted or created

here is what I used (for update only):

@api.multi

def write(self, values):

"""Override default Odoo write function and extend."""

self.env['mail.message'].create({

'body': 'Personal Document ' + self.number + ' Updated',

'model': 'hr.employee',

'res_id': self.employee_ref.id,

'subtype_id': '2',

})

return super(HrEmployeePersonalDocument, self).write(values)

it seems the current implementation of chatter doesn't track change on one2many field and post-change entry on chatter.

you want to track the change of one2many field (employee_family_ids) on hr.employee

https://github.com/odoo/odoo/blob/10.0/addons/mail/models/mail_tracking_value.py#L35

I talked about related field mean getting a related field on 'hr.employee.family' like

employee_name = fields.Char(related="related_employee.name")

but it will not work because of you want post entry on hr.employee

your solution looks good on change/write of a relevant field of family mode post message on employee model

Best Answer

can you try after adding _rec_name in`hr.employee.family`

class EmployeeFamily(models.Model):   
     _name = 'hr.employee.family'   
     _inherit = 'employee.record'  
     _rec_name = 'family_name'​

Avatar
Discard
Related Posts Replies Views Activity
4
Apr 20
7555
1
Nov 19
2897
2
Feb 18
12053
0
Jan 18
7535
3
Jun 24
3171