mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Form for creating a new price break for a supplier part
This commit is contained in:
parent
1163f60b23
commit
fc3072a459
@ -14,6 +14,7 @@ from company.urls import company_urls
|
||||
|
||||
from part.urls import part_urls
|
||||
from part.urls import supplier_part_urls
|
||||
from part.urls import price_break_urls
|
||||
|
||||
from stock.urls import stock_urls
|
||||
|
||||
@ -50,6 +51,7 @@ apipatterns = [
|
||||
urlpatterns = [
|
||||
url(r'^part/', include(part_urls)),
|
||||
url(r'^supplier-part/', include(supplier_part_urls)),
|
||||
url(r'^price-break/', include(price_break_urls)),
|
||||
|
||||
url(r'^stock/', include(stock_urls)),
|
||||
|
||||
|
@ -223,6 +223,7 @@ class AjaxCreateView(AjaxMixin, CreateView):
|
||||
|
||||
super(CreateView, self).get(request, *args, **kwargs)
|
||||
|
||||
self.request = request
|
||||
form = self.get_form()
|
||||
return self.renderJsonResponse(request, form)
|
||||
|
||||
@ -233,6 +234,7 @@ class AjaxCreateView(AjaxMixin, CreateView):
|
||||
- If valid, save form
|
||||
- Return status info (success / failure)
|
||||
"""
|
||||
self.request = request
|
||||
form = self.get_form()
|
||||
|
||||
# Extra JSON data sent alongside form
|
||||
|
@ -10,7 +10,7 @@ InvenTree | {{ company.name }} - Parts
|
||||
<div class='row'>
|
||||
<div class='col-sm-6'>
|
||||
<h3>Supplier Part</h3>
|
||||
<p>{{ part.SKU }} - <a href="{% url 'company-detail-parts' part.supplier.id %}">{{ part.supplier.name }}</a></p>
|
||||
<p><a href="{% url 'company-detail-parts' part.supplier.id %}">{{ part.supplier.name }}</a> - {{ part.SKU }}</p>
|
||||
</div>
|
||||
<div class='col-sm-6'>
|
||||
<h3>
|
||||
@ -59,29 +59,41 @@ InvenTree | {{ company.name }} - Parts
|
||||
|
||||
<div class='col-sm-6'>
|
||||
<table class="table table-striped table-condensed">
|
||||
<tr><th colspan='2'>Pricing</th></tr>
|
||||
<tr><td>Single Price</td><td>{{ part.single_price }}</td></tr>
|
||||
{% if part.multiple > 1 %}
|
||||
<tr>
|
||||
<th colspan='2'>Pricing</th>
|
||||
</tr>
|
||||
<tr><td>Order Multiple</td><td>{{ part.multiple }}</td></tr>
|
||||
{% endif %}
|
||||
{% if part.base_cost > 0 %}
|
||||
<tr><td>Base Price (Flat Fee)</td><td>{{ part.base_cost }}</td></tr>
|
||||
{% endif %}
|
||||
{% if part.minimum > 1 %}
|
||||
<tr><td>Minimum Order Quantity</td><td>{{ part.minimum }}</td></tr>
|
||||
{% endif %}
|
||||
{% if part.price_breaks.all %}
|
||||
<tr><th colspan='2'>Price Breaks</th></tr>
|
||||
<tr>
|
||||
<th>Price Breaks</th>
|
||||
<th>
|
||||
<div style='float: right;'>
|
||||
<button class='btn btn-primary' id='new-price-break' type='button'>New Price Break</button>
|
||||
</div>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Quantity</th>
|
||||
<th>Price</th>
|
||||
</tr>
|
||||
{% if part.price_breaks.all %}
|
||||
{% for pb in part.price_breaks.all %}
|
||||
<tr>
|
||||
<td>{{ pb.quantity }}</td>
|
||||
<td>{{ pb.cost }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan='2'>
|
||||
<span class='warning-msg'><i>No price breaks have been added for this part</i></span>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
</div>
|
||||
@ -89,9 +101,7 @@ InvenTree | {{ company.name }} - Parts
|
||||
|
||||
<br>
|
||||
|
||||
<div>
|
||||
<button class='btn btn-primary' type='button'>New Price Break</button>
|
||||
</div>
|
||||
|
||||
|
||||
{% include 'modals.html' %}
|
||||
|
||||
@ -116,4 +126,16 @@ InvenTree | {{ company.name }} - Parts
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$('#new-price-break').click(function() {
|
||||
launchModalForm("{% url 'price-break-create' %}",
|
||||
{
|
||||
reload: true,
|
||||
data: {
|
||||
part: {{ part.id }},
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
{% endblock %}
|
@ -12,6 +12,7 @@ from django import forms
|
||||
from .models import Part, PartCategory, PartAttachment
|
||||
from .models import BomItem
|
||||
from .models import SupplierPart
|
||||
from .models import SupplierPriceBreak
|
||||
|
||||
|
||||
class PartImageForm(HelperForm):
|
||||
@ -161,3 +162,15 @@ class EditSupplierPartForm(HelperForm):
|
||||
'packaging',
|
||||
'lead_time'
|
||||
]
|
||||
|
||||
|
||||
class EditPriceBreakForm(HelperForm):
|
||||
""" Form for creating / editing a supplier price break """
|
||||
|
||||
class Meta:
|
||||
model = SupplierPriceBreak
|
||||
fields = [
|
||||
'part',
|
||||
'quantity',
|
||||
'cost'
|
||||
]
|
@ -12,6 +12,13 @@ from django.conf.urls import url, include
|
||||
|
||||
from . import views
|
||||
|
||||
price_break_urls = [
|
||||
url('^new/', views.PriceBreakCreate.as_view(), name='price-break-create'),
|
||||
|
||||
url(r'^(?P<pk>\d+)/edit/', views.PriceBreakEdit.as_view(), name='price-break-edit'),
|
||||
url(r'^(?P<pk>\d+)/delete/', views.PriceBreakDelete.as_view(), name='price-break-delete'),
|
||||
]
|
||||
|
||||
supplier_part_detail_urls = [
|
||||
url(r'edit/?', views.SupplierPartEdit.as_view(), name='supplier-part-edit'),
|
||||
url(r'delete/?', views.SupplierPartDelete.as_view(), name='supplier-part-delete'),
|
||||
|
@ -16,6 +16,7 @@ from company.models import Company
|
||||
from .models import PartCategory, Part, PartAttachment
|
||||
from .models import BomItem
|
||||
from .models import SupplierPart
|
||||
from .models import SupplierPriceBreak
|
||||
from .models import match_part_names
|
||||
|
||||
from . import forms as part_forms
|
||||
@ -809,3 +810,58 @@ class SupplierPartDelete(AjaxDeleteView):
|
||||
ajax_template_name = 'company/partdelete.html'
|
||||
ajax_form_title = 'Delete Supplier Part'
|
||||
context_object_name = 'supplier_part'
|
||||
|
||||
|
||||
class PriceBreakCreate(AjaxCreateView):
|
||||
""" View for creating a supplier price break """
|
||||
|
||||
model = SupplierPriceBreak
|
||||
form_class = part_forms.EditPriceBreakForm
|
||||
ajax_form_title = 'Add Price Break'
|
||||
ajax_template_name = 'modal_form.html'
|
||||
|
||||
def get_data(self):
|
||||
return {
|
||||
'success': 'Added new price break'
|
||||
}
|
||||
|
||||
def get_part(self):
|
||||
try:
|
||||
return SupplierPart.objects.get(id=self.request.GET.get('part'))
|
||||
except SupplierPart.DoesNotExist:
|
||||
return SupplierPart.objects.get(id=self.request.POST.get('part'))
|
||||
|
||||
def get_form(self):
|
||||
|
||||
form = super(AjaxCreateView, self).get_form()
|
||||
|
||||
form.fields['part'].widget = HiddenInput()
|
||||
|
||||
return form
|
||||
|
||||
def get_initial(self):
|
||||
|
||||
initials = super(AjaxCreateView, self).get_initial()
|
||||
|
||||
print("GETTING INITIAL DAtA")
|
||||
|
||||
initials['part'] = self.get_part()
|
||||
|
||||
return initials
|
||||
|
||||
|
||||
class PriceBreakEdit(AjaxUpdateView):
|
||||
""" View for editing a supplier price break """
|
||||
|
||||
model = SupplierPriceBreak
|
||||
form_class = part_forms.EditPriceBreakForm
|
||||
ajax_form_title = 'Edit Price Break'
|
||||
ajax_template_name = 'modal_form.html'
|
||||
|
||||
|
||||
class PriceBreakDelete(AjaxDeleteView):
|
||||
""" View for deleting a supplier price break """
|
||||
|
||||
model = SupplierPriceBreak
|
||||
ajax_form_title = "Delete Price Break"
|
||||
ajax_template_name = 'modal_delete_form.html'
|
||||
|
Loading…
Reference in New Issue
Block a user