mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
price break js refactor
This commit is contained in:
parent
d7d080fb96
commit
9f27a77689
@ -359,84 +359,15 @@
|
|||||||
// Internal pricebreaks
|
// Internal pricebreaks
|
||||||
{% settings_value "PART_INTERNAL_PRICE" as show_internal_price %}
|
{% settings_value "PART_INTERNAL_PRICE" as show_internal_price %}
|
||||||
{% if show_internal_price and roles.sales_order.view %}
|
{% if show_internal_price and roles.sales_order.view %}
|
||||||
function reloadPriceBreaks() {
|
initPriceBreakSet(
|
||||||
$("#internal-price-break-table").bootstrapTable("refresh");
|
$('#internal-price-break-table'),
|
||||||
}
|
{{part.id}},
|
||||||
|
'internal price break',
|
||||||
$('#new-internal-price-break').click(function() {
|
'internal-price',
|
||||||
launchModalForm("{% url 'internal-price-break-create' %}",
|
"{% url 'api-part-internal-price-list' %}",
|
||||||
{
|
$('#new-internal-price-break'),
|
||||||
success: reloadPriceBreaks,
|
'{% url 'internal-price-break-create' %}'
|
||||||
data: {
|
|
||||||
part: {{ part.id }},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
$('#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 += `<div class='btn-group float-right' role='group'>`
|
|
||||||
|
|
||||||
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 += `</div>`;
|
|
||||||
|
|
||||||
return html;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
@ -452,85 +383,15 @@
|
|||||||
|
|
||||||
// Sales pricebreaks
|
// Sales pricebreaks
|
||||||
{% if part.salable and roles.sales_order.view %}
|
{% if part.salable and roles.sales_order.view %}
|
||||||
function reloadPriceBreaks() {
|
initPriceBreakSet(
|
||||||
$("#price-break-table").bootstrapTable("refresh");
|
$('#price-break-table'),
|
||||||
}
|
{{part.id}},
|
||||||
|
'sale price break',
|
||||||
$('#new-price-break').click(function() {
|
'sale-price',
|
||||||
launchModalForm("{% url 'sale-price-break-create' %}",
|
"{% url 'api-part-sale-price-list' %}",
|
||||||
{
|
$('#new-price-break'),
|
||||||
success: reloadPriceBreaks,
|
'{% url 'sale-price-break-create' %}'
|
||||||
data: {
|
|
||||||
part: {{ part.id }},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
$('#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 += `<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" %}');
|
|
||||||
|
|
||||||
html += `</div>`;
|
|
||||||
|
|
||||||
return html;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -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 += `<div class='btn-group float-right' role='group'>`
|
||||||
|
|
||||||
|
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 += `</div>`;
|
||||||
|
|
||||||
|
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) {
|
function loadStockPricingChart(context, data) {
|
||||||
return new Chart(context, {
|
return new Chart(context, {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
|
Loading…
Reference in New Issue
Block a user