Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
7022 Vizualizări

how can I show a popup message when click defalut save button in odoo. here i want to add a confirmation message when clicking the default save button.

how can I do that if anyone know please help me. i can not find any solution regarding this.

Imagine profil
Abandonează
Cel mai bun răspuns

Hello,


Try this


from odoo import models, fields, api
from odoo.exceptions import ValidationError


class MyClass(models.Model):
_name = 'my.class'
name = fields.Char('Name')

@api.model
def create(self, vals):
if not self.name:
raise ValidationError("Write your message ")
return super(MyClass, self).create(vals)


@api.model
def write(self, vals):
if not self.name:
raise ValidationError("Write your message ")
return super(MyClass, self).create(vals)





In the provided code, if we want the message after creating a record and then save use the create method, and if we want the message after editing the created record we can use the write method


Imagine profil
Abandonează
Cel mai bun răspuns
  1. Create a new module or identify the existing module where you want to add the customization.

  2. Inside your module, create a new JavaScript file, let's call it custom_script.js, and add your custom JavaScript code in it. For example:


odoo.define('your_module.custom_script', function (require) {
"use strict";

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

FormController.include({
_saveRecord: function () {
var self = this;
var confirmMessage = "Are you sure you want to save?"; # Custom confirmation message

Dialog.confirm(this, confirmMessage, {
confirm_callback: function () {
self._super.apply(self, arguments);
},
cancel_callback: function () {
#Perform actions when the user cancels the save action
# ...
},
});
},
});
});

In the above code, we define a new JavaScript module named your_module.custom_script. We include the necessary dependencies web.FormController, web.core, and web.Dialog. We extend the FormController and override the _saveRecord method, which is responsible for handling the Save action.

Inside the overridden method, we create a confirmation dialog using web.Dialog.confirm(). The confirm_callback function is executed when the user confirms the save action, and the default save behavior is invoked. The cancel_callback function is executed when the user cancels the save action, allowing you to perform any additional actions if needed.

Imagine profil
Abandonează
Autor

js not working here I added js file in manifest
"assets": {
"web.assets_backend": [
"popup_js/static/src/js/popup.js",
],
},
but js not working and added your js code in popup.js. do i need any other thing to work this js?

Cel mai bun răspuns

Hi,

Please refer this forum answer:

https://www.odoo.com/forum/help-1/how-can-i-make-a-popup-warning-message-93419

Regards

Imagine profil
Abandonează
Autor

In this forum they are showing pop up in wizard. but i want to show popup on clicking default save button. Though save button is not visible so I can not define the confirmation message and i applied js but its also not working.