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 %}
|
{% 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>
|
<li><a class='dropdown-item' href='#' id='build-cancel'><span class='fas fa-times-circle icon-red'></span> {% trans "Cancel Build" %}</a></li>
|
||||||
{% endif %}
|
{% 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 %}
|
{% 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>
|
<li><a class='dropdown-item' href='#' id='build-delete'><span class='fas fa-trash-alt icon-red'></span> {% trans "Delete Build" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -209,6 +212,7 @@ src="{% static 'img/blank_image.png' %}"
|
|||||||
|
|
||||||
{% block js_ready %}
|
{% block js_ready %}
|
||||||
|
|
||||||
|
{% if roles.build.change %}
|
||||||
$("#build-edit").click(function () {
|
$("#build-edit").click(function () {
|
||||||
editBuildOrder({{ build.pk }});
|
editBuildOrder({{ build.pk }});
|
||||||
});
|
});
|
||||||
@ -230,6 +234,13 @@ src="{% static 'img/blank_image.png' %}"
|
|||||||
completed: {% if build.remaining == 0 %}true{% else %}false{% endif %},
|
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 %}
|
{% if report_enabled %}
|
||||||
$('#print-build-report').click(function() {
|
$('#print-build-report').click(function() {
|
||||||
|
@ -219,28 +219,10 @@ $('#print-order-report').click(function() {
|
|||||||
|
|
||||||
$("#edit-order").click(function() {
|
$("#edit-order").click(function() {
|
||||||
|
|
||||||
constructForm('{% url "api-po-detail" order.pk %}', {
|
editPurchaseOrder({{ order.pk }}, {
|
||||||
fields: {
|
{% if order.lines.count > 0 or order.status != PurchaseOrderStatus.PENDING %}
|
||||||
reference: {
|
hide_supplier: true,
|
||||||
icon: 'fa-hashtag',
|
{% endif %}
|
||||||
},
|
|
||||||
{% 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" %}',
|
|
||||||
reload: true,
|
reload: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
cancelBuildOrder,
|
cancelBuildOrder,
|
||||||
completeBuildOrder,
|
completeBuildOrder,
|
||||||
createBuildOutput,
|
createBuildOutput,
|
||||||
|
duplicateBuildOrder,
|
||||||
editBuildOrder,
|
editBuildOrder,
|
||||||
loadAllocationTable,
|
loadAllocationTable,
|
||||||
loadBuildOrderAllocationTable,
|
loadBuildOrderAllocationTable,
|
||||||
@ -75,7 +76,9 @@ function buildFormFields() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Edit an existing BuildOrder via the API
|
||||||
|
*/
|
||||||
function editBuildOrder(pk) {
|
function editBuildOrder(pk) {
|
||||||
|
|
||||||
var fields = buildFormFields();
|
var fields = buildFormFields();
|
||||||
@ -87,6 +90,10 @@ function editBuildOrder(pk) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a new build order via an API form
|
||||||
|
*/
|
||||||
function newBuildOrder(options={}) {
|
function newBuildOrder(options={}) {
|
||||||
/* Launch modal form to create a new BuildOrder.
|
/* Launch modal form to create a new BuildOrder.
|
||||||
*/
|
*/
|
||||||
@ -113,8 +120,13 @@ function newBuildOrder(options={}) {
|
|||||||
fields.sales_order.value = options.sales_order;
|
fields.sales_order.value = options.sales_order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.data) {
|
||||||
|
delete options.data.pk;
|
||||||
|
}
|
||||||
|
|
||||||
constructForm(`/api/build/`, {
|
constructForm(`/api/build/`, {
|
||||||
fields: fields,
|
fields: fields,
|
||||||
|
data: options.data,
|
||||||
follow: true,
|
follow: true,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
title: '{% trans "Create Build Order" %}',
|
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 */
|
/* Construct a form to cancel a build order */
|
||||||
function cancelBuildOrder(build_id, options={}) {
|
function cancelBuildOrder(build_id, options={}) {
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
createPurchaseOrderLineItem,
|
createPurchaseOrderLineItem,
|
||||||
createSalesOrder,
|
createSalesOrder,
|
||||||
createSalesOrderShipment,
|
createSalesOrderShipment,
|
||||||
|
editPurchaseOrder,
|
||||||
editPurchaseOrderLineItem,
|
editPurchaseOrderLineItem,
|
||||||
exportOrder,
|
exportOrder,
|
||||||
issuePurchaseOrder,
|
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
|
// Create a new PurchaseOrder
|
||||||
function createPurchaseOrder(options={}) {
|
function createPurchaseOrder(options={}) {
|
||||||
|
|
||||||
|
var fields = purchaseOrderFields(options);
|
||||||
|
|
||||||
constructForm('{% url "api-po-list" %}', {
|
constructForm('{% url "api-po-list" %}', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
fields: {
|
fields: 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',
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onSuccess: function(data) {
|
onSuccess: function(data) {
|
||||||
|
|
||||||
if (options.onSuccess) {
|
if (options.onSuccess) {
|
||||||
|
Loading…
Reference in New Issue
Block a user