mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Allow edit or delete of supplier part price breaks from part pricing overview page
This commit is contained in:
parent
1afe982241
commit
4028ab1837
@ -295,7 +295,9 @@ $("#barcode-unlink").click(function() {
|
||||
{% endif %}
|
||||
|
||||
loadSupplierPriceBreakTable({
|
||||
part: {{ part.pk }}
|
||||
part: {{ part.pk }},
|
||||
allowEdit: {% js_bool roles.purchase_order.change %},
|
||||
allowDelete: {% js_bool roles.purchase_order.delete %},
|
||||
});
|
||||
|
||||
$('#new-price-break').click(function() {
|
||||
|
@ -41,6 +41,8 @@ loadPurchasePriceHistoryTable({
|
||||
// Supplier pricing information
|
||||
loadPartSupplierPricingTable({
|
||||
part: {{ part.pk }},
|
||||
allowEdit: {% js_bool roles.purchase_order.change %},
|
||||
allowDelete: {% js_bool roles.purchase_order.delete %},
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
|
@ -1144,33 +1144,43 @@ function loadSupplierPartTable(table, url, options) {
|
||||
*/
|
||||
function loadSupplierPriceBreakTable(options={}) {
|
||||
|
||||
if (!options.part) {
|
||||
console.error('No part provided to loadPurchasePriceHistoryTable');
|
||||
return;
|
||||
}
|
||||
|
||||
var table = options.table || $('#price-break-table');
|
||||
|
||||
// Setup button callbacks once table is loaded
|
||||
function setupCallbacks() {
|
||||
table.find('.button-price-break-delete').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
constructForm(`/api/company/price-break/${pk}/`, {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete Price Break" %}',
|
||||
onSuccess: function() {
|
||||
table.bootstrapTable('refresh');
|
||||
},
|
||||
if (options.allowDelete) {
|
||||
table.find('.button-price-break-delete').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
constructForm(`/api/company/price-break/${pk}/`, {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete Price Break" %}',
|
||||
onSuccess: function() {
|
||||
table.bootstrapTable('refresh');
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
table.find('.button-price-break-edit').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
if (options.allowDelete) {
|
||||
table.find('.button-price-break-edit').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
constructForm(`/api/company/price-break/${pk}/`, {
|
||||
fields: supplierPartPriceBreakFields(),
|
||||
title: '{% trans "Edit Price Break" %}',
|
||||
onSuccess: function() {
|
||||
table.bootstrapTable('refresh');
|
||||
}
|
||||
constructForm(`/api/company/price-break/${pk}/`, {
|
||||
fields: supplierPartPriceBreakFields(),
|
||||
title: '{% trans "Edit Price Break" %}',
|
||||
onSuccess: function() {
|
||||
table.bootstrapTable('refresh');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setupFilterList('supplierpricebreak', table, '#filter-list-supplierpricebreak');
|
||||
@ -1211,14 +1221,21 @@ function loadSupplierPriceBreakTable(options={}) {
|
||||
},
|
||||
{
|
||||
field: 'updated',
|
||||
title: '{% trans "Last updated" %}',
|
||||
title: '{% trans "Last Updated" %}',
|
||||
sortable: true,
|
||||
formatter: function(value, row) {
|
||||
var html = renderDate(value);
|
||||
|
||||
html += `<div class='btn-group float-right' role='group'>`;
|
||||
html += makeIconButton('fa-edit icon-blue', 'button-price-break-edit', row.pk, '{% trans "Edit price break" %}');
|
||||
html += makeIconButton('fa-trash-alt icon-red', 'button-price-break-delete', row.pk, '{% trans "Delete price break" %}');
|
||||
|
||||
if (options.allowEdit) {
|
||||
html += makeIconButton('fa-edit icon-blue', 'button-price-break-edit', row.pk, '{% trans "Edit price break" %}');
|
||||
}
|
||||
|
||||
if (options.allowDelete) {
|
||||
html += makeIconButton('fa-trash-alt icon-red', 'button-price-break-delete', row.pk, '{% trans "Delete price break" %}');
|
||||
}
|
||||
|
||||
html += `</div>`;
|
||||
|
||||
return html;
|
||||
|
@ -427,6 +427,39 @@ function loadPartSupplierPricingTable(options={}) {
|
||||
options.params.base_part = part;
|
||||
options.params.supplier_detail = true;
|
||||
options.params.part_detail = true;
|
||||
options.params.ordering = '-price';
|
||||
|
||||
// Setup button callbacks once table is loaded
|
||||
function setupCallbacks() {
|
||||
|
||||
if (options.allowDelete) {
|
||||
table.find('.button-price-break-delete').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
constructForm(`/api/company/price-break/${pk}/`, {
|
||||
method: 'DELETE',
|
||||
title: '{% trans "Delete Price Break" %}',
|
||||
onSuccess: function() {
|
||||
table.bootstrapTable('refresh');
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (options.allowDelete) {
|
||||
table.find('.button-price-break-edit').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
constructForm(`/api/company/price-break/${pk}/`, {
|
||||
fields: supplierPartPriceBreakFields(),
|
||||
title: '{% trans "Edit Price Break" %}',
|
||||
onSuccess: function() {
|
||||
table.bootstrapTable('refresh');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
table.inventreeTable({
|
||||
url: '{% url "api-part-supplier-price-list" %}',
|
||||
@ -441,6 +474,7 @@ function loadPartSupplierPricingTable(options={}) {
|
||||
formatNoMatches: function() {
|
||||
return '{% trans "No supplier pricing data available" %}';
|
||||
},
|
||||
onPostBody: setupCallbacks,
|
||||
onLoadSuccess: function(data) {
|
||||
// Update supplier pricing chart
|
||||
|
||||
@ -511,16 +545,26 @@ function loadPartSupplierPricingTable(options={}) {
|
||||
}
|
||||
|
||||
// Convert to unit pricing
|
||||
var unit_price = row.price / row.part_detail.pack_size;
|
||||
let unit_price = row.price / row.part_detail.pack_size;
|
||||
|
||||
var html = formatCurrency(unit_price, {
|
||||
let html = formatCurrency(unit_price, {
|
||||
currency: row.price_currency
|
||||
});
|
||||
|
||||
if (row.updated != null) {
|
||||
html += `<span class='badge badge-right rounded-pill bg-dark'>${renderDate(row.updated)}</span>`;
|
||||
}
|
||||
if (options.allowEdit || options.allowDelete) {
|
||||
|
||||
html += `<div class='btn-group float-right' role='group'>`;
|
||||
|
||||
if (options.allowEdit) {
|
||||
html += makeIconButton('fa-edit icon-blue', 'button-price-break-edit', row.pk, '{% trans "Edit price break" %}');
|
||||
}
|
||||
|
||||
if (options.allowDelete) {
|
||||
html += makeIconButton('fa-trash-alt icon-red', 'button-price-break-delete', row.pk, '{% trans "Delete price break" %}');
|
||||
}
|
||||
|
||||
html += `</div>`;
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user