mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor SOLineItemCreate view
This commit is contained in:
parent
699b21f6fd
commit
3cc9299b41
@ -96,23 +96,6 @@ class ReceivePurchaseOrderForm(HelperForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class EditSalesOrderLineItemForm(HelperForm):
|
|
||||||
""" Form for editing a SalesOrderLineItem object """
|
|
||||||
|
|
||||||
quantity = RoundingDecimalFormField(max_digits=10, decimal_places=5, label=_('Quantity'))
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = SalesOrderLineItem
|
|
||||||
fields = [
|
|
||||||
'order',
|
|
||||||
'part',
|
|
||||||
'quantity',
|
|
||||||
'reference',
|
|
||||||
'sale_price',
|
|
||||||
'notes'
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class AllocateSerialsToSalesOrderForm(forms.Form):
|
class AllocateSerialsToSalesOrderForm(forms.Form):
|
||||||
"""
|
"""
|
||||||
Form for assigning stock to a sales order,
|
Form for assigning stock to a sales order,
|
||||||
|
@ -38,13 +38,23 @@ function reloadTable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$("#new-so-line").click(function() {
|
$("#new-so-line").click(function() {
|
||||||
launchModalForm("{% url 'so-line-item-create' %}", {
|
|
||||||
success: reloadTable,
|
constructForm('{% url "api-so-line-list" %}', {
|
||||||
data: {
|
fields: {
|
||||||
order: {{ order.id }},
|
order: {
|
||||||
|
value: {{ order.pk }},
|
||||||
|
hidden: true,
|
||||||
|
},
|
||||||
|
part: {},
|
||||||
|
quantity: {},
|
||||||
|
reference: {},
|
||||||
|
sale_price: {},
|
||||||
|
sale_price_currency: {},
|
||||||
|
notes: {},
|
||||||
},
|
},
|
||||||
secondary: [
|
method: 'POST',
|
||||||
]
|
title: '{% trans "Add Line Item" %}',
|
||||||
|
onSuccess: reloadTable,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -50,11 +50,6 @@ sales_order_detail_urls = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
sales_order_urls = [
|
sales_order_urls = [
|
||||||
|
|
||||||
url(r'^line/', include([
|
|
||||||
url(r'^new/', views.SOLineItemCreate.as_view(), name='so-line-item-create'),
|
|
||||||
])),
|
|
||||||
|
|
||||||
# URLs for sales order allocations
|
# URLs for sales order allocations
|
||||||
url(r'^allocation/', include([
|
url(r'^allocation/', include([
|
||||||
url(r'^new/', views.SalesOrderAllocationCreate.as_view(), name='so-allocation-create'),
|
url(r'^new/', views.SalesOrderAllocationCreate.as_view(), name='so-allocation-create'),
|
||||||
|
@ -1049,70 +1049,6 @@ class OrderParts(AjaxView):
|
|||||||
order.add_line_item(supplier_part, quantity, purchase_price=purchase_price)
|
order.add_line_item(supplier_part, quantity, purchase_price=purchase_price)
|
||||||
|
|
||||||
|
|
||||||
class SOLineItemCreate(AjaxCreateView):
|
|
||||||
""" Ajax view for creating a new SalesOrderLineItem object """
|
|
||||||
|
|
||||||
model = SalesOrderLineItem
|
|
||||||
context_order_name = 'line'
|
|
||||||
form_class = order_forms.EditSalesOrderLineItemForm
|
|
||||||
ajax_form_title = _('Add Line Item')
|
|
||||||
|
|
||||||
def get_form(self, *args, **kwargs):
|
|
||||||
|
|
||||||
form = super().get_form(*args, **kwargs)
|
|
||||||
|
|
||||||
# If the order is specified, hide the widget
|
|
||||||
order_id = form['order'].value()
|
|
||||||
|
|
||||||
if SalesOrder.objects.filter(id=order_id).exists():
|
|
||||||
form.fields['order'].widget = HiddenInput()
|
|
||||||
|
|
||||||
return form
|
|
||||||
|
|
||||||
def get_initial(self):
|
|
||||||
"""
|
|
||||||
Extract initial data for this line item:
|
|
||||||
|
|
||||||
Options:
|
|
||||||
order: The SalesOrder object
|
|
||||||
part: The Part object
|
|
||||||
"""
|
|
||||||
|
|
||||||
initials = super().get_initial().copy()
|
|
||||||
|
|
||||||
order_id = self.request.GET.get('order', None)
|
|
||||||
part_id = self.request.GET.get('part', None)
|
|
||||||
|
|
||||||
if order_id:
|
|
||||||
try:
|
|
||||||
order = SalesOrder.objects.get(id=order_id)
|
|
||||||
initials['order'] = order
|
|
||||||
except (SalesOrder.DoesNotExist, ValueError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
if part_id:
|
|
||||||
try:
|
|
||||||
part = Part.objects.get(id=part_id)
|
|
||||||
if part.salable:
|
|
||||||
initials['part'] = part
|
|
||||||
except (Part.DoesNotExist, ValueError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
return initials
|
|
||||||
|
|
||||||
def save(self, form):
|
|
||||||
ret = form.save()
|
|
||||||
# check if price s set in form - else autoset
|
|
||||||
if not ret.sale_price:
|
|
||||||
price = ret.part.get_price(ret.quantity)
|
|
||||||
# only if price is avail
|
|
||||||
if price:
|
|
||||||
ret.sale_price = price / ret.quantity
|
|
||||||
ret.save()
|
|
||||||
self.object = ret
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
class SalesOrderAssignSerials(AjaxView, FormMixin):
|
class SalesOrderAssignSerials(AjaxView, FormMixin):
|
||||||
"""
|
"""
|
||||||
View for assigning stock items to a sales order,
|
View for assigning stock items to a sales order,
|
||||||
|
Loading…
Reference in New Issue
Block a user