diff --git a/edi_notification_oca/README.rst b/edi_notification_oca/README.rst new file mode 100644 index 000000000..4b005ae12 --- /dev/null +++ b/edi_notification_oca/README.rst @@ -0,0 +1,82 @@ +================ +EDI Notification +================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d8651cf2a0e90d542e65ce8083a2bccffd0b1a3549867bb7a8e91843bd62a770 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/licence-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/18.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-18-0/edi-framework-18-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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module provides sending notification feature when exchange record. + +.. 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: + +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..f24d3e242 --- /dev/null +++ b/edi_notification_oca/__init__.py @@ -0,0 +1,2 @@ +from . import components +from . import models diff --git a/edi_notification_oca/__manifest__.py b/edi_notification_oca/__manifest__.py new file mode 100644 index 000000000..56e8db586 --- /dev/null +++ b/edi_notification_oca/__manifest__.py @@ -0,0 +1,15 @@ +# 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": "18.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_oca"], + "data": ["data/mail_activity_type.xml", "views/edi_exchange_type.xml"], + "installable": True, +} diff --git a/edi_notification_oca/components/__init__.py b/edi_notification_oca/components/__init__.py new file mode 100644 index 000000000..9430369c2 --- /dev/null +++ b/edi_notification_oca/components/__init__.py @@ -0,0 +1 @@ +from . import listener diff --git a/edi_notification_oca/components/listener.py b/edi_notification_oca/components/listener.py new file mode 100644 index 000000000..30945e128 --- /dev/null +++ b/edi_notification_oca/components/listener.py @@ -0,0 +1,44 @@ +# Copyright 2024 Camptocamp SA +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo.addons.component.core import Component + + +class EdiNotificationListener(Component): + _name = "edi.notification.component.listener" + _inherit = "base.event.listener" + + def on_edi_exchange_error(self, record): + exc_type = record.type_id + notify_on_process_error = exc_type.notify_on_process_error + activity_type = exc_type.notify_on_process_error_activity_type_id + if ( + not notify_on_process_error + or not activity_type + or not ( + exc_type.notify_on_process_error_groups_ids + or exc_type.notify_on_process_error_users_ids + ) + ): + return True + users = self._get_users_to_notify(exc_type) + # Send notification to defined users + for user in users: + record.activity_schedule( + activity_type_id=activity_type.id, + summary=self.env._( + "EDI: Process error on record '%(identifier)s'.", + identifier=record.identifier, + ), + note=record.exchange_error, + user_id=user.id, + automated=True, + ) + return True + + def _get_users_to_notify(self, exc_type): + exc_type.ensure_one() + return ( + exc_type.notify_on_process_error_groups_ids.users + | exc_type.notify_on_process_error_users_ids + ) 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..43162d14e --- /dev/null +++ b/edi_notification_oca/i18n/edi_notification_oca.pot @@ -0,0 +1,150 @@ +# 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" +"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: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_exchange_record +msgid "EDI exchange Record" +msgstr "" + +#. 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 "" + +#. 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__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_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..6128f744d --- /dev/null +++ b/edi_notification_oca/models/__init__.py @@ -0,0 +1,2 @@ +from . import edi_exchange_type +from . import edi_exchange_record 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..3f29d606e --- /dev/null +++ b/edi_notification_oca/models/edi_exchange_type.py @@ -0,0 +1,52 @@ +# Copyright 2024 Camptocamp SA +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import 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(), + ) + + 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 = None + self.notify_on_process_error_users_ids = None + + 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/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/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..46a845420 --- /dev/null +++ b/edi_notification_oca/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module provides sending notification feature when exchange record. 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..540ecfbe0 --- /dev/null +++ b/edi_notification_oca/static/description/index.html @@ -0,0 +1,430 @@ + + + + + +EDI Notification + + + +
+

EDI Notification

+ + +

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

+

This module provides sending notification feature when exchange record.

+
+

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

+ +
+

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..cd9ee4f88 --- /dev/null +++ b/edi_notification_oca/tests/test_edi_notification.py @@ -0,0 +1,177 @@ +# Copyright 2024 Camptocamp SA +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + + +import base64 + +from odoo.tests.common import RecordCapturer + +from odoo.addons.edi_oca.tests.common import EDIBackendCommonComponentRegistryTestCase +from odoo.addons.edi_oca.tests.fake_components import FakeInputProcess + + +class TestEDINotification(EDIBackendCommonComponentRegistryTestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls._setup_env() + cls._build_components( + cls, + FakeInputProcess, + ) + cls._load_module_components(cls, "edi_notification_oca") + 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") + + def setUp(self): + super().setUp() + FakeInputProcess.reset_faked() + + @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}", + "groups_id": [(6, 0, [cls.group_portal.id])], + } + ) + ) + + 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": [(6, 0, [self.group_portal.id])], + "notify_on_process_error_users_ids": [(6, 0, [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 + self.record.write({"edi_exchange_state": "input_received"}) + self.record._set_file_content("TEST %d" % self.record.id) + with RecordCapturer(self.env["mail.activity"], []) as capture: + self.record.with_context( + test_break_process="OOPS! Something went wrong :(" + ).action_exchange_process() + self.assertRecordValues( + self.record, + [ + { + "edi_exchange_state": "input_processed_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": [(6, 0, [self.group_portal.id])], + } + ) + # Remove group on user C to test + self.user_c.groups_id = None + self.record.write({"edi_exchange_state": "input_received"}) + self.record._set_file_content("TEST %d" % self.record.id) + with RecordCapturer(self.env["mail.activity"], []) as capture: + self.record.with_context( + test_break_process="OOPS! Something went wrong :(" + ).action_exchange_process() + # Send notification to all users in defined groups when 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(a_noti), 1) + self.assertEqual( + b_noti.summary, + f"EDI: Process error on record '{self.record.identifier}'.", + ) + self.assertIn( + "OOPS! Something went wrong :(", + b_noti.note, + ) + # We don't send notification to user C + # because C is not belonging to the group_portal + 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": [(6, 0, [self.user_c.id])], + } + ) + self.record.write({"edi_exchange_state": "input_received"}) + self.record._set_file_content("TEST %d" % self.record.id) + with RecordCapturer(self.env["mail.activity"], []) as capture: + self.record.with_context( + test_break_process="OOPS! Something went wrong :(" + ).action_exchange_process() + # Send notification to all users in defined users when 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": [(6, 0, [self.group_portal.id])], + "notify_on_process_error_users_ids": [(6, 0, [self.user_c.id])], + } + ) + # Remove group on user C to test + self.user_c.groups_id = None + self.record.write({"edi_exchange_state": "input_received"}) + self.record._set_file_content("TEST %d" % self.record.id) + with RecordCapturer(self.env["mail.activity"], []) as capture: + self.record.with_context( + test_break_process="OOPS! Something went wrong :(" + ).action_exchange_process() + # Send notification to all users in defined users when 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..e052b6eb5 --- /dev/null +++ b/edi_notification_oca/views/edi_exchange_type.xml @@ -0,0 +1,36 @@ + + + + edi.exchange.type + + + + + + + + + + + + + + + + +