mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add ability to quickly duplicate build orders (#3565)
* Adds ability to easily duplicate an existing build order * Refactor purchase order editing code
This commit is contained in:
parent
32b11ec5af
commit
b70a0164ae
@ -55,6 +55,9 @@ src="{% static 'img/blank_image.png' %}"
|
||||
{% if build.is_active %}
|
||||
<li><a class='dropdown-item' href='#' id='build-cancel'><span class='fas fa-times-circle icon-red'></span> {% trans "Cancel Build" %}</a></li>
|
||||
{% endif %}
|
||||
{% if roles.build.add %}
|
||||
<li><a class='dropdown-item' href='#' id='build-duplicate'><span class='fas fa-clone'></span> {% trans "Duplicate Build" %}</a></li>
|
||||
{% endif %}
|
||||
{% if build.status == BuildStatus.CANCELLED and roles.build.delete %}
|
||||
<li><a class='dropdown-item' href='#' id='build-delete'><span class='fas fa-trash-alt icon-red'></span> {% trans "Delete Build" %}</a>
|
||||
{% endif %}
|
||||
@ -209,6 +212,7 @@ src="{% static 'img/blank_image.png' %}"
|
||||
|
||||
{% block js_ready %}
|
||||
|
||||
{% if roles.build.change %}
|
||||
$("#build-edit").click(function () {
|
||||
editBuildOrder({{ build.pk }});
|
||||
});
|
||||
@ -230,6 +234,13 @@ src="{% static 'img/blank_image.png' %}"
|
||||
completed: {% if build.remaining == 0 %}true{% else %}false{% endif %},
|
||||
});
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
{% if roles.build.add %}
|
||||
$('#build-duplicate').click(function() {
|
||||
duplicateBuildOrder({{ build.pk }});
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
{% if report_enabled %}
|
||||
$('#print-build-report').click(function() {
|
||||
|
@ -219,28 +219,10 @@ $('#print-order-report').click(function() {
|
||||
|
||||
$("#edit-order").click(function() {
|
||||
|
||||
constructForm('{% url "api-po-detail" order.pk %}', {
|
||||
fields: {
|
||||
reference: {
|
||||
icon: 'fa-hashtag',
|
||||
},
|
||||
{% if order.lines.count == 0 and order.status == PurchaseOrderStatus.PENDING %}
|
||||
supplier: {
|
||||
},
|
||||
{% endif %}
|
||||
supplier_reference: {},
|
||||
description: {},
|
||||
target_date: {
|
||||
icon: 'fa-calendar-alt',
|
||||
},
|
||||
link: {
|
||||
icon: 'fa-link',
|
||||
},
|
||||
responsible: {
|
||||
icon: 'fa-user',
|
||||
},
|
||||
},
|
||||
title: '{% trans "Edit Purchase Order" %}',
|
||||
editPurchaseOrder({{ order.pk }}, {
|
||||
{% if order.lines.count > 0 or order.status != PurchaseOrderStatus.PENDING %}
|
||||
hide_supplier: true,
|
||||
{% endif %}
|
||||
reload: true,
|
||||
});
|
||||
});
|
||||
|
@ -23,6 +23,7 @@
|
||||
cancelBuildOrder,
|
||||
completeBuildOrder,
|
||||
createBuildOutput,
|
||||
duplicateBuildOrder,
|
||||
editBuildOrder,
|
||||
loadAllocationTable,
|
||||
loadBuildOrderAllocationTable,
|
||||
@ -75,7 +76,9 @@ function buildFormFields() {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Edit an existing BuildOrder via the API
|
||||
*/
|
||||
function editBuildOrder(pk) {
|
||||
|
||||
var fields = buildFormFields();
|
||||
@ -87,6 +90,10 @@ function editBuildOrder(pk) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create a new build order via an API form
|
||||
*/
|
||||
function newBuildOrder(options={}) {
|
||||
/* Launch modal form to create a new BuildOrder.
|
||||
*/
|
||||
@ -113,8 +120,13 @@ function newBuildOrder(options={}) {
|
||||
fields.sales_order.value = options.sales_order;
|
||||
}
|
||||
|
||||
if (options.data) {
|
||||
delete options.data.pk;
|
||||
}
|
||||
|
||||
constructForm(`/api/build/`, {
|
||||
fields: fields,
|
||||
data: options.data,
|
||||
follow: true,
|
||||
method: 'POST',
|
||||
title: '{% trans "Create Build Order" %}',
|
||||
@ -123,6 +135,26 @@ function newBuildOrder(options={}) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Duplicate an existing build order.
|
||||
*/
|
||||
function duplicateBuildOrder(build_id, options={}) {
|
||||
|
||||
inventreeGet(`/api/build/${build_id}/`, {}, {
|
||||
success: function(data) {
|
||||
// Clear out data we do not want to be duplicated
|
||||
delete data['pk'];
|
||||
delete data['issued_by'];
|
||||
delete data['reference'];
|
||||
|
||||
options.data = data;
|
||||
newBuildOrder(options);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Construct a form to cancel a build order */
|
||||
function cancelBuildOrder(build_id, options={}) {
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
createPurchaseOrderLineItem,
|
||||
createSalesOrder,
|
||||
createSalesOrderShipment,
|
||||
editPurchaseOrder,
|
||||
editPurchaseOrderLineItem,
|
||||
exportOrder,
|
||||
issuePurchaseOrder,
|
||||
@ -493,41 +494,79 @@ function createSalesOrder(options={}) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Construct a set of fields for a purchase order form
|
||||
*/
|
||||
function purchaseOrderFields(options={}) {
|
||||
|
||||
var fields = {
|
||||
reference: {
|
||||
icon: 'fa-hashtag',
|
||||
},
|
||||
supplier: {
|
||||
icon: 'fa-building',
|
||||
secondary: {
|
||||
title: '{% trans "Add Supplier" %}',
|
||||
fields: function() {
|
||||
var fields = companyFormFields();
|
||||
|
||||
fields.is_supplier.value = true;
|
||||
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
},
|
||||
description: {},
|
||||
supplier_reference: {},
|
||||
target_date: {
|
||||
icon: 'fa-calendar-alt',
|
||||
},
|
||||
link: {
|
||||
icon: 'fa-link',
|
||||
},
|
||||
responsible: {
|
||||
icon: 'fa-user',
|
||||
},
|
||||
};
|
||||
|
||||
if (options.supplier) {
|
||||
fields.supplier.value = options.supplier;
|
||||
}
|
||||
|
||||
if (options.hide_supplier) {
|
||||
fields.supplier.hidden = true;
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Edit an existing PurchaseOrder
|
||||
*/
|
||||
function editPurchaseOrder(pk, options={}) {
|
||||
|
||||
var fields = purchaseOrderFields(options);
|
||||
|
||||
constructForm(`/api/order/po/${pk}/`, {
|
||||
fields: fields,
|
||||
title: '{% trans "Edit Purchase Order" %}',
|
||||
onSuccess: function(response) {
|
||||
handleFormSuccess(response, options);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Create a new PurchaseOrder
|
||||
function createPurchaseOrder(options={}) {
|
||||
|
||||
var fields = purchaseOrderFields(options);
|
||||
|
||||
constructForm('{% url "api-po-list" %}', {
|
||||
method: 'POST',
|
||||
fields: {
|
||||
reference: {
|
||||
icon: 'fa-hashtag',
|
||||
},
|
||||
supplier: {
|
||||
icon: 'fa-building',
|
||||
value: options.supplier,
|
||||
secondary: {
|
||||
title: '{% trans "Add Supplier" %}',
|
||||
fields: function() {
|
||||
var fields = companyFormFields();
|
||||
|
||||
fields.is_supplier.value = true;
|
||||
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
},
|
||||
description: {},
|
||||
supplier_reference: {},
|
||||
target_date: {
|
||||
icon: 'fa-calendar-alt',
|
||||
},
|
||||
link: {
|
||||
icon: 'fa-link',
|
||||
},
|
||||
responsible: {
|
||||
icon: 'fa-user',
|
||||
}
|
||||
},
|
||||
fields: fields,
|
||||
onSuccess: function(data) {
|
||||
|
||||
if (options.onSuccess) {
|
||||
|
Loading…
Reference in New Issue
Block a user