İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

Prevent navigation if records are not save

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
v15
2 Cevaplar
3125 Görünümler
Avatar
Antonio Krsnik

I am trying to implement warning to user when there is a change in the records, but Save button is not hit and they are navigation to some other screen or closing the window. 

I tried multiple things


Adding flag like below

has_unsaved_changes = fields.Boolean(string="Has Unsaved Changes", default=False)


which should be modified onchange of certain fields to give validation error:


    @api.constrains('has_unsaved_changes')

    def _check_unsaved_changes(self):

        for record in self:

            if record.has_unsaved_changes:

                _logger.warning(f"ValidationError: Unsaved changes detected for record {record.id}.")

                raise ValidationError("You have unsaved changes. Please save your changes before proceeding.")

Which then should be modified to true when button is pressed. But no write or create function work on it, as it immediately triggers the warning 

Annoying thing is also that Odoo is automatically trying to save when you navigate. 

Another thing I tried is using custom button and context

But even when I introduce a button it still get an error when user clicks it:


def write(self, vals):

        """Override write to prevent automatic saving unless explicitly triggered."""

        if not self.env.context.get('is_user_action', False):

            raise UserError("Automatic save is not allowed. Please save explicitly using the appropriate action.")

        if 'has_unsaved_changes' in vals or any(field in vals for field in self._fields):

            vals['has_unsaved_changes'] = False

        return super(CreateTargetMetrics, self).write(vals)


    def save_changes(self):

        """Button action to save changes."""

        for record in self:

            # Save new record

            _logger.info("********Creating new record ********")

            _logger.info("record._convert_to_write(record._cache)==", record._convert_to_write(record._cache))

            record.with_context(is_user_action=True).create(record._convert_to_write(record._cache))


I added the logs also, and when pressing custom button I don't get any, meaning the button is not even triggered

0
Avatar
Vazgeç
Christoph Farnleitner

You could check out how this is done for the Settings page - any change there will lead to a warning, when navigating elsewhere - and adapt this feature to your needs.

Avatar
Cybrosys Techno Solutions Pvt.Ltd
En İyi Yanıt

Hi,

Please refer to the module:

1. https://apps.odoo.com/apps/modules/18.0/auto_save_restrict

Displays a popup asking if you want to save changes when attempting to navigate away from a record with unsaved changes.


Hope it helps




0
Avatar
Vazgeç
Avatar
D Enterprise
En İyi Yanıt
  1. Use Odoo's JS window.onbeforeunload event to detect unsaved changes on the client and warn the user.
  2. Hook into Odoo's FormView JS to detect changes to form fields and set a flag in the browser.
  3. Allow save normally (don’t block server-side writes) — just warn client-side.
How to implement this in Odoo 15/16/17+ (example concept):

1. Create a small JS module extending FormView
odoo.define('your_module.form_warning', function (require) {

    "use strict";


    var FormController = require('web.FormController');


    FormController.include({

        init: function () {

            this._super.apply(this, arguments);

            this.hasUnsavedChanges = false;

        },


        _onFieldChanged: function (event) {

            this.hasUnsavedChanges = true;

            this._super.apply(this, arguments);

        },


        _onSave: function () {

            this.hasUnsavedChanges = false;

            return this._super.apply(this, arguments);

        },

    });


    window.addEventListener('beforeunload', function (e) {

        // If user has unsaved changes, show warning dialog

        if (odoo.__DEBUG__.services.form_controller && odoo.__DEBUG__.services.form_controller.hasUnsavedChanges) {

            var confirmationMessage = 'You have unsaved changes. Are you sure you want to leave?';

            e.returnValue = confirmationMessage; // Gecko + IE

            return confirmationMessage; // Webkit, Chrome

        }

    });

});

This example overrides the form controller to track changes, reset on save, and warn on page unload.
Include this JS file in your module manifest:
'assets': {

    'web.assets_backend': [

        'your_module/static/src/js/form_warning.js',

    ],

},

On the server side:

  • Remove the constrains and write overrides related to unsaved changes flag.
  • Keep the database model simple; no need for has_unsaved_changes boolean.
  • Let Odoo handle saves normally.

0
Avatar
Vazgeç
Enjoying the discussion? Don't just read, join in!

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

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
Creating user creates duplicated partner_id
v15
Avatar
Avatar
1
Eyl 25
3040
Sales order line comment to Purchase order line comment Çözüldü
v15
Avatar
Avatar
3
Tem 25
4351
attribute is not applied when dynamically rendering
v15
Avatar
1
May 25
2458
Odoo Custome Module Language Creation
v15
Avatar
Avatar
Avatar
Avatar
4
May 25
3872
Odoo 15 previous question papers/practice tests. Çözüldü
v15
Avatar
Avatar
1
Şub 25
8103
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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