From b5c5842e7d77498788cc7aa54e97c6aceffdc7b4 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 6 Oct 2021 17:26:48 +1100 Subject: [PATCH] Add ability to create a new sales order allocation using the API forms framework --- InvenTree/templates/js/translated/order.js | 40 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index 771490b134..62f68f6f40 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -1616,13 +1616,41 @@ function loadSalesOrderLineItemTable(table, options={}) { $(table).find('.button-add').click(function() { var pk = $(this).attr('pk'); - // TODO: Migrate this form to the API forms - launchModalForm(`/order/sales-order/allocation/new/`, { - success: reloadTable, - data: { - line: pk, + var line_item = $(table).bootstrapTable('getRowByUniqueId', pk); + + var fields = { + // SalesOrderLineItem reference + line: { + hidden: true, + value: pk, }, - }); + item: { + filters: { + part_detail: true, + location_detail: true, + in_stock: true, + part: line_item.part, + // TODO: Exclude items already allocated to this sales order + } + }, + quantity: { + }, + }; + + // Exclude expired stock? + if (global_settings.STOCK_ENABLE_EXPIRY && !global_settings.STOCK_ALLOW_EXPIRED_SALE) { + fields.item.filters.expired = false; + } + + constructForm( + `/api/order/so-allocation/`, + { + method: 'POST', + fields: fields, + title: '{% trans "Allocate Stock Item" %}', + onSuccess: reloadTable, + } + ); }); // Callback for creating a new build