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
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • 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
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • 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

Custom Code: How to reload the Kanban view in Odoo after moving a lead to a different stage?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
development
2 Respostes
2219 Vistes
Avatar
Martin Bando

I have transferred the _track_subtype method from the CRM module to my module and inserted the is_lost field, which changes the status to true when the lead is moved to the stage with the label lost. It is just that the state does not always change. If I now move it back to another stage, it remains lost with the heading at the top right. Only when I refresh the page is the state updated and the heading disappears. 


How can I reload the Kanban view in Odoo after moving a lead to a different stage?


class Lead(models.Model):

    _inherit = 'crm.lead'

   

    is_lost = fields.Boolean(string='Is Lost', default=False)

   

    def _track_subtype(self, init_values):

        self.ensure_one()


        if self.stage_id.name.find("Lost") != -1:

            # If a lead is moved to Lost, then set is_lost to True

            self.is_lost = True

           

        else:

            # For all other lead set is_lost to False           

            self.is_lost = False     

       

        if 'stage_id' in init_values and self.probability == 100 and self.stage_id:

            return self.env.ref('crm.mt_lead_won')

        elif 'lost_reason_id' in init_values and self.lost_reason_id:

            return self.env.ref('crm.mt_lead_lost')

        elif 'stage_id' in init_values:

            return self.env.ref('crm.mt_lead_stage')

        elif 'active' in init_values and self.active:

            return self.env.ref('crm.mt_lead_restored')

        elif 'active' in init_values and not self.active:

            return self.env.ref('crm.mt_lead_lost')

        return super(Lead, self)._track_subtype(init_values)


<record id="mymodule_crm_case_kanban_view_leads" model="ir.ui.view">

    <field name="name">mymodule.crm.lead.kanban.lead</field>

    <field name="model">crm.lead</field>

    <field name="inherit_id" ref="crm.crm_case_kanban_view_leads"/>

    <field name="arch" type="xml">

        <!--  Aperture with red background and white lettering 'Lost' in the window -->

        <xpath expr="//widget[@name='web_ribbon']" position="replace">

            <field name="is_lost" invisible="0"/>

            <widget name="web_ribbon" title="lost" bg_color="text-bg-danger" invisible="is_lost == False"/>

        </xpath>

    </field>

</record>

0
Avatar
Descartar
Martin Bando
Autor

Hi, there is still the error, now it is not updated when i move it back to lost. i think i have to use javascript here. i use odoo 18. how can i integrate javascript. i don't know anything about this. Could you describe this in detail.

Avatar
Martin Bando
Autor Best Answer

I have tried to automatically reload the Kanban view in Odoo 18 when a data record (e.g. a lead) is moved via drag & drop:


Javascript:

import { patch } from '@web/core/utils/patch';


patch(KanbanController.prototype, {

    async dropRecord(record, targetColumn) {

        await this._super(...arguments);


        if (this.model.root.resModel === 'crm.lead') {

            await this.model.load(); 

            this.render(true);    

        }

    }

});


Manifest:'assets': {

    'web.assets_backend': [

        'my_module/static/src/js/kanban_stage_change_refresh.js',

    ],

},

This is a code that was created with Copilot. Is it sufficient to insert the Javscript and change the manifest? Because it doesn't work when I try.

0
Avatar
Descartar
Avatar
Sergio Infante
Best Answer

Hey,

You’re on the right track by inheriting _track_subtype and managing the is_lost flag based on the stage. The behavior you’re seeing—where the ribbon doesn’t update until a page refresh—comes down to how Odoo handles view updates in the Kanban.

Odoo doesn’t automatically re-render the whole Kanban card when a field like is_lost is changed via Python unless that field is part of a computed or onchange method triggered by the UI. Since is_lost is being set in backend logic, the frontend doesn’t get the update immediately.

How to fix it?

To force the UI to reflect the is_lost status change immediately when you move the lead:

Use a computed field with store=True and make it depend on the stage_id. That way, the ORM knows to recompute and store the value when the stage changes.

@api.depends('stage_id')

def _compute_is_lost(self):

    for lead in self:

        lead.is_lost = 'lost' in (lead.stage_id.name or '').lower()


is_lost = fields.Boolean(string='Is Lost', compute='_compute_is_lost', store=True)

Make sure the Kanban view includes the is_lost field directly (which you’ve already done with the ribbon), so it knows to watch for updates on that field.

This way, as soon as you move the lead to a different stage, Odoo will recompute the is_lost value and update the UI accordingly—no need to manually refresh the page.

Let me know if you want to go one step further and make it dynamic with JS or override write() instead. But for 99% of cases, the computed field with store=True handles it perfectly.

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
Feature Request: Native “Dialog Filters” in Search Panel
development
Avatar
0
de nov. 25
149
Solution to the Getting Started tutorial from the official Odoo 16 documentation
development
Avatar
Avatar
Avatar
2
de nov. 25
1521
How do I change the name of the module, or rather the name assigned to the module, after I created it in Odoo Studio?
development
Avatar
1
de nov. 25
366
Guest House Module - Rental Search Bar
development
Avatar
Avatar
1
de nov. 25
237
How to make all branches for user active automatically after login his account?
development
Avatar
Avatar
Avatar
3
de nov. 25
432
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