diff --git a/smart_alert_warning/README.rst b/smart_alert_warning/README.rst new file mode 100644 index 000000000..de3714456 --- /dev/null +++ b/smart_alert_warning/README.rst @@ -0,0 +1,47 @@ +.. image:: https://img.shields.io/badge/license-LGPL--3-green.svg + :target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 + +Smart Alerts +============ +User can see smart alerts on any model based on different conditions set by the admin. + +Configuration +============= +* After installing the module, set the user group, and reload the window. + +Company +------- +* `Cybrosys Techno Solutions `__ + +License +======= +GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) +(https://www.gnu.org/licenses/lgpl-3.0-standalone.html) + +Credits +------- +* Developer: (V15) Mohammed Irfan T, Contact: odoo@cybrosys.com + + +Contacts +-------- +* Mail Contact : odoo@cybrosys.com +* Website : https://cybrosys.com + +Bug Tracker +----------- +Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. + +Maintainer +========== +.. image:: https://cybrosys.com/images/logo.png + :target: https://cybrosys.com + +This module is maintained by Cybrosys Technologies. + +For support and more information, please visit `Our Website `__ + +Further information +=================== +HTML Description: ``__ diff --git a/smart_alert_warning/__init__.py b/smart_alert_warning/__init__.py new file mode 100644 index 000000000..f7a1cde1f --- /dev/null +++ b/smart_alert_warning/__init__.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies() +# Author: Mohammed Irfan T () +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +from . import models +from odoo import api, SUPERUSER_ID + + +def _post_init_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + modules = env['alert.message'].browse(1) + modules.sudo().action_confirm() + + +def _uninstall_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + modules = env['ir.ui.view'].search([('is_alert_boolean', '=', True)]) + for rec in modules: + rec.unlink() diff --git a/smart_alert_warning/__manifest__.py b/smart_alert_warning/__manifest__.py new file mode 100644 index 000000000..64343f87f --- /dev/null +++ b/smart_alert_warning/__manifest__.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies() +# Author: Mohammed Irfan T () +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +{ + 'name': 'Smart Alerts', + 'version': '15.0.1.0.0', + 'category': 'Extra Tools', + 'summary': 'Smart alerts on any model based on different conditions', + 'description': "User can see smart alerts on any model based on different" + " conditions set by the admin.", + 'author': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'website': 'https://www.cybrosys.com', + 'depends': ['base'], + 'data': [ + 'security/smart_alert_warning_groups.xml', + 'security/ir.model.access.csv', + 'views/alert_message_views.xml', + 'views/ir_ui_view_views.xml', + ], + 'demo': [ + 'data/alert_message_data.xml', + ], + 'images': ['static/description/banner.jpg'], + 'license': 'LGPL-3', + 'installable': True, + 'post_init_hook': '_post_init_hook', + 'uninstall_hook': '_uninstall_hook', + 'auto_install': False, + 'application': True, +} diff --git a/smart_alert_warning/data/alert_message_data.xml b/smart_alert_warning/data/alert_message_data.xml new file mode 100644 index 000000000..e632f3da5 --- /dev/null +++ b/smart_alert_warning/data/alert_message_data.xml @@ -0,0 +1,13 @@ + + + + + Draft Alert Message + Your alert record is still in draft. Please change the state. + alert-warning + + + [['state', '=', 'draft']] + + + \ No newline at end of file diff --git a/smart_alert_warning/doc/RELEASE_NOTES.md b/smart_alert_warning/doc/RELEASE_NOTES.md new file mode 100644 index 000000000..4bc7a5903 --- /dev/null +++ b/smart_alert_warning/doc/RELEASE_NOTES.md @@ -0,0 +1,7 @@ +## Module + +#### 22.1.2024 +#### Version 15.0.1.0.0 +#### ADD + +- Initial Commit for Smart Alerts diff --git a/smart_alert_warning/models/__init__.py b/smart_alert_warning/models/__init__.py new file mode 100644 index 000000000..1f3f9ce3d --- /dev/null +++ b/smart_alert_warning/models/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies() +# Author: Mohammed Irfan T () +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +from . import alert_message +from . import ir_ui_view diff --git a/smart_alert_warning/models/alert_message.py b/smart_alert_warning/models/alert_message.py new file mode 100644 index 000000000..e6bb869be --- /dev/null +++ b/smart_alert_warning/models/alert_message.py @@ -0,0 +1,163 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies() +# Author: Mohammed Irfan T () +# +# You can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# (LGPL v3) along with this program. +# If not, see . +# +############################################################################# +import ast +from odoo import api, fields, models, _ +from odoo.exceptions import UserError + +OBJECT_VALS = { + '=': '!=', + '!=': '=', + '>': '<', + '<': '>', + '>=': '<=;', + '<=': '>=;', + 'ilike': 'not in', + 'not ilike': 'in', + 'in': 'not in', + 'not in': 'in' +} + + +class AlertMessage(models.Model): + """ + This class used to create the smart alert warnings + """ + _name = 'alert.message' + _description = 'Alert Message' + + name = fields.Char(string='Name', required=True, + help="Name for the smart alert warning") + document_type_id = fields.Many2one('ir.model', required=True, + help="Choose the model in which where " + "you need to show the warning", + string="Document Type", + ondelete='cascade') + group_id = fields.Many2one('res.groups', + help="Choose which user groups need to see " + "the warnings", string="Group") + alert_messages = fields.Char(string='Alert Message', required=True, + help='Alert message that will show ' + 'in the view.') + type = fields.Selection([('alert-primary', 'Alert Primary'), + ('alert-secondary', 'Alert Secondary'), + ('alert-success', 'Alert Success'), + ('alert-danger', 'Alert Danger'), + ('alert-warning', 'Alert Warning'), + ('alert-info', 'Alert Info')], + required=True, help='Type of alert message', + string="Type") + model_name = fields.Char(string="Model Name", help="name of selected " + "model", + related="document_type_id.model") + field_filter = fields.Char(default="[]", + help="Add any filtration if you need to show" + " the warning messages", + string="Field Filter") + view_id = fields.Many2one('ir.ui.view', required=True, + domain='[("model", "=", model_name), ' + '("type", "=", "form"), ' + '("is_alert_boolean", "=", False)]', + help="Choose the view in which the alert need " + "to show", string='View') + new_view_id = fields.Many2one('ir.ui.view', + string="Created New view Id", + readonly=True, + help="To generate the view id of newly " + "created record") + state = fields.Selection( + [('draft', 'Draft'), ('done', 'Done')], + default="draft", help="Stages of the record", string="State") + is_edit_mode = fields.Boolean(string="Is Edit", + help="To check is it is in edit mode") + + def action_confirm(self): + """ + This method is responsible for creating a new record and related + view based on provided parameters and conditions. + + It performs the following actions: + - Deletes the existing new_view_id if it exists. + - Retrieves model and model_view based on document_type_id and + view_id. + - Constructs an XML snippet (arch) for the view with dynamic + attributes. + - Attempts to create the new view and updates related fields. + + :return: The ID of the newly created view. + """ + if self.new_view_id: + self.new_view_id.unlink() + model_view = self.view_id + class_name = 'alert ' + self.type + xml_id = '' + if self.group_id.id: + xml_ids = self.group_id.get_external_id() + xml_id = xml_ids.get(self.group_id.id) + filter = ast.literal_eval(self.field_filter) + for i in range(len(filter)): + if filter[i] == '&': + filter[i] = '|' + elif filter[i] == '|': + filter[i] = '&' + else: + filter_list = list(filter[i]) + filter_list[1] = OBJECT_VALS[filter[i][1]] + filter[i] = tuple(filter_list) + invisible_filter = str(filter).replace("'", '"') + arch = '' + arch += '