-
-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[16.0][NEW] stock_picking_status_notification: Add new module to noti…
…fy user after change picking states
- Loading branch information
1 parent
46f39e5
commit 9e417fa
Showing
23 changed files
with
766 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
setup/stock_picking_status_notification/odoo/addons/stock_picking_status_notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../stock_picking_status_notification |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
========================== | ||
Notify Users about Picking | ||
========================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:584e6579cf1f7315aeb3162a9b846dc43e8cb3d7a0f432b774fb822db18f43e1 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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%2Fstock--logistics--workflow-lightgray.png?logo=github | ||
:target: https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_status_notification | ||
:alt: OCA/stock-logistics-workflow | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-16-0/stock-logistics-workflow-16-0-stock_picking_status_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/stock-logistics-workflow&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to send notifications to selected backend users when | ||
the state of stock picking changes . For this configurable notification | ||
rules are used. Rules are checked using flexible patterns. The first one | ||
rule matching the pattern is triggered. | ||
|
||
By default notifications are sent when a picking is set to the "Waiting" | ||
or "Ready" status. However you can enable notifications for other | ||
pickings too. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Use Cases / Context | ||
=================== | ||
|
||
Imagine you have a warehouse that is serving a retail store and online | ||
shop. | ||
|
||
Each time a sale is done in the retail shop you would like to process | ||
that order immediately. For this you need to notify selected employees | ||
about such order so that they could switch to it **asap**. | ||
|
||
Configuration | ||
============= | ||
|
||
To configure notification rules: | ||
|
||
- Go to | ||
``"Inventory -> Configuration -> Warehouse Management -> New Picking Notifications"`` | ||
and create a new notification | ||
- Put the following data in the notification form: | ||
|
||
- ``Priority``. Defines the order in which notification rules are | ||
checked. The lower is the number the higher is the priority. | ||
Default is ``10`` | ||
- ``Operation Types``, required. Specifies the operation types for | ||
which this notification will be triggered | ||
- ``Notified Users``, required. List of users to be notified | ||
- ``Source Document Pattern``, optional. Notification will be sent | ||
if source document name matches the specified regex pattern. Leave | ||
blank to match any source | ||
- ``Custom Message``, optional. Custom message to be used instead of | ||
the default one. Leave blank to use the default message | ||
- ``Allow Notify DRAFT`` - optional. If enabled, notifications will | ||
be sent when a picking is in the "Draft" state | ||
- ``Allow Notify WAITING ANOTHER OPERATION`` - optional. If enabled, | ||
notifications will be sent when a picking is in the "Waiting | ||
Another Operation" state | ||
- ``Allow notify WAITIN`` - optional. If enabled, notifications will | ||
be sent when a picking is in the "WAITING" state | ||
- ``Allow notify READY`` - optional. If enabled, notifications will | ||
be sent when a picking is in the "READY" state. | ||
- ``Allow notify DONE`` - optional. If enabled, notifications will | ||
be sent when a picking is in the "Done" state. | ||
- ``Allow notify CANCEL`` - optional. If enabled, notifications will | ||
be sent when a picking is in the "Cancelled" state | ||
|
||
- Go to | ||
``"Inventory -> Configuration -> Settings -> Notification -> UPLOAD YOUR FILE"`` | ||
and upload your notification sound. | ||
|
||
Usage | ||
===== | ||
|
||
When a new picking is created and this picking matches some notification | ||
rule a notification will be shown for selected users: | ||
|
||
- Document number in the notification title | ||
- Message text in the notification body | ||
- "Open document" button. Click it to open the related document | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/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 <https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_status_notification%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
------- | ||
|
||
* Cetmix | ||
|
||
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/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/16.0/stock_picking_status_notification>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (C) 2024 Cetmix OÜ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Notify Users about Picking", | ||
"version": "16.0.1.0.0", | ||
"category": "Inventory/Inventory", | ||
"summary": "Notify selected internal users of changes in picking states", | ||
"depends": ["stock", "web_notify"], | ||
"website": "https://github.com/OCA/stock-logistics-workflow", | ||
"author": "Cetmix, Odoo Community Association (OCA)", | ||
"installable": True, | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/res_config_settings_view.xml", | ||
"views/stock_picking_notification_template_view.xml", | ||
"views/menuitems.xml", | ||
], | ||
"demo": [ | ||
"demo/stock_picking_notification_template_demo.xml", | ||
], | ||
"license": "AGPL-3", | ||
} |
12 changes: 12 additions & 0 deletions
12
stock_picking_status_notification/demo/stock_picking_notification_template_demo.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<record | ||
id="delivery_picking_notification_template" | ||
model="stock.picking.notification.template" | ||
> | ||
<field name="picking_type_id" ref="stock.picking_type_out" /> | ||
<field name="user_ids" eval="[(6, 0, [ref('base.user_admin')])]" /> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import res_config_settings | ||
from . import stock_picking | ||
from . import stock_picking_notification_template |
59 changes: 59 additions & 0 deletions
59
stock_picking_status_notification/models/res_config_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright (C) 2024 Cetmix OÜ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
picking_notification_sound_file = fields.Binary( | ||
string="Notification Sound", | ||
help="Select the sound file that will be used for notifications. This setting " | ||
"allows you to customize the notification sound played when certain actions " | ||
"occur, such as when a stock picking status is updated.", | ||
) | ||
picking_notification_sound_filename = fields.Char( | ||
string="Notification Sound Filename", | ||
) | ||
|
||
@api.model | ||
def set_values(self): | ||
res = super().set_values() | ||
if self.picking_notification_sound_file: | ||
attachment = ( | ||
self.env["ir.attachment"] | ||
.sudo() | ||
.create( | ||
{ | ||
"name": self.picking_notification_sound_filename, | ||
"type": "binary", | ||
"datas": self.picking_notification_sound_file, | ||
} | ||
) | ||
) | ||
self.env["ir.config_parameter"].sudo().set_param( | ||
"stock_picking_status_notification.picking_notification_sound_file", | ||
attachment.id, | ||
) | ||
return res | ||
|
||
@api.model | ||
def get_values(self): | ||
res = super().get_values() | ||
# Retrieve the attachment ID | ||
attachment_id = ( | ||
self.env["ir.config_parameter"] | ||
.sudo() | ||
.get_param( | ||
"stock_picking_status_notification.picking_notification_sound_file" | ||
) | ||
) | ||
if attachment_id: | ||
attachment = self.env["ir.attachment"].sudo().browse(int(attachment_id)) | ||
res.update( | ||
{ | ||
"picking_notification_sound_filename": attachment.name, | ||
} | ||
) | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (C) 2024 Cetmix OÜ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class StockPicking(models.Model): | ||
_inherit = "stock.picking" | ||
|
||
def _write(self, vals): | ||
# We use the _write method instead of write because _write is a low-level implementation | ||
# that bypasses certain restrictions related to computed fields. In this case, it is | ||
# crucial to ensure that notifications are triggered correctly when the state of the | ||
# picking changes, even if this field (state) was computed by dependent fields | ||
res = super()._write(vals) | ||
if "state" in vals: | ||
self.sudo()._trigger_picking_notification() | ||
return res | ||
|
||
def _trigger_picking_notification(self): | ||
""" | ||
Check notification rules and trigger notifications if conditions are met. | ||
""" | ||
notify_template_obj = self.env["stock.picking.notification.template"] | ||
for picking in self: | ||
template = notify_template_obj._get_matching_template(picking) | ||
if template: | ||
template._notify_picking_users(picking) |
Oops, something went wrong.