summaryrefslogtreecommitdiff
path: root/archaeological_warehouse
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-01-16 20:41:28 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-01-16 20:41:28 +0100
commit1dbb0a765456dead8ef85f446b82f7737762f56a (patch)
treeb78d3d870f2c4657136f6be4eb84b817fcefeb00 /archaeological_warehouse
parent936c2a83dda4ecc3b6db8f3ee81a43ff4340de12 (diff)
downloadIshtar-1dbb0a765456dead8ef85f446b82f7737762f56a.tar.bz2
Ishtar-1dbb0a765456dead8ef85f446b82f7737762f56a.zip
Fix container creation (refs #3415)
Diffstat (limited to 'archaeological_warehouse')
-rw-r--r--archaeological_warehouse/models.py9
-rw-r--r--archaeological_warehouse/tests.py58
-rw-r--r--archaeological_warehouse/wizards.py3
3 files changed, 62 insertions, 8 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 9ff615332..038910d17 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -211,6 +211,15 @@ class Container(LightHistorizedItem):
]
return u" | ".join(locas)
+ def pre_save(self):
+ if not self.index:
+ q = Container.objects.filter(responsible=self.responsible).order_by(
+ '-index')
+ if q.count():
+ self.index = q.all()[0].index + 1
+ else:
+ self.index = 1
+
def save(self, *args, **kwargs):
super(Container, self).save(*args, **kwargs)
diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py
index f4ce52732..938d1cbc0 100644
--- a/archaeological_warehouse/tests.py
+++ b/archaeological_warehouse/tests.py
@@ -56,7 +56,31 @@ class ContainerWizardCreationTest(WizardTest, FindInit, TestCase):
},
'localisation-container_creation': []
},
- )
+ ),
+ FormData(
+ 'Other container on the same warehouse',
+ form_datas={
+ 'container-container_creation': {
+ 'reference': 'hop-ref2',
+ 'container_type': None,
+ 'location': None,
+ 'responsible': None,
+ },
+ 'localisation-container_creation': []
+ },
+ ),
+ FormData(
+ 'Container creation with location',
+ form_datas={
+ 'container-container_creation': {
+ 'reference': 'hop-ref3',
+ 'container_type': None,
+ 'location': None,
+ 'responsible': None,
+ },
+ 'localisation-container_creation': []
+ },
+ ),
]
def pre_wizard(self):
@@ -64,17 +88,37 @@ class ContainerWizardCreationTest(WizardTest, FindInit, TestCase):
name="Main",
warehouse_type=models.WarehouseType.objects.all()[0]
)
- forms_data = self.form_datas[0].form_datas[
- 'container-container_creation']
- forms_data["responsible"] = main_warehouse.pk
- forms_data["location"] = main_warehouse.pk
- forms_data["container_type"] = models.ContainerType.objects.all()[0].pk
+ main_data = self.form_datas[0].form_datas
+ main_data_bis = self.form_datas[1].form_datas
+ alt_data = self.form_datas[2].form_datas
+ for data in [main_data, main_data_bis, alt_data]:
+ forms_data = data['container-container_creation']
+ forms_data["responsible"] = main_warehouse.pk
+ forms_data["location"] = main_warehouse.pk
+ forms_data["container_type"] = \
+ models.ContainerType.objects.all()[0].pk
+ alt_warehouse = models.Warehouse.objects.create(
+ name="Alt",
+ warehouse_type=models.WarehouseType.objects.all()[0]
+ )
+ div = models.WarehouseDivision.objects.create(label='division')
+ div_link = models.WarehouseDivisionLink.objects.create(
+ warehouse=alt_warehouse, division=div)
+ alt_data['container-container_creation']["location"] = alt_warehouse.pk
+ alt_data['localisation-container_creation'] = {
+ 'division_{}'.format(div_link.pk): 'Combien ?'
+ }
+
self.container_number = models.Container.objects.count()
+ self.localisation_detail_number = \
+ models.ContainerLocalisation.objects.count()
super(ContainerWizardCreationTest, self).pre_wizard()
def post_wizard(self):
self.assertEqual(models.Container.objects.count(),
- self.container_number + 1)
+ self.container_number + 3)
+ self.assertEqual(models.ContainerLocalisation.objects.count(),
+ self.localisation_detail_number + 1)
class ContainerTest(FindInit, TestCase):
diff --git a/archaeological_warehouse/wizards.py b/archaeological_warehouse/wizards.py
index 817ed75a5..0adb06f75 100644
--- a/archaeological_warehouse/wizards.py
+++ b/archaeological_warehouse/wizards.py
@@ -101,7 +101,8 @@ class ContainerWizard(Wizard):
for idx, form in enumerate(form_list):
if not form.is_valid():
return self.render(form)
- container = self.get_current_object() or self.current_object
+ container = self.get_current_object() or \
+ hasattr(self, 'current_object') and self.current_object
if container and form.prefix == 'localisation-' + self.url_name:
for div_name in form.cleaned_data:
try: