Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Tracking One2many fields of a model

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
trackingchatterv18CommunityEditionrelational fields
1 Odpowiedz
1762 Widoki
Awatar
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
Awatar
Odrzuć
Awatar
D Enterprise
Najlepsza odpowiedź


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
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
Is it possible to receive an email and log it to the chatter in contacts? Rozwiązane
email chatter v18
Awatar
Awatar
1
wrz 25
1601
Modify Pivot View
Pivot v18 CommunityEdition
Awatar
Awatar
1
cze 25
1712
Unable to send email notifications through write
notifications v18 CommunityEdition
Awatar
Awatar
1
cze 25
1757
Track m2o field changes in chatter with link instead of text note? Rozwiązane
tracking sale.order chatter
Awatar
Awatar
1
sie 21
4642
Hide Records based on user group only in a particular view
views record_rule v18 CommunityEdition
Awatar
Awatar
Awatar
2
wrz 25
1460
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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