diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-07-01 20:56:07 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-07-01 20:56:07 +0200 |
commit | e946d15e8532c40e9581b539691179e8b9dbfa9c (patch) | |
tree | bf633d5f57baab695160ed4bb949c8ab77c27ce8 /ishtar/ishtar_base/forms_items.py | |
parent | d66686f332337211929ddb505eeab8eff42cd4e4 (diff) | |
download | Ishtar-e946d15e8532c40e9581b539691179e8b9dbfa9c.tar.bz2 Ishtar-e946d15e8532c40e9581b539691179e8b9dbfa9c.zip |
Work on warehouse packaging (refs #500)
Diffstat (limited to 'ishtar/ishtar_base/forms_items.py')
-rw-r--r-- | ishtar/ishtar_base/forms_items.py | 91 |
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), |