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 += `
`; - 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 += `
`; return html; diff --git a/InvenTree/templates/js/translated/pricing.js b/InvenTree/templates/js/translated/pricing.js index 690ed1762a..5ef7beea6b 100644 --- a/InvenTree/templates/js/translated/pricing.js +++ b/InvenTree/templates/js/translated/pricing.js @@ -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 += `${renderDate(row.updated)}`; - } + if (options.allowEdit || options.allowDelete) { + html += `
`; + + 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 += `
`; + } return html; }