Skip to content

Commit 42aa14c

Browse files
Sales Order Allocation (#244)
* Add SalesOrderAllocation model * Update tasks.py * Update version number * Update unit test * Update unit test
1 parent a331dd4 commit 42aa14c

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed

inventree/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from . import api as inventree_api
88

9-
INVENTREE_PYTHON_VERSION = "0.17.0"
9+
INVENTREE_PYTHON_VERSION = "0.17.1"
1010

1111

1212
logger = logging.getLogger('inventree')

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,

tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def reset_data(c, debug=False):
3434

3535
hide = None if debug else 'both'
3636

37-
c.run("docker-compose -f test/docker-compose.yml run --rm inventree-py-test-server invoke delete-data -f", hide=hide)
37+
c.run("docker-compose -f test/docker-compose.yml run --rm inventree-py-test-server invoke dev.delete-data -f", hide=hide)
3838
c.run("docker-compose -f test/docker-compose.yml run --rm inventree-py-test-server invoke migrate", hide=hide)
39-
c.run("docker-compose -f test/docker-compose.yml run --rm inventree-py-test-server invoke import-fixtures", hide=hide)
39+
c.run("docker-compose -f test/docker-compose.yml run --rm inventree-py-test-server invoke dev.import-fixtures", hide=hide)
4040

4141

4242
@task(post=[reset_data])

test/test_order.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,16 +674,25 @@ def test_so_shipment(self):
674674
# Make sure date is not None
675675
self.assertIsNotNone(shipment_2.shipment_date)
676676

677+
# SalesOrderAllocations are broken prior to server API version 267
678+
if self.api.api_version < 267:
679+
return
680+
677681
# Try to complete this order
678682
# Ship remaining shipments first
679683
for shp in so.getShipments():
684+
685+
allocations = shp.getAllocations()
686+
680687
# Delete shipment if it has no allocations
681-
if len(shp.allocations) == 0:
688+
if len(allocations) == 0:
682689
shp.delete()
683690
continue
691+
684692
# If the shipment has no date, try to mark it shipped
685693
if shp.shipment_date is None:
686694
shp.ship()
695+
687696
so.complete()
688697
self.assertEqual(so.status, 20)
689698
self.assertEqual(so.status_text, 'Shipped')

0 commit comments

Comments
 (0)