diff --git a/README.md b/README.md index 0c94c22dc..9e7033cf7 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ addon | version | maintainers | summary [edi_core_oca](edi_core_oca/) | 19.0.1.2.2 | simahawk etobella | Define backends, exchange types, exchange records, basic automation and views for handling EDI exchanges. [edi_endpoint_oca](edi_endpoint_oca/) | 19.0.1.1.1 | | Base module allowing configuration of custom endpoints for EDI framework. [edi_exchange_deduplicate_oca](edi_exchange_deduplicate_oca/) | 19.0.1.1.0 | simahawk etobella | Introduce a deduplication mechanism at the sending step +[edi_notification_oca](edi_notification_oca/) | 19.0.1.0.0 | | Define notification activities on exchange records. [edi_product_oca](edi_product_oca/) | 19.0.1.0.0 | | EDI framework configuration and base logic for products and units of measure [edi_purchase_oca](edi_purchase_oca/) | 19.0.1.0.0 | | Define EDI Configuration for Purchase Orders [edi_queue_oca](edi_queue_oca/) | 19.0.1.0.0 | | Set Queue Jobs on EDI diff --git a/edi_notification_oca/README.rst b/edi_notification_oca/README.rst new file mode 100644 index 000000000..0a555f8d4 --- /dev/null +++ b/edi_notification_oca/README.rst @@ -0,0 +1,118 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +================ +EDI Notification +================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:336ed83d634ebf124c8ec0d6eca3911e74efbb0ee5b720825f37a4e48f703a0c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi--framework-lightgray.png?logo=github + :target: https://github.com/OCA/edi-framework/tree/19.0/edi_notification_oca + :alt: OCA/edi-framework +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/edi-framework-19-0/edi-framework-19-0-edi_notification_oca + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/edi-framework&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module creates activities for users when an exchange record's +process fails. + +It also installs an ``edi.configuration`` rule +(``Notify Users On Exchange Error``) that calls +``edi.notification.tool`` on process errors. + +Exchange types must be configured properly to create such activities: + +- field "Notify On Process Error" must be checked to activate the + feature for the current exchange type +- field "Activity Type Used When Notify On Process Error" is used to + define the type of the newly created activity +- fields "Notify Groups On Process Error" and "Notify Users On Process + Error" are used to define the users that will be assigned to the newly + created activity + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +The module provides an ``edi.configuration`` entry named +``Notify Users On Exchange Error``. + +You can review or adapt this configuration under EDI configurations if +you need to change the trigger behavior or the executed snippets. + +To enable notifications for a specific exchange type: + +- enable *Notify On Process Error* +- select an activity type in *Activity Type Used When Notify On Process + Error* +- assign recipients with *Notify Groups On Process Error* and/or *Notify + Users On Process Error* + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- Duong (Tran Quoc) +- Simone Orsi + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/edi-framework `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/edi_notification_oca/__init__.py b/edi_notification_oca/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/edi_notification_oca/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/edi_notification_oca/__manifest__.py b/edi_notification_oca/__manifest__.py new file mode 100644 index 000000000..2d3204b2b --- /dev/null +++ b/edi_notification_oca/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 Camptocamp SA +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "EDI Notification", + "summary": """Define notification activities on exchange records.""", + "version": "19.0.1.0.0", + "development_status": "Alpha", + "license": "LGPL-3", + "website": "https://github.com/OCA/edi-framework", + "author": "Camptocamp,Odoo Community Association (OCA)", + "depends": ["edi_core_oca"], + "data": [ + "data/mail_activity_type.xml", + "data/edi_configuration.xml", + "views/edi_exchange_type.xml", + ], + "installable": True, +} diff --git a/edi_notification_oca/data/edi_configuration.xml b/edi_notification_oca/data/edi_configuration.xml new file mode 100644 index 000000000..425d37668 --- /dev/null +++ b/edi_notification_oca/data/edi_configuration.xml @@ -0,0 +1,20 @@ + + + + Notify Users On Exchange Error + + Schedule activities for configured users/groups on EDI process errors. + + True + + +exc_type = record.type_id +result = { + "todo": exc_type.notify_on_process_error_enabled +} + + +result = env["edi.notification.tool"].on_edi_exchange_error(record) + + + diff --git a/edi_notification_oca/data/mail_activity_type.xml b/edi_notification_oca/data/mail_activity_type.xml new file mode 100644 index 000000000..7fa92c0d4 --- /dev/null +++ b/edi_notification_oca/data/mail_activity_type.xml @@ -0,0 +1,12 @@ + + + + EDI Exchange Record: Failed + fa-warning + edi.exchange.record + warning + + diff --git a/edi_notification_oca/i18n/edi_notification_oca.pot b/edi_notification_oca/i18n/edi_notification_oca.pot new file mode 100644 index 000000000..a26531e33 --- /dev/null +++ b/edi_notification_oca/i18n/edi_notification_oca.pot @@ -0,0 +1,173 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * edi_notification_oca +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.0\n" +"Report-Msgid-Bugs-To: \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: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_ids +msgid "Activities" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_exception_decoration +msgid "Activity Exception Decoration" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_state +msgid "Activity State" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_type_icon +msgid "Activity Type Icon" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_type__notify_on_process_error_activity_type_id +msgid "Activity Type Used When Notify On Process Error" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__display_name +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_type__display_name +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_notification_tool__display_name +msgid "Display Name" +msgstr "" + +#. module: edi_notification_oca +#: model:mail.activity.type,name:edi_notification_oca.mail_activity_failed_exchange_record_warning +msgid "EDI Exchange Record: Failed" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model,name:edi_notification_oca.model_edi_exchange_type +msgid "EDI Exchange Type" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model,name:edi_notification_oca.model_edi_notification_tool +msgid "EDI Notification Tool" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model,name:edi_notification_oca.model_edi_exchange_record +msgid "EDI exchange Record" +msgstr "" + +#. module: edi_notification_oca +#. odoo-python +#: code:addons/edi_notification_oca/models/edi_notification_tool.py:0 +msgid "EDI: Process error on record '%(identifier)s'." +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_record__activity_type_icon +msgid "Font awesome icon e.g. fa-tasks" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__id +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_type__id +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_notification_tool__id +msgid "ID" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_exception_icon +msgid "Icon" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_record__activity_exception_icon +msgid "Icon to indicate an exception activity." +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_type__notify_on_process_error +msgid "" +"If an error happens on process, a notification will be sent to all selected " +"users. If active, please select the specific groups and specific users in " +"the 'Notifications' page." +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__my_activity_date_deadline +msgid "My Activity Deadline" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_date_deadline +msgid "Next Activity Deadline" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_summary +msgid "Next Activity Summary" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_type_id +msgid "Next Activity Type" +msgstr "" + +#. module: edi_notification_oca +#: model_terms:ir.ui.view,arch_db:edi_notification_oca.edi_exchange_type_view_form +msgid "Notification" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_type__notify_on_process_error_groups_ids +msgid "Notify Groups On Process Error" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_type__notify_on_process_error +msgid "Notify On Process Error" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_type__notify_on_process_error_enabled +msgid "Notify On Process Error Enabled" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_type__notify_on_process_error_users_ids +msgid "Notify Users On Process Error" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_user_id +msgid "Responsible User" +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_type__notify_on_process_error_users_ids +msgid "" +"Select users to send notifications to. If 'Notification Groups' have been " +"selected, notifications will also be sent to users selected in here." +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_record__activity_state +msgid "" +"Status based on activities\n" +"Overdue: Due date is already passed\n" +"Today: Activity date is today\n" +"Planned: Future activities." +msgstr "" + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_record__activity_exception_decoration +msgid "Type of the exception activity on record." +msgstr "" diff --git a/edi_notification_oca/i18n/it.po b/edi_notification_oca/i18n/it.po new file mode 100644 index 000000000..5a02a680f --- /dev/null +++ b/edi_notification_oca/i18n/it.po @@ -0,0 +1,163 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * edi_notification_oca +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-09-10 14:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_ids +msgid "Activities" +msgstr "Attività" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_exception_decoration +msgid "Activity Exception Decoration" +msgstr "Decorazione eccezione attività" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_state +msgid "Activity State" +msgstr "Stato attività" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_type_icon +msgid "Activity Type Icon" +msgstr "Icona tipo attività" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_type__notify_on_process_error_activity_type_id +msgid "Activity Type Used When Notify On Process Error" +msgstr "Tipo attività utilizzata nelle notifiche di errori di processo" + +#. module: edi_notification_oca +#: model:mail.activity.type,name:edi_notification_oca.mail_activity_failed_exchange_record_warning +msgid "EDI Exchange Record: Failed" +msgstr "Record scambio EDI: fallito" + +#. module: edi_notification_oca +#: model:ir.model,name:edi_notification_oca.model_edi_exchange_type +msgid "EDI Exchange Type" +msgstr "Tipo scambio EDI" + +#. module: edi_notification_oca +#: model:ir.model,name:edi_notification_oca.model_edi_exchange_record +msgid "EDI exchange Record" +msgstr "Record di scambio EDI" + +#. module: edi_notification_oca +#. odoo-python +#: code:addons/edi_notification_oca/components/listener.py:0 +#, python-format +msgid "EDI: Process error on record '%(identifier)s'." +msgstr "EDI: errore di processo nel record '%(identifier)s'." + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_record__activity_type_icon +msgid "Font awesome icon e.g. fa-tasks" +msgstr "Icona Font Awesome es. fa-tasks" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_exception_icon +msgid "Icon" +msgstr "Icona" + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_record__activity_exception_icon +msgid "Icon to indicate an exception activity." +msgstr "Icona per indicare un'attività eccezione." + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_type__notify_on_process_error +msgid "" +"If an error happens on process, a notification will be sent to all selected " +"users. If active, please select the specific groups and specific users in " +"the 'Notifications' page." +msgstr "" +"Se si verifica un errore durante il processo, verrà inviata una notifica a " +"tutti gli utenti selezionati. Se attiva, selezionare i gruppi e gli utenti " +"specifici nella pagina \"Notifiche\"." + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__my_activity_date_deadline +msgid "My Activity Deadline" +msgstr "Scadenza mia attività" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_date_deadline +msgid "Next Activity Deadline" +msgstr "Scadenza prossima attività" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_summary +msgid "Next Activity Summary" +msgstr "Riepilogo prossima attività" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_type_id +msgid "Next Activity Type" +msgstr "Tipo prossima attività" + +#. module: edi_notification_oca +#: model_terms:ir.ui.view,arch_db:edi_notification_oca.edi_exchange_type_view_form +msgid "Notification" +msgstr "Notifica" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_type__notify_on_process_error_groups_ids +msgid "Notify Groups On Process Error" +msgstr "Avvisa i gruppi all'errore di processo" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_type__notify_on_process_error +msgid "Notify On Process Error" +msgstr "Avvisa all'errore di processo" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_type__notify_on_process_error_users_ids +msgid "Notify Users On Process Error" +msgstr "Avvisa gli utenti all'errore di processo" + +#. module: edi_notification_oca +#: model:ir.model.fields,field_description:edi_notification_oca.field_edi_exchange_record__activity_user_id +msgid "Responsible User" +msgstr "Utente responsabile" + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_type__notify_on_process_error_users_ids +msgid "" +"Select users to send notifications to. If 'Notification Groups' have been " +"selected, notifications will also be sent to users selected in here." +msgstr "" +"Seleziona gli utenti a cui inviare le notifiche. Se sono stati selezionati " +"'Gruppi di notifica', le notifiche saranno inviate anche agli utenti " +"selezionati qui." + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_record__activity_state +msgid "" +"Status based on activities\n" +"Overdue: Due date is already passed\n" +"Today: Activity date is today\n" +"Planned: Future activities." +msgstr "" +"Stato in base alle attività\n" +"Scaduto: la data richiesta è trascorsa\n" +"Oggi: la data attività è oggi\n" +"Pianificato: attività future." + +#. module: edi_notification_oca +#: model:ir.model.fields,help:edi_notification_oca.field_edi_exchange_record__activity_exception_decoration +msgid "Type of the exception activity on record." +msgstr "Tipo di attività eccezione sul record." diff --git a/edi_notification_oca/models/__init__.py b/edi_notification_oca/models/__init__.py new file mode 100644 index 000000000..d02f28d9f --- /dev/null +++ b/edi_notification_oca/models/__init__.py @@ -0,0 +1,3 @@ +from . import edi_exchange_type +from . import edi_exchange_record +from . import edi_notification_tool diff --git a/edi_notification_oca/models/edi_exchange_record.py b/edi_notification_oca/models/edi_exchange_record.py new file mode 100644 index 000000000..e6b48bc68 --- /dev/null +++ b/edi_notification_oca/models/edi_exchange_record.py @@ -0,0 +1,9 @@ +# Copyright 2024 Camptocamp SA +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import models + + +class EDIExchangeRecord(models.Model): + _name = "edi.exchange.record" + _inherit = ["edi.exchange.record", "mail.activity.mixin"] diff --git a/edi_notification_oca/models/edi_exchange_type.py b/edi_notification_oca/models/edi_exchange_type.py new file mode 100644 index 000000000..acea88e56 --- /dev/null +++ b/edi_notification_oca/models/edi_exchange_type.py @@ -0,0 +1,72 @@ +# Copyright 2024 Camptocamp SA +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import Command, api, fields, models + + +class EDIExchangeType(models.Model): + _inherit = "edi.exchange.type" + + notify_on_process_error = fields.Boolean( + help="If an error happens on process, a notification will be sent to all" + " selected users. If active, please select the specific groups and" + " specific users in the 'Notifications' page.", + default=False, + ) + notify_on_process_error_groups_ids = fields.Many2many( + comodel_name="res.groups", + string="Notify Groups On Process Error", + inverse="_inverse_notify_on_process_error_groups_users", + ) + notify_on_process_error_users_ids = fields.Many2many( + comodel_name="res.users", + string="Notify Users On Process Error", + inverse="_inverse_notify_on_process_error_groups_users", + help="Select users to send notifications to." + " If 'Notification Groups' have been selected, notifications will also be sent" + " to users selected in here.", + ) + notify_on_process_error_activity_type_id = fields.Many2one( + "mail.activity.type", + string="Activity Type Used When Notify On Process Error", + default=lambda self: self._default_notify_on_process_error_activity_type_id(), + ) + notify_on_process_error_enabled = fields.Boolean( + compute="_compute_notify_on_process_error_enabled", + ) + + @api.depends( + "notify_on_process_error", + "notify_on_process_error_activity_type_id", + "notify_on_process_error_groups_ids", + "notify_on_process_error_users_ids", + ) + def _compute_notify_on_process_error_enabled(self): + for rec in self: + rec.notify_on_process_error_enabled = bool( + rec.notify_on_process_error + and rec.notify_on_process_error_activity_type_id + and ( + rec.notify_on_process_error_groups_ids + or rec.notify_on_process_error_users_ids + ) + ) + + def _default_notify_on_process_error_activity_type_id(self): + return self.env.ref( + "edi_notification_oca.mail_activity_failed_exchange_record_warning", False + ) + + @api.onchange("notify_on_process_error") + def _onchange_notify_on_process_error(self): + if not self.notify_on_process_error: + self.notify_on_process_error_groups_ids = [Command.clear()] + self.notify_on_process_error_users_ids = [Command.clear()] + + def _inverse_notify_on_process_error_groups_users(self): + for rec in self: + if ( + rec.notify_on_process_error_groups_ids + or rec.notify_on_process_error_users_ids + ): + rec.notify_on_process_error = True diff --git a/edi_notification_oca/models/edi_notification_tool.py b/edi_notification_oca/models/edi_notification_tool.py new file mode 100644 index 000000000..c9d5605b7 --- /dev/null +++ b/edi_notification_oca/models/edi_notification_tool.py @@ -0,0 +1,38 @@ +# Copyright 2024 Camptocamp SA +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import models + + +class EDINotificationTool(models.AbstractModel): + _name = "edi.notification.tool" + _description = "EDI Notification Tool" + + def on_edi_exchange_error(self, exchange_record): + """Schedule notification activities for a failed exchange record. + + This hook is intended to be called by an ``edi.configuration`` snippet + (see ``edi_notification_oca/data/edi_configuration.xml``) when an + exchange record process ends in error. + """ + exchange_record.ensure_one() + exc_type = exchange_record.type_id + activity_type = exc_type.notify_on_process_error_activity_type_id + groups = exc_type.notify_on_process_error_groups_ids + group_users_field = "users" if "users" in groups._fields else "user_ids" + users = ( + groups.mapped(group_users_field) + | exc_type.notify_on_process_error_users_ids + ) + for user in users: + exchange_record.activity_schedule( + activity_type_id=activity_type.id, + summary=self.env._( + "EDI: Process error on record '%(identifier)s'.", + identifier=exchange_record.identifier, + ), + note=exchange_record.exchange_error, + user_id=user.id, + automated=True, + ) + return True diff --git a/edi_notification_oca/pyproject.toml b/edi_notification_oca/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/edi_notification_oca/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/edi_notification_oca/readme/CONFIGURE.md b/edi_notification_oca/readme/CONFIGURE.md new file mode 100644 index 000000000..4c0ff62ad --- /dev/null +++ b/edi_notification_oca/readme/CONFIGURE.md @@ -0,0 +1,12 @@ +The module provides an ``edi.configuration`` entry named +``Notify Users On Exchange Error``. + +You can review or adapt this configuration under EDI configurations if you need +to change the trigger behavior or the executed snippets. + +To enable notifications for a specific exchange type: + +- enable *Notify On Process Error* +- select an activity type in *Activity Type Used When Notify On Process Error* +- assign recipients with *Notify Groups On Process Error* and/or + *Notify Users On Process Error* diff --git a/edi_notification_oca/readme/CONTRIBUTORS.md b/edi_notification_oca/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..289708028 --- /dev/null +++ b/edi_notification_oca/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Duong (Tran Quoc) \<\> +- Simone Orsi \<\> diff --git a/edi_notification_oca/readme/DESCRIPTION.md b/edi_notification_oca/readme/DESCRIPTION.md new file mode 100644 index 000000000..e4a5be458 --- /dev/null +++ b/edi_notification_oca/readme/DESCRIPTION.md @@ -0,0 +1,13 @@ +This module creates activities for users when an exchange record's process fails. + +It also installs an ``edi.configuration`` rule (``Notify Users On Exchange +Error``) that calls ``edi.notification.tool`` on process errors. + +Exchange types must be configured properly to create such activities: + +- field "Notify On Process Error" must be checked to activate the feature + for the current exchange type +- field "Activity Type Used When Notify On Process Error" is used to define + the type of the newly created activity +- fields "Notify Groups On Process Error" and "Notify Users On Process Error" are used + to define the users that will be assigned to the newly created activity diff --git a/edi_notification_oca/static/description/icon.png b/edi_notification_oca/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/edi_notification_oca/static/description/icon.png differ diff --git a/edi_notification_oca/static/description/index.html b/edi_notification_oca/static/description/index.html new file mode 100644 index 000000000..6fd4b0def --- /dev/null +++ b/edi_notification_oca/static/description/index.html @@ -0,0 +1,466 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

