mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Adds unit testing for order overdue status
This commit is contained in:
parent
914fe15921
commit
82e6b87e1c
@ -225,21 +225,18 @@ class Build(MPTTModel):
|
||||
blank=True, help_text=_('Extra build notes')
|
||||
)
|
||||
|
||||
@property
|
||||
def is_overdue(self):
|
||||
"""
|
||||
Returns true if this build is "overdue":
|
||||
|
||||
- Not completed
|
||||
- Target date is "in the past"
|
||||
Makes use of the OVERDUE_FILTER to avoid code duplication
|
||||
"""
|
||||
|
||||
# Cannot be deemed overdue if target_date is not set
|
||||
if self.target_date is None:
|
||||
return False
|
||||
query = Build.objects.filter(pk=self.pk)
|
||||
query = query.filter(Build.OVERDUE_FILTER)
|
||||
|
||||
today = datetime.now().date()
|
||||
|
||||
return self.active and self.target_date < today
|
||||
return query.exists()
|
||||
|
||||
@property
|
||||
def active(self):
|
||||
|
@ -10,6 +10,7 @@ from rest_framework.test import APITestCase
|
||||
from rest_framework import status
|
||||
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from .models import Build
|
||||
from stock.models import StockItem
|
||||
@ -70,6 +71,24 @@ class BuildTestSimple(TestCase):
|
||||
|
||||
self.assertEqual(b2.status, BuildStatus.COMPLETE)
|
||||
|
||||
def test_overdue(self):
|
||||
"""
|
||||
Test overdue status functionality
|
||||
"""
|
||||
|
||||
today = datetime.now().date()
|
||||
|
||||
build = Build.objects.get(pk=1)
|
||||
self.assertFalse(build.is_overdue)
|
||||
|
||||
build.target_date = today - timedelta(days=1)
|
||||
build.save()
|
||||
self.assertTrue(build.is_overdue)
|
||||
|
||||
build.target_date = today + timedelta(days=80)
|
||||
build.save()
|
||||
self.assertFalse(build.is_overdue)
|
||||
|
||||
def test_is_active(self):
|
||||
b1 = Build.objects.get(pk=1)
|
||||
b2 = Build.objects.get(pk=2)
|
||||
|
@ -272,6 +272,7 @@ class PurchaseOrder(Order):
|
||||
self.complete_date = datetime.now().date()
|
||||
self.save()
|
||||
|
||||
@property
|
||||
def is_overdue(self):
|
||||
"""
|
||||
Returns True if this PurchaseOrder is "overdue"
|
||||
|
@ -5,6 +5,8 @@ from django.test import TestCase
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db.utils import IntegrityError
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from company.models import Company
|
||||
from stock.models import StockItem
|
||||
from order.models import SalesOrder, SalesOrderLineItem, SalesOrderAllocation
|
||||
@ -40,6 +42,26 @@ class SalesOrderTest(TestCase):
|
||||
# Create a line item
|
||||
self.line = SalesOrderLineItem.objects.create(quantity=50, order=self.order, part=self.part)
|
||||
|
||||
def test_overdue(self):
|
||||
"""
|
||||
Tests for overdue functionality
|
||||
"""
|
||||
|
||||
today = datetime.now().date()
|
||||
|
||||
# By default, order is *not* overdue as the target date is not set
|
||||
self.assertFalse(self.order.is_overdue)
|
||||
|
||||
# Set target date in the past
|
||||
self.order.target_date = today - timedelta(days=5)
|
||||
self.order.save()
|
||||
self.assertTrue(self.order.is_overdue)
|
||||
|
||||
# Set target date in the future
|
||||
self.order.target_date = today + timedelta(days=5)
|
||||
self.order.save()
|
||||
self.assertFalse(self.order.is_overdue)
|
||||
|
||||
def test_empty_order(self):
|
||||
self.assertEqual(self.line.quantity, 50)
|
||||
self.assertEqual(self.line.allocated_quantity(), 0)
|
||||
|
@ -1,3 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from django.test import TestCase
|
||||
import django.core.exceptions as django_exceptions
|
||||
|
||||
@ -37,6 +41,24 @@ class OrderTest(TestCase):
|
||||
|
||||
self.assertEqual(str(line), "100 x ACME0001 from ACME (for PO0001 - ACME)")
|
||||
|
||||
def test_overdue(self):
|
||||
"""
|
||||
Test overdue status functionality
|
||||
"""
|
||||
|
||||
today = datetime.now().date()
|
||||
|
||||
order = PurchaseOrder.objects.get(pk=1)
|
||||
self.assertFalse(order.is_overdue)
|
||||
|
||||
order.target_date = today - timedelta(days=5)
|
||||
order.save()
|
||||
self.assertTrue(order.is_overdue)
|
||||
|
||||
order.target_date = today + timedelta(days=1)
|
||||
order.save()
|
||||
self.assertFalse(order.is_overdue)
|
||||
|
||||
def test_increment(self):
|
||||
|
||||
next_ref = PurchaseOrder.getNextOrderNumber()
|
||||
|
Loading…
Reference in New Issue
Block a user