{% load i18n %} {% load inventree_extras %} /* globals companyFormFields, constructForm, createSupplierPart, global_settings, imageHoverIcon, inventreeGet, launchModalForm, loadTableFilters, makeIconBadge, purchaseOrderStatusDisplay, receivePurchaseOrderItems, renderLink, salesOrderStatusDisplay, setupFilterList, */ /* exported createSalesOrder, editPurchaseOrderLineItem, loadPurchaseOrderLineItemTable, loadPurchaseOrderTable, loadSalesOrderAllocationTable, loadSalesOrderLineItemTable, loadSalesOrderTable, newPurchaseOrderFromOrderWizard, newSupplierPartFromOrderWizard, removeOrderRowFromOrderWizard, removePurchaseOrderLineItem, */ // Create a new SalesOrder function createSalesOrder(options={}) { constructForm('{% url "api-so-list" %}', { method: 'POST', fields: { reference: { prefix: global_settings.SALESORDER_REFERENCE_PREFIX, }, customer: { value: options.customer, secondary: { title: '{% trans "Add Customer" %}', fields: function() { var fields = companyFormFields(); fields.is_customer.value = true; return fields; } } }, customer_reference: {}, description: {}, target_date: { icon: 'fa-calendar-alt', }, link: { icon: 'fa-link', }, responsible: { icon: 'fa-user', } }, onSuccess: function(data) { location.href = `/order/sales-order/${data.pk}/`; }, title: '{% trans "Create Sales Order" %}', }); } // Create a new PurchaseOrder function createPurchaseOrder(options={}) { constructForm('{% url "api-po-list" %}', { method: 'POST', fields: { reference: { prefix: global_settings.PURCHASEORDER_REFERENCE_PREFIX, }, supplier: { value: options.supplier, secondary: { title: '{% trans "Add Supplier" %}', fields: function() { var fields = companyFormFields(); fields.is_supplier.value = true; return fields; } } }, supplier_reference: {}, description: {}, target_date: { icon: 'fa-calendar-alt', }, link: { icon: 'fa-link', }, responsible: { icon: 'fa-user', } }, onSuccess: function(data) { if (options.onSuccess) { options.onSuccess(data); } else { // Default action is to redirect browser to the new PO location.href = `/order/purchase-order/${data.pk}/`; } }, title: '{% trans "Create Purchase Order" %}', }); } function removeOrderRowFromOrderWizard(e) { /* Remove a part selection from an order form. */ e = e || window.event; var src = e.target || e.srcElement; var row = $(src).attr('row'); $('#' + row).remove(); } function newSupplierPartFromOrderWizard(e) { /* Create a new supplier part directly from an order form. * Launches a secondary modal and (if successful), * back-populates the selected row. */ e = e || window.event; var src = e.srcElement || e.target; var part = $(src).attr('part'); if (!part) { part = $(src).closest('button').attr('part'); } createSupplierPart({ part: part, onSuccess: function(data) { // TODO: 2021-08-23 - This whole form wizard needs to be refactored. // In the future, use the API forms functionality to add the new item // For now, this hack will have to do... var dropdown = `#id_supplier_part_${part}`; var pk = data.pk; inventreeGet( `/api/company/part/${pk}/`, { supplier_detail: true, }, { success: function(response) { var text = ''; if (response.supplier_detail) { text += response.supplier_detail.name; text += ' | '; } text += response.SKU; var option = new Option(text, pk, true, true); $('#modal-form').find(dropdown).append(option).trigger('change'); } } ); } }); } function newPurchaseOrderFromOrderWizard(e) { /* Create a new purchase order directly from an order form. * Launches a secondary modal and (if successful), * back-fills the newly created purchase order. */ e = e || window.event; var src = e.target || e.srcElement; var supplier = $(src).attr('supplierid'); createPurchaseOrder({ supplier: supplier, onSuccess: function(data) { // TODO: 2021-08-23 - The whole form wizard needs to be refactored // In the future, the drop-down should be using a dynamic AJAX request // to fill out the select2 options! var pk = data.pk; inventreeGet( `/api/order/po/${pk}/`, { supplier_detail: true, }, { success: function(response) { var text = global_settings.PURCHASEORDER_REFERENCE_PREFIX || ''; text += response.reference; if (response.supplier_detail) { text += ` ${response.supplier_detail.name}`; } var dropdown = `#id-purchase-order-${supplier}`; var option = new Option(text, pk, true, true); $('#modal-form').find(dropdown).append(option).trigger('change'); } } ); } }); } /** * Receive stock items against a PurchaseOrder * Uses the POReceive API endpoint * * arguments: * - order_id, ID / PK for the PurchaseOrder instance * - line_items: A list of PurchaseOrderLineItems objects to be allocated * * options: * - */ function receivePurchaseOrderItems(order_id, line_items, options={}) { if (line_items.length == 0) { showAlertDialog( '{% trans "Select Line Items" %}', '{% trans "At least one line item must be selected" %}', ); return; } function renderLineItem(line_item, opts={}) { var pk = line_item.pk; // Part thumbnail + description var thumb = thumbnailImage(line_item.part_detail.thumbnail); var quantity = (line_item.quantity || 0) - (line_item.received || 0); if (quantity < 0) { quantity = 0; } // Quantity to Receive var quantity_input = constructField( `items_quantity_${pk}`, { type: 'decimal', min_value: 0, value: quantity, title: '{% trans "Quantity to receive" %}', required: true, }, { hideLabels: true, } ); // Construct list of StockItem status codes var choices = []; for (var key in stockCodes) { choices.push({ value: key, display_name: stockCodes[key].value, }); } var destination_input = constructField( `items_location_${pk}`, { type: 'related field', label: '{% trans "Location" %}', required: false, }, { hideLabels: true, } ); var status_input = constructField( `items_status_${pk}`, { type: 'choice', label: '{% trans "Stock Status" %}', required: true, choices: choices, value: 10, // OK }, { hideLabels: true, } ); // Button to remove the row var delete_button = `
{% trans "Part" %} | {% trans "Order Code" %} | {% trans "Ordered" %} | {% trans "Received" %} | {% trans "Receive" %} | {% trans "Status" %} | {% trans "Destination" %} |
---|