Skip to content

Commit

Permalink
[IMP] web_create_write_confirm: fix JS, usage. Minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyasProgrammer committed Jul 27, 2023
1 parent 5f98b52 commit 1dd067b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
7 changes: 3 additions & 4 deletions web_create_write_confirm/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
class BaseModel(models.AbstractModel):
_inherit = "base"

def get_message_informations(self, values=False):
def get_popup_message_info(self, values=False):
"""
This function gives us the possibility to know
if we display the message or not
Retrieve popup messages' data.
- In create self is empty
- In write self is not empty contains current ID
:param values:
Expand All @@ -22,7 +21,7 @@ def get_message_informations(self, values=False):
"""
return False

def execute_processing(self, values=False):
def process_popup_message(self, values=False):
"""
This function gives us the possibility to execute a
specific treatment after the confirmation of the message
Expand Down
4 changes: 2 additions & 2 deletions web_create_write_confirm/models/popup_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class PopupMessage(models.Model):
default="confirm",
selection=[("confirm", "Confirmation"), ("alert", "Alert")],
)
title = fields.Char(string="Title")
message = fields.Text(string="Message", required=True)
title = fields.Char(string="Title", translate=True)
message = fields.Text(string="Message", required=True, translate=True)
active = fields.Boolean(string="Active", default=True)

@api.depends("field_ids")
Expand Down
4 changes: 2 additions & 2 deletions web_create_write_confirm/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Confirm res.partner change:
msg = self.env['popup.message'].create(
{
'model_id': self.env['ir.model'].search([('model', '=', 'res.partner')]).id,
'model_id': self.env['ir.model']._get_id('res.partner')
'field_ids': [(6, 0, self.env['ir.model.fields'].search([('model', '=', 'res.partner')]).ids)],
'popup_type': 'confirm',
'title': 'Warning',
Expand All @@ -24,7 +24,7 @@ Sale order alert:
msg = self.env['popup.message'].create(
{
'model_id': self.env['ir.model'].search([('model', '=', 'sale.order')]).id,
'model_id': self.env['ir.model']._get_id('sale.order'),
'field_ids': [(6, 0, self.env['ir.model.fields'].search([('model', '=', 'sale.order')]).ids)],
'popup_type': 'alert',
'title': 'Attention',
Expand Down
12 changes: 6 additions & 6 deletions web_create_write_confirm/static/src/js/pop_up_confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ odoo.define("web_create_write_confirm.pop_up_confirmation", function (require) {
var changes = self.model.localData[self.handle]._changes;
self.getMessageInformation(
modelName,
"get_message_informations",
"get_popup_message_info",
record_id,
changes === null ? {} : changes
).then(function (results) {
this.display_popup(results, record, record_id, ev, changes, modelName);
self.display_popup(results, record, record_id, ev, changes, modelName);
});
},

Expand Down Expand Up @@ -76,7 +76,7 @@ odoo.define("web_create_write_confirm.pop_up_confirmation", function (require) {
} else if (popup_values.length === index) {
self.getMessageInformation(
modelName,
"execute_processing",
"process_popup_message",
record_id,
datas
);
Expand All @@ -90,14 +90,14 @@ odoo.define("web_create_write_confirm.pop_up_confirmation", function (require) {
});
}
} else {
this.save(ev);
self.save(event);
}
});
},

save: function ev() {
save: function ev(event) {
var self = this;
ev.stopPropagation();
event.stopPropagation();
self._disableButtons();
self.saveRecord()
.then(self._enableButtons.bind(self))
Expand Down
4 changes: 2 additions & 2 deletions web_create_write_confirm/tests/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_compute_field_name(self):

def test_get_message_informations(self):
"""Test correct flow of get_message_informations method"""
ret_value_of_method = self.base_model.get_message_informations()
ret_value_of_method = self.base_model.get_popup_message_info()
check_ret_value = False
if (ret_value_of_method is False) or isinstance(
ret_value_of_method, type(self.env["popup.message"])
Expand All @@ -51,5 +51,5 @@ def test_get_message_informations(self):
def test_execute_processing(self):
"""Test correct flow of execute_processing method"""
self.assertFalse(
self.base_model.execute_processing(), msg="Return value must be False"
self.base_model.process_popup_message(), msg="Return value must be False"
)

0 comments on commit 1dd067b

Please sign in to comment.