mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 11:10:54 +00:00
client side form for assigning stock items to customers
This commit is contained in:
@ -21,20 +21,6 @@ from part.models import Part
|
||||
from .models import StockLocation, StockItem, StockItemTracking
|
||||
|
||||
|
||||
class AssignStockItemToCustomerForm(HelperForm):
|
||||
"""
|
||||
Form for manually assigning a StockItem to a Customer
|
||||
|
||||
TODO: This could be a simple API driven form!
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = StockItem
|
||||
fields = [
|
||||
'customer',
|
||||
]
|
||||
|
||||
|
||||
class ReturnStockItemForm(HelperForm):
|
||||
"""
|
||||
Form for manually returning a StockItem into stock
|
||||
|
@ -568,11 +568,19 @@ $("#stock-convert").click(function() {
|
||||
|
||||
{% if item.in_stock %}
|
||||
$("#stock-assign-to-customer").click(function() {
|
||||
launchModalForm("{% url 'stock-item-assign' item.id %}",
|
||||
{
|
||||
reload: true,
|
||||
|
||||
inventreeGet('{% url "api-stock-detail" item.pk %}', {}, {
|
||||
success: function(response) {
|
||||
assignStockToCustomer(
|
||||
[response],
|
||||
{
|
||||
success: function() {
|
||||
location.reload();
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
$("#stock-move").click(function() {
|
||||
|
@ -23,7 +23,6 @@ stock_item_detail_urls = [
|
||||
url(r'^delete/', views.StockItemDelete.as_view(), name='stock-item-delete'),
|
||||
url(r'^qr_code/', views.StockItemQRCode.as_view(), name='stock-item-qr'),
|
||||
url(r'^delete_test_data/', views.StockItemDeleteTestData.as_view(), name='stock-item-delete-test-data'),
|
||||
url(r'^assign/', views.StockItemAssignToCustomer.as_view(), name='stock-item-assign'),
|
||||
url(r'^return/', views.StockItemReturnToStock.as_view(), name='stock-item-return'),
|
||||
url(r'^install/', views.StockItemInstall.as_view(), name='stock-item-install'),
|
||||
|
||||
|
@ -294,39 +294,6 @@ class StockLocationQRCode(QRCodeView):
|
||||
return None
|
||||
|
||||
|
||||
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 validate(self, item, form, **kwargs):
|
||||
|
||||
customer = form.cleaned_data.get('customer', None)
|
||||
|
||||
if not customer:
|
||||
form.add_error('customer', _('Customer must be specified'))
|
||||
|
||||
def save(self, item, form, **kwargs):
|
||||
"""
|
||||
Assign the stock item to the customer.
|
||||
"""
|
||||
|
||||
customer = form.cleaned_data.get('customer', None)
|
||||
|
||||
if customer:
|
||||
item = item.allocateToCustomer(
|
||||
customer,
|
||||
user=self.request.user
|
||||
)
|
||||
|
||||
item.clearAllocations()
|
||||
|
||||
|
||||
class StockItemReturnToStock(AjaxUpdateView):
|
||||
"""
|
||||
View for returning a stock item (which is assigned to a customer) to stock.
|
||||
|
Reference in New Issue
Block a user