diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-12-10 16:55:17 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-12-10 16:55:17 +0100 |
commit | 9227051e8bdbbae75064da3e537aba499a794289 (patch) | |
tree | be0552b8eaaefbce6d4094343634f245f3cc4f55 | |
parent | 4f7ee53df30339980ac0ed38a3a2af17a84c34e2 (diff) | |
download | Ishtar-9227051e8bdbbae75064da3e537aba499a794289.tar.bz2 Ishtar-9227051e8bdbbae75064da3e537aba499a794289.zip |
Treatments: manage loan, loan return and packaging by parameters
-rw-r--r-- | archaeological_finds/admin.py | 12 | ||||
-rw-r--r-- | archaeological_finds/forms_treatments.py | 83 | ||||
-rw-r--r-- | archaeological_finds/migrations/0049_auto_20181210_1518.py (renamed from archaeological_finds/migrations/0049_auto_20181210_1216.py) | 12 | ||||
-rw-r--r-- | archaeological_finds/models_finds.py | 3 | ||||
-rw-r--r-- | archaeological_finds/models_treatments.py | 11 |
5 files changed, 80 insertions, 41 deletions
diff --git a/archaeological_finds/admin.py b/archaeological_finds/admin.py index 8903ca5d7..2fb3b492b 100644 --- a/archaeological_finds/admin.py +++ b/archaeological_finds/admin.py @@ -156,11 +156,13 @@ admin_site.register(models.CommunicabilityType, HierarchicalTypeAdmin) class TreatmentTypeAdmin(GeneralTypeAdmin): - list_display = HierarchicalTypeAdmin.list_display + [ - 'order', 'virtual', 'destructive', 'create_new_find', - 'upstream_is_many', 'downstream_is_many'] - list_filter = ['virtual', 'destructive', 'create_new_find', - 'upstream_is_many', 'downstream_is_many'] + list_display = HierarchicalTypeAdmin.list_display[:-1] + ['order'] + \ + [HierarchicalTypeAdmin.list_display[-1]] + list_filter = [ + 'virtual', 'destructive', 'create_new_find', 'upstream_is_many', + 'downstream_is_many', 'destructive', 'change_reference_location', + 'change_current_location', 'restore_reference_location' + ] model = models.TreatmentType diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py index 5f3e49887..8ae0dbd36 100644 --- a/archaeological_finds/forms_treatments.py +++ b/archaeological_finds/forms_treatments.py @@ -131,7 +131,8 @@ class BaseTreatmentForm(CustomForm, ManageOldType): end_date = forms.DateField(label=_(u"Closing date"), required=False, widget=DatePicker) container = forms.IntegerField( - label=_(u"Destination container (relevant for packaging and loan)"), + label=_(u"Destination container (relevant for treatment that change " + u"location)"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-container'), associated_model=Container, new=True), @@ -193,41 +194,62 @@ class BaseTreatmentForm(CustomForm, ManageOldType): def clean(self, *args, **kwargs): data = self.cleaned_data - loan = models.TreatmentType.get_cache('loan') - loan_return = models.TreatmentType.get_cache('loan-return') - packaging = models.TreatmentType.get_cache('packaging') - if not packaging: - logger.warning("No 'packaging' treatment type defined") - return - treatment_types = data.get('treatment_type', []) - if (str(packaging.pk) in treatment_types - or str(loan.pk) in treatment_types) and \ - str(loan_return.pk) in treatment_types: - raise forms.ValidationError( - _(u"\"Loan return\" is not compatible with \"loan\" or " - u"\"packaging\" treatments.")) + treatment_types = data.get('treatment_type', []) - if str(packaging.pk) in treatment_types \ - and str(loan.pk) in treatment_types: + change_current_location = [ + unicode(tp) for tp in treatment_types if tp.change_current_location] + restore_reference_location = [ + unicode(tp) for tp in treatment_types + if tp.restore_reference_location + ] + change_ref_location = [ + unicode(tp) for tp in treatment_types + if tp.change_reference_location + ] + + if (change_ref_location or change_current_location + ) and restore_reference_location: + if change_ref_location: + raise forms.ValidationError( + unicode( + _(u"{} is not compatible with {} " + u"treatments.")).format( + u' ; '.join(restore_reference_location), + u' ; '.join(change_ref_location), + ) + ) + else: + raise forms.ValidationError( + unicode( + _(u"{} is not compatible with {} " + u"treatments.")).format( + u' ; '.join(restore_reference_location), + u' ; '.join(change_current_location) + ) + ) + + if change_ref_location and change_current_location: raise forms.ValidationError( - _(u"Packaging (concerning the reference location) and loan " - u"(concerning a temporary location) cannot be in the same " - u"treatment.")) + unicode( + _(u"{} is not compatible with {} " + u"treatments.")).format( + u' ; '.join(change_ref_location), + u' ; '.join(change_current_location) + ) + ) if data.get('container', None) \ - and str(packaging.pk) not in treatment_types\ - and str(loan.pk) not in treatment_types: + and not change_ref_location\ + and not change_current_location: raise forms.ValidationError( - _(u"The container field is attached to the treatment. If " - u"no packaging or no loan treatment is done it is not " - u"relevant.")) + _(u"The container field is attached to the treatment but " + u"no treatment with container change is defined.")) if not data.get('container', None) and ( - str(packaging.pk) in treatment_types or - str(loan.pk) in treatment_types): + change_ref_location or change_current_location): raise forms.ValidationError( - _(u"If a packaging/loan treatment is done, the container field " - u"must be filled.")) + _(u"A treatment with location change is defined, the container " + u"field must be filled.")) if not data.get('person', None) and not data.get('organization', None): raise forms.ValidationError( _(u"A responsible or an organization must be defined.")) @@ -381,8 +403,9 @@ class QAFindTreatmentForm(IshtarForm): container = Container.objects.get(pk=self.cleaned_data['container']) if self.cleaned_data['create_treatment']: packaging, created = models.TreatmentType.objects.get_or_create( - label=u"Conditionnement", - txt_idx='packaging' + txt_idx='packaging', + defaults={"label": _(u"Packaging"), + "change_reference_location": True} ) t = models.Treatment.objects.create( container=container, diff --git a/archaeological_finds/migrations/0049_auto_20181210_1216.py b/archaeological_finds/migrations/0049_auto_20181210_1518.py index debe1b775..d2510c7fd 100644 --- a/archaeological_finds/migrations/0049_auto_20181210_1216.py +++ b/archaeological_finds/migrations/0049_auto_20181210_1518.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.10 on 2018-12-10 12:16 +# Generated by Django 1.11.10 on 2018-12-10 15:18 from __future__ import unicode_literals from django.db import migrations, models @@ -17,6 +17,11 @@ def migrate_treatment_types(apps, schema): loan_r = q.all()[0] loan_r.restore_reference_location = True loan_r.save() + q = TreatmentType.objects.filter(txt_idx="packaging") + if q.count(): + packaging = q.all()[0] + packaging.change_reference_location = True + packaging.save() q = TreatmentType.objects.filter(txt_idx="virtual-reassembly") if q.count(): v = q.all()[0] @@ -46,6 +51,11 @@ class Migration(migrations.Migration): ), migrations.AddField( model_name='treatmenttype', + name='change_reference_location', + field=models.BooleanField(default=False, help_text='The treatment change the reference location.', verbose_name='Change reference location'), + ), + migrations.AddField( + model_name='treatmenttype', name='restore_reference_location', field=models.BooleanField(default=False, help_text='The treatment change restore reference location to the current location.', verbose_name='Restore the reference location'), ), diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 318388da1..393583749 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -106,6 +106,9 @@ class TreatmentType(HierarchicalType): help_text=_( u"Check this if for this treatment from one find you'll get " u"many.")) + change_reference_location = models.BooleanField( + _(u"Change reference location"), default=False, + help_text=_(u"The treatment change the reference location.")) change_current_location = models.BooleanField( _(u"Change current location"), default=False, help_text=_(u"The treatment change the current location.")) diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index 3d3827596..ee4fde0f0 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -477,7 +477,7 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem, # manage loan return for tp in treatment_types: - if tp.txt_idx == 'loan-return': + if tp.restore_reference_location: for find in q.all(): if find.container_ref: find.container = find.container_ref @@ -485,6 +485,7 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem, # don't record twice history find.skip_history_when_saving = True find.save() + break # manage containers if not self.container: @@ -492,13 +493,13 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem, container_attr = None for tp in treatment_types: - if tp.txt_idx == 'loan': - if container_attr: + if tp.change_current_location: + if container_attr == 'container_ref': # non consistent treatment return container_attr = 'container' - if tp.txt_idx == 'packaging': - if container_attr: + if tp.change_reference_location: + if container_attr == 'container': # non consistent treatment return container_attr = 'container_ref' |