Skip to content

Commit d7ebb12

Browse files
Add SalesOrderAllocation model
1 parent a331dd4 commit d7ebb12

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

inventree/sales_order.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import inventree.company
77
import inventree.part
88
import inventree.report
9+
import inventree.stock
910

1011

1112
class SalesOrder(
@@ -190,6 +191,35 @@ def getOrder(self):
190191
return SalesOrder(self._api, self.order)
191192

192193

194+
class SalesOrderAllocation(
195+
inventree.base.InventreeObject
196+
):
197+
"""Class representing the SalesOrderAllocation database model."""
198+
199+
URL = 'order/so-allocation'
200+
201+
def getOrder(self):
202+
"""Return the SalesOrder to which this SalesOrderAllocation belongs."""
203+
return SalesOrder(self._api, self.order)
204+
205+
def getShipment(self):
206+
"""Return the SalesOrderShipment to which this SalesOrderAllocation belongs."""
207+
from sales_order import SalesOrderShipment
208+
return SalesOrderShipment(self._api, self.shipment)
209+
210+
def getLineItem(self):
211+
"""Return the SalesOrderLineItem to which this SalesOrderAllocation belongs."""
212+
return SalesOrderLineItem(self._api, self.line)
213+
214+
def getStockItem(self):
215+
"""Return the StockItem to which this SalesOrderAllocation belongs."""
216+
return inventree.stock.StockItem(self._api, self.item)
217+
218+
def getPart(self):
219+
"""Return the Part to which this SalesOrderAllocation belongs."""
220+
return inventree.part.Part(self._api, self.part)
221+
222+
193223
class SalesOrderShipment(
194224
inventree.base.InventreeObject,
195225
inventree.base.StatusMixin,
@@ -200,9 +230,7 @@ class SalesOrderShipment(
200230
URL = 'order/so/shipment'
201231

202232
def getOrder(self):
203-
"""
204-
Return the SalesOrder to which this SalesOrderShipment belongs
205-
"""
233+
"""Return the SalesOrder to which this SalesOrderShipment belongs."""
206234
return SalesOrder(self._api, self.order)
207235

208236
def allocateItems(self, items=[]):
@@ -219,7 +247,7 @@ def allocateItems(self, items=[]):
219247
}
220248
"""
221249

222-
# Customise URL
250+
# Customize URL
223251
url = f'order/so/{self.getOrder().pk}/allocate'
224252

225253
# Create data from given inputs
@@ -237,6 +265,18 @@ def allocateItems(self, items=[]):
237265
# Return
238266
return response
239267

268+
def getAllocations(self):
269+
"""Return the allocations associated with this shipment"""
270+
return SalesOrderAllocation.list(self._api, shipment=self.pk)
271+
272+
@property
273+
def allocations(self):
274+
"""Return the allocations associated with this shipment.
275+
276+
Note: This is an overload of getAllocations() method, for legacy compatibility.
277+
"""
278+
return self.getAllocations()
279+
240280
def complete(
241281
self,
242282
shipment_date=None,

0 commit comments

Comments
 (0)