mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1997 from SchrodingersGat/new-po-from-order
Refactor buttons in "order parts" wizard
This commit is contained in:
commit
b6df623554
@ -78,7 +78,13 @@ function createPurchaseOrder(options={}) {
|
||||
}
|
||||
},
|
||||
onSuccess: function(data) {
|
||||
location.href = `/order/purchase-order/${data.pk}/`;
|
||||
|
||||
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" %}',
|
||||
});
|
||||
@ -109,27 +115,47 @@ function newSupplierPartFromOrderWizard(e) {
|
||||
|
||||
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',
|
||||
data: {
|
||||
part: part,
|
||||
},
|
||||
success: function(response) {
|
||||
/* A new supplier part has been created! */
|
||||
createSupplierPart({
|
||||
part: part,
|
||||
onSuccess: function(data) {
|
||||
|
||||
var dropdown = '#id_supplier_part_' + part;
|
||||
// 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 option = new Option(response.text, response.pk, true, true);
|
||||
var dropdown = `#id_supplier_part_${part}`;
|
||||
|
||||
$('#modal-form').find(dropdown).append(option).trigger('change');
|
||||
},
|
||||
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');
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -145,20 +171,40 @@ function newPurchaseOrderFromOrderWizard(e) {
|
||||
|
||||
var supplier = $(src).attr('supplierid');
|
||||
|
||||
launchModalForm("/order/purchase-order/new/", {
|
||||
modal: '#modal-form-secondary',
|
||||
data: {
|
||||
supplier: supplier,
|
||||
},
|
||||
success: function(response) {
|
||||
/* A new purchase order has been created! */
|
||||
createPurchaseOrder({
|
||||
supplier: supplier,
|
||||
onSuccess: function(data) {
|
||||
|
||||
var dropdown = '#id-purchase-order-' + supplier;
|
||||
// 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 option = new Option(response.text, response.pk, true, true);
|
||||
var pk = data.pk;
|
||||
|
||||
$('#modal-form').find(dropdown).append(option).trigger('change');
|
||||
},
|
||||
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');
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user