Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/a245447677040468_cpv_336' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Jan 16, 2017
2 parents 73d3797 + 5126c44 commit 37da8df
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
10 changes: 6 additions & 4 deletions openprocurement/planning/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ class PlanItem(Model):
def validate_classification(self, data, classification):
plan = data['__parent__']
plan_from_2017 = (plan.get('revisions')[0].date if plan.get('revisions') else get_now()) > CPV_ITEMS_CLASS_FROM
base_cpv_code = data['__parent__'].classification.id[:4] if plan_from_2017 else data['__parent__'].classification.id[:3]
if plan_from_2017 and (base_cpv_code != classification.id[:4]):
cpv_336_group = plan.classification.id[:3] == '336'
base_cpv_code = plan.classification.id[:4] if not cpv_336_group and plan_from_2017 else plan.classification.id[:3]
if not cpv_336_group and plan_from_2017 and (base_cpv_code != classification.id[:4]):
raise ValidationError(u"CPV class of items should be identical to root cpv")
elif not plan_from_2017 and (base_cpv_code != classification.id[:3]):
elif (cpv_336_group or not plan_from_2017) and (base_cpv_code != classification.id[:3]):
raise ValidationError(u"CPV group of items be identical to root cpv")

def validate_additionalClassifications(self, data, items):
Expand Down Expand Up @@ -205,7 +206,8 @@ def doc_id(self):
return self._id

def validate_items(self, data, items):
if (data.get('revisions')[0].date if data.get('revisions') else get_now()) > CPV_ITEMS_CLASS_FROM and items and len(set([i.classification.id[:4] for i in items])) != 1:
cpv_336_group = items[0].classification.id[:3] == '336' if items else False
if not cpv_336_group and (data.get('revisions')[0].date if data.get('revisions') else get_now()) > CPV_ITEMS_CLASS_FROM and items and len(set([i.classification.id[:4] for i in items])) != 1:
raise ValidationError(u"CPV class of items should be identical")
else:
validate_cpv_group(items)
Expand Down
29 changes: 29 additions & 0 deletions openprocurement/planning/api/tests/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,35 @@ def test_create_plan_invalid(self):
u'location': u'body', u'name': u'items'}
])

classification_id = test_plan_data["classification"]["id"]
test_plan_data["classification"]["id"] = u'33600000-6'
response = self.app.post_json(request_path, {'data': test_plan_data}, status=422)
test_plan_data["classification"]["id"] = classification_id
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description': [{u'classification': [u'CPV group of items be identical to root cpv']}],
u'location': u'body', u'name': u'items'}
])

classification_id = test_plan_data["classification"]["id"]
test_plan_data["classification"]["id"] = u'33600000-6'
item = test_plan_data["items"][0].copy()
data = test_plan_data["items"][0].copy()
classification = data['classification'].copy()
classification["id"] = u'33610000-9'
data['classification'] = classification
data2 = test_plan_data["items"][0].copy()
classification = data2['classification'].copy()
classification["id"] = u'33620000-2'
data2['classification'] = classification
test_plan_data["items"] = [data, data2]
response = self.app.post_json(request_path, {'data': test_plan_data})
test_plan_data["classification"]["id"] = classification_id
test_plan_data["items"] = [item]
self.assertEqual(response.status, '201 Created')

def test_create_plan_generated(self):
data = test_plan_data.copy()
data.update({'id': 'hash', 'doc_id': 'hash2', 'planID': 'hash3'})
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os

version = '2.3.4'
version = '2.3.5'

requires = [
'setuptools',
Expand Down

0 comments on commit 37da8df

Please sign in to comment.