Commit b7af0cedf46a54d322be6758106464d984446e0c

Authored by OrysiaDrabych
1 parent 2373656b

Add additional classifications for all items

@@ -120,6 +120,7 @@ class OP_Provider(BaseProvider): @@ -120,6 +120,7 @@ class OP_Provider(BaseProvider):
120 from a specific cpv group. Cpv group is three digits 120 from a specific cpv group. Cpv group is three digits
121 in the beginning of each cpv id. 121 in the beginning of each cpv id.
122 """ 122 """
  123 + item_base_data = None
123 if cpv_group is None: 124 if cpv_group is None:
124 item_base_data = self.random_element(self.items_base_data) 125 item_base_data = self.random_element(self.items_base_data)
125 else: 126 else:
@@ -133,12 +134,16 @@ class OP_Provider(BaseProvider): @@ -133,12 +134,16 @@ class OP_Provider(BaseProvider):
133 if entity["cpv_id"] == cpv: 134 if entity["cpv_id"] == cpv:
134 item_base_data = entity 135 item_base_data = entity
135 break 136 break
  137 + if not item_base_data:
  138 + raise ValueError('unable to find an item with CPV ' + cpv)
136 139
137 # choose appropriate additional classification for item_base_data's cpv 140 # choose appropriate additional classification for item_base_data's cpv
138 additional_class = [] 141 additional_class = []
139 for entity in self.classifications: 142 for entity in self.classifications:
140 if entity["classification"]["id"] == item_base_data["cpv_id"]: 143 if entity["classification"]["id"] == item_base_data["cpv_id"]:
141 additional_class.append(entity) 144 additional_class.append(entity)
  145 + if not additional_class:
  146 + raise ValueError('unable to find a matching additional classification for CPV ' + cpv)
142 classification = self.random_element(additional_class) 147 classification = self.random_element(additional_class)
143 148
144 dk_descriptions = { 149 dk_descriptions = {
@@ -148,6 +153,7 @@ class OP_Provider(BaseProvider): @@ -148,6 +153,7 @@ class OP_Provider(BaseProvider):
148 } 153 }
149 address = self.random_element(self.addresses) 154 address = self.random_element(self.addresses)
150 item = { 155 item = {
  156 + "additionalClassifications": classification["additionalClassifications"],
151 "classification": classification["classification"], 157 "classification": classification["classification"],
152 "deliveryAddress": address["deliveryAddress"], 158 "deliveryAddress": address["deliveryAddress"],
153 "deliveryLocation": address["deliveryLocation"], 159 "deliveryLocation": address["deliveryLocation"],
@@ -157,7 +163,6 @@ class OP_Provider(BaseProvider): @@ -157,7 +163,6 @@ class OP_Provider(BaseProvider):
157 if item_base_data["cpv_id"] == "99999999-9": 163 if item_base_data["cpv_id"] == "99999999-9":
158 scheme = classification["additionalClassifications"][0]["scheme"] 164 scheme = classification["additionalClassifications"][0]["scheme"]
159 item.update({ 165 item.update({
160 - "additionalClassifications": classification["additionalClassifications"],  
161 "description": dk_descriptions[scheme][0], 166 "description": dk_descriptions[scheme][0],
162 "description_ru": dk_descriptions[scheme][1], 167 "description_ru": dk_descriptions[scheme][1],
163 "description_en": dk_descriptions[scheme][2] 168 "description_en": dk_descriptions[scheme][2]
Please register or login to post a comment