Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Tracking One2many fields of a model

Odoberať

Get notified when there's activity on this post

This question has been flagged
trackingchatterv18CommunityEditionrelational fields
1 Odpoveď
1746 Zobrazenia
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
Zrušiť
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
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
Is it possible to receive an email and log it to the chatter in contacts? Solved
email chatter v18
Avatar
Avatar
1
sep 25
1596
Modify Pivot View
Pivot v18 CommunityEdition
Avatar
Avatar
1
jún 25
1708
Unable to send email notifications through write
notifications v18 CommunityEdition
Avatar
Avatar
1
jún 25
1753
Track m2o field changes in chatter with link instead of text note? Solved
tracking sale.order chatter
Avatar
Avatar
1
aug 21
4639
Hide Records based on user group only in a particular view
views record_rule v18 CommunityEdition
Avatar
Avatar
Avatar
2
sep 25
1455
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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