Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
5 Respostas
6493 Visualizações

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

Avatar
Cancelar
Melhor resposta

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

Avatar
Cancelar
Melhor resposta

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!

Avatar
Cancelar
Melhor resposta

Try the following technical name module in the App Store.

"tracking_manager"


Avatar
Cancelar
Melhor resposta

One2many_tracking in odoo apps store 

Avatar
Cancelar
Melhor resposta

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


 

Avatar
Cancelar