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

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")


 

อวตาร
ละทิ้ง