-
-
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_notify: Add new module to notify user after…
… change picking states
- Loading branch information
1 parent
46f39e5
commit 8627894
Showing
20 changed files
with
542 additions
and
0 deletions.
There are no files selected for viewing
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_notify |
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,133 @@ | ||
========================== | ||
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_notify | ||
: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_notify | ||
: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 | ||
|
||
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_notify%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_notify>`_ 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,21 @@ | ||
# 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/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_notify/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,2 @@ | ||
from . import stock_picking | ||
from . import stock_picking_notification_template |
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) |
115 changes: 115 additions & 0 deletions
115
stock_picking_notify/models/stock_picking_notification_template.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,115 @@ | ||
# Copyright (C) 2024 Cetmix OÜ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
import re | ||
|
||
from odoo import _, fields, models | ||
|
||
|
||
class StockPickingNotificationTemplate(models.Model): | ||
_name = "stock.picking.notification.template" | ||
_description = "Picking Notification Template" | ||
_order = "sequence, id" | ||
_rec_name = "picking_type_id" | ||
|
||
sequence = fields.Integer( | ||
default=10, | ||
string="Priority", | ||
) | ||
active = fields.Boolean( | ||
default=True, | ||
) | ||
picking_type_id = fields.Many2one( | ||
comodel_name="stock.picking.type", | ||
string="Operation Type", | ||
required=True, | ||
help="Operation types for which the notification will be triggered", | ||
) | ||
user_ids = fields.Many2many( | ||
string="Notified Users", | ||
comodel_name="res.users", | ||
relation="picking_notify_template_user_rel", | ||
column1="picking_notify_template_id", | ||
column2="user_id", | ||
required=True, | ||
) | ||
source_document_regex = fields.Char( | ||
string="Source Document Pattern", | ||
help="Notification will be sent if source document name matches " | ||
"the specified regex pattern. Leave blank to match any source", | ||
) | ||
allow_notify_draft = fields.Boolean( | ||
string="Allow Notify DRAFT", | ||
default=False, | ||
) | ||
allow_notify_waiting = fields.Boolean( | ||
string="Allow Notify WAITING ANOTHER OPERATION", | ||
default=False, | ||
) | ||
allow_notify_confirmed = fields.Boolean( | ||
string="Allow notify WAITING", | ||
default=True, | ||
) | ||
allow_notify_assigned = fields.Boolean( | ||
string="Allow notify READY", | ||
default=True, | ||
) | ||
allow_notify_done = fields.Boolean( | ||
string="Allow notify DONE", | ||
default=False, | ||
) | ||
allow_notify_cancel = fields.Boolean( | ||
string="Allow notify CANCEL", | ||
default=False, | ||
) | ||
message = fields.Text( | ||
string="Custom Message", | ||
help="Custom message to be used instead of the default one. " | ||
"Leave blank to use the default message", | ||
) | ||
|
||
def _get_matching_template(self, picking): | ||
""" | ||
Return the first matching notification template for the given picking. | ||
""" | ||
templates = self.search( | ||
[ | ||
("picking_type_id", "=", picking.picking_type_id.id), | ||
(f"allow_notify_{picking.state}", "=", True), | ||
], | ||
order="sequence ASC", | ||
) | ||
for template in templates: | ||
if template._matches_picking(picking): | ||
return template | ||
return None | ||
|
||
def _matches_picking(self, picking): | ||
""" | ||
Check if the picking matches this notification template. | ||
""" | ||
if self.source_document_regex and not re.match( | ||
self.source_document_regex, picking.origin or "" | ||
): | ||
return False | ||
|
||
return True | ||
|
||
def _notify_picking_users(self, picking): | ||
""" | ||
Send notifications to the users about the picking. | ||
""" | ||
self.ensure_one() | ||
return self.user_ids.sudo().notify_info( | ||
message=self.message or _("New picking created."), | ||
title=picking.name, | ||
sticky=True, | ||
action={ | ||
"type": "ir.actions.act_window", | ||
"name": picking.name, | ||
"res_model": "stock.picking", | ||
"res_id": picking.id, | ||
"view_mode": "form", | ||
"view_type": "form", | ||
"target": "current", | ||
}, | ||
) |
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,15 @@ | ||
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 |
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 @@ | ||
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**. |
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 @@ | ||
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. |
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,5 @@ | ||
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 |
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 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_picking_notification_template_group_stock_user,access_stock_picking_notify group_stock_user,model_stock_picking_notification_template,stock.group_stock_user,1,0,0,0 | ||
access_picking_notification_template_group_stock_manager,access_stock_picking_notify group_stock_manager,model_stock_picking_notification_template,stock.group_stock_manager,1,1,1,1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,8 @@ | ||
<section class="oe_container"> | ||
<div class="oe_row oe_spaced"> | ||
<div class="oe_span12"> | ||
<h2 class="oe_slogan">Notify Users about Picking</h2> | ||
<p>Notify selected internal users of changes in picking states.</p> | ||
</div> | ||
</div> | ||
</section> |
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 test_notification_template |
Oops, something went wrong.