From 607cc90ce03cd5b39d3cb8c96fd45ac7b7d85dd6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 27 Nov 2020 11:17:55 +1100 Subject: [PATCH 1/3] Add extra context to SupplierPartCreate form (cherry picked from commit 5f8f0232a9d556b6c6622ce6efa9488efd7eed68) --- .../company/supplier_part_create.html | 17 ++++++++++++++ InvenTree/company/views.py | 23 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 InvenTree/company/templates/company/supplier_part_create.html diff --git a/InvenTree/company/templates/company/supplier_part_create.html b/InvenTree/company/templates/company/supplier_part_create.html new file mode 100644 index 0000000000..21c23f9075 --- /dev/null +++ b/InvenTree/company/templates/company/supplier_part_create.html @@ -0,0 +1,17 @@ +{% extends "modal_form.html" %} + +{% load i18n %} + +{% block pre_form_content %} +{{ block.super }} + +{% if part %} +
+ {% include "hover_image.html" with image=part.image %} + {{ part.full_name}} +
+ {{ part.description }} +
+{% endif %} + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/company/views.py b/InvenTree/company/views.py index 2720f4ccac..e863fa1d72 100644 --- a/InvenTree/company/views.py +++ b/InvenTree/company/views.py @@ -291,7 +291,7 @@ class SupplierPartCreate(AjaxCreateView): model = SupplierPart form_class = EditSupplierPartForm - ajax_template_name = 'modal_form.html' + ajax_template_name = 'company/supplier_part_create.html' ajax_form_title = _('Create new Supplier Part') context_object_name = 'part' role_required = 'purchase_order.add' @@ -304,6 +304,27 @@ class SupplierPartCreate(AjaxCreateView): # TODO - What validation steps can be performed on the single_pricing field? pass + def get_context_data(self): + """ + Supply context data to the form + """ + + ctx = super().get_context_data() + + # Add 'part' object + form = self.get_form() + + part = form['part'].value() + + try: + part = Part.objects.get(pk=part) + except (ValueError, Part.DoesNotExist): + part = None + + ctx['part'] = part + + return ctx + def save(self, form): """ If single_pricing is defined, add a price break for quantity=1 From 7068f7081120bb37d6dc0fd2a8d450c3e1ed7eb9 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 27 Nov 2020 11:18:45 +1100 Subject: [PATCH 2/3] Fixes for 'order parts' form - Sometimes the part pk was not being retrieved properly --- .../order/order_wizard/select_parts.html | 8 ++++---- InvenTree/templates/js/order.js | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/InvenTree/order/templates/order/order_wizard/select_parts.html b/InvenTree/order/templates/order/order_wizard/select_parts.html index 9c7c90ac26..c93e26e363 100644 --- a/InvenTree/order/templates/order/order_wizard/select_parts.html +++ b/InvenTree/order/templates/order/order_wizard/select_parts.html @@ -11,11 +11,11 @@ {% if parts|length > 0 %} {% else %} {% endif %} @@ -39,8 +39,8 @@ {{ part.full_name }} {{ part.description }} - diff --git a/InvenTree/templates/js/order.js b/InvenTree/templates/js/order.js index 41a1b4c046..69d4f584d9 100644 --- a/InvenTree/templates/js/order.js +++ b/InvenTree/templates/js/order.js @@ -21,9 +21,16 @@ function newSupplierPartFromOrderWizard(e) { e = e || window.event; - var src = e.target || e.srcElement; + var src = e.srcElement || e.target; - var part = $(src).attr('part-id'); + var part = $(src).attr('part'); + + console.log('part: ' + part); + + if (!part) { + part = $(src).closest('button').attr('part'); + console.log('parent: ' + part); + } launchModalForm("/supplier-part/new/", { modal: '#modal-form-secondary', @@ -125,7 +132,7 @@ function loadPurchaseOrderTable(table, options) { name: 'purchaseorder', groupBy: false, original: options.params, - formatNoMatches: function() { return "{% trans "No purchase orders found" %}"; }, + formatNoMatches: function() { return '{% trans "No purchase orders found" %}'; }, columns: [ { field: 'pk', @@ -208,7 +215,7 @@ function loadSalesOrderTable(table, options) { name: 'salesorder', groupBy: false, original: options.params, - formatNoMatches: function() { return "{% trans "No sales orders found" %}"; }, + formatNoMatches: function() { return '{% trans "No sales orders found" %}'; }, columns: [ { field: 'pk', @@ -265,7 +272,7 @@ function loadSalesOrderTable(table, options) { { sortable: true, field: 'shipment_date', - title: "{% trans "Shipment Date" %}", + title: '{% trans "Shipment Date" %}', }, { sortable: true, From 6c68197e617d6a1a0d95a7ec96402d1140197917 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 27 Nov 2020 11:18:58 +1100 Subject: [PATCH 3/3] Allow part ordering from build view --- InvenTree/templates/js/build.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/InvenTree/templates/js/build.js b/InvenTree/templates/js/build.js index ab6f0e4e0a..a3c7bd5186 100644 --- a/InvenTree/templates/js/build.js +++ b/InvenTree/templates/js/build.js @@ -243,6 +243,22 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { }); }); + // Callback for 'buy' button + $(table).find('.button-buy').click(function() { + var pk = $(this).attr('pk'); + + var idx = $(this).closest('tr').attr('data-index'); + var row = $(table).bootstrapTable('getData')[idx]; + + launchModalForm('{% url "order-parts" %}', { + data: { + parts: [ + pk, + ] + } + }); + }); + // Callback for 'build' button $(table).find('.button-build').click(function() { var pk = $(this).attr('pk'); @@ -563,7 +579,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { } if (row.sub_part_detail.purchaseable) { - html += makeIconButton('fa-shopping-cart icon-blue', 'button-buy', row.sub_part, '{% trans "Order stock" %}', {disabled: true}); + html += makeIconButton('fa-shopping-cart icon-blue', 'button-buy', row.sub_part, '{% trans "Order stock" %}'); } html += makeIconButton('fa-sign-in-alt icon-green', 'button-add', row.sub_part, '{% trans "Allocate stock" %}');