diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html index 4fe24d7caf..ece6de36bb 100644 --- a/InvenTree/build/templates/build/build_base.html +++ b/InvenTree/build/templates/build/build_base.html @@ -196,26 +196,7 @@ src="{% static 'img/blank_image.png' %}" }); $("#build-edit").click(function () { - - constructForm('{% url "api-build-detail" build.pk %}', { - fields: { - reference: { - prefix: "{% settings_value 'BUILDORDER_REFERENCE_PREFIX' %}", - }, - title: {}, - part: {}, - quantity: {}, - batch: {}, - target_date: {}, - take_from: {}, - destination: {}, - link: {}, - issued_by: {}, - responsible: {}, - }, - title: '{% trans "Edit Build Order" %}', - reload: true, - }); + editBuildOrder({{ build.pk }}); }); $("#build-cancel").click(function() { diff --git a/InvenTree/build/tests.py b/InvenTree/build/tests.py index 9a440e0b93..9c5134cc66 100644 --- a/InvenTree/build/tests.py +++ b/InvenTree/build/tests.py @@ -252,23 +252,6 @@ class TestBuildViews(TestCase): self.assertIn(build.title, content) - def test_build_create(self): - """ Test the build creation view (ajax form) """ - - url = reverse('build-create') - - # Create build without specifying part - response = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - - # Create build with valid part - response = self.client.get(url, {'part': 1}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - - # Create build with invalid part - response = self.client.get(url, {'part': 9999}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - def test_build_allocate(self): """ Test the part allocation view for a Build """ diff --git a/InvenTree/build/urls.py b/InvenTree/build/urls.py index 588e44fb35..c354a17ac7 100644 --- a/InvenTree/build/urls.py +++ b/InvenTree/build/urls.py @@ -35,8 +35,6 @@ build_urls = [ url('^new/', views.BuildItemCreate.as_view(), name='build-item-create'), ])), - url(r'new/', views.BuildCreate.as_view(), name='build-create'), - url(r'^(?P\d+)/', include(build_detail_urls)), url(r'.*$', views.BuildIndex.as_view(), name='build-index'), diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index e94cc869db..2bae825b0f 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -667,83 +667,6 @@ class BuildAllocate(InvenTreeRoleMixin, DetailView): return context -class BuildCreate(AjaxCreateView): - """ - View to create a new Build object - """ - - model = Build - context_object_name = 'build' - form_class = forms.EditBuildForm - ajax_form_title = _('New Build Order') - ajax_template_name = 'modal_form.html' - - def get_form(self): - form = super().get_form() - - if form['part'].value(): - form.fields['part'].widget = HiddenInput() - - return form - - def get_initial(self): - """ Get initial parameters for Build creation. - - If 'part' is specified in the GET query, initialize the Build with the specified Part - """ - - initials = super(BuildCreate, self).get_initial().copy() - - initials['parent'] = self.request.GET.get('parent', None) - - # User has provided a SalesOrder ID - initials['sales_order'] = self.request.GET.get('sales_order', None) - - initials['quantity'] = self.request.GET.get('quantity', 1) - - part = self.request.GET.get('part', None) - - if part: - - try: - part = Part.objects.get(pk=part) - # User has provided a Part ID - initials['part'] = part - initials['destination'] = part.get_default_location() - - to_order = part.quantity_to_order - - if to_order < 1: - to_order = 1 - - initials['quantity'] = to_order - except (ValueError, Part.DoesNotExist): - pass - - initials['reference'] = Build.getNextBuildNumber() - - # Pre-fill the issued_by user - initials['issued_by'] = self.request.user - - return initials - - def get_data(self): - return { - 'success': _('Created new build'), - } - - def validate(self, build, form, **kwargs): - """ - Perform extra form validation. - - - If part is trackable, check that either batch or serial numbers are calculated - - By this point form.is_valid() has been executed - """ - - pass - - class BuildDelete(AjaxDeleteView): """ View to delete a build """ diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 22f70d0f3c..99c71d1c3e 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -43,8 +43,10 @@ def get_next_po_number(): attempts = set([order.reference]) + reference = order.reference + while 1: - reference = increment(order.reference) + reference = increment(reference) if reference in attempts: # Escape infinite recursion @@ -70,8 +72,10 @@ def get_next_so_number(): attempts = set([order.reference]) + reference = order.reference + while 1: - reference = increment(order.reference) + reference = increment(reference) if reference in attempts: # Escape infinite recursion diff --git a/InvenTree/part/templates/part/build.html b/InvenTree/part/templates/part/build.html index 4c28bef3d4..29f32c770a 100644 --- a/InvenTree/part/templates/part/build.html +++ b/InvenTree/part/templates/part/build.html @@ -34,9 +34,7 @@ {{ block.super }} $("#start-build").click(function() { newBuildOrder({ - data: { - part: {{ part.id }}, - } + part: {{ part.pk }}, }); }); diff --git a/InvenTree/templates/js/build.js b/InvenTree/templates/js/build.js index 67961d1b73..55bd7172e1 100644 --- a/InvenTree/templates/js/build.js +++ b/InvenTree/templates/js/build.js @@ -1,34 +1,59 @@ {% load i18n %} {% load inventree_extras %} + +function buildFormFields() { + return { + reference: { + prefix: "{% settings_value 'BUILDORDER_REFERENCE_PREFIX' %}", + }, + title: {}, + part: {}, + quantity: {}, + batch: {}, + target_date: {}, + take_from: {}, + destination: {}, + link: { + icon: 'fa-link', + }, + issued_by: { + icon: 'fa-user', + }, + responsible: { + icon: 'fa-users', + }, + }; +} + + +function editBuildOrder(pk, options={}) { + + var fields = buildFormFields(); + + constructForm(`/api/build/${pk}/`, { + fields: fields, + reload: true, + title: '{% trans "Edit Build Order" %}', + }); +} + function newBuildOrder(options={}) { /* Launch modal form to create a new BuildOrder. */ - launchModalForm( - "{% url 'build-create' %}", - { - follow: true, - data: options.data || {}, - callback: [ - { - field: 'part', - action: function(value) { - inventreeGet( - `/api/part/${value}/`, {}, - { - success: function(response) { + var fields = buildFormFields(); - //enableField('serial_numbers', response.trackable); - //clearField('serial_numbers'); - } - } - ); - }, - } - ], - } - ) + if (options.part) { + fields.part.value = options.part; + } + + constructForm(`/api/build/`, { + fields: fields, + follow: true, + method: 'POST', + title: '{% trans "Create Build Order" %}' + }); }