aboutsummaryrefslogtreecommitdiffstats
path: root/servo/forms
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-10-01 00:31:02 +0300
committerFilipp Lepalaan <filipp@mac.com>2015-10-01 00:31:02 +0300
commit0c6d66e7ced5f1c7843eba4221b08db79e56a021 (patch)
treec16473f761eb5d26d2a3d1a4ceb2f9f2875b44e4 /servo/forms
parentec6276e2fb2bb0785f14469bbe8eb292f4a6e6b7 (diff)
downloadServo-0c6d66e7ced5f1c7843eba4221b08db79e56a021.tar.gz
Servo-0c6d66e7ced5f1c7843eba4221b08db79e56a021.tar.bz2
Servo-0c6d66e7ced5f1c7843eba4221b08db79e56a021.zip
Inventory bug fixes
and performance enhancements
Diffstat (limited to 'servo/forms')
-rw-r--r--servo/forms/product.py20
-rw-r--r--servo/forms/returns.py10
2 files changed, 23 insertions, 7 deletions
diff --git a/servo/forms/product.py b/servo/forms/product.py
index a70d69f..61969f1 100644
--- a/servo/forms/product.py
+++ b/servo/forms/product.py
@@ -7,7 +7,7 @@ from django.core.exceptions import ValidationError
from servo.models import Location, User, TaggedItem
from servo.models.purchases import PurchaseOrderItem
-from servo.models.product import Product, ProductCategory
+from servo.models.product import Product, ProductCategory, Inventory
from servo.forms.base import BaseModelForm, DatepickerInput, TextInput
@@ -114,7 +114,8 @@ class ProductForm(forms.ModelForm):
def clean_code(self):
code = self.cleaned_data.get('code')
if not re.match(r'^[\w\-/]+$', code):
- raise ValidationError(_('Product code %s contains invalid characters') % code)
+ msg = _('Product code %s contains invalid characters') % code
+ raise ValidationError(msg)
return code
@@ -207,3 +208,18 @@ class IncomingSearchForm(forms.Form):
label=_('Service order is')
)
+
+class ReserveProductForm(forms.Form):
+ """
+ Form for reserving products for a given SO
+ """
+ inventory = forms.ModelChoiceField(
+ queryset=Inventory.objects.none(),
+ label=_('Inventory')
+ )
+
+ def __init__(self, order, *args, **kwargs):
+ super(ReserveProductForm, self).__init__(*args, **kwargs)
+ inventory = Inventory.objects.filter(location=order.location,
+ product__in=order.products.all())
+ self.fields['inventory'].queryset = inventory
diff --git a/servo/forms/returns.py b/servo/forms/returns.py
index 9a011b9..ec339ae 100644
--- a/servo/forms/returns.py
+++ b/servo/forms/returns.py
@@ -59,19 +59,19 @@ class BulkReturnPartForm(forms.ModelForm):
class Meta:
model = ServicePart
widgets = {
- 'box_number': forms.Select(attrs={'class': 'input-small'}),
- 'part_number': forms.HiddenInput(),
- 'part_title': forms.HiddenInput(),
+ 'box_number' : forms.Select(attrs={'class': 'input-small'}),
+ 'part_number' : forms.HiddenInput(),
+ 'part_title' : forms.HiddenInput(),
'service_order': forms.HiddenInput(),
- 'return_order': forms.HiddenInput(),
+ 'return_order' : forms.HiddenInput(),
}
exclude = []
def __init__(self, *args, **kwargs):
super(BulkReturnPartForm, self).__init__(*args, **kwargs)
if 'instance' in kwargs:
- box_choices = [(0, 'Individual',)]
instance = kwargs['instance']
+ box_choices = [(0, 'Individual',)]
# @TODO: This seems like a totally unnecessary hack...
# Why can't I just pass the number of options directly to the form?
part_count = instance.shipment.servicepart_set.all().count()