Refactor update and delete forms for SupplierPriceBreak

This commit is contained in:
Oliver 2021-06-30 14:14:31 +10:00
parent 09fff5b644
commit 2b394174bc
5 changed files with 30 additions and 46 deletions

View File

@ -13,7 +13,6 @@ from django.contrib.auth import views as auth_views
from company.urls import company_urls from company.urls import company_urls
from company.urls import manufacturer_part_urls from company.urls import manufacturer_part_urls
from company.urls import supplier_part_urls from company.urls import supplier_part_urls
from company.urls import price_break_urls
from common.urls import common_urls from common.urls import common_urls
from part.urls import part_urls from part.urls import part_urls
@ -126,7 +125,6 @@ urlpatterns = [
url(r'^part/', include(part_urls)), url(r'^part/', include(part_urls)),
url(r'^manufacturer-part/', include(manufacturer_part_urls)), url(r'^manufacturer-part/', include(manufacturer_part_urls)),
url(r'^supplier-part/', include(supplier_part_urls)), url(r'^supplier-part/', include(supplier_part_urls)),
url(r'^price-break/', include(price_break_urls)),
# "Dynamic" javascript files which are rendered using InvenTree templating. # "Dynamic" javascript files which are rendered using InvenTree templating.
url(r'^dynamic/', include(dynamic_javascript_urls)), url(r'^dynamic/', include(dynamic_javascript_urls)),

View File

@ -394,6 +394,15 @@ class SupplierPriceBreakList(generics.ListCreateAPIView):
] ]
class SupplierPriceBreakDetail(generics.RetrieveUpdateDestroyAPIView):
"""
Detail endpoint for SupplierPriceBreak object
"""
queryset = SupplierPriceBreak.objects.all()
serializer_class = SupplierPriceBreakSerializer
manufacturer_part_api_urls = [ manufacturer_part_api_urls = [
url(r'^parameter/', include([ url(r'^parameter/', include([
@ -424,7 +433,12 @@ company_api_urls = [
url(r'^part/', include(supplier_part_api_urls)), url(r'^part/', include(supplier_part_api_urls)),
url(r'^price-break/', SupplierPriceBreakList.as_view(), name='api-part-supplier-price-list'), # Supplier price breaks
url(r'^price-break/', include([
url(r'^(?P<pk>\d+)/?', SupplierPriceBreakDetail.as_view(), name='api-part-supplier-price-detail'),
url(r'^.*$', SupplierPriceBreakList.as_view(), name='api-part-supplier-price-list'),
])),
url(r'^(?P<pk>\d+)/?', CompanyDetail.as_view(), name='api-company-detail'), url(r'^(?P<pk>\d+)/?', CompanyDetail.as_view(), name='api-company-detail'),

View File

@ -46,23 +46,25 @@ $('#price-break-table').inventreeTable({
table.find('.button-price-break-delete').click(function() { table.find('.button-price-break-delete').click(function() {
var pk = $(this).attr('pk'); var pk = $(this).attr('pk');
launchModalForm( constructForm(`/api/company/price-break/${pk}/`, {
`/price-break/${pk}/delete/`, method: 'DELETE',
{ onSuccess: reloadPriceBreaks,
success: reloadPriceBreaks title: '{% trans "Delete Price Break" %}',
} });
);
}); });
table.find('.button-price-break-edit').click(function() { table.find('.button-price-break-edit').click(function() {
var pk = $(this).attr('pk'); var pk = $(this).attr('pk');
launchModalForm( constructForm(`/api/company/price-break/${pk}/`, {
`/price-break/${pk}/edit/`, fields: {
{ quantity: {},
success: reloadPriceBreaks price: {},
} price_currency: {},
); },
onSuccess: reloadPriceBreaks,
title: '{% trans "Edit Price Break" %}',
});
}); });
}, },
columns: [ columns: [
@ -114,7 +116,7 @@ $('#new-price-break').click(function() {
}, },
}, },
title: '{% trans "Add Price Break" %}', title: '{% trans "Add Price Break" %}',
reload: true onSuccess: reloadPriceBreaks,
} }
); );
}); });

View File

@ -39,12 +39,6 @@ company_urls = [
url(r'^.*$', views.CompanyIndex.as_view(), name='company-index'), url(r'^.*$', views.CompanyIndex.as_view(), name='company-index'),
] ]
price_break_urls = [
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'),
]
manufacturer_part_urls = [ manufacturer_part_urls = [
url(r'^new/?', views.ManufacturerPartCreate.as_view(), name='manufacturer-part-create'), url(r'^new/?', views.ManufacturerPartCreate.as_view(), name='manufacturer-part-create'),

View File

@ -759,27 +759,3 @@ class SupplierPartDelete(AjaxDeleteView):
part.delete() part.delete()
return self.renderJsonResponse(self.request, data=data, form=self.get_form()) return self.renderJsonResponse(self.request, data=data, form=self.get_form())
class PriceBreakEdit(AjaxUpdateView):
""" View for editing a supplier price break """
model = SupplierPriceBreak
form_class = EditPriceBreakForm
ajax_form_title = _('Edit Price Break')
ajax_template_name = 'modal_form.html'
def get_form(self):
form = super(AjaxUpdateView, self).get_form()
form.fields['part'].widget = HiddenInput()
return form
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'