Skip to content

Commit 81ac887

Browse files
Fix for PurchaseOrderLineItem.receive (#258)
* Fix for PurchaseOrderLineItem.receive - Fix default value for "expiry_date" * Refactor PurchaseOrderLineItem.receive
1 parent d508bc6 commit 81ac887

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

inventree/purchase_order.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def getOrder(self):
163163
"""
164164
return PurchaseOrder(self._api, self.order)
165165

166-
def receive(self, quantity=None, status=10, location=None, expiry_date='', batch_code='', serial_numbers=''):
166+
def receive(self, quantity=None, status=10, location=None, expiry_date=None, batch_code=None, serial_numbers=None):
167167
"""
168168
Mark this line item as received.
169169
@@ -202,19 +202,28 @@ def receive(self, quantity=None, status=10, location=None, expiry_date='', batch
202202
except: # noqa:E722
203203
location_id = int(location)
204204

205+
item_data = {
206+
'line_item': self.pk,
207+
'supplier_part': self.part,
208+
'quantity': quantity,
209+
'status': status,
210+
'location': location_id
211+
}
212+
213+
# Optional fields which may be set
214+
if expiry_date:
215+
item_data['expiry_date'] = expiry_date
216+
217+
if batch_code:
218+
item_data['batch_code'] = batch_code
219+
220+
if serial_numbers:
221+
item_data['serial_numbers'] = serial_numbers
222+
205223
# Prepare request data
206224
data = {
207225
'items': [
208-
{
209-
'line_item': self.pk,
210-
'supplier_part': self.part,
211-
'quantity': quantity,
212-
'status': status,
213-
'location': location_id,
214-
'expiry_date': expiry_date,
215-
'batch_code': batch_code,
216-
'serial_numbers': serial_numbers
217-
}
226+
item_data,
218227
],
219228
'location': location_id
220229
}

0 commit comments

Comments
 (0)