mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
SupplierPart price break table now uses API rather than django template
This commit is contained in:
parent
805e8daa57
commit
e51fee081b
@ -12,7 +12,7 @@ INVENTREE_SW_VERSION = "0.1.3 pre"
|
||||
|
||||
def inventreeInstanceName():
|
||||
""" Returns the InstanceName settings for the current database """
|
||||
return common.modelsInvenTreeSetting.get_setting("InstanceName", "")
|
||||
return common.models.InvenTreeSetting.get_setting("InstanceName", "")
|
||||
|
||||
|
||||
def inventreeVersion():
|
||||
|
@ -176,6 +176,14 @@ class PriceBreak(models.Model):
|
||||
|
||||
currency = models.ForeignKey(Currency, blank=True, null=True, on_delete=models.SET_NULL)
|
||||
|
||||
@property
|
||||
def symbol(self):
|
||||
return self.currency.symbol if self.currency else ''
|
||||
|
||||
@property
|
||||
def suffix(self):
|
||||
return self.currency.suffix if self.currency else ''
|
||||
|
||||
@property
|
||||
def converted_cost(self):
|
||||
"""
|
||||
|
@ -137,11 +137,22 @@ class SupplierPartSerializer(InvenTreeModelSerializer):
|
||||
class SupplierPriceBreakSerializer(InvenTreeModelSerializer):
|
||||
""" Serializer for SupplierPriceBreak object """
|
||||
|
||||
symbol = serializers.CharField(read_only=True)
|
||||
|
||||
suffix = serializers.CharField(read_only=True)
|
||||
|
||||
quantity = serializers.FloatField()
|
||||
|
||||
cost = serializers.FloatField()
|
||||
|
||||
class Meta:
|
||||
model = SupplierPriceBreak
|
||||
fields = [
|
||||
'pk',
|
||||
'part',
|
||||
'quantity',
|
||||
'cost'
|
||||
'cost',
|
||||
'currency',
|
||||
'symbol',
|
||||
'suffix',
|
||||
]
|
||||
|
@ -10,45 +10,12 @@
|
||||
<hr>
|
||||
|
||||
<h4>{% trans "Pricing Information" %}</h4>
|
||||
<table class="table table-striped table-condensed">
|
||||
<tr><td>{% trans "Order Multiple" %}</td><td>{{ part.multiple }}</td></tr>
|
||||
{% if part.base_cost > 0 %}
|
||||
<tr><td>{% trans "Base Price (Flat Fee)" %}</td><td>{{ part.base_cost }}</td></tr>
|
||||
{% endif %}
|
||||
<tr>
|
||||
<th>{% trans "Price Breaks" %}</th>
|
||||
<th>
|
||||
<div style='float: right;'>
|
||||
<button class='btn btn-primary' id='new-price-break' type='button'>{% trans "New Price Break" %}</button>
|
||||
</div>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans "Quantity" %}</th>
|
||||
<th>{% trans "Price" %}</th>
|
||||
</tr>
|
||||
{% if part.price_breaks.all %}
|
||||
{% for pb in part.price_breaks.all %}
|
||||
<tr>
|
||||
<td>{% decimal pb.quantity %}</td>
|
||||
<td>
|
||||
{% if pb.currency %}{{ pb.currency.symbol }}{% endif %}
|
||||
{% decimal pb.cost %}
|
||||
{% if pb.currency %}{{ pb.currency.suffix }}{% endif %}
|
||||
<div class='btn-group' style='float: right;'>
|
||||
<button title='Edit Price Break' class='btn btn-default btn-sm pb-edit-button' type='button' url="{% url 'price-break-edit' pb.id %}"><span class='fas fa-edit icon-green'></span></button>
|
||||
<button title='Delete Price Break' class='btn btn-default btn-sm pb-delete-button' type='button' url="{% url 'price-break-delete' pb.id %}"><span class='fas fa-trash-alt icon-red'></span></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan='2'>
|
||||
<span class='warning-msg'><i>{% trans "No price breaks have been added for this part" %}</i></span>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
|
||||
<div id='price-break-toolbar' class='btn-group'>
|
||||
<button class='btn btn-primary' id='new-price-break' type='button'>{% trans "Add Price Break" %}</button>
|
||||
</div>
|
||||
|
||||
<table class='table table-striped table-condensed' id='price-break-table' data-toolbar='#price-break-toolbar'>
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
@ -56,7 +23,80 @@
|
||||
{% block js_ready %}
|
||||
{{ block.super }}
|
||||
|
||||
function reloadPriceBreaks() {
|
||||
$("#price-break-table").bootstrapTable("refresh");
|
||||
}
|
||||
|
||||
$('#price-break-table').inventreeTable({
|
||||
name: 'buypricebreaks',
|
||||
formatNoMatches: function() { return "{% trans "No price break information found" %}"; },
|
||||
queryParams: {
|
||||
part: {{ part.id }},
|
||||
},
|
||||
url: "{% url 'api-part-supplier-price' %}",
|
||||
onLoadSuccess: function() {
|
||||
var table = $('#price-break-table');
|
||||
|
||||
table.find('.button-price-break-delete').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
launchModalForm(
|
||||
`/price-break/${pk}/delete/`,
|
||||
{
|
||||
success: reloadPriceBreaks
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
table.find('.button-price-break-edit').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
launchModalForm(
|
||||
`/price-break/${pk}/edit/`,
|
||||
{
|
||||
success: reloadPriceBreaks
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'pk',
|
||||
title: 'ID',
|
||||
visible: false,
|
||||
switchable: false,
|
||||
},
|
||||
{
|
||||
field: 'quantity',
|
||||
title: '{% trans "Quantity" %}',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'cost',
|
||||
title: '{% trans "Price" %}',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index) {
|
||||
var html = '';
|
||||
|
||||
html += row.symbol || '';
|
||||
html += value;
|
||||
|
||||
if (row.suffix) {
|
||||
html += ' ' + row.suffix || '';
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
},
|
||||
]
|
||||
});
|
||||
|
||||
$('#new-price-break').click(function() {
|
||||
launchModalForm("{% url 'price-break-create' %}",
|
||||
@ -69,24 +109,4 @@ $('#new-price-break').click(function() {
|
||||
);
|
||||
});
|
||||
|
||||
$('.pb-edit-button').click(function() {
|
||||
var button = $(this);
|
||||
|
||||
launchModalForm(button.attr('url'),
|
||||
{
|
||||
reload: true,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$('.pb-delete-button').click(function() {
|
||||
var button = $(this);
|
||||
|
||||
launchModalForm(button.attr('url'),
|
||||
{
|
||||
reload: true,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user