From 4b13f3b0defde5f621971e25b9b9918a393776df Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 5 Oct 2023 00:31:50 +1100 Subject: [PATCH] Fix location priority when receiving items (#5661) * Fix location priority when receiving items Fixes POReceiveBarcodeHandler * Unit test adjustment --- InvenTree/order/serializers.py | 6 +++--- InvenTree/order/test_api.py | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/InvenTree/order/serializers.py b/InvenTree/order/serializers.py index 36dc8a4516..0153d9c5aa 100644 --- a/InvenTree/order/serializers.py +++ b/InvenTree/order/serializers.py @@ -674,8 +674,8 @@ class PurchaseOrderReceiveSerializer(serializers.Serializer): with transaction.atomic(): for item in items: - # Select location - loc = item.get('location', None) or item['line_item'].get_destination() or location + # Select location (in descending order of priority) + loc = location or item.get('location', None) or item['line_item'].get_destination() try: order.receive_line_item( @@ -880,7 +880,7 @@ class SalesOrderLineItemSerializer(InvenTreeModelSerializer): ] def __init__(self, *args, **kwargs): - """Initializion routine for the serializer: + """Initialization routine for the serializer: - Add extra related serializer information if required """ diff --git a/InvenTree/order/test_api.py b/InvenTree/order/test_api.py index 9f6e30a88e..09c891cc91 100644 --- a/InvenTree/order/test_api.py +++ b/InvenTree/order/test_api.py @@ -982,9 +982,9 @@ class PurchaseOrderReceiveTest(OrderTest): self.assertEqual(stock_1.count(), 1) self.assertEqual(stock_2.count(), 1) - # Different location for each received item + # Same location for each received item, as overall 'location' field is provided self.assertEqual(stock_1.last().location.pk, 1) - self.assertEqual(stock_2.last().location.pk, 2) + self.assertEqual(stock_2.last().location.pk, 1) # Barcodes should have been assigned to the stock items self.assertTrue(StockItem.objects.filter(barcode_data='MY-UNIQUE-BARCODE-123').exists()) @@ -1562,7 +1562,7 @@ class SalesOrderDownloadTest(OrderTest): self.assertTrue(isinstance(file, io.BytesIO)) def test_download_csv(self): - """Tesst that the list of sales orders can be downloaded as a .csv file""" + """Test that the list of sales orders can be downloaded as a .csv file""" url = reverse('api-so-list') required_cols = [ @@ -1846,7 +1846,7 @@ class SalesOrderAllocateTest(OrderTest): self.assertEqual(self.shipment.delivery_date, datetime(2023, 12, 5).date()) self.assertTrue(self.shipment.is_delivered()) - def test_shipment_deliverydate(self): + def test_shipment_delivery_date(self): """Test delivery date functions via API.""" url = reverse('api-so-shipment-detail', kwargs={'pk': self.shipment.pk}) @@ -1891,7 +1891,7 @@ class SalesOrderAllocateTest(OrderTest): url = reverse('api-so-shipment-list') # Count before creation - countbefore = models.SalesOrderShipment.objects.count() + count_before = models.SalesOrderShipment.objects.count() # Create some new shipments via the API for order in models.SalesOrder.objects.all(): @@ -1922,7 +1922,7 @@ class SalesOrderAllocateTest(OrderTest): # List *all* shipments response = self.get(url, expected_code=200) - self.assertEqual(len(response.data), countbefore + 3 * models.SalesOrder.objects.count()) + self.assertEqual(len(response.data), count_before + 3 * models.SalesOrder.objects.count()) class ReturnOrderTests(InvenTreeAPITestCase):