summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-06-07 22:04:17 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-06-07 22:04:17 +0200
commitb7c4e4ef3a907c4d2e5f0053e9d7628e387fadd4 (patch)
tree3cdde95ef30583456d20421c61bd7de995011a93 /archaeological_operations
parent0a826dae3fc14fefd4bae00a84676ce88a9b7d88 (diff)
downloadIshtar-b7c4e4ef3a907c4d2e5f0053e9d7628e387fadd4.tar.bz2
Ishtar-b7c4e4ef3a907c4d2e5f0053e9d7628e387fadd4.zip
Fix operation_code for year "0" and no year
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/models.py2
-rw-r--r--archaeological_operations/tests.py13
2 files changed, 12 insertions, 3 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index e3453f0cf..6ae05ca30 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -359,8 +359,6 @@ class Operation(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,
@classmethod
def get_available_operation_code(cls, year=None):
- if not year:
- year = datetime.date.today().year
max_val = cls.objects.filter(year=year).aggregate(
Max('operation_code'))["operation_code__max"]
return (max_val + 1) if max_val else 1
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 578382ccd..c22cf4b37 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -441,9 +441,10 @@ def create_orga(user):
return orga
-def create_operation(user, orga=None):
+def create_operation(user, orga=None, values={}):
dct = {'year': 2010, 'operation_type_id': 1,
'history_modifier': user}
+ dct.update(values)
if orga:
dct['operator'] = orga
operation = models.Operation.objects.create(**dct)
@@ -578,6 +579,16 @@ class OperationTest(TestCase, OperationInitTest):
{'operator': self.orgas[0].pk})
self.assertTrue(json.loads(response.content)['total'] == 1)
+ def testIndex(self):
+ ope = create_operation(self.user, values={'year': 2042})
+ self.assertEqual(ope.operation_code, 1)
+ ope2 = create_operation(self.user, values={'year': 2042})
+ self.assertEqual(ope2.operation_code, 2)
+ ope = create_operation(self.user, values={'year': 0})
+ self.assertEqual(ope.operation_code, 1)
+ ope2 = create_operation(self.user, values={'year': 0})
+ self.assertEqual(ope2.operation_code, 2)
+
def create_administrativact(user, operation):
act_type, created = models.ActType.objects.get_or_create(