From 615a954e094c748c4984d0c6d8429fc0ce2cf88e Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 28 Feb 2022 23:31:23 +1100 Subject: [PATCH] Refactor UI for adding batch code and serial numbers --- InvenTree/templates/js/translated/forms.js | 2 +- InvenTree/templates/js/translated/helpers.js | 4 ++ InvenTree/templates/js/translated/order.js | 49 ++++++++++++-------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js index 63598a8676..b3f54033e0 100644 --- a/InvenTree/templates/js/translated/forms.js +++ b/InvenTree/templates/js/translated/forms.js @@ -1884,7 +1884,7 @@ function getFieldName(name, options={}) { * - Field description (help text) * - Field errors */ -function constructField(name, parameters, options) { +function constructField(name, parameters, options={}) { var html = ''; diff --git a/InvenTree/templates/js/translated/helpers.js b/InvenTree/templates/js/translated/helpers.js index 2d35513e78..1925cb47ac 100644 --- a/InvenTree/templates/js/translated/helpers.js +++ b/InvenTree/templates/js/translated/helpers.js @@ -116,6 +116,10 @@ function makeIconButton(icon, cls, pk, title, options={}) { extraProps += `disabled='true' `; } + if (options.collapseTarget) { + extraProps += `data-bs-toggle='collapse' href='#${options.collapseTarget}'`; + } + html += ``; diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index 0ec50022aa..ab437df426 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -489,12 +489,6 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) { `; - var prefix_buttons = toggle_batch; - - if (line_item.part_detail.trackable) { - prefix_buttons += toggle_serials; - } - // Quantity to Receive var quantity_input = constructField( `items_quantity_${pk}`, @@ -504,7 +498,6 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) { value: quantity, title: '{% trans "Quantity to receive" %}', required: true, - prefixRaw: prefix_buttons, }, { hideLabels: true, @@ -516,13 +509,10 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) { `items_batch_code_${pk}`, { type: 'string', - required: true, + required: false, label: '{% trans "Batch Code" %}', help_text: '{% trans "Enter batch code for incoming stock items" %}', prefixRaw: toggle_batch, - }, - { - hideLabels: true, } ); @@ -530,13 +520,10 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) { `items_serial_numbers_${pk}`, { type: 'string', - required: true, + required: false, label: '{% trans "Serial Numbers" %}', help_text: '{% trans "Enter serial numbers for incoming stock items" %}', prefixRaw: toggle_serials, - }, - { - hideLabels: true } ); @@ -584,16 +571,38 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) { ); // Button to remove the row - var delete_button = `
`; + var buttons = `
`; - delete_button += makeIconButton( + buttons += makeIconButton( + 'fa-layer-group', + 'button-row-add-batch', + pk, + '{% trans "Add batch code" %}', + { + collapseTarget: `div-batch-${pk}` + } + ); + + if (line_item.part_detail.trackable) { + buttons += makeIconButton( + 'fa-hashtag', + 'button-row-add-serials', + pk, + '{% trans "Add serial numbers" %}', + { + collapseTarget: `div-serials-${pk}`, + } + ); + } + + buttons += makeIconButton( 'fa-times icon-red', 'button-row-remove', pk, '{% trans "Remove row" %}', ); - delete_button += '
'; + buttons += '
'; var html = ` @@ -619,7 +628,7 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) { ${destination_input} - ${delete_button} + ${buttons} `; @@ -643,7 +652,7 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) { {% trans "Order Code" %} {% trans "Ordered" %} {% trans "Received" %} - {% trans "Receive" %} + {% trans "Quantity to Receive" %} {% trans "Status" %} {% trans "Destination" %}