diff --git a/InvenTree/company/templates/company/supplier_part.html b/InvenTree/company/templates/company/supplier_part.html index 58ac0fa0eb..6f332d011f 100644 --- a/InvenTree/company/templates/company/supplier_part.html +++ b/InvenTree/company/templates/company/supplier_part.html @@ -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() { diff --git a/InvenTree/part/templates/part/pricing_javascript.html b/InvenTree/part/templates/part/pricing_javascript.html index 7385d60b7c..d3e29a00ae 100644 --- a/InvenTree/part/templates/part/pricing_javascript.html +++ b/InvenTree/part/templates/part/pricing_javascript.html @@ -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 %} diff --git a/InvenTree/templates/js/translated/company.js b/InvenTree/templates/js/translated/company.js index 10eee69f48..84120e4e06 100644 --- a/InvenTree/templates/js/translated/company.js +++ b/InvenTree/templates/js/translated/company.js @@ -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 += `