2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-05 05:00:58 +00:00

Add forms/views for manually assigning a stock item to a customer

This commit is contained in:
Oliver Walters
2020-06-04 19:45:41 +10:00
parent d907136264
commit 80019a3ed8
7 changed files with 139 additions and 26 deletions

View File

@ -223,6 +223,44 @@ class StockItemAttachmentDelete(AjaxDeleteView):
}
class StockItemAssignToCustomer(AjaxUpdateView):
"""
View for manually assigning a StockItem to a Customer
"""
model = StockItem
ajax_form_title = _("Assign to Customer")
context_object_name = "item"
form_class = StockForms.AssignStockItemToCustomerForm
def post(self, request, *args, **kwargs):
customer = request.POST.get('customer', None)
if customer:
try:
customer = Company.objects.get(pk=customer)
except (ValueError, Company.DoesNotExist):
customer = None
if customer is not None:
stock_item = self.get_object()
item = stock_item.allocateToCustomer(
customer,
user=request.user
)
item.clearAllocations()
data = {
'form_valid': True,
}
return self.renderJsonResponse(request, self.get_form(), data)
class StockItemDeleteTestData(AjaxUpdateView):
"""
View for deleting all test data