diff --git a/web_warning_on_save/README.rst b/web_warning_on_save/README.rst new file mode 100644 index 00000000..ce3a7837 --- /dev/null +++ b/web_warning_on_save/README.rst @@ -0,0 +1,78 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Raise warning when saving +========================= + +This module was written to extend the functionality of saving a record in the web interface. + +/!\\/!\\/!\\ + +In no way this module stops the save of the record. You must consider this as a warning displayed +to the user AFTER save completed. + +/!\\/!\\/!\\ + +If you don't want OpenERP to save the record, you should use constraints. + +Usage +===== + +To use this module, you need to: + +* write a method called 'check_warning_on_save' which will make some checks and return a string + +example : + +.. code:: python + + def check_warning_on_save(self, cr, uid, id, context=None): + """ + @param: int: record_id + @return: string: message that should be displayed to the user + """ + res = "" + + record = self.browse(cr, uid, id, context=context) + # ... make some checks + + return res + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + + +Credits +======= + +Contributors +------------ + +* Damien Crier +* Vincent Renaville + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. + diff --git a/web_warning_on_save/__init__.py b/web_warning_on_save/__init__.py new file mode 100644 index 00000000..dde4f90b --- /dev/null +++ b/web_warning_on_save/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import controllers +from . import orm diff --git a/web_warning_on_save/__openerp__.py b/web_warning_on_save/__openerp__.py new file mode 100644 index 00000000..60e538d3 --- /dev/null +++ b/web_warning_on_save/__openerp__.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + "name": "Web warning on save", + "version": "1.0", + "depends": ['web'], + "author": "Camptocamp,Odoo Community Association (OCA)", + 'license': 'AGPL-3', + 'website': 'http://www.camptocamp.com', + 'description': """ + This module was written to extend the functionality of + saving a record in the web interface. + /!\/!\/!\ In no way this module stops the save of the record. + You must consider this as a warning displayed + to the user AFTER save completed. /!\/!\/!\ + If you don't want OpenERP to save the record, you should use constraints. + + Usage + ===== + + To use this module, you need to: + + * write a method called 'check_warning_on_save' which will make some checks + and return a string + + example : + + def check_warning_on_save(self, cr, uid, id, context=None): + ''' + @param: int: record_id + @return: string: message that should be displayed to the user + ''' + res = "" + + record = self.browse(cr, uid, id, context=context) + # ... make some checks + + return res + """, + 'data': [ + ], + 'js': [ + 'static/src/js/web_warning_on_save.js', + ], + 'css': [ + ], + 'qweb': [ + ], + 'installable': True, + 'auto_install': False, +} diff --git a/web_warning_on_save/controllers/__init__.py b/web_warning_on_save/controllers/__init__.py new file mode 100644 index 00000000..7c5f67fb --- /dev/null +++ b/web_warning_on_save/controllers/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import controller diff --git a/web_warning_on_save/controllers/controller.py b/web_warning_on_save/controllers/controller.py new file mode 100644 index 00000000..67336390 --- /dev/null +++ b/web_warning_on_save/controllers/controller.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import xmlrpclib +import openerp + + +class WarningOnSaveController(openerp.addons.web.http.Controller): + _cp_path = "/web_warning_on_save" + + @openerp.addons.web.http.jsonrequest + def check_warning_on_save(self, req, model, id): + """ + try to call a method on the model given in parameter + if method does not exist in the model, do nothing + """ + m = req.session.model(model) + try: + return m.check_warning_on_save(id, req.context) + + except xmlrpclib.Fault as e: + if 'AttributeError' in e.faultString: + return False + else: + raise openerp.osv.osv.except_osv('Error', e.faultCode) diff --git a/web_warning_on_save/i18n/web_warning_on_save.pot b/web_warning_on_save/i18n/web_warning_on_save.pot new file mode 100644 index 00000000..48747415 --- /dev/null +++ b/web_warning_on_save/i18n/web_warning_on_save.pot @@ -0,0 +1,31 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * web_warning_on_save +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-06-08 09:04+0000\n" +"PO-Revision-Date: 2015-06-08 09:04+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_warning_on_save +#: code:_description:0 +#: model:ir.model,name:web_warning_on_save.model_res_users +#, python-format +msgid "Users" +msgstr "" + +#. module: web_warning_on_save +#. openerp-web +#: code:addons/web_warning_on_save/static/src/js/web_warning_on_save.js:18 +#, python-format +msgid "Warning" +msgstr "" + diff --git a/web_warning_on_save/orm.py b/web_warning_on_save/orm.py new file mode 100644 index 00000000..cbaf029a --- /dev/null +++ b/web_warning_on_save/orm.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import orm + + +def check_warning_on_save(self, cr, uid, id, context=None): + return False + +orm.BaseModel.check_warning_on_save = check_warning_on_save diff --git a/web_warning_on_save/static/src/js/web_warning_on_save.js b/web_warning_on_save/static/src/js/web_warning_on_save.js new file mode 100644 index 00000000..7f91baf6 --- /dev/null +++ b/web_warning_on_save/static/src/js/web_warning_on_save.js @@ -0,0 +1,28 @@ +openerp.web_warning_on_save = function (instance) { + + instance.web.FormView.include({ + on_button_save: function(e) { +// inherit method to be able to display an alert if +// method called returns a string + var self = this; + return self._super.apply(this, arguments).done(function(id){ + var model = self.model; + var param = { + 'model': model, + 'id': self.datarecord.id ? self.datarecord.id : id + }; + self.rpc('/web_warning_on_save/check_warning_on_save', param) + .done(function(res) { + if (res != false){ + var dialog = new instance.web.Dialog(this, { + title: _t("Warning"), + width: 850, + }).open(); + dialog.$el.html(res); + } + }); + }) + }, + }); + +};