mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-19 21:45:39 +00:00
Form for creating a new price break for a supplier part
This commit is contained in:
@ -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'
|
||||
|
Reference in New Issue
Block a user