Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Real Estate
    • Real Estate Agency
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consulting
    • Accounting Firm
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Solar Energy Systems
    • Shoe Maker
    • Serveis de neteja
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Tracking One2many fields of a model

Subscriure's

Get notified when there's activity on this post

This question has been flagged
trackingchatterv18CommunityEditionrelational fields
1 Respondre
1758 Vistes
Avatar
Shreya Doodipala

I want to track changes in records of my One2many fields. I've tried the following code:

@api.model_create_multi

    def create(self, vals_list):

        records = super().create(vals_list)

        for record in records:

            if record.lead_id:

                message = f"New Secondary Salesman Added: {record.name}"

                record.lead_id.message_post(body=message, **{'body_is_html': True})

        return records


    def write(self, vals):

        # Store original values before the write operation

        old_values = {}

        for field_name, value in vals.items():

            if field_name in self._fields and self._fields[field_name].tracking:

                # For basic fields (Char, Float, Integer, etc.), directly store the old value

                # For Many2one, you might want to store the display_name or ID

                if self._fields[field_name].relational:

                    old_values[field_name] = self[field_name].display_name if self[field_name] else False

                else:

                    old_values[field_name] = self[field_name]



        res = super().write(vals)


        for record in self:

            if record.lead_id:

                body_message = f"<b>Changes to Secondary Salesman info '{record.display_name}':</b><br/>"

                has_changes = False

                for field_name, new_value in vals.items():

                    if field_name in record._fields and record._fields[field_name].tracking:

                        old_value = old_values.get(field_name)

                        current_value = record[field_name]


                        # Handle different field types for comparison and display

                        if record._fields[field_name].relational:

                            current_display_value = current_value.display_name if current_value else False

                            if str(old_value) != str(current_display_value): Compare display names or IDs

                                has_changes = True

                                field_description = record._fields[field_name].string

                                body_message += f"<li>{old_value or ''} to {current_display_value or ''} ({field_description})<br/>"

    #                     elif str(old_value) != str(current_value): # For non-relational fields

    #                         has_changes = True

    #                         field_description = record._fields[field_name].string

    #                         body_message += f"<li>{old_value or ''} to {current_value or ''} ({field_description}) <br/>"


    #             if has_changes:

    #                 record.lead_id.message_post(body=body_message, **{'body_is_html': True})

    #     return res

    # def unlink(self):

    #     for record in self:

    #         if record.lead_id:

    #             message = f"<b>Salesman Deleted:</b> {record.display_name}"

    #             record.lead_id.message_post(body=message, **{'body_is_html': True})

    #     return super().unlink()

While this works well for one model, when I add this to multiple models, I get the following error either while creating a new record or updating an existing one.

❌

UncaughtPromiseError > OwlError


Uncaught Promise > An error occured in the owl lifecycle (see this Error's "cause" property)


Occured on localhost:8069 on 2025-05-26 10:41:28 GMT


OwlError: An error occured in the owl lifecycle (see this Error's "cause" property)

    Error: An error occured in the owl lifecycle (see this Error's "cause" property)

        at handleError (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:961:101)

        at App.handleError (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:1608:29)

        at RootFiber.complete (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:993:28)

        at Scheduler.processFiber (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:1578:43)

        at Scheduler.processTasks (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:1572:62)

        at http://localhost:8069/web/assets/f129831/web.assets_web.min.js:1569:67


Caused by: NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.

    at VMulti.patch (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:796:116)

    at B.patch (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:881:178)

    at VMulti.patch (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:795:224)

    at VList.patch (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:902:88)

    at B.patch (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:881:178)

    at VToggler.patch (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:721:78)

    at VList.patch (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:902:88)

    at VMulti.patch (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:795:224)

    at VMulti.patch (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:795:224)

    at VToggler.patch (http://localhost:8069/web/assets/f129831/web.assets_web.min.js:721:78)

What is causing the error? OR 
How can I add tracking information to my form's chatter?


Odoo v18 Community edition

0
Avatar
Descartar
Avatar
D Enterprise
Best Answer


This error is not actually caused by the Python backend logic itself (your create, write, unlink methods), but by how the frontend (Owl JS framework in Odoo) is attempting to render the result of the operation, especially if a view or widget is affected in a way it wasn't expecting.Add this at the top of your file:
from odoo.tools import html_escape

Then sanitize your HTML message in the write method:

Replace:

body_message += f"<li>{old_value or ''} to {current_display_value or ''} ({field_description})<br/>"

with:
body_message += f"<li>{html_escape(str(old_value) or '')} → {html_escape(str(current_display_value) or '')} ({html_escape(field_description)})</li>"



0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Is it possible to receive an email and log it to the chatter in contacts? Solved
email chatter v18
Avatar
Avatar
1
de set. 25
1600
Modify Pivot View
Pivot v18 CommunityEdition
Avatar
Avatar
1
de juny 25
1712
Unable to send email notifications through write
notifications v18 CommunityEdition
Avatar
Avatar
1
de juny 25
1757
Track m2o field changes in chatter with link instead of text note? Solved
tracking sale.order chatter
Avatar
Avatar
1
d’ag. 21
4642
Hide Records based on user group only in a particular view
views record_rule v18 CommunityEdition
Avatar
Avatar
Avatar
2
de set. 25
1459
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now