콘텐츠로 건너뛰기
메뉴
신고된 질문입니다
5 답글
6460 화면

Hello guys,

    I added Tracking for many2one and many2many fields, it works fine for many2one but it dosen't works for many2many field.Can anyone post solution for this?


Regards,

OdooPlanet

아바타
취소
베스트 답변

Hi,

For many2many fields we cannot enable tracking just like other fields. But you can use message post function for this, which will allow you to post message in to chatter from code

Please refer this link:Odoo Message Post Function || Add Message To Chatter From Code in Odoo
 
Thank you

아바타
취소
베스트 답변

Add tracking for many2many and one2many field in odoo16 is here:

from odoo import fields, Command


field_name = fields.Many2many('comodel_name', tracking=True)


Add the bellow function :

def _mail_track(self, tracked_fields, initial_values):
changes, tracking_value_ids = super()._mail_track(tracked_fields, initial_values)
# Many2many tracking
if len(changes) > len(tracking_value_ids):
for changed_field in changes:
if tracked_fields[changed_field]['type'] in ['one2many', 'many2many']:
field = self.env['ir.model.fields']._get(self._name, changed_field)
vals = {
'field': field.id,
'field_desc': field.field_description,
'field_type': field.ttype,
'tracking_sequence': field.tracking,
'old_value_char': ', '.join(initial_values[changed_field].mapped('name')),
'new_value_char': ', '.join(self[changed_field].mapped('name')),
}
tracking_value_ids.append(Command.create(vals))
return changes, tracking_value_ids

Thanks!

아바타
취소
베스트 답변

Try the following technical name module in the App Store.

"tracking_manager"


아바타
취소
베스트 답변

One2many_tracking in odoo apps store 

아바타
취소
베스트 답변

models.py:

# -*- coding: utf-8 -*-
from openerp import models, fields, api
# Chef Section  classchef(models.Model):    _name = 'restaurantsystemreve.chef'    _rec_name = 'firstname'        chefid = fields.Char(string='Chef ID', required=True)    firstname = fields.Char(string='First Name', required=True)    lastname = fields.Char(string='Last Name', required=True)    phoneno = fields.Char(string='Phone', required=True)    orderid = fields.Many2one('restaurantsystemreve.order', string="Oder ID", help="Oder ID", ondelete="restrict")


 

아바타
취소