EDI Notification

+ +

Alpha License: LGPL-3 OCA/edi-framework Translate me on Weblate Try me on Runboat

+

This module creates activities for users when an exchange record’s +process fails.

+

It also installs an edi.configuration rule +(Notify Users On Exchange Error) that calls +edi.notification.tool on process errors.

+

Exchange types must be configured properly to create such activities:

+
    +
  • field “Notify On Process Error” must be checked to activate the +feature for the current exchange type
  • +
  • field “Activity Type Used When Notify On Process Error” is used to +define the type of the newly created activity
  • +
  • fields “Notify Groups On Process Error” and “Notify Users On Process +Error” are used to define the users that will be assigned to the newly +created activity
  • +
+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+

The module provides an edi.configuration entry named +Notify Users On Exchange Error.

+

You can review or adapt this configuration under EDI configurations if +you need to change the trigger behavior or the executed snippets.

+

To enable notifications for a specific exchange type:

+
    +
  • enable Notify On Process Error
  • +
  • select an activity type in Activity Type Used When Notify On Process +Error
  • +
  • assign recipients with Notify Groups On Process Error and/or Notify +Users On Process Error
  • +
+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

This module is part of the OCA/edi-framework project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/edi_notification_oca/tests/__init__.py b/edi_notification_oca/tests/__init__.py new file mode 100644 index 000000000..ab8b6e8bd --- /dev/null +++ b/edi_notification_oca/tests/__init__.py @@ -0,0 +1 @@ +from . import test_edi_notification diff --git a/edi_notification_oca/tests/test_edi_notification.py b/edi_notification_oca/tests/test_edi_notification.py new file mode 100644 index 000000000..d78c7e5d9 --- /dev/null +++ b/edi_notification_oca/tests/test_edi_notification.py @@ -0,0 +1,145 @@ +# Copyright 2024 Camptocamp SA +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + + +import base64 + +from odoo import Command +from odoo.tests.common import RecordCapturer + +from odoo.addons.edi_core_oca.tests.common import EDIBackendCommonTestCase + + +class TestEDINotification(EDIBackendCommonTestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls._setup_env() + vals = { + "model": cls.partner._name, + "res_id": cls.partner.id, + "exchange_file": base64.b64encode(b"1234"), + } + cls.record = cls.backend.create_record("test_csv_input", vals) + cls.group_portal = cls.env.ref("base.group_portal") + cls.user_a = cls._create_user("A") + cls.user_b = cls._create_user("B") + cls.user_c = cls._create_user("C") + + @classmethod + def _create_user(cls, letter: str): + return ( + cls.env["res.users"] + .with_context(no_reset_password=True) + .create( + { + "name": f"User {letter}", + "login": f"user_{letter}", + "group_ids": [Command.set([cls.group_portal.id])], + } + ) + ) + + def _trigger_process_error(self, message="OOPS! Something went wrong :("): + self.record.exchange_error = message + self.record._notify_error("process_ko") + + def test_inverse_notify_on_process_error(self): + self.exchange_type_in.notify_on_process_error = False + # If we forgot to enable notify_on_process_error + self.exchange_type_in.write( + { + "notify_on_process_error_groups_ids": [ + Command.set([self.group_portal.id]) + ], + "notify_on_process_error_users_ids": [Command.set([self.user_c.id])], + } + ) + # Make sure notify_on_process_error should be enabled + self.assertTrue(self.exchange_type_in.notify_on_process_error) + + def test_dont_notify_on_process_error(self): + self.exchange_type_in.notify_on_process_error = False + with RecordCapturer(self.env["mail.activity"], []) as capture: + self._trigger_process_error() + self.assertIn("OOPS! Something went wrong :(", self.record.exchange_error) + # We don't expect any notification + self.assertEqual(len(capture.records), 0) + + def test_notify_on_process_error_to_group(self): + self.exchange_type_in.write( + { + "notify_on_process_error": True, + "notify_on_process_error_groups_ids": [ + Command.set([self.group_portal.id]) + ], + } + ) + # Remove group on user C to test + self.user_c.group_ids = [Command.clear()] + with RecordCapturer(self.env["mail.activity"], []) as capture: + # Send notification to all users in defined groups when error + self._trigger_process_error() + a_noti = capture.records.filtered(lambda x: x.user_id == self.user_a) + self.assertEqual(len(a_noti), 1) + self.assertEqual( + a_noti.summary, + f"EDI: Process error on record '{self.record.identifier}'.", + ) + self.assertIn("OOPS! Something went wrong :(", a_noti.note) + b_noti = capture.records.filtered(lambda x: x.user_id == self.user_b) + self.assertEqual(len(b_noti), 1) + self.assertEqual( + b_noti.summary, + f"EDI: Process error on record '{self.record.identifier}'.", + ) + # We don't send notification to user C + # because C is not belonging to the group_portal + self.assertIn("OOPS! Something went wrong :(", b_noti.note) + c_noti = capture.records.filtered(lambda x: x.user_id == self.user_c) + self.assertEqual(len(c_noti), 0) + + def test_notify_on_process_error_to_users(self): + self.exchange_type_in.write( + { + "notify_on_process_error": True, + "notify_on_process_error_users_ids": [Command.set([self.user_c.id])], + } + ) + with RecordCapturer(self.env["mail.activity"], []) as capture: + # Send notification to all users in defined users when error + self._trigger_process_error() + a_b_noti = capture.records.filtered( + lambda x: x.user_id in (self.user_a | self.user_b) + ) + self.assertEqual(len(a_b_noti), 0) + c_noti = capture.records.filtered(lambda x: x.user_id == self.user_c) + self.assertEqual(len(c_noti), 1) + self.assertEqual( + c_noti.summary, + f"EDI: Process error on record '{self.record.identifier}'.", + ) + self.assertIn("OOPS! Something went wrong :(", c_noti.note) + + def test_notify_on_process_error_to_groups_and_users(self): + self.exchange_type_in.write( + { + "notify_on_process_error": True, + "notify_on_process_error_groups_ids": [ + Command.set([self.group_portal.id]) + ], + "notify_on_process_error_users_ids": [Command.set([self.user_c.id])], + } + ) + # Remove group on user C to test + self.user_c.group_ids = [Command.clear()] + with RecordCapturer(self.env["mail.activity"], []) as capture: + # Send notification to all users in defined users when error + self._trigger_process_error() + a_b_noti = capture.records.filtered( + lambda x: x.user_id in (self.user_a | self.user_b) + ) + self.assertEqual(len(a_b_noti), 2) + # also send notification to user C + c_noti = capture.records.filtered(lambda x: x.user_id == self.user_c) + self.assertEqual(len(c_noti), 1) diff --git a/edi_notification_oca/views/edi_exchange_type.xml b/edi_notification_oca/views/edi_exchange_type.xml new file mode 100644 index 000000000..058cf7311 --- /dev/null +++ b/edi_notification_oca/views/edi_exchange_type.xml @@ -0,0 +1,36 @@ + + + + edi.exchange.type + + + + + + + + + + + + + + + + + diff --git a/setup/_metapackage/pyproject.toml b/setup/_metapackage/pyproject.toml index 6971a1cc7..b2cced5ad 100644 --- a/setup/_metapackage/pyproject.toml +++ b/setup/_metapackage/pyproject.toml @@ -1,11 +1,12 @@ [project] name = "odoo-addons-oca-edi-framework" -version = "19.0.20260610.0" +version = "19.0.20260611.0" dependencies = [ "odoo-addon-edi_component_oca==19.0.*", "odoo-addon-edi_core_oca==19.0.*", "odoo-addon-edi_endpoint_oca==19.0.*", "odoo-addon-edi_exchange_deduplicate_oca==19.0.*", + "odoo-addon-edi_notification_oca==19.0.*", "odoo-addon-edi_product_oca==19.0.*", "odoo-addon-edi_purchase_oca==19.0.*", "odoo-addon-edi_queue_oca==19.0.*",