Siirry sisältöön
Odoo Menu
  • Kirjaudu sisään
  • Kokeile ilmaiseksi
  • Sovellukset
    Talous
    • Kirjanpito
    • Laskutus
    • Kulut
    • Datataulukot (BI)
    • Asiakirjat
    • Allekirjoita
    Myynti
    • CRM
    • Myynti
    • Kassajärjestelmä myymälään
    • Kassajärjestelmä ravintolaan
    • Tilaukset
    • Vuokraus
    Verkkosivut
    • Verkkosivun Rakennustyökalu
    • Verkkokauppa
    • Blogi
    • Foorumi
    • Livechat
    • Verkko-oppiminen
    Toimitusketju
    • Varastointi
    • Tuotanto
    • Tuotteen elinkaaren hallinta (PLM)
    • Ostot
    • Huolto
    • Laatu
    Henkilöstöhallinto
    • Työntekijät
    • Rekrytointi
    • Vapaat
    • Arvioinnit
    • Suositukset
    • Kuljetuskalusto
    Markkinointi
    • Somemarkkinointi
    • Sähköpostimarkkinointi
    • Tekstiviestimarkkinointi
    • Tapahtumat
    • Markkinoinnin automaatio
    • Kyselyt
    Palvelut
    • Projekti
    • Työaikakirjaukset
    • Kenttähuolto
    • Asiakaspalvelu
    • Suunnittelu
    • Ajanvaraukset
    Tuottavuus
    • Viestintä
    • Hyväksynnät
    • IoT
    • IP-puhe
    • Tietokirjasto
    • WhatsApp
    Kolmannen osapuolen sovellukset Odoo-Studio Odoo-Pilvialusta
  • Toimialat
    Vähittäiskauppa
    • Kirjakauppa
    • Vaatekauppa
    • Huonekaluliike
    • Ruokakauppa
    • Laitteistokauppa
    • Lelukauppa
    Ruoka & Majoitus
    • Baari ja Pubi
    • Ravintola
    • Pikaruoka
    • Majatalo
    • Juomien jakelija
    • Hotelli
    Kiinteistöt
    • Kiinteistönvälitystoimisto
    • Arkkitehtitoimisto
    • Rakentaminen
    • Kiinteistönhallinta
    • Puutarhanhoito
    • Kiinteistön omistajien yhdistys
    Konsultointi
    • Tilitoimisto
    • Odoo-kumppani
    • Markkinointitoimisto
    • Lakitoimisto
    • Osaajahankinta
    • Tilintarkastus & sertifiointi
    Tuotanto
    • Tekstiili
    • Metalli
    • Huonekalut
    • Ruoka
    • Panimo
    • Yrityslahjat
    Terveys & Liikunta
    • Urheiluseura
    • Silmälasiliike
    • Kuntokeskus
    • Hyvinvointialan ammattilaiset
    • Apteekki
    • Kampaamo
    Kaupat
    • Yleismies
    • IT-laitteisto & Tuki
    • Aurinkoenergiajärjestelmät
    • Suutari
    • Siivouspalvelut
    • LVI-palvelut
    Muut
    • Voittoa tavoittelematon järjestö
    • Ympäristötoimisto
    • Mainostaulujen vuokraus  
    • Valokuvaus
    • Leasing-pyörät
    • Ohjelmistojen jälleenmyyjä
    Selaa kaikkia toimialoja
  • Yhteisö
    Opi
    • Kurssit
    • Dokumentaatio
    • Todistukset
    • Koulutus
    • Blogi
    • Podcast
    Kannusta kouluttautumaan
    • Koulutusohjelmat
    • Scale Up! Liiketoimintapeli
    • Vieraile Odoolla
    Hanki ohjelmisto
    • Lataa
    • Vertaile versioita
    • Julkaisut
    Tee yhteistyötä
    • Github
    • Foorumi
    • Tapahtumat
    • Käännökset
    • Ryhdy kumppaniksi
    • Kumppanipalvelut
    • Rekisteröi tilitoimistosi
    Hanki palveluja
    • Löydä kumppani
    • Löydä kirjanpitäjä
    • Varaa asiantuntijatapaaminen
    • Implementaatiopalvelut
    • Asiakasreferenssit
    • Tuki
    • Versionkorotukset
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Varaa demo
  • Hinnoittelu
  • Asiakaspalvelu

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

  • CRM
  • e-Commerce
  • Kirjanpito
  • Varastointi
  • PoS
  • Projekti
  • MRP
All apps
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Apua

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

Tilaa

Saat ilmoituksen, kun tähän viestiin ilmaantuu aktiviteettia

Tämä kysymys on merkitty
development
2 Vastaukset
2188 Näkymät
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
Hylkää
Martin Bando
Tekijä

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
Tekijä Paras vastaus

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
Hylkää
Avatar
Sergio Infante
Paras vastaus

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
Hylkää
Nautitko keskustelusta? Älä vain lue, vaan osallistu!

Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!

Rekisteröidy
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
Feature Request: Native “Dialog Filters” in Search Panel
development
Avatar
0
marrask. 25
113
Solution to the Getting Started tutorial from the official Odoo 16 documentation
development
Avatar
Avatar
Avatar
2
marrask. 25
1484
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
marrask. 25
349
Guest House Module - Rental Search Bar
development
Avatar
Avatar
1
marrask. 25
220
How to make all branches for user active automatically after login his account?
development
Avatar
Avatar
Avatar
3
marrask. 25
404
Yhteisö
  • Kurssit
  • Dokumentaatio
  • Foorumi
Avoin lähdekoodi
  • Lataa
  • Github
  • Runbot
  • Käännökset
Palvelut
  • Odoo.sh hosting
  • Tuki
  • Versionkorotus
  • Räätälöidyt kehitykset
  • Koulutus
  • Löydä kirjanpitäjä
  • Löydä kumppani
  • Ryhdy kumppaniksi
Meistä
  • Yrityksemme
  • Brändiominaisuudet
  • Ota yhteyttä
  • Työpaikat
  • Tapahtumat
  • Podcast
  • Blogi
  • Asiakkaat
  • Oikeudellinen ilmoitus • Yksityisyys
  • Tietoturva
الْعَرَبيّة 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 on kokoelma avoimen lähdekoodin yrityssovelluksia, jotka kattavat kaikki yrityksesi tarpeet: asiakkuudenhallinta eli CRM, verkkokauppa, kirjanpito, varastointi, kassajärjestelmä, projektinhallinta, jne.

Odoon uniikki arvolupaus on olla samanaikaisesti erittäin helppokäyttöinen ja täysin integroitu.

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