mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Adds option for duplicating an existing purchase order (#3567)
* Adds option for duplicating an existing purchase order - Copy line items across * Update API version * JS linting * Adds option for duplication of extra lines * Decimal point rounding fix * Unit tests for PO duplication via the API
This commit is contained in:
@ -1049,7 +1049,7 @@ function loadBomTable(table, options={}) {
|
||||
available += row.on_order;
|
||||
can_build = available / row.quantity;
|
||||
|
||||
text += `<span class='fas fa-info-circle icon-blue float-right' title='{% trans "Including On Order" %}: ${can_build}'></span>`;
|
||||
text += `<span class='fas fa-info-circle icon-blue float-right' title='{% trans "Including On Order" %}: ${formatDecimal(can_build, 2)}'></span>`;
|
||||
}
|
||||
|
||||
return text;
|
||||
|
@ -30,6 +30,7 @@
|
||||
createPurchaseOrderLineItem,
|
||||
createSalesOrder,
|
||||
createSalesOrderShipment,
|
||||
duplicatePurchaseOrder,
|
||||
editPurchaseOrder,
|
||||
editPurchaseOrderLineItem,
|
||||
exportOrder,
|
||||
@ -538,6 +539,39 @@ function purchaseOrderFields(options={}) {
|
||||
fields.supplier.hidden = true;
|
||||
}
|
||||
|
||||
// Add fields for order duplication (only if required)
|
||||
if (options.duplicate_order) {
|
||||
fields.duplicate_order = {
|
||||
value: options.duplicate_order,
|
||||
group: 'duplicate',
|
||||
required: 'true',
|
||||
type: 'related field',
|
||||
model: 'purchaseorder',
|
||||
filters: {
|
||||
supplier_detail: true,
|
||||
},
|
||||
api_url: '{% url "api-po-list" %}',
|
||||
label: '{% trans "Purchase Order" %}',
|
||||
help_text: '{% trans "Select purchase order to duplicate" %}',
|
||||
};
|
||||
|
||||
fields.duplicate_line_items = {
|
||||
value: true,
|
||||
group: 'duplicate',
|
||||
type: 'boolean',
|
||||
label: '{% trans "Duplicate Line Items" %}',
|
||||
help_text: '{% trans "Duplicate all line items from the selected order" %}',
|
||||
};
|
||||
|
||||
fields.duplicate_extra_lines = {
|
||||
value: true,
|
||||
group: 'duplicate',
|
||||
type: 'boolean',
|
||||
label: '{% trans "Duplicate Extra Lines" %}',
|
||||
help_text: '{% trans "Duplicate extra line items from the selected order" %}',
|
||||
};
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
@ -564,9 +598,20 @@ function createPurchaseOrder(options={}) {
|
||||
|
||||
var fields = purchaseOrderFields(options);
|
||||
|
||||
var groups = {};
|
||||
|
||||
if (options.duplicate_order) {
|
||||
groups.duplicate = {
|
||||
title: '{% trans "Duplication Options" %}',
|
||||
collapsible: false,
|
||||
};
|
||||
};
|
||||
|
||||
constructForm('{% url "api-po-list" %}', {
|
||||
method: 'POST',
|
||||
fields: fields,
|
||||
groups: groups,
|
||||
data: options.data,
|
||||
onSuccess: function(data) {
|
||||
|
||||
if (options.onSuccess) {
|
||||
@ -576,7 +621,29 @@ function createPurchaseOrder(options={}) {
|
||||
location.href = `/order/purchase-order/${data.pk}/`;
|
||||
}
|
||||
},
|
||||
title: '{% trans "Create Purchase Order" %}',
|
||||
title: options.title || '{% trans "Create Purchase Order" %}',
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Duplicate an existing PurchaseOrder
|
||||
* Provides user with option to duplicate line items for the order also.
|
||||
*/
|
||||
function duplicatePurchaseOrder(order_id, options={}) {
|
||||
|
||||
options.duplicate_order = order_id;
|
||||
|
||||
inventreeGet(`/api/order/po/${order_id}/`, {}, {
|
||||
success: function(data) {
|
||||
|
||||
// Clear out data we do not want to be duplicated
|
||||
delete data['pk'];
|
||||
delete data['reference'];
|
||||
|
||||
options.data = data;
|
||||
|
||||
createPurchaseOrder(options);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user