mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-02 03:30:54 +00:00
Overdue order notification (#3114)
* Adds a background task to notify users when a PurchaseOrder becomes overdue * Schedule the overdue purchaseorder check to occur daily * Allow notifications to be sent to "Owner" instances - Extract user information from the Owner instance * add unit test to ensure notifications are sent for overdue purchase orders * Adds notification for overdue sales orders * Clean up notification display panel - Simplify rendering - Order "newest at top" - Element alignment tweaks * style fixes * More style fixes * Tweak notification padding * Fix import order * Adds task to notify user of overdue build orders * Adds unit tests for build order notifications * Refactor subject line for emails: - Use the configured instance title as a prefix for the subject line * Add email template for overdue build orders * Fix unit tests to accommodate new default value * Logic error fix
This commit is contained in:
@ -2,21 +2,29 @@
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.test import TestCase
|
||||
|
||||
from common.models import InvenTreeSetting
|
||||
import order.tasks
|
||||
from common.models import InvenTreeSetting, NotificationMessage
|
||||
from company.models import Company
|
||||
from InvenTree import status_codes as status
|
||||
from order.models import (SalesOrder, SalesOrderAllocation, SalesOrderLineItem,
|
||||
SalesOrderShipment)
|
||||
from part.models import Part
|
||||
from stock.models import StockItem
|
||||
from users.models import Owner
|
||||
|
||||
|
||||
class SalesOrderTest(TestCase):
|
||||
"""Run tests to ensure that the SalesOrder model is working correctly."""
|
||||
|
||||
fixtures = [
|
||||
'users',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
"""Initial setup for this set of unit tests"""
|
||||
# Create a Company to ship the goods to
|
||||
@ -235,3 +243,20 @@ class SalesOrderTest(TestCase):
|
||||
|
||||
# Shipment should have default reference of '1'
|
||||
self.assertEqual('1', order_2.pending_shipments()[0].reference)
|
||||
|
||||
def test_overdue_notification(self):
|
||||
"""Test overdue sales order notification"""
|
||||
|
||||
self.order.created_by = get_user_model().objects.get(pk=3)
|
||||
self.order.responsible = Owner.create(obj=Group.objects.get(pk=2))
|
||||
self.order.target_date = datetime.now().date() - timedelta(days=1)
|
||||
self.order.save()
|
||||
|
||||
# Check for overdue sales orders
|
||||
order.tasks.check_overdue_sales_orders()
|
||||
|
||||
messages = NotificationMessage.objects.filter(
|
||||
category='order.overdue_sales_order',
|
||||
)
|
||||
|
||||
self.assertEqual(len(messages), 2)
|
||||
|
Reference in New Issue
Block a user