diff --git a/sale_channel_notification/README.rst b/sale_channel_notification/README.rst new file mode 100644 index 00000000..2d9e9c30 --- /dev/null +++ b/sale_channel_notification/README.rst @@ -0,0 +1,76 @@ +========================= +Sale Channel Notification +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:4f88f5cef4adddfd9f7c2262daadde531bd4d5e907be63fb53e4b8d8b0838bf9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--channel-lightgray.png?logo=github + :target: https://github.com/OCA/sale-channel/tree/16.0/sale_channel_notification + :alt: OCA/sale-channel +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-channel-16-0/sale-channel-16-0-sale_channel_notification + :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/sale-channel&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Simple module that adds the posibility to link an email template to an action. + +**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 +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Mathieu Delva + +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/sale-channel `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_channel_notification/__init__.py b/sale_channel_notification/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/sale_channel_notification/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_channel_notification/__manifest__.py b/sale_channel_notification/__manifest__.py new file mode 100644 index 00000000..3f099295 --- /dev/null +++ b/sale_channel_notification/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright 2024 Akretion (https://www.akretion.com). +# @author Mathieu Delva +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Sale Channel Notification", + "summary": "", + "version": "16.0.1.0.1", + "category": "Sale Channel", + "website": "https://github.com/OCA/sale-channel", + "author": "Akretion,Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "external_dependencies": { + "python": [], + "bin": [], + }, + "depends": [ + "sale_channel", + ], + "data": [ + "security/ir.model.access.csv", + "views/sale_channel_notification_view.xml", + ], + "demo": [], +} diff --git a/sale_channel_notification/models/__init__.py b/sale_channel_notification/models/__init__.py new file mode 100644 index 00000000..43ba304f --- /dev/null +++ b/sale_channel_notification/models/__init__.py @@ -0,0 +1,4 @@ +from . import sale_channel_notification +from . import sale_channel +from . import sale_order +from . import stock_picking \ No newline at end of file diff --git a/sale_channel_notification/models/sale_channel.py b/sale_channel_notification/models/sale_channel.py new file mode 100644 index 00000000..757eb2b0 --- /dev/null +++ b/sale_channel_notification/models/sale_channel.py @@ -0,0 +1,35 @@ +# Copyright 2024 Akretion (https://www.akretion.com). +# @author Mathieu Delva +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.tools.translate import _ + + +class SaleChannel(models.Model): + _inherit = "sale.channel" + + notification_ids = fields.One2many( + "sale.channel.notification", + "sale_channel_id", + "Notification", + help="Send mail for predefined events", + ) + + def _send_notification(self, notification, record): + self.ensure_one() + record.ensure_one() + notifs = self.env["sale.channel.notification"].search( + [ + ("sale_channel_id", "=", self.id), + ("notification_type", "=", notification), + ] + ) + description = _("Notify %s for %s,%s") % ( + notification, + record._name, + record.id, + ) + for notif in notifs: + notif.send(record.id) + return True diff --git a/sale_channel_notification/models/sale_channel_notification.py b/sale_channel_notification/models/sale_channel_notification.py new file mode 100644 index 00000000..ddf73149 --- /dev/null +++ b/sale_channel_notification/models/sale_channel_notification.py @@ -0,0 +1,67 @@ +# Copyright 2024 Akretion (https://www.akretion.com). +# @author Mathieu Delva +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.tools.translate import _ + + +class SaleChannelNotification(models.Model): + _name = "sale.channel.notification" + + sale_channel_id = fields.Many2one("sale.channel") + notification_type = fields.Selection( + selection="_selection_notification_type", + string="Notification Type", + required=True, + ) + model_id = fields.Many2one("ir.model", "Model", required=True, ondelete="cascade") + template_id = fields.Many2one("mail.template", "Mail Template", required=True) + + + def _selection_notification_type(self): + notifications = self._get_all_notification() + return [(key, notifications[key]["name"]) for key in notifications] + + def _get_all_notification(self): + return { + "sale_confirmation": { + "name": _("Sale Confirmation"), + "model": "sale.order", + }, + "invoice_open": { + "name": _("Invoice Validated"), + "model": "account.move", + }, + "picking_shipped": { + "name": _("Picking Shipped"), + "model": "stock.picking", + } + } + + + @api.onchange("notification_type") + def on_notification_type_change(self): + self.ensure_one() + notifications = self._get_all_notification() + if self.notification_type: + model = notifications[self.notification_type].get("model") + if model: + self.model_id = self.env["ir.model"].search([("model", "=", model)]) + return {"domain": {"model_id": [("id", "=", self.model_id.id)]}} + else: + return {"domain": {"model_id": []}} + + def send(self, record_id): + self.ensure_one() + return ( + self.sudo() + .template_id.with_context(**self._get_template_context()) + .send_mail(record_id) + ) + + def _get_template_context(self): + return { + "notification_type": self.notification_type, + "sale_channel": self.sale_channel_id, + } \ No newline at end of file diff --git a/sale_channel_notification/models/sale_order.py b/sale_channel_notification/models/sale_order.py new file mode 100644 index 00000000..6b633b51 --- /dev/null +++ b/sale_channel_notification/models/sale_order.py @@ -0,0 +1,26 @@ +# Copyright 2024 Akretion (https://www.akretion.com). +# @author Mathieu Delva +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models +from odoo.tools.translate import _ + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + + def action_confirm(self): + if 'send_email' in self._context and self._context.get('send_email'): + self.env.context = dict(self.env.context) + self.env.context.pop('send_email') + res = super().action_confirm() + for record in self: + if record.state != "draft" and record.sale_channel_id: + record.sale_channel_id._send_notification( + "sale_confirmation", record + ) + return res + + def _get_confirmation_template(self): + return False \ No newline at end of file diff --git a/sale_channel_notification/models/stock_picking.py b/sale_channel_notification/models/stock_picking.py new file mode 100644 index 00000000..6d0de4b4 --- /dev/null +++ b/sale_channel_notification/models/stock_picking.py @@ -0,0 +1,17 @@ +# Copyright 2024 Akretion (https://www.akretion.com). +# @author Mathieu Delva +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.tools.translate import _ + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + @api.onchange("carrier_id") + def onchange_carrier_id(self): + if self.carrier_id and self.sale_id.sale_channel_id: + self.sale_id.sale_channel_id._send_notification( + "picking_shipped", self.env["stock.picking"].browse(self.ids) + ) \ No newline at end of file diff --git a/sale_channel_notification/readme/CONTRIBUTORS.rst b/sale_channel_notification/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..bec244e3 --- /dev/null +++ b/sale_channel_notification/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Mathieu Delva diff --git a/sale_channel_notification/readme/DESCRIPTION.rst b/sale_channel_notification/readme/DESCRIPTION.rst new file mode 100644 index 00000000..287b3f61 --- /dev/null +++ b/sale_channel_notification/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Simple module that adds the posibility to link an email template to an action. diff --git a/sale_channel_notification/security/ir.model.access.csv b/sale_channel_notification/security/ir.model.access.csv new file mode 100644 index 00000000..b5a2e99c --- /dev/null +++ b/sale_channel_notification/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sale_channel_notification,sale_channel_notification,model_sale_channel_notification,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/sale_channel_notification/static/description/index.html b/sale_channel_notification/static/description/index.html new file mode 100644 index 00000000..8f59daf0 --- /dev/null +++ b/sale_channel_notification/static/description/index.html @@ -0,0 +1,423 @@ + + + + + +Sale Channel Notification + + + +
+

Sale Channel Notification

+ + +

Beta License: AGPL-3 OCA/sale-channel Translate me on Weblate Try me on Runboat

+

Simple module that adds the posibility to link an email template to an action.

+

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

+
    +
  • Akretion
  • +
+
+
+

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/sale-channel project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_channel_notification/views/sale_channel_notification_view.xml b/sale_channel_notification/views/sale_channel_notification_view.xml new file mode 100644 index 00000000..fd46e553 --- /dev/null +++ b/sale_channel_notification/views/sale_channel_notification_view.xml @@ -0,0 +1,27 @@ + + + + + sale.channel + + + + + + + + + + + + + + + + + + + diff --git a/setup/sale_channel_notification/odoo/addons/sale_channel_notification b/setup/sale_channel_notification/odoo/addons/sale_channel_notification new file mode 120000 index 00000000..e800f01a --- /dev/null +++ b/setup/sale_channel_notification/odoo/addons/sale_channel_notification @@ -0,0 +1 @@ +../../../../sale_channel_notification \ No newline at end of file diff --git a/setup/sale_channel_notification/setup.py b/setup/sale_channel_notification/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/sale_channel_notification/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)