mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add tests for get_purchase_orders logic (#6236)
This commit is contained in:
parent
f27503b1af
commit
d2d59e0709
@ -8,6 +8,8 @@ from InvenTree.unit_test import InvenTreeAPITestCase
|
|||||||
from part.models import Part
|
from part.models import Part
|
||||||
from stock.models import StockItem
|
from stock.models import StockItem
|
||||||
|
|
||||||
|
from .mixins import SupplierBarcodeMixin
|
||||||
|
|
||||||
|
|
||||||
class BarcodeAPITest(InvenTreeAPITestCase):
|
class BarcodeAPITest(InvenTreeAPITestCase):
|
||||||
"""Tests for barcode api."""
|
"""Tests for barcode api."""
|
||||||
@ -354,3 +356,142 @@ class SOAllocateTest(InvenTreeAPITestCase):
|
|||||||
self.line_item.refresh_from_db()
|
self.line_item.refresh_from_db()
|
||||||
self.assertEqual(self.line_item.allocated_quantity(), 10)
|
self.assertEqual(self.line_item.allocated_quantity(), 10)
|
||||||
self.assertTrue(self.line_item.is_fully_allocated())
|
self.assertTrue(self.line_item.is_fully_allocated())
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierBarcodeMixinTest(InvenTreeAPITestCase):
|
||||||
|
"""Unit tests for the SupplierBarcodeMixin class."""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
"""Setup for all tests."""
|
||||||
|
super().setUpTestData()
|
||||||
|
|
||||||
|
cls.supplier = company.models.Company.objects.create(
|
||||||
|
name='Supplier Barcode Mixin Test Company', is_supplier=True
|
||||||
|
)
|
||||||
|
|
||||||
|
cls.supplier_other = company.models.Company.objects.create(
|
||||||
|
name='Other Supplier Barcode Mixin Test Company', is_supplier=True
|
||||||
|
)
|
||||||
|
|
||||||
|
cls.supplier_no_orders = company.models.Company.objects.create(
|
||||||
|
name='Supplier Barcode Mixin Test Company with no Orders', is_supplier=True
|
||||||
|
)
|
||||||
|
|
||||||
|
cls.purchase_order_pending = order.models.PurchaseOrder.objects.create(
|
||||||
|
status=order.models.PurchaseOrderStatus.PENDING.value,
|
||||||
|
supplier=cls.supplier,
|
||||||
|
supplier_reference='ORDER#1337',
|
||||||
|
)
|
||||||
|
|
||||||
|
cls.purchase_order_1 = order.models.PurchaseOrder.objects.create(
|
||||||
|
status=order.models.PurchaseOrderStatus.PLACED.value,
|
||||||
|
supplier=cls.supplier,
|
||||||
|
supplier_reference='ORDER#1338',
|
||||||
|
)
|
||||||
|
|
||||||
|
cls.purchase_order_duplicate_1 = order.models.PurchaseOrder.objects.create(
|
||||||
|
status=order.models.PurchaseOrderStatus.PLACED.value,
|
||||||
|
supplier=cls.supplier,
|
||||||
|
supplier_reference='ORDER#1339',
|
||||||
|
)
|
||||||
|
|
||||||
|
cls.purchase_order_duplicate_2 = order.models.PurchaseOrder.objects.create(
|
||||||
|
status=order.models.PurchaseOrderStatus.PLACED.value,
|
||||||
|
supplier=cls.supplier_other,
|
||||||
|
supplier_reference='ORDER#1339',
|
||||||
|
)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
"""Setup method for each test."""
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
def test_order_not_placed(self):
|
||||||
|
"""Check that purchase order which has not been placed doesn't get returned."""
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
self.purchase_order_pending.reference, None
|
||||||
|
)
|
||||||
|
self.assertIsNone(purchase_orders.first())
|
||||||
|
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
None, self.purchase_order_pending.supplier_reference
|
||||||
|
)
|
||||||
|
self.assertIsNone(purchase_orders.first())
|
||||||
|
|
||||||
|
def test_order_simple(self):
|
||||||
|
"""Check that we can get a purchase order by either reference, supplier_reference or both."""
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
self.purchase_order_1.reference, None
|
||||||
|
)
|
||||||
|
self.assertEqual(purchase_orders.count(), 1)
|
||||||
|
self.assertEqual(purchase_orders.first(), self.purchase_order_1)
|
||||||
|
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
None, self.purchase_order_1.supplier_reference
|
||||||
|
)
|
||||||
|
self.assertEqual(purchase_orders.count(), 1)
|
||||||
|
self.assertEqual(purchase_orders.first(), self.purchase_order_1)
|
||||||
|
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
self.purchase_order_1.reference, self.purchase_order_1.supplier_reference
|
||||||
|
)
|
||||||
|
self.assertEqual(purchase_orders.count(), 1)
|
||||||
|
self.assertEqual(purchase_orders.first(), self.purchase_order_1)
|
||||||
|
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
self.purchase_order_1.reference,
|
||||||
|
self.purchase_order_1.supplier_reference,
|
||||||
|
supplier=self.supplier,
|
||||||
|
)
|
||||||
|
self.assertEqual(purchase_orders.count(), 1)
|
||||||
|
self.assertEqual(purchase_orders.first(), self.purchase_order_1)
|
||||||
|
|
||||||
|
def test_wrong_supplier_order(self):
|
||||||
|
"""Check that no orders get returned if the wrong supplier is specified."""
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
self.purchase_order_1.reference, None, supplier=self.supplier_no_orders
|
||||||
|
)
|
||||||
|
self.assertIsNone(purchase_orders.first())
|
||||||
|
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
None,
|
||||||
|
self.purchase_order_1.supplier_reference,
|
||||||
|
supplier=self.supplier_no_orders,
|
||||||
|
)
|
||||||
|
self.assertIsNone(purchase_orders.first())
|
||||||
|
|
||||||
|
def test_supplier_order_duplicate(self):
|
||||||
|
"""Test getting purchase_orders with the same supplier_reference works correctly."""
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
None, self.purchase_order_duplicate_1.supplier_reference
|
||||||
|
)
|
||||||
|
self.assertEqual(purchase_orders.count(), 2)
|
||||||
|
self.assertEqual(
|
||||||
|
set(purchase_orders),
|
||||||
|
{self.purchase_order_duplicate_1, self.purchase_order_duplicate_2},
|
||||||
|
)
|
||||||
|
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
self.purchase_order_duplicate_1.reference,
|
||||||
|
self.purchase_order_duplicate_1.supplier_reference,
|
||||||
|
)
|
||||||
|
self.assertEqual(purchase_orders.count(), 1)
|
||||||
|
self.assertEqual(purchase_orders.first(), self.purchase_order_duplicate_1)
|
||||||
|
|
||||||
|
# check that mixing the reference and supplier_reference doesn't work
|
||||||
|
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
self.purchase_order_duplicate_1.supplier_reference,
|
||||||
|
self.purchase_order_duplicate_1.reference,
|
||||||
|
)
|
||||||
|
self.assertIsNone(purchase_orders.first())
|
||||||
|
|
||||||
|
# check that specifying the right supplier works
|
||||||
|
|
||||||
|
purchase_orders = SupplierBarcodeMixin.get_purchase_orders(
|
||||||
|
None,
|
||||||
|
self.purchase_order_duplicate_1.supplier_reference,
|
||||||
|
supplier=self.supplier_other,
|
||||||
|
)
|
||||||
|
self.assertEqual(purchase_orders.count(), 1)
|
||||||
|
self.assertEqual(purchase_orders.first(), self.purchase_order_duplicate_2)
|
||||||
|
Loading…
Reference in New Issue
Block a user