summaryrefslogtreecommitdiff
path: root/ishtar/ishtar_base/forms_items.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar/ishtar_base/forms_items.py')
-rw-r--r--ishtar/ishtar_base/forms_items.py91
1 files changed, 81 insertions, 10 deletions
diff --git a/ishtar/ishtar_base/forms_items.py b/ishtar/ishtar_base/forms_items.py
index 484902341..a89dc7cf1 100644
--- a/ishtar/ishtar_base/forms_items.py
+++ b/ishtar/ishtar_base/forms_items.py
@@ -185,10 +185,7 @@ class BaseTreatmentForm(forms.Form):
associated_models = {'treatment_type':models.TreatmentType,
'person':models.Person,
'location':models.Warehouse}
- treatment_type = forms.ChoiceField(label=_(u"Treatment type"),
- choices=models.TreatmentType.get_types())
- description = forms.CharField(label=_(u"Description"),
- widget=forms.Textarea, required=False)
+ treatment_type = forms.ChoiceField(label=_(u"Treatment type"), choices=[])
person = forms.IntegerField(label=_(u"Person"),
widget=widgets.JQueryAutoComplete(
reverse_lazy('autocomplete-person'), associated_model=models.Person),
@@ -198,11 +195,20 @@ class BaseTreatmentForm(forms.Form):
reverse_lazy('autocomplete-warehouse'), associated_model=models.Warehouse,
new=True),
validators=[models.valid_id(models.Warehouse)])
+ description = forms.CharField(label=_(u"Description"),
+ widget=forms.Textarea, required=False)
start_date = forms.DateField(label=_(u"Start date"), required=False,
widget=widgets.JQueryDate)
end_date = forms.DateField(label=_(u"End date"), required=False,
widget=widgets.JQueryDate)
+ def __init__(self, *args, **kwargs):
+ super(BaseTreatmentForm, self).__init__(*args, **kwargs)
+ self.fields['treatment_type'].choices = models.TreatmentType.get_types(
+ exclude=['packaging'])
+ self.fields['treatment_type'].help_text = models.TreatmentType.get_help(
+ exclude=['packaging'])
+
class ItemMultipleFormSelection(forms.Form):
form_label = _(u"Upstream items")
associated_models = {'items':models.Item}
@@ -213,13 +219,42 @@ class ItemMultipleFormSelection(forms.Form):
class ContainerForm(forms.Form):
form_label = _(u"Container")
- associated_models = {'container_type':models.ContainerType,}
reference = forms.CharField(label=_(u"Reference"))
- container_type = forms.ChoiceField(label=_(u"Container type"),
- choices=models.ContainerType.get_types())
+ container_type = forms.ChoiceField(label=_(u"Container type"), choices=[])
+ location = forms.IntegerField(label=_(u"Location"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-warehouse'), associated_model=models.Warehouse,
+ new=True),
+ validators=[models.valid_id(models.Warehouse)])
comment = forms.CharField(label=_(u"Comment"),
widget=forms.Textarea, required=False)
+ def __init__(self, *args, **kwargs):
+ super(ContainerForm, self).__init__(*args, **kwargs)
+ self.fields['container_type'].choices = \
+ models.ContainerType.get_types()
+ self.fields['container_type'].help_text = \
+ models.ContainerType.get_help()
+
+ def save(self, user):
+ dct = self.cleaned_data
+ dct['history_modifier'] = user
+ dct['container_type'] = models.ContainerType.objects.get(
+ pk=dct['container_type'])
+ dct['location'] = models.Warehouse.objects.get(pk=dct['location'])
+ new_item = models.Container(**dct)
+ new_item.save()
+ return new_item
+
+class ContainerSelectForm(forms.Form):
+ form_label = _(u"Container")
+ associated_models = {'container':models.Container,}
+ container = forms.IntegerField(label=_(u"Container"),
+ widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-container'),
+ associated_model=models.Container, new=True),
+ validators=[models.valid_id(models.Container)])
+
+
def check_treatment(form_name, type_key, type_list=[], not_type_list=[]):
type_list = [models.TreatmentType.objects.get(txt_idx=tpe).pk
for tpe in type_list]
@@ -242,13 +277,13 @@ def check_treatment(form_name, type_key, type_list=[], not_type_list=[]):
return func
class ResultItemForm(forms.Form):
- form_label = _("Resulting item")
+ form_label = _(u"Resulting item")
associated_models = {'material_type':models.MaterialType}
label = forms.CharField(label=_(u"ID"),
validators=[validators.MaxLengthValidator(60)])
- description = forms.CharField(label=_("Precise description"),
+ description = forms.CharField(label=_(u"Precise description"),
widget=forms.Textarea)
- material_type = forms.ChoiceField(label=_("Material type"),
+ material_type = forms.ChoiceField(label=_(u"Material type"),
choices=models.MaterialType.get_types())
volume = forms.IntegerField(label=_(u"Volume (l)"))
weight = forms.IntegerField(label=_(u"Weight (g)"))
@@ -292,6 +327,42 @@ treatment_creation_wizard = TreatmentWizard([
# Warehouse management #
########################
+class PackagingWizard(TreatmentWizard):
+ pass
+
+class BasePackagingForm(forms.Form):
+ form_label = _(u"Packaging")
+ associated_models = {'treatment_type':models.TreatmentType,
+ 'person':models.Person,
+ 'location':models.Warehouse}
+ treatment_type = forms.IntegerField(label="", widget=forms.HiddenInput)
+ person = forms.IntegerField(label=_(u"Person"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-person'), associated_model=models.Person),
+ validators=[models.valid_id(models.Person)])
+ location = forms.IntegerField(label=_(u"Location"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-warehouse'), associated_model=models.Warehouse,
+ new=True),
+ validators=[models.valid_id(models.Warehouse)])
+ start_date = forms.DateField(label=_(u"Date"), required=False,
+ widget=widgets.JQueryDate)
+
+ def __init__(self, *args, **kwargs):
+ super(BasePackagingForm, self).__init__(*args, **kwargs)
+ self.fields['treatment_type'].initial = \
+ models.TreatmentType.objects.get(txt_idx='packaging').pk
+
+class ItemPackagingFormSelection(ItemMultipleFormSelection):
+ form_label = _(u"Packaged items")
+
+warehouse_packaging_wizard = PackagingWizard([
+ ('base-packaging', BasePackagingForm),
+ ('container-packaging', ContainerSelectForm),
+ ('multiselecitems-packaging', ItemPackagingFormSelection),
+ ('final-packaging', FinalForm)],
+ url_name='warehouse_packaging',)
+
"""
warehouse_packaging_wizard = ItemSourceWizard([
('selec-warehouse_packaging', ItemsSelection),