| Line 69... |
Line 69... |
| 69 |
our_color = color
|
69 |
our_color = color
|
| 70 |
|
70 |
|
| 71 |
if sp == '':
|
71 |
if sp == '':
|
| 72 |
sp = mop
|
72 |
sp = mop
|
| 73 |
item = None
|
73 |
item = None
|
| - |
|
74 |
similar_item = None
|
| 74 |
vendor_item_pricing = None
|
75 |
vendor_item_pricing = None
|
| 75 |
|
76 |
|
| 76 |
key = product_group.strip().lower() + '|' + brand.strip().lower() + '|' + model_number.strip().lower() + '|' + color.strip().lower()
|
77 |
key = product_group.strip().lower() + '|' + brand.strip().lower() + '|' + model_number.strip().lower() + '|' + color.strip().lower()
|
| 77 |
if key in existing_vendor_item_mappings_set:
|
78 |
if key in existing_vendor_item_mappings_set:
|
| 78 |
existing_vendor_item_mappings_set.remove(key)
|
79 |
existing_vendor_item_mappings_set.remove(key)
|
| 79 |
|
80 |
|
| 80 |
# Check if a similar items already exists in our database
|
81 |
# Check if a similar items already exists in our database
|
| 81 |
similar_items = Item.query.filter_by(brand=our_brand.strip(), model_number=our_model_number.strip(), model_name=model_name.strip()).all()
|
82 |
similar_items = Item.query.filter_by(brand=our_brand.strip(), model_number=our_model_number.strip(), model_name=model_name.strip()).all()
|
| 82 |
|
83 |
|
| - |
|
84 |
# Check if a similar item already exists in our database
|
| 83 |
for old_item in similar_items:
|
85 |
for old_item in similar_items:
|
| 84 |
if old_item.color == our_color.strip():
|
86 |
if old_item.color != None and old_item.color.strip().lower() == our_color.strip().lower():
|
| 85 |
item = old_item
|
87 |
item = old_item
|
| 86 |
break
|
88 |
break
|
| 87 |
|
89 |
|
| - |
|
90 |
# Check if a similar item already exists in our database with out valid color if similar item with same color is not found
|
| 88 |
if item is None:
|
91 |
if item is None:
|
| 89 |
for old_item in similar_items:
|
92 |
for old_item in similar_items:
|
| 90 |
if old_item.color == None or old_item.color.lower() == 'na' or old_item.color.lower() == 'blank' or old_item.color.lower() == '(blank)' or old_item.color == '':
|
93 |
if not check_color_valid(old_item.color):
|
| 91 |
item = old_item
|
94 |
item = old_item
|
| 92 |
break
|
95 |
break
|
| 93 |
|
96 |
|
| 94 |
i = 0
|
97 |
i = 0
|
| 95 |
color_of_similar_item = None
|
98 |
color_of_similar_item = None
|
| - |
|
99 |
# Check if a similar item already exists in our database to be used to get catalog_item_id
|
| 96 |
for old_item in similar_items:
|
100 |
for old_item in similar_items:
|
| 97 |
if old_item.color != None and old_item.color.lower() != 'na' and old_item.color.lower() != 'blank' and old_item.color.lower() != '(blank)' and old_item.color != '':
|
101 |
# get a similar item already existing in our database with valid color
|
| - |
|
102 |
if check_color_valid(old_item.color):
|
| 98 |
similar_item = old_item
|
103 |
similar_item = old_item
|
| 99 |
color_of_similar_item = similar_item.color
|
104 |
color_of_similar_item = similar_item.color
|
| 100 |
break
|
105 |
break
|
| 101 |
i = i + 1
|
106 |
i = i + 1
|
| - |
|
107 |
# get a similar item already existing in our database if similar item with valid color is not found
|
| 102 |
if i == len(similar_items):
|
108 |
if i == len(similar_items):
|
| 103 |
similar_item = old_item
|
109 |
similar_item = old_item
|
| 104 |
color_of_similar_item = similar_item.color
|
110 |
color_of_similar_item = similar_item.color
|
| 105 |
|
111 |
|
| - |
|
112 |
# Check if a similar item that is obtained above is having a valid color
|
| - |
|
113 |
if check_color_valid(color_of_similar_item):
|
| 106 |
if color_of_similar_item != None and color_of_similar_item.lower() != 'na' and color_of_similar_item.lower() != 'blank' and color_of_similar_item.lower() != '(blank)' and color_of_similar_item != '':
|
114 |
# 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.
|
| 107 |
if item is None and (our_color.strip().lower() == 'na' or our_color.strip().lower() == 'blank' or our_color.strip().lower() == '(blank)' or our_color.strip() == ''):
|
115 |
# 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.
|
| - |
|
116 |
if item is None and not check_color_valid(our_color):
|
| 108 |
not_created_items.append(rownum)
|
117 |
not_created_items.append(rownum)
|
| 109 |
continue
|
118 |
continue
|
| 110 |
|
119 |
|
| 111 |
|
120 |
|
| 112 |
if item is None:
|
121 |
if item is None:
|
| Line 158... |
Line 167... |
| 158 |
# in which case we add it to the list of updated items for reporting.
|
167 |
# in which case we add it to the list of updated items for reporting.
|
| 159 |
if item.status == status.PHASED_OUT:
|
168 |
if item.status == status.PHASED_OUT:
|
| 160 |
item.status = status.IN_PROCESS #Not the ideal choice but we don't know whether content has been generated for it beforehand.
|
169 |
item.status = status.IN_PROCESS #Not the ideal choice but we don't know whether content has been generated for it beforehand.
|
| 161 |
item.status_description = "This item is in process"
|
170 |
item.status_description = "This item is in process"
|
| 162 |
|
171 |
|
| 163 |
if item.color != our_color.strip() and our_color.strip().lower() != 'na' and our_color.strip().lower() != 'blank' and our_color.strip().lower() != '(blank)' and our_color.strip() != '':
|
172 |
if check_color_valid(our_color) and (item.color == None or item.color.strip().lower() != our_color.strip().lower()):
|
| 164 |
item.color = our_color.strip()
|
173 |
item.color = our_color.strip()
|
| 165 |
|
174 |
|
| 166 |
vendor_item_mapping = VendorItemMapping.get_by(vendor=vendor, item=item)
|
175 |
vendor_item_mapping = VendorItemMapping.get_by(vendor=vendor, item=item)
|
| 167 |
if vendor_item_mapping is None:
|
176 |
if vendor_item_mapping is None:
|
| 168 |
vendor_item_mapping = VendorItemMapping(vendor=vendor, item=item, item_key=key, vendor_category=category)
|
177 |
vendor_item_mapping = VendorItemMapping(vendor=vendor, item=item, item_key=key, vendor_category=category)
|
| 169 |
session.add(vendor_item_mapping)
|
178 |
session.add(vendor_item_mapping)
|
| - |
|
179 |
else:
|
| - |
|
180 |
vendor_item_mapping.item_key = key
|
| - |
|
181 |
vendor_item_mapping.vendor_category = category
|
| - |
|
182 |
|
| 170 |
vendor_item_pricing = VendorItemPricing.get_by(vendor=vendor, item=item)
|
183 |
vendor_item_pricing = VendorItemPricing.get_by(vendor=vendor, item=item)
|
| 171 |
if vendor_item_pricing is None:
|
184 |
if vendor_item_pricing is None:
|
| 172 |
vendor_item_pricing = VendorItemPricing(vendor=vendor, item=item)
|
185 |
vendor_item_pricing = VendorItemPricing(vendor=vendor, item=item)
|
| 173 |
session.add(vendor_item_pricing)
|
186 |
session.add(vendor_item_pricing)
|
| 174 |
|
187 |
|
| Line 266... |
Line 279... |
| 266 |
session.execute(query_string, mapper=Item)
|
279 |
session.execute(query_string, mapper=Item)
|
| 267 |
session.commit()
|
280 |
session.commit()
|
| 268 |
|
281 |
|
| 269 |
print "Successfully updated the item list information."
|
282 |
print "Successfully updated the item list information."
|
| 270 |
|
283 |
|
| - |
|
284 |
def check_color_valid(color):
|
| - |
|
285 |
if color is not None:
|
| - |
|
286 |
color = color.strip().lower()
|
| - |
|
287 |
if color != '' and color != 'na' and color != 'blank' and color != '(blank)':
|
| - |
|
288 |
return True
|
| - |
|
289 |
return False
|
| - |
|
290 |
|
| 271 |
def write_report(filename, items, sheet, is_item):
|
291 |
def write_report(filename, items, sheet, is_item):
|
| 272 |
'''
|
292 |
'''
|
| 273 |
Iterates through the items list and writes all the values to the specified
|
293 |
Iterates through the items list and writes all the values to the specified
|
| 274 |
filename in the CSV format. 'is_item' indicates whether the list consists
|
294 |
filename in the CSV format. 'is_item' indicates whether the list consists
|
| 275 |
of row numbers or complete row data.
|
295 |
of row numbers or complete row data.
|