Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
5 Odpowiedzi
6445 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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!

Awatar
Odrzuć
Najlepsza odpowiedź

Try the following technical name module in the App Store.

"tracking_manager"


Awatar
Odrzuć
Najlepsza odpowiedź

One2many_tracking in odoo apps store 

Awatar
Odrzuć
Najlepsza odpowiedź

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


 

Awatar
Odrzuć