summaryrefslogtreecommitdiff
path: root/ishtar/furnitures/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar/furnitures/forms.py')
-rw-r--r--ishtar/furnitures/forms.py155
1 files changed, 151 insertions, 4 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py
index 0cd704f53..b88fa19af 100644
--- a/ishtar/furnitures/forms.py
+++ b/ishtar/furnitures/forms.py
@@ -66,6 +66,46 @@ def clean_duplicated(formset, key_names):
_("There are identical items.")
items.append(item)
+regexp_name = re.compile(r'^[\w\- ]+$', re.UNICODE)
+name_validator = validators.RegexValidator(regexp_name,
+_(u"Enter a valid name consisting of letters, spaces and hyphens."), 'invalid')
+
+class WarehouseForm(forms.Form):
+ name = forms.CharField(label=_(u"Name"), max_length=40,
+ validators=[name_validator])
+ warehouse_type = forms.ChoiceField(label=_(u"Warehouse type"),
+ choices=models.WarehouseType.get_types())
+ person_in_charge = forms.IntegerField(label=_(u"Person in charge"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-person'), associated_model=models.Person),
+ validators=[models.valid_id(models.Person)],
+ required=False)
+ comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea,
+ required=False)
+ address = forms.CharField(label=_(u"Address"), widget=forms.Textarea,
+ required=False)
+ address_complement = forms.CharField(label=_(u"Address complement"),
+ widget=forms.Textarea, required=False)
+ postal_code = forms.CharField(label=_(u"Postal code"), max_length=10,
+ required=False)
+ town = forms.CharField(label=_(u"Town"), max_length=30, required=False)
+ country = forms.CharField(label=_(u"Country"), max_length=30,
+ required=False)
+ phone = forms.CharField(label=_(u"Phone"), max_length=18, required=False)
+ mobile_phone = forms.CharField(label=_(u"Town"), max_length=18,
+ required=False)
+
+ def save(self):
+ dct = self.cleaned_data
+ dct['warehouse_type'] = models.WarehouseType.objects.get(
+ pk=dct['warehouse_type'])
+ if 'person_in_charge' in dct and dct['person_in_charge']:
+ dct['person_in_charge'] = models.Person.objects.get(
+ pk=dct['person_in_charge'])
+ new_item = models.Warehouse(**dct)
+ new_item.save()
+ return new_item
+
class FinalForm(forms.Form):
final = True
form_label = _("Confirm")
@@ -544,10 +584,6 @@ def get_now():
value = datetime.datetime.now().strftime(format)
return value
-regexp_name = re.compile(r'^[\w\- ]+$', re.UNICODE)
-name_validator = validators.RegexValidator(regexp_name,
-_(u"Enter a valid name consisting of letters, spaces and hyphens."), 'invalid')
-
class PersonWizard(Wizard):
model = models.Person
@@ -1985,3 +2021,114 @@ item_modification_wizard = ItemWizard([
('final-item_modification', FinalForm)],
url_name='item_modification',)
+class TreatmentWizard(Wizard):
+ model = models.Treatment
+
+class BaseTreatmentForm(forms.Form):
+ form_label = _(u"Base treatment")
+ 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)
+ 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"Start date"), required=False,
+ widget=widgets.JQueryDate)
+ end_date = forms.DateField(label=_(u"End date"), required=False,
+ widget=widgets.JQueryDate)
+
+class ItemMultipleFormSelection(forms.Form):
+ form_label = _(u"Upstream items")
+ associated_models = {'items':models.Item}
+ items = forms.IntegerField(label="", required=False,
+ widget=widgets.JQueryJqGrid(reverse_lazy('get-item'),
+ ItemSelect(), models.Item, multiple=True),
+ validators=[models.valid_id(models.Item)])
+
+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())
+ comment = forms.CharField(label=_(u"Comment"),
+ widget=forms.Textarea, required=False)
+
+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]
+ not_type_list = [models.TreatmentType.objects.get(txt_idx=tpe).pk
+ for tpe in not_type_list]
+ def func(self, request, storage):
+ if storage.prefix not in request.session or \
+ 'step_data' not in request.session[storage.prefix] or \
+ form_name not in request.session[storage.prefix]['step_data'] or\
+ form_name + '-' + type_key not in \
+ request.session[storage.prefix]['step_data'][form_name]:
+ return False
+ try:
+ type = int(request.session[storage.prefix]['step_data']\
+ [form_name][form_name+'-'+type_key])
+ return (not type_list or type in type_list) \
+ and type not in not_type_list
+ except ValueError:
+ return False
+ return func
+
+class ResultItemForm(forms.Form):
+ form_label = _("Resulting item")
+ associated_models = {'material_type':models.MaterialType}
+ label = forms.CharField(label=_(u"Label"),
+ validators=[validators.MaxLengthValidator(60)])
+ description = forms.CharField(label=_("Precise description"),
+ widget=forms.Textarea)
+ material_type = forms.ChoiceField(label=_("Material type"),
+ choices=models.MaterialType.get_types())
+ volume = forms.IntegerField(label=_(u"Volume"))
+ weight = forms.IntegerField(label=_(u"Weight"))
+ item_number = forms.IntegerField(label=_(u"Item number"))
+
+ResultItemFormSet = formset_factory(ResultItemForm, can_delete=True,
+ formset=FormSet)
+ResultItemFormSet.form_label = _(u"Resulting items")
+
+UpstreamItemFormSelection = ItemFormSelection
+
+UpstreamItemFormSelection.form_label = _(u"Upstream item")
+
+treatment_creation_wizard = TreatmentWizard([
+ ('basetreatment-treatment_creation', BaseTreatmentForm),
+ ('selecitem-treatment_creation', UpstreamItemFormSelection),
+ ('multiselecitems-treatment_creation', ItemMultipleFormSelection),
+ ('container-treatment_creation', ContainerForm),
+ ('resultitem-treatment_creation', ResultItemForm),
+ ('resultitems-treatment_creation', ResultItemFormSet),
+ ('final-treatment_creation', FinalForm)],
+ condition_list={
+'selecitem-treatment_creation':
+ check_treatment('basetreatment-treatment_creation', 'treatment_type',
+ not_type_list=['physical_grouping']),
+'multiselecitems-treatment_creation':
+ check_treatment('basetreatment-treatment_creation', 'treatment_type',
+ ['physical_grouping']),
+'resultitems-treatment_creation':
+ check_treatment('basetreatment-treatment_creation', 'treatment_type',
+ ['split']),
+'resultitem-treatment_creation':
+ check_treatment('basetreatment-treatment_creation', 'treatment_type',
+ not_type_list=['split']),
+'container-treatment_creation':
+ check_treatment('basetreatment-treatment_creation', 'treatment_type',
+ ['packaging']),
+ },
+ url_name='treatment_creation',)