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

How to create a custom discard button?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
odooodoo17
4 Odpowiedzi
3560 Widoki
Awatar
Sebastian

I have these buttons:




def update(self):

evaluation_cycle_model = self.env[
'sst.initial.evaluation.by.cycles'].search([('id', '=',self.evaluation_id.id)],limit=1)

if evaluation_cycle_model:
evaluation_cycle_model.update_records()

view_id = self.env.ref('sst.view_sst_qualification_form').id
return {
'type': 'ir.actions.act_window',
'name': 'Calificar Items',
'res_model': 'sst.initial.evaluation.by.cycles',
'res_id': self.id,
'view_mode': 'form',
'views': [[view_id, 'form']],
'target': 'new',
'tag': 'reload'
}

def action_discard(self):

view_id = self.env.ref('sst.view_sst_qualification_form').id
return {
'type': 'ir.actions.act_window',
'name': 'Calificar Items',
'res_model': 'sst.initial.evaluation.by.cycles',
'res_id': self.id,
'view_mode': 'form',
'views': [[view_id, 'form']],
'target': 'new',
}


I have this action_discard button, which returns an action to return to a specific view, my question is, how can I make the button works? The action it returns works, but it does not discard the information, on the contrary it saves it in the database.

0
Awatar
Odrzuć
Awatar
Simon Mburu Njoroge
Najlepsza odpowiedź

To implement a custom "Discard" button in Odoo 17 that effectively reverts unsaved changes, you can follow these steps:

  1. Define the Discard Button in Your XML View:
    Add a button to your form view with the special="cancel" attribute. This attribute ensures that the button functions as a discard action.
    xml Copy code < footer > 
        < button  string = "Discard"  special = "cancel"  class = "oe_link" /> 
    </ footer >
    
    The special="cancel" attribute is recognized by Odoo to trigger the discard operation, reverting any unsaved changes and closing the form view.
  2. Implement the Discard Functionality in Your Python Model:
    If you need to perform additional actions when the discard button is pressed, you can define a method in your model. However, for the standard discard behavior, the special="cancel" attribute handles the necessary operations.
    python Copy code from odoo import models, fields, api
    
    class  YourModel (models.Model):
        _name = 'your.model'
    
        # Define your fields here
    
        @api.multi 
        def  action_discard ( self ):
             # Custom actions before discarding changes 
            self.env.cr.rollback()   # Revert unsaved changes 
            return {
                 'type' : 'ir.actions.act_window' ,
                 'name' : 'Your Form ' ,
                 'res_model' : 'your.model' ,
                 'view_mode' : 'form' ,
                 'res_id' : self. id ,
                 'target' : 'current' ,
            }
    
    In this method, self.env.cr.rollback() is used to discard any uncommitted changes in the current transaction. The returned action reloads the form view without saving the modifications.

Additional Considerations:

  • Using special="cancel" : This attribute is a built-in feature in Odoo that provides standard discard functionality without the need for custom methods.
  • Custom Discard Logic: If your discard operation requires additional logic, such as resetting specific fields or triggering other actions, you can define a method like action_discard in your model and link it to a button without the special="cancel" attribute.

By following these steps, you can create a custom discard button in Odoo 17 that effectively reverts unsaved changes, ensuring a seamless user experience.

Sources

1
Awatar
Odrzuć
Awatar
Eileen Duran
Najlepsza odpowiedź
  • self.env.cr.rollback() will discard any changes made in the current transaction.
  • This prevents the record from being saved when returning to the form view.

Now, when the action_discard button is clicked, the record’s changes will be discarded and the user will be taken back to the form view without saving any modifications.

0
Awatar
Odrzuć
Eileen Duran

Hope this answer helps you. If you have any questions, you can contact me via the following page: https://basketballlegends.pro
Playing in the basketball competition is a great way to get in on the championship race and join the other competitors.

Awatar
ZaraBisliev
Najlepsza odpowiedź

Hi! I like yours very much. I think you should check out for some custom dismiss button options. It helps you a lot in this regard.

0
Awatar
Odrzuć
ZaraBisliev

The best idea is to refer to https://geometrydashdeadlocked.com/ to have suitable selection methods for the above problem.

Awatar
Sebastian
Autor Najlepsza odpowiedź

I did it guys.
I just save each field in the context:

'context': {
'default_item_id': self.id,
'default_evaluation_id': evaluation_id,
'default_item_weight': self.weight,
'default_date': evaluation.date,
'default_compliance': evaluation.compliance,
'default_weight': evaluation.compliance_weight,
'default_responsible': evaluation.responsible.id,
'default_observation': evaluation.observation
}
def action_discard(self):
original_data = {
'date': self.env.context.get('default_date'),
'compliance': self.env.context.get('default_compliance'),
'compliance_weight': self.env.context.get('default_weight'),
'responsible': self.env.context.get('default_responsible'),
'observation': self.env.context.get('default_observation')
}
self.write(original_data)
view_id = self.env.ref('sst.view_sst_qualification_form').id
return {
'type': 'ir.actions.act_window',
'name': 'Calificar Items',
'res_model': 'sst.initial.evaluation.by.cycles',
'res_id': self.id,
'view_mode': 'form',
'views': [[view_id, 'form']],
'target': 'new',
}
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ść
How to create a dynamic domain in Odoo 17? Rozwiązane
odoo odoo17
Awatar
Awatar
Awatar
Awatar
3
mar 25
4218
How to Change the Error Dialog Box, Odoo Title Name, and Odoo Server Name?
odoo odoo17
Awatar
0
mar 25
2272
'\n' new line option not working in UserError in Odoo 17
odoo odoo17
Awatar
Awatar
1
lis 24
3446
Error when entering settings
odoo odoo17 Odoo17
Awatar
Awatar
Awatar
2
kwi 25
4147
Odoo JsonRPC : Get m2m, m2o or o2m nested field with read method
odoo jsonrpc odoo17
Awatar
0
lut 25
1926
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