Include pricing information in part supplier view

Also some CSS tweaks to secondary modal buttons
This commit is contained in:
Oliver Walters 2019-05-22 22:11:27 +10:00
parent 49425efef9
commit cd7bc6cce5
8 changed files with 55 additions and 8 deletions

View File

@ -81,7 +81,8 @@ class SupplierPartList(generics.ListCreateAPIView):
'part__stock_items',
'part__bom_items',
'part__builds',
'supplier')
'supplier',
'pricebreaks')
serializer_class = SupplierPartSerializer

View File

@ -239,6 +239,10 @@ class SupplierPart(models.Model):
""" Return the associated price breaks in the correct order """
return self.pricebreaks.order_by('quantity').all()
@property
def unit_pricing(self):
return self.get_price(1)
def get_price(self, quantity, moq=True, multiples=True):
""" Calculate the supplier price based on quantity price breaks.

View File

@ -62,6 +62,8 @@ class SupplierPartSerializer(serializers.ModelSerializer):
supplier_name = serializers.CharField(source='supplier.name', read_only=True)
supplier_logo = serializers.CharField(source='supplier.get_image_url', read_only=True)
pricing = serializers.CharField(source='unit_pricing', read_only=True)
class Meta:
model = SupplierPart
fields = [
@ -76,6 +78,7 @@ class SupplierPartSerializer(serializers.ModelSerializer):
'manufacturer',
'MPN',
'URL',
'pricing',
]

View File

@ -3,7 +3,8 @@
{% block pre_form_content %}
<div class='alert alert-info alert-block'>
Calculate pricing information for {{ part }}.
Pricing information for:<br>
{{ part }}.
</div>
<h4>Quantity</h4>

View File

@ -57,6 +57,15 @@
title: 'Create New Part',
url: "{% url 'part-create' %}",
},
{
field: 'supplier_part',
label: 'New Supplier Part',
title: 'Create new Supplier Part',
url: "{% url 'supplier-part-create' %}",
data: {
part: {{ part.id }}
},
},
{
field: 'location',
label: 'New Location',

View File

@ -38,11 +38,21 @@
$('#supplier-create').click(function () {
launchModalForm(
"{% url 'supplier-part-create' %}",
{
reload: true,
data: {part: {{ part.id }} }
});
"{% url 'supplier-part-create' %}",
{
reload: true,
data: {
part: {{ part.id }}
},
secondary: [
{
field: 'supplier',
label: 'New Supplier',
title: 'Create new supplier',
url: "{% url 'company-create' %}"
}
]
});
});
$("#supplier-table").bootstrapTable({
@ -83,6 +93,18 @@
sortable: true,
field: 'MPN',
title: 'MPN',
},
{
sortable: true,
field: 'pricing',
title: 'Price',
formatter: function(value, row, index, field) {
if (value) {
return value;
} else {
return "<span class='warning-msg'><i>No pricing available</i></span>";
}
},
}
],
url: "{% url 'api-part-supplier-list' %}"

View File

@ -226,6 +226,10 @@
padding-bottom: 3px;
}
.modal .btn-secondary {
background-color: #5e7d87;
}
/* The side navigation menu */
.sidenav {
height: 100%; /* 100% Full-height */

View File

@ -362,7 +362,7 @@ function insertNewItemButton(modal, options) {
var html = "<span style='float: right;'>";
html += "<div type='button' class='btn btn-primary'";
html += "<div type='button' class='btn btn-primary btn-secondary'";
if (options.title) {
html += " title='" + options.title + "'";
@ -392,6 +392,8 @@ function attachSecondaryModal(modal, options) {
// Insert the button
insertNewItemButton(modal, options);
var data = options.data || {};
// Add a callback to the button
$(modal).find("#btn-new-" + options.field).on('click', function() {
@ -400,6 +402,7 @@ function attachSecondaryModal(modal, options) {
options.url,
{
modal: '#modal-form-secondary',
data: data,
success: function(response) {
/* A successful object creation event should return a response which contains: