From bee760d184ca196fedad4864d2787a64ef752585 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 30 Apr 2018 00:59:36 +1000 Subject: [PATCH] Deleted extraneous form code --- InvenTree/InvenTree/forms.py | 14 +++++++++++ InvenTree/build/forms.py | 11 ++------ InvenTree/company/forms.py | 37 ++++----------------------- InvenTree/part/forms.py | 49 ++++++++---------------------------- InvenTree/stock/forms.py | 40 ++++++++++++++++++----------- InvenTree/stock/models.py | 10 ++++++++ 6 files changed, 66 insertions(+), 95 deletions(-) create mode 100644 InvenTree/InvenTree/forms.py diff --git a/InvenTree/InvenTree/forms.py b/InvenTree/InvenTree/forms.py new file mode 100644 index 0000000000..d3ff976984 --- /dev/null +++ b/InvenTree/InvenTree/forms.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django import forms +from crispy_forms.helper import FormHelper + + +class HelperForm(forms.ModelForm): + + def __init__(self, *args, **kwargs): + super(forms.ModelForm, self).__init__(*args, **kwargs) + self.helper = FormHelper() + + self.helper.form_tag = False \ No newline at end of file diff --git a/InvenTree/build/forms.py b/InvenTree/build/forms.py index ace5a95168..8addb0614b 100644 --- a/InvenTree/build/forms.py +++ b/InvenTree/build/forms.py @@ -1,19 +1,12 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django import forms -from crispy_forms.helper import FormHelper +from InvenTree.forms import HelperForm from .models import Build -class EditBuildForm(forms.ModelForm): - - def __init__(self, *args, **kwargs): - super(EditBuildForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - - self.helper.form_tag = False +class EditBuildForm(HelperForm): class Meta: model = Build diff --git a/InvenTree/company/forms.py b/InvenTree/company/forms.py index 9a1a49df06..a8d833ce13 100644 --- a/InvenTree/company/forms.py +++ b/InvenTree/company/forms.py @@ -1,39 +1,12 @@ -from django import forms -from crispy_forms.helper import FormHelper +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from InvenTree.forms import HelperForm from .models import Company -""" -class EditSupplierOrderForm(forms.ModelForm): - - def __init__(self, *args, **kwargs): - super(EditSupplierOrderForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - - self.helper.form_id = 'id-edit-part-form' - self.helper.form_class = 'blueForms' - self.helper.form_method = 'post' - - self.helper.add_input(Submit('submit', 'Submit')) - - class Meta: - model = SupplierOrder - fields = [ - 'internal_ref', - 'supplier', - 'notes', - 'issued_date', - ] -""" - - -class EditCompanyForm(forms.ModelForm): - - def __init__(self, *args, **kwargs): - super(EditCompanyForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - self.helper.form_tag = False +class EditCompanyForm(HelperForm): class Meta: model = Company diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 1297da567f..d0ad7571be 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -1,18 +1,13 @@ -from django import forms -from crispy_forms.helper import FormHelper +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from InvenTree.forms import HelperForm from .models import Part, PartCategory, BomItem from .models import SupplierPart -class PartImageForm(forms.ModelForm): - - def __init__(self, *args, **kwargs): - - super(PartImageForm, self).__init__(*args, **kwargs) - - self.helper = FormHelper() - self.helper.form_tag = False +class PartImageForm(HelperForm): class Meta: model = Part @@ -21,13 +16,7 @@ class PartImageForm(forms.ModelForm): ] -class EditPartForm(forms.ModelForm): - - def __init__(self, *args, **kwargs): - super(EditPartForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - - self.helper.form_tag = False +class EditPartForm(HelperForm): class Meta: model = Part @@ -45,16 +34,11 @@ class EditPartForm(forms.ModelForm): 'purchaseable', 'salable', 'notes', + 'image', ] -class EditCategoryForm(forms.ModelForm): - - def __init__(self, *args, **kwargs): - super(EditCategoryForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - - self.helper.form_tag = False +class EditCategoryForm(HelperForm): class Meta: model = PartCategory @@ -65,15 +49,7 @@ class EditCategoryForm(forms.ModelForm): ] -class EditBomItemForm(forms.ModelForm): - - def __init__(self, *args, **kwargs): - super(EditBomItemForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - - self.helper.form_method = 'post' - - self.helper.form_tag = False +class EditBomItemForm(HelperForm): class Meta: model = BomItem @@ -84,12 +60,7 @@ class EditBomItemForm(forms.ModelForm): ] -class EditSupplierPartForm(forms.ModelForm): - def __init__(self, *args, **kwargs): - super(EditSupplierPartForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - - self.helper.form_tag = False +class EditSupplierPartForm(HelperForm): class Meta: model = SupplierPart diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index 1b49b8e223..1727c35329 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -2,18 +2,12 @@ from __future__ import unicode_literals from django import forms -from crispy_forms.helper import FormHelper +from InvenTree.forms import HelperForm from .models import StockLocation, StockItem -class EditStockLocationForm(forms.ModelForm): - - def __init__(self, *args, **kwargs): - super(EditStockLocationForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - - self.helper.form_tag = False +class EditStockLocationForm(HelperForm): class Meta: model = StockLocation @@ -24,13 +18,7 @@ class EditStockLocationForm(forms.ModelForm): ] -class EditStockItemForm(forms.ModelForm): - - def __init__(self, *args, **kwargs): - super(EditStockItemForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - - self.helper.form_tag = False +class CreateStockItemForm(HelperForm): class Meta: model = StockItem @@ -46,3 +34,25 @@ class EditStockItemForm(forms.ModelForm): # 'customer', 'URL', ] + + +class MoveStockItemForm(forms.ModelForm): + + class Meta: + model = StockItem + + fields = [ + 'location', + ] + + +class EditStockItemForm(HelperForm): + + class Meta: + model = StockItem + + fields = [ + 'quantity', + 'batch', + 'status', + ] \ No newline at end of file diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 8db3d7095b..528349931c 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -166,6 +166,16 @@ class StockItem(models.Model): infinite = models.BooleanField(default=False) + @property + def in_stock(self): + if self.quantity == 0: + return False + + if self.belongs_to or self.customer: + return False + + return True + @property def has_tracking_info(self): return self.tracking_info.count() > 0