| Line 298... |
Line 298... |
| 298 |
|
298 |
|
| 299 |
if item.preferredWarehouse:
|
299 |
if item.preferredWarehouse:
|
| 300 |
ds_item.preferredWarehouse = item.preferredWarehouse
|
300 |
ds_item.preferredWarehouse = item.preferredWarehouse
|
| 301 |
|
301 |
|
| 302 |
# Check if a similar item already exists in our database
|
302 |
# Check if a similar item already exists in our database
|
| 303 |
similar_item = Item.query.filter_by(product_group=item.productGroup, brand = item.brand, model_number=item.modelNumber, hotspotCategory=item.hotspotCategory).first()
|
303 |
similar_item = Item.query.filter_by(brand=item.brand, model_number=item.modelNumber, model_name=item.modelName).first()
|
| 304 |
print "[SIMILAR ITEM FOUND:] FOR {0} {1} {2} {3} {4}".format(item.productGroup, item.brand, item.modelNumber, item.hotspotCategory, item.color)
|
304 |
print "[SIMILAR ITEM FOUND:] FOR {0} {1} {2}".format(item.brand, item.modelNumber, item.modelName)
|
| 305 |
|
305 |
|
| 306 |
if similar_item is None or similar_item.catalog_item_id is None:
|
306 |
if similar_item is None or similar_item.catalog_item_id is None:
|
| 307 |
# If there is no similar item in the database from before,
|
307 |
# If there is no similar item in the database from before,
|
| 308 |
# use the entity_id_generator
|
308 |
# use the entity_id_generator
|
| 309 |
entity_id = EntityIDGenerator.query.first()
|
309 |
entity_id = EntityIDGenerator.query.first()
|
| 310 |
ds_item.catalog_item_id = entity_id.id + 1
|
310 |
ds_item.catalog_item_id = entity_id.id + 1
|
| 311 |
ds_item.status = status.IN_PROCESS
|
311 |
ds_item.status = status.IN_PROCESS
|
| 312 |
ds_item.status_description = "This item is in process."
|
312 |
ds_item.status_description = "This item is in process."
|
| 313 |
entity_id.id = entity_id.id + 1
|
313 |
entity_id.id = entity_id.id + 1
|
| - |
|
314 |
if similar_item is not None and similar_item.catalog_item_id is None:
|
| - |
|
315 |
similar_item.catalog_item_id = entity_id.id
|
| 314 |
else:
|
316 |
else:
|
| 315 |
#If a similar item already exists for a product group, brand and model_number, set it as same.
|
317 |
#If a similar item already exists for a product group, brand and model_number, set it as same.
|
| 316 |
ds_item.catalog_item_id = similar_item.catalog_item_id
|
318 |
ds_item.catalog_item_id = similar_item.catalog_item_id
|
| 317 |
ds_item.category = similar_item.category
|
319 |
ds_item.category = similar_item.category
|
| 318 |
ds_item.status = similar_item.status
|
320 |
ds_item.status = similar_item.status
|
| Line 1117... |
Line 1119... |
| 1117 |
return
|
1119 |
return
|
| 1118 |
|
1120 |
|
| 1119 |
def get_all_vendors():
|
1121 |
def get_all_vendors():
|
| 1120 |
return Vendor.query.all()
|
1122 |
return Vendor.query.all()
|
| 1121 |
|
1123 |
|
| - |
|
1124 |
def check_color_valid(color):
|
| - |
|
1125 |
if color is not None:
|
| - |
|
1126 |
color = color.strip().lower()
|
| - |
|
1127 |
if color != '' and color != 'na' and color != 'blank' and color != '(blank)':
|
| - |
|
1128 |
return True
|
| - |
|
1129 |
return False
|
| - |
|
1130 |
|
| 1122 |
def check_similar_item(product_group, brand, model_number, color):
|
1131 |
def check_similar_item(brand, model_number, model_name, color):
|
| 1123 |
query = Item.query
|
1132 |
query = Item.query
|
| 1124 |
query = query.filter_by(product_group=product_group)
|
- |
|
| 1125 |
query = query.filter_by(brand=brand)
|
1133 |
query = query.filter_by(brand=brand)
|
| 1126 |
query = query.filter_by(model_number=model_number)
|
1134 |
query = query.filter_by(model_number=model_number)
|
| - |
|
1135 |
query = query.filter_by(model_name=model_name)
|
| - |
|
1136 |
similar_items = query.all()
|
| 1127 |
if color:
|
1137 |
item = None
|
| - |
|
1138 |
# Check if a similar item already exists in our database
|
| - |
|
1139 |
for old_item in similar_items:
|
| - |
|
1140 |
if old_item.color != None and old_item.color.strip().lower() == color.strip().lower():
|
| - |
|
1141 |
item = old_item
|
| - |
|
1142 |
break
|
| - |
|
1143 |
|
| - |
|
1144 |
# Check if a similar item already exists in our database with out valid color if similar item with same color is not found
|
| - |
|
1145 |
if item is None:
|
| - |
|
1146 |
for old_item in similar_items:
|
| 1128 |
query = query.filter_by(color=color)
|
1147 |
if not check_color_valid(old_item.color):
|
| - |
|
1148 |
item = old_item
|
| 1129 |
item = query.first()
|
1149 |
break
|
| - |
|
1150 |
i = 0
|
| - |
|
1151 |
color_of_similar_item = None
|
| - |
|
1152 |
# Check if a similar item already exists in our database to be used to get catalog_item_id
|
| - |
|
1153 |
for old_item in similar_items:
|
| - |
|
1154 |
# get a similar item already existing in our database with valid color
|
| - |
|
1155 |
if check_color_valid(old_item.color):
|
| - |
|
1156 |
similar_item = old_item
|
| - |
|
1157 |
color_of_similar_item = similar_item.color
|
| - |
|
1158 |
break
|
| - |
|
1159 |
i = i + 1
|
| - |
|
1160 |
# get a similar item already existing in our database if similar item with valid color is not found
|
| - |
|
1161 |
if i == len(similar_items):
|
| - |
|
1162 |
similar_item = old_item
|
| - |
|
1163 |
color_of_similar_item = similar_item.color
|
| - |
|
1164 |
|
| - |
|
1165 |
# Check if a similar item that is obtained above is having a valid color
|
| - |
|
1166 |
if check_color_valid(color_of_similar_item):
|
| - |
|
1167 |
# if a similar item that is obtained above is having a valid color and new item is about to be created with out valid color it is not done.
|
| - |
|
1168 |
# since for example if their is a item with red color in our database and we are creating a new item with no color for the same product which is wrong.
|
| - |
|
1169 |
if item is None and not check_color_valid(color):
|
| - |
|
1170 |
return similar_item.id
|
| - |
|
1171 |
|
| 1130 |
if item is None:
|
1172 |
if item is None:
|
| 1131 |
return 0
|
1173 |
return 0
|
| 1132 |
else:
|
1174 |
else:
|
| 1133 |
return item.id
|
1175 |
return item.id
|
| 1134 |
|
1176 |
|