2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

Mark a SalesOrder as "shipped"

- Option to hide non-stock items from stock list
- Update models with new feature
This commit is contained in:
Oliver Walters
2020-04-25 08:46:28 +10:00
parent c5b93e2392
commit b351976ae9
8 changed files with 73 additions and 12 deletions

View File

@ -315,10 +315,15 @@ class SalesOrder(Order):
def ship_order(self, user):
""" Mark this order as 'shipped' """
return False
# The order can only be 'shipped' if the current status is PENDING
if not self.status == SalesOrderStatus.PENDING:
return False
raise ValidationError({'status': _("SalesOrder cannot be shipped as it is not currently pending")})
# Complete the allocation for each allocated StockItem
for line in self.lines.all():
for allocation in line.allocations.all():
allocation.complete_allocation(user)
# Ensure the order status is marked as "Shipped"
self.status = SalesOrderStatus.SHIPPED
@ -552,3 +557,30 @@ class SalesOrderAllocation(models.Model):
return self.item.location.pathstring
else:
return ""
def complete_allocation(self, user):
"""
Complete this allocation (called when the parent SalesOrder is marked as "shipped"):
- Determine if the referenced StockItem needs to be "split" (if allocated quantity != stock quantity)
- Mark the StockItem as belonging to the Customer (this will remove it from stock)
"""
item = self.item
# If the allocated quantity is less than the amount available,
# then split the stock item into two lots
if item.quantity > self.quantity:
# Grab a copy of the new stock item (which will keep track of its "parent")
item = item.splitStock(self.quantity, None, user)
# Assign the StockItem to the SalesOrder customer
item.customer = self.line.order.customer
# Clear the location
item.location = None
item.save()
print("Finalizing allocation for: " + str(self.item))

View File

@ -22,6 +22,8 @@
{% endif %}
<div class='alert alert-block alert-info'>
<b>{% trans "Sales Order" %} {{ order.reference }} - {{ order.customer.name }}</b>
<br>
{% trans "Shipping this order means that the order will no longer be editable." %}
</div>

View File

@ -504,16 +504,14 @@ class SalesOrderShip(AjaxUpdateView):
context_object_name = 'order'
ajax_template_name = 'order/sales_order_ship.html'
ajax_form_title = _('Ship Order')
def context_data(self):
ctx = super().get_context_data()
ctx['order'] = self.get_object()
return ctx
def post(self, request, *args, **kwargs):
self.request = request
order = self.get_object()
self.object = order
form = self.get_form()
confirm = str2bool(request.POST.get('confirm', False))
@ -534,7 +532,11 @@ class SalesOrderShip(AjaxUpdateView):
'form_valid': valid,
}
return self.renderJsonResponse(request, form, data)
context = self.get_context_data()
context['order'] = order
return self.renderJsonResponse(request, form, data, context)
class PurchaseOrderExport(AjaxView):