From 29ab77affee911f08876f2f69f3719e43229a779 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 13 Jan 2025 12:59:04 +1100 Subject: [PATCH 1/2] Fix for PurchaseOrderLineItem.receive - Fix default value for "expiry_date" --- inventree/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inventree/purchase_order.py b/inventree/purchase_order.py index 5746f1a..912dc35 100644 --- a/inventree/purchase_order.py +++ b/inventree/purchase_order.py @@ -163,7 +163,7 @@ def getOrder(self): """ return PurchaseOrder(self._api, self.order) - def receive(self, quantity=None, status=10, location=None, expiry_date='', batch_code='', serial_numbers=''): + def receive(self, quantity=None, status=10, location=None, expiry_date=None, batch_code='', serial_numbers=''): """ Mark this line item as received. From 315b69c9ff7e5cd6b45c3d99a9980dab2563a6db Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 13 Jan 2025 13:25:42 +1100 Subject: [PATCH 2/2] Refactor PurchaseOrderLineItem.receive --- inventree/purchase_order.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/inventree/purchase_order.py b/inventree/purchase_order.py index 912dc35..1accf50 100644 --- a/inventree/purchase_order.py +++ b/inventree/purchase_order.py @@ -163,7 +163,7 @@ def getOrder(self): """ return PurchaseOrder(self._api, self.order) - def receive(self, quantity=None, status=10, location=None, expiry_date=None, batch_code='', serial_numbers=''): + def receive(self, quantity=None, status=10, location=None, expiry_date=None, batch_code=None, serial_numbers=None): """ Mark this line item as received. @@ -202,19 +202,28 @@ def receive(self, quantity=None, status=10, location=None, expiry_date=None, bat except: # noqa:E722 location_id = int(location) + item_data = { + 'line_item': self.pk, + 'supplier_part': self.part, + 'quantity': quantity, + 'status': status, + 'location': location_id + } + + # Optional fields which may be set + if expiry_date: + item_data['expiry_date'] = expiry_date + + if batch_code: + item_data['batch_code'] = batch_code + + if serial_numbers: + item_data['serial_numbers'] = serial_numbers + # Prepare request data data = { 'items': [ - { - 'line_item': self.pk, - 'supplier_part': self.part, - 'quantity': quantity, - 'status': status, - 'location': location_id, - 'expiry_date': expiry_date, - 'batch_code': batch_code, - 'serial_numbers': serial_numbers - } + item_data, ], 'location': location_id }