diff --git a/InvenTree/part/templates/part/prices.html b/InvenTree/part/templates/part/prices.html
index 21bc8d405a..749b5cb928 100644
--- a/InvenTree/part/templates/part/prices.html
+++ b/InvenTree/part/templates/part/prices.html
@@ -359,84 +359,15 @@
// Internal pricebreaks
{% settings_value "PART_INTERNAL_PRICE" as show_internal_price %}
{% if show_internal_price and roles.sales_order.view %}
- function reloadPriceBreaks() {
- $("#internal-price-break-table").bootstrapTable("refresh");
- }
-
- $('#new-internal-price-break').click(function() {
- launchModalForm("{% url 'internal-price-break-create' %}",
- {
- success: reloadPriceBreaks,
- data: {
- part: {{ part.id }},
- }
- }
+ initPriceBreakSet(
+ $('#internal-price-break-table'),
+ {{part.id}},
+ 'internal price break',
+ 'internal-price',
+ "{% url 'api-part-internal-price-list' %}",
+ $('#new-internal-price-break'),
+ '{% url 'internal-price-break-create' %}'
);
- });
-
- $('#internal-price-break-table').inventreeTable({
- name: 'internalprice',
- formatNoMatches: function() { return "{% trans 'No internal price break information found' %}"; },
- queryParams: {
- part: {{ part.id }},
- },
- url: "{% url 'api-part-internal-price-list' %}",
- onPostBody: function() {
- var table = $('#internal-price-break-table');
-
- table.find('.button-internal-price-break-delete').click(function() {
- var pk = $(this).attr('pk');
-
- launchModalForm(
- `/part/internal-price/${pk}/delete/`,
- {
- success: reloadPriceBreaks
- }
- );
- });
-
- table.find('.button-internal-price-break-edit').click(function() {
- var pk = $(this).attr('pk');
-
- launchModalForm(
- `/part/internal-price/${pk}/edit/`,
- {
- success: reloadPriceBreaks
- }
- );
- });
- },
- columns: [
- {
- field: 'pk',
- title: 'ID',
- visible: false,
- switchable: false,
- },
- {
- field: 'quantity',
- title: '{% trans "Quantity" %}',
- sortable: true,
- },
- {
- field: 'price',
- title: '{% trans "Price" %}',
- sortable: true,
- formatter: function(value, row, index) {
- var html = value;
-
- html += `
`
-
- html += makeIconButton('fa-edit icon-blue', 'button-internal-price-break-edit', row.pk, '{% trans "Edit internal price break" %}');
- html += makeIconButton('fa-trash-alt icon-red', 'button-internal-price-break-delete', row.pk, '{% trans "Delete internal price break" %}');
-
- html += `
`;
-
- return html;
- }
- },
- ]
- })
{% endif %}
@@ -452,85 +383,15 @@
// Sales pricebreaks
{% if part.salable and roles.sales_order.view %}
- function reloadPriceBreaks() {
- $("#price-break-table").bootstrapTable("refresh");
- }
-
- $('#new-price-break').click(function() {
- launchModalForm("{% url 'sale-price-break-create' %}",
- {
- success: reloadPriceBreaks,
- data: {
- part: {{ part.id }},
- }
- }
+ initPriceBreakSet(
+ $('#price-break-table'),
+ {{part.id}},
+ 'sale price break',
+ 'sale-price',
+ "{% url 'api-part-sale-price-list' %}",
+ $('#new-price-break'),
+ '{% url 'sale-price-break-create' %}'
);
- });
-
- $('#price-break-table').inventreeTable({
- name: 'saleprice',
- formatNoMatches: function() { return "{% trans 'No price break information found' %}"; },
- queryParams: {
- part: {{ part.id }},
- },
- url: "{% url 'api-part-sale-price-list' %}",
- onPostBody: function() {
- var table = $('#price-break-table');
-
- table.find('.button-price-break-delete').click(function() {
- var pk = $(this).attr('pk');
-
- launchModalForm(
- `/part/sale-price/${pk}/delete/`,
- {
- success: reloadPriceBreaks
- }
- );
- });
-
- table.find('.button-price-break-edit').click(function() {
- var pk = $(this).attr('pk');
-
- launchModalForm(
- `/part/sale-price/${pk}/edit/`,
- {
- success: reloadPriceBreaks
- }
- );
- });
- },
- columns: [
- {
- field: 'pk',
- title: 'ID',
- visible: false,
- switchable: false,
- },
- {
- field: 'quantity',
- title: '{% trans "Quantity" %}',
- sortable: true,
- },
- {
- field: 'price',
- title: '{% trans "Price" %}',
- sortable: true,
- formatter: function(value, row, index) {
- var html = 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" %}');
-
- html += `
`;
-
- return html;
- }
- },
- ]
- })
-
{% endif %}
{% endblock %}
diff --git a/InvenTree/templates/js/part.js b/InvenTree/templates/js/part.js
index 66174e2f15..82fd416e15 100644
--- a/InvenTree/templates/js/part.js
+++ b/InvenTree/templates/js/part.js
@@ -769,6 +769,105 @@ function loadPartTestTemplateTable(table, options) {
}
+function loadPriceBreakTable(table, options) {
+ /*
+ * Load PriceBreak table.
+ */
+
+ var name = options.name || 'pricebreak';
+ var human_name = options.human_name || 'price break';
+
+ table.inventreeTable({
+ name: name,
+ method: 'get',
+ formatNoMatches: function() {
+ return `{% trans "No ${human_name} information found" %}`;
+ },
+ url: options.url,
+ columns: [
+ {
+ field: 'pk',
+ title: 'ID',
+ visible: false,
+ switchable: false,
+ },
+ {
+ field: 'quantity',
+ title: '{% trans "Quantity" %}',
+ sortable: true,
+ },
+ {
+ field: 'price',
+ title: '{% trans "Price" %}',
+ sortable: true,
+ formatter: function(value, row, index) {
+ var html = value;
+
+ html += ``
+
+ html += makeIconButton('fa-edit icon-blue', `button-${name}-edit`, row.pk, `{% trans "Edit ${human_name}" %}`);
+ html += makeIconButton('fa-trash-alt icon-red', `button-${name}-delete`, row.pk, `{% trans "Delete ${human_name}" %}`);
+
+ html += `
`;
+
+ return html;
+ }
+ },
+ ]
+ });
+}
+
+
+function initPriceBreakSet(table, part_id, pb_human_name, pb_url_slug, pb_url, pb_new_btn, pb_new_url) {
+
+ loadPriceBreakTable(
+ table,
+ {
+ name: pb_url_slug,
+ human_name: pb_human_name,
+ url: pb_url,
+ }
+ );
+
+ function reloadPriceBreakTable(){
+ table.bootstrapTable("refresh");
+ }
+
+ pb_new_btn.click(function() {
+ launchModalForm(pb_new_url,
+ {
+ success: reloadPriceBreakTable,
+ data: {
+ part: part_id,
+ }
+ }
+ );
+ });
+
+ table.on('click', `.button-${pb_url_slug}-delete`, function() {
+ var pk = $(this).attr('pk');
+
+ launchModalForm(
+ `/part/${pb_url_slug}/${pk}/delete/`,
+ {
+ success: reloadPriceBreakTable
+ }
+ );
+ });
+
+ table.on('click', `.button-${pb_url_slug}-edit`, function() {
+ var pk = $(this).attr('pk');
+
+ launchModalForm(
+ `/part/${pb_url_slug}/${pk}/edit/`,
+ {
+ success: reloadPriceBreakTable
+ }
+ );
+ });
+}
+
+
function loadStockPricingChart(context, data) {
return new Chart(context, {
type: 'bar',