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
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • 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
    Iní
    • 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
  • Pomoc

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

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
development
2 Replies
2178 Zobrazenia
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
Zrušiť
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
Zrušiť
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
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
Feature Request: Native “Dialog Filters” in Search Panel
development
Avatar
0
nov 25
89
Solution to the Getting Started tutorial from the official Odoo 16 documentation
development
Avatar
Avatar
Avatar
2
nov 25
1471
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
nov 25
338
Guest House Module - Rental Search Bar
development
Avatar
Avatar
1
nov 25
212
How to make all branches for user active automatically after login his account?
development
Avatar
Avatar
Avatar
3
nov 25
399
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