| 19221 |
amit.gupta |
1 |
|
| 94 |
ashish |
2 |
'''
|
|
|
3 |
Created on 23-Mar-2010
|
|
|
4 |
|
|
|
5 |
@author: ashish
|
|
|
6 |
'''
|
|
|
7 |
from elixir import *
|
| 5393 |
mandeep.dh |
8 |
from functools import partial
|
| 5944 |
mandeep.dh |
9 |
from shop2020.clients.CatalogClient import CatalogClient
|
| 4748 |
mandeep.dh |
10 |
from shop2020.clients.HelperClient import HelperClient
|
| 5944 |
mandeep.dh |
11 |
from shop2020.clients.InventoryClient import InventoryClient
|
| 19221 |
amit.gupta |
12 |
from shop2020.clients.UserClient import UserClient
|
| 4748 |
mandeep.dh |
13 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 94 |
ashish |
14 |
from shop2020.model.v1.catalog.impl import DataService
|
| 4748 |
mandeep.dh |
15 |
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
|
| 8274 |
amit.gupta |
16 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item, to_t_source, \
|
| 19221 |
amit.gupta |
17 |
to_t_brand_info, to_t_private_deal, to_t_exclusive_affiliate_item_info, \
|
|
|
18 |
to_t_bulk_pricing
|
| 5944 |
mandeep.dh |
19 |
from shop2020.model.v1.catalog.impl.DataService import Item, ItemChangeLog, \
|
|
|
20 |
Category, EntityIDGenerator, SimilarItems, ProductNotification, Source, \
|
| 6531 |
vikram.rag |
21 |
SourceItemPricing, AuthorizationLog, VoucherItemMapping, CategoryVatMaster, \
|
| 7340 |
amit.gupta |
22 |
OOSTracker, EntityTag, ItemInsurerMapping, Insurer, Banner, BannerMap, \
|
| 7977 |
kshitij.so |
23 |
FreebieItem, BrandInfo, Amazonlisted, StorePricing, ItemVatMaster, \
|
| 9242 |
kshitij.so |
24 |
PageViewEvents, CartEvents, EbayItem, BannerUriMapping, Campaign, SnapdealItem, \
|
| 10097 |
kshitij.so |
25 |
ProductFeedSubmit, MarketplaceItems, MarketPlaceItemPrice, \
|
| 12620 |
amit.gupta |
26 |
SourcePercentageMaster, SourceItemPercentage, FlipkartItem, \
|
|
|
27 |
MarketPlaceUpdateHistory, SourceCategoryPercentage, MarketPlaceHistory, \
|
|
|
28 |
PrivateDeals, AmazonOutOfSync, PrivateDealsPriceComparison, \
|
|
|
29 |
SourceReturnPercentage, CompetitorPricing, CompetitorPricingRequest, \
|
| 19221 |
amit.gupta |
30 |
AmazonPromotion, ExclusiveAffiliateItemInfo, OutboundAffiliateMaster, HsItem, \
|
|
|
31 |
BulkItemPricing
|
|
|
32 |
from shop2020.model.v1.inventory.impl.DataService import \
|
|
|
33 |
ItemLocationAvailabilityCache
|
| 5944 |
mandeep.dh |
34 |
from shop2020.thriftpy.model.v1.catalog.ttypes import status, ItemShippingInfo, \
|
| 7340 |
amit.gupta |
35 |
ItemType, PremiumType, FreebieItem as t_FreebieItem, \
|
| 13136 |
amit.gupta |
36 |
StorePricing as tStorePricing, CatalogServiceException, BannerType, InsurerType, \
|
|
|
37 |
Banner as t_banner, CompetitorPricing as TCompetitorPricing, AmazonPromotionType
|
| 12567 |
amit.gupta |
38 |
from shop2020.thriftpy.model.v1.inventory.ttypes import VatType, \
|
| 19221 |
amit.gupta |
39 |
InventoryServiceException, IgnoredInventoryUpdateItems, SnapdealInventoryItem, \
|
|
|
40 |
ItemLocationAvailability
|
|
|
41 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderSource
|
| 13709 |
manish.sha |
42 |
from shop2020.thriftpy.utils.ttypes import UserSmsInfo, SmsType
|
| 4873 |
mandeep.dh |
43 |
from shop2020.utils import EmailAttachmentSender
|
| 4748 |
mandeep.dh |
44 |
from shop2020.utils.EmailAttachmentSender import mail
|
| 13709 |
manish.sha |
45 |
from shop2020.utils.Utils import to_py_date, log_risky_flag, to_java_date
|
| 621 |
chandransh |
46 |
from sqlalchemy import desc, asc
|
| 19221 |
amit.gupta |
47 |
from sqlalchemy.sql.expression import or_, distinct, func, and_, tuple_
|
| 11630 |
amit.gupta |
48 |
from sqlalchemy.sql.functions import now
|
| 3086 |
rajveer |
49 |
from string import Template
|
| 4748 |
mandeep.dh |
50 |
import datetime
|
| 8274 |
amit.gupta |
51 |
import math
|
| 19221 |
amit.gupta |
52 |
import operator
|
| 4748 |
mandeep.dh |
53 |
import sys
|
| 5393 |
mandeep.dh |
54 |
import threading
|
| 3924 |
rajveer |
55 |
import urllib2
|
| 94 |
ashish |
56 |
|
| 5978 |
rajveer |
57 |
sourceId = int(ConfigClient().get_property("sourceid"))
|
| 10687 |
rajveer |
58 |
to_addresses = ["khushal.bhatia@shop2020.in", "chandan.kumar@shop2020.in", "chaitnaya.vats@shop2020.in",'manoj.kumar@shop2020.in']
|
| 7777 |
kshitij.so |
59 |
to_store_addresses = ["rajveer.singh@shop2020.in"]
|
| 6029 |
rajveer |
60 |
mail_user = "cnc.center@shop2020.in"
|
|
|
61 |
mail_password = "5h0p2o2o"
|
|
|
62 |
source_name = "Saholic"
|
|
|
63 |
source_url = "www.saholic.com"
|
| 5885 |
mandeep.dh |
64 |
skippedItems = { 175 : [27, 2160, 2175, 2163, 2158, 7128, 26, 2154],
|
|
|
65 |
193 : [5839] }
|
| 12567 |
amit.gupta |
66 |
stateIdMap = {}
|
|
|
67 |
def fetchStateMaster():
|
|
|
68 |
global stateIdMap
|
|
|
69 |
if stateIdMap:
|
|
|
70 |
return stateIdMap
|
|
|
71 |
else:
|
|
|
72 |
try:
|
|
|
73 |
glob_inventory_client = InventoryClient().get_client()
|
|
|
74 |
stateIdMap = glob_inventory_client.getStateMaster()
|
|
|
75 |
return stateIdMap
|
|
|
76 |
except:
|
|
|
77 |
print "Could not fetch"
|
|
|
78 |
|
| 5295 |
rajveer |
79 |
def initialize(dbname='catalog', db_hostname="localhost"):
|
|
|
80 |
DataService.initialize(dbname, db_hostname)
|
| 7770 |
kshitij.so |
81 |
|
| 3849 |
chandransh |
82 |
def get_all_items_by_status(status, offset=0, limit=None):
|
|
|
83 |
query = Item.query
|
| 4539 |
rajveer |
84 |
if status is not None:
|
| 3849 |
chandransh |
85 |
query = query.filter_by(status=status)
|
|
|
86 |
query = query.order_by(Item.product_group, Item.brand, Item.model_number, Item.model_name).offset(offset)
|
|
|
87 |
if limit:
|
|
|
88 |
query = query.limit(limit)
|
|
|
89 |
items = query.all()
|
|
|
90 |
return items
|
|
|
91 |
|
| 6821 |
amar.kumar |
92 |
def get_all_alive_items():
|
|
|
93 |
query = Item.query
|
| 10403 |
rajveer |
94 |
query = query.filter(or_(Item.status==status.ACTIVE, Item.status==status.PAUSED, Item.status==status.PAUSED_BY_RISK, Item.status==status.PARTIALLY_ACTIVE))
|
| 6821 |
amar.kumar |
95 |
items = query.all()
|
|
|
96 |
return items
|
|
|
97 |
|
|
|
98 |
|
| 3849 |
chandransh |
99 |
def get_all_items(is_active, offset=0, limit=None):
|
| 103 |
ashish |
100 |
if is_active:
|
| 3849 |
chandransh |
101 |
items = get_all_items_by_status(status.ACTIVE, offset, limit)
|
| 103 |
ashish |
102 |
else:
|
| 3849 |
chandransh |
103 |
items = get_all_items_by_status(None, offset, limit)
|
| 766 |
rajveer |
104 |
return items
|
|
|
105 |
|
| 3849 |
chandransh |
106 |
def get_item_count_by_status(use_status, status):
|
|
|
107 |
if use_status:
|
|
|
108 |
return Item.query.filter_by(status=status).count()
|
| 103 |
ashish |
109 |
else:
|
| 3849 |
chandransh |
110 |
return Item.query.count()
|
| 103 |
ashish |
111 |
|
| 635 |
rajveer |
112 |
def get_item(item_id):
|
| 766 |
rajveer |
113 |
item = Item.get_by(id=item_id)
|
|
|
114 |
return item
|
| 94 |
ashish |
115 |
|
| 13493 |
amit.gupta |
116 |
def get_items(item_ids):
|
| 13519 |
amit.gupta |
117 |
items = Item.query.filter(Item.id.in_(item_ids)).all()
|
| 13493 |
amit.gupta |
118 |
return items
|
|
|
119 |
|
| 635 |
rajveer |
120 |
def get_items_by_catalog_id(catalog_id):
|
| 447 |
rajveer |
121 |
query = Item.query.filter_by(catalog_item_id=catalog_id)
|
| 437 |
rajveer |
122 |
try:
|
| 635 |
rajveer |
123 |
items = query.all()
|
| 4934 |
amit.gupta |
124 |
return items
|
| 1399 |
rajveer |
125 |
except Exception as ex:
|
|
|
126 |
print ex
|
| 437 |
rajveer |
127 |
raise InventoryServiceException(109, "Item not found")
|
| 5586 |
phani.kuma |
128 |
|
|
|
129 |
def is_valid_catalog_id(catalog_id):
|
|
|
130 |
item = Item.query.filter_by(catalog_item_id=catalog_id).first()
|
|
|
131 |
if item is not None:
|
|
|
132 |
return True
|
|
|
133 |
else:
|
|
|
134 |
return False
|
| 19221 |
amit.gupta |
135 |
|
|
|
136 |
def get_item_location_availability_by_item_ids(item_ids):
|
|
|
137 |
pass
|
|
|
138 |
def get_item_location_availability(item_locations):
|
|
|
139 |
item_location = ItemLocationAvailability()
|
|
|
140 |
tuples = []
|
|
|
141 |
for item_location in item_locations:
|
|
|
142 |
tuples.append((item_location.itemId, item_location.locationId))
|
|
|
143 |
return session.query(ItemLocationAvailabilityCache).filter(tuple_(ItemLocationAvailabilityCache.item_id, ItemLocationAvailabilityCache.location_id).in_(tuples)).all()
|
| 5586 |
phani.kuma |
144 |
|
| 576 |
chandransh |
145 |
def is_active(item_id):
|
| 2983 |
chandransh |
146 |
t_item_shipping_info = ItemShippingInfo()
|
| 576 |
chandransh |
147 |
try:
|
| 635 |
rajveer |
148 |
item = get_item(item_id)
|
| 3281 |
chandransh |
149 |
t_item_shipping_info.isRisky = item.risky
|
| 5944 |
mandeep.dh |
150 |
client = InventoryClient().get_client()
|
| 5978 |
rajveer |
151 |
itemInfo = client.getItemAvailabilityAtLocation(item.id, sourceId)
|
| 17782 |
amit.gupta |
152 |
availability = itemInfo[4]
|
| 5393 |
mandeep.dh |
153 |
if item.risky and item.status == status.ACTIVE:
|
| 5944 |
mandeep.dh |
154 |
if availability <= 0:
|
| 5393 |
mandeep.dh |
155 |
add_status_change_log(item, status.PAUSED_BY_RISK)
|
|
|
156 |
item.status = status.PAUSED_BY_RISK
|
|
|
157 |
item.status_description = "This item is currently out of stock"
|
|
|
158 |
session.commit()
|
|
|
159 |
__send_mail_for_oos_item(item)
|
|
|
160 |
#This will clear cache from tomcat
|
| 10223 |
amit.gupta |
161 |
#__clear_homepage_cache()
|
| 2983 |
chandransh |
162 |
t_item_shipping_info.isActive = (item.status == status.ACTIVE)
|
| 3281 |
chandransh |
163 |
t_item_shipping_info.quantity = availability
|
| 576 |
chandransh |
164 |
except InventoryServiceException:
|
| 2983 |
chandransh |
165 |
print "[ERROR] Unexpected error:", sys.exc_info()[0]
|
|
|
166 |
return t_item_shipping_info
|
|
|
167 |
|
| 7438 |
amit.gupta |
168 |
def get_items_status(item_ids):
|
|
|
169 |
itemsStatus = dict()
|
| 12963 |
amit.gupta |
170 |
# for item_id in item_ids:
|
|
|
171 |
# try:
|
|
|
172 |
# item = get_item(item_id)
|
|
|
173 |
# if item is None:
|
|
|
174 |
# continue
|
|
|
175 |
# client = InventoryClient().get_client()
|
|
|
176 |
# itemInfo = client.getItemAvailabilityAtLocation(item.id, sourceId)
|
|
|
177 |
# warehouse_id = itemInfo[0]
|
|
|
178 |
# if item.risky and item.status == status.ACTIVE:
|
|
|
179 |
# availability = client.getItemAvailibilityAtWarehouse(warehouse_id, item_id)
|
|
|
180 |
# if availability <= 0:
|
|
|
181 |
# item.status = status.PAUSED_BY_RISK
|
|
|
182 |
# itemsStatus[item_id] = (item.status == status.ACTIVE)
|
|
|
183 |
# except InventoryServiceException:
|
|
|
184 |
# print "[ERROR] Unexpected error:", sys.exc_info()[0]
|
| 7438 |
amit.gupta |
185 |
return itemsStatus
|
|
|
186 |
|
| 2035 |
rajveer |
187 |
def get_item_status_description(itemId):
|
|
|
188 |
item = get_item(itemId)
|
|
|
189 |
return item.status_description
|
| 94 |
ashish |
190 |
|
| 122 |
ashish |
191 |
def update_item(item):
|
|
|
192 |
if not item:
|
|
|
193 |
raise InventoryServiceException(108, "Bad item in request")
|
| 7770 |
kshitij.so |
194 |
|
| 122 |
ashish |
195 |
if not item.id:
|
| 609 |
chandransh |
196 |
raise InventoryServiceException(101, "Missing id for update")
|
| 7770 |
kshitij.so |
197 |
|
| 2120 |
ankur.sing |
198 |
validate_item_prices(item)
|
| 7770 |
kshitij.so |
199 |
|
| 635 |
rajveer |
200 |
ds_item = get_item(item.id)
|
| 5047 |
amit.gupta |
201 |
message = ""
|
| 7384 |
rajveer |
202 |
store_message = ""
|
| 122 |
ashish |
203 |
if not ds_item:
|
| 609 |
chandransh |
204 |
raise InventoryServiceException(101, "Item missing in our database")
|
| 7770 |
kshitij.so |
205 |
|
| 963 |
chandransh |
206 |
if item.productGroup:
|
| 7770 |
kshitij.so |
207 |
ds_item.product_group = item.productGroup
|
| 963 |
chandransh |
208 |
if item.brand:
|
|
|
209 |
ds_item.brand = item.brand
|
| 511 |
rajveer |
210 |
if item.modelNumber:
|
|
|
211 |
ds_item.model_number = item.modelNumber
|
| 2497 |
ankur.sing |
212 |
ds_item.color = item.color
|
|
|
213 |
ds_item.model_name = item.modelName
|
|
|
214 |
ds_item.category = item.category
|
| 19221 |
amit.gupta |
215 |
# if item.category == 10006:
|
|
|
216 |
# itemInsurerMapping = ItemInsurerMapping.query.filter(ItemInsurerMapping.itemId == item.id).filter(ItemInsurerMapping.insurerType == InsurerType._NAMES_TO_VALUES.get("DEVICE")).first()
|
|
|
217 |
# if itemInsurerMapping is None:
|
|
|
218 |
# itemInsurerMapping = ItemInsurerMapping()
|
|
|
219 |
# itemInsurerMapping.itemId = item.id
|
|
|
220 |
# itemInsurerMapping.insurerId = 1
|
|
|
221 |
# itemInsurerMapping.insurerType = 1
|
| 7770 |
kshitij.so |
222 |
|
| 2497 |
ankur.sing |
223 |
ds_item.comments = item.comments
|
| 7770 |
kshitij.so |
224 |
|
| 2497 |
ankur.sing |
225 |
ds_item.catalog_item_id = item.catalogItemId
|
| 483 |
rajveer |
226 |
|
| 7384 |
rajveer |
227 |
if ds_item.activeOnStore and ds_item.mrp and item.mrp and ds_item.mrp != item.mrp:
|
|
|
228 |
sp = get_store_pricing(item.id)
|
|
|
229 |
if sp.maxPrice > item.mrp:
|
|
|
230 |
sp.maxPrice = item.mrp
|
|
|
231 |
store_message += "MRP is changed from {0} to {1}.\n".format(sp.maxPrice, item.mrp)
|
| 7770 |
kshitij.so |
232 |
|
| 7384 |
rajveer |
233 |
|
|
|
234 |
if ds_item.activeOnStore and ds_item.sellingPrice and item.sellingPrice and ds_item.sellingPrice != item.sellingPrice:
|
|
|
235 |
sp = get_store_pricing(item.id)
|
|
|
236 |
if sp.minPrice < item.sellingPrice:
|
|
|
237 |
store_message += "Saholic MOP Changed. DP {0} is less than Saholic MOP.\n".format(sp.minPrice)
|
| 7770 |
kshitij.so |
238 |
|
| 2129 |
ankur.sing |
239 |
ds_item.mrp = item.mrp
|
| 5047 |
amit.gupta |
240 |
if ds_item.sellingPrice or item.sellingPrice:
|
|
|
241 |
if ds_item.sellingPrice != item.sellingPrice:
|
| 12407 |
kshitij.so |
242 |
amazonItem = (get_amazon_item_details(item.id))[0]
|
| 7761 |
kshitij.so |
243 |
if amazonItem is not None:
|
| 12701 |
kshitij.so |
244 |
#outOfSync = AmazonOutOfSync.get_by(item_id=item.id)
|
|
|
245 |
sync = True
|
|
|
246 |
if amazonItem.isFba:
|
|
|
247 |
if ds_item.sellingPrice != amazonItem.fbaPrice:
|
|
|
248 |
sync = False
|
|
|
249 |
if amazonItem.isNonFba:
|
|
|
250 |
if ds_item.sellingPrice != amazonItem.sellingPrice:
|
|
|
251 |
sync = False
|
|
|
252 |
if amazonItem.isFbb:
|
|
|
253 |
if ds_item.sellingPrice != amazonItem.fbbPrice:
|
|
|
254 |
sync = False
|
| 12888 |
kshitij.so |
255 |
if amazonItem.isFbg:
|
|
|
256 |
if ds_item.sellingPrice != amazonItem.fbgPrice:
|
|
|
257 |
sync = False
|
| 12701 |
kshitij.so |
258 |
if sync:
|
| 11816 |
kshitij.so |
259 |
amazonItem.fbaPrice = item.sellingPrice
|
|
|
260 |
amazonItem.sellingPrice=item.sellingPrice
|
|
|
261 |
amazonItem.fbbPrice=item.sellingPrice
|
| 12888 |
kshitij.so |
262 |
amazonItem.fbgPrice=item.sellingPrice
|
| 11816 |
kshitij.so |
263 |
amazonItem.mfnPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
264 |
amazonItem.fbaPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
265 |
amazonItem.fbbPriceLastUpdatedOn = datetime.datetime.now()
|
| 12888 |
kshitij.so |
266 |
amazonItem.fbgPriceLastUpdatedOn = datetime.datetime.now()
|
| 11816 |
kshitij.so |
267 |
message +="Amazon Prices Synced."
|
|
|
268 |
else:
|
| 12701 |
kshitij.so |
269 |
message +="Amazon Prices Not Synced."
|
|
|
270 |
|
| 5047 |
amit.gupta |
271 |
message += "Selling Price is changed from {0} to {1}.\n".format(ds_item.sellingPrice, item.sellingPrice)
|
| 7770 |
kshitij.so |
272 |
|
| 2129 |
ankur.sing |
273 |
ds_item.sellingPrice = item.sellingPrice
|
| 2174 |
ankur.sing |
274 |
ds_item.weight = item.weight
|
| 6241 |
amit.gupta |
275 |
ds_item.showSellingPrice = item.showSellingPrice
|
| 7770 |
kshitij.so |
276 |
|
| 7291 |
vikram.rag |
277 |
if item.asin:
|
|
|
278 |
ds_item.asin = item.asin
|
|
|
279 |
ds_item.holdInventory = item.holdInventory
|
|
|
280 |
ds_item.defaultInventory = item.defaultInventory
|
| 9841 |
rajveer |
281 |
ds_item.holdOverride = item.holdOverride
|
| 7770 |
kshitij.so |
282 |
|
| 6826 |
amit.gupta |
283 |
if item.startDate:
|
|
|
284 |
ds_item.startDate = to_py_date(item.startDate)
|
|
|
285 |
ds_item.startDate = ds_item.startDate.replace(hour=0,second=0,minute=0)
|
|
|
286 |
if item.itemStatus == status.COMING_SOON and ds_item.startDate < datetime.datetime.now() :
|
|
|
287 |
item.itemStatus = status.ACTIVE
|
|
|
288 |
item.status_description = "This item is active"
|
|
|
289 |
else:
|
|
|
290 |
ds_item.startDate = None
|
|
|
291 |
|
| 2358 |
ankur.sing |
292 |
if ds_item.status != item.itemStatus:
|
| 2402 |
rajveer |
293 |
add_status_change_log(ds_item, item.itemStatus)
|
| 5047 |
amit.gupta |
294 |
if item.itemStatus == status.PHASED_OUT:
|
|
|
295 |
message += "Item is phased out."
|
| 2358 |
ankur.sing |
296 |
ds_item.status = item.itemStatus
|
| 2035 |
rajveer |
297 |
if item.status_description:
|
|
|
298 |
ds_item.status_description = item.status_description
|
| 7770 |
kshitij.so |
299 |
|
| 511 |
rajveer |
300 |
if item.retireDate:
|
| 2116 |
ankur.sing |
301 |
ds_item.retireDate = to_py_date(item.retireDate)
|
| 2497 |
ankur.sing |
302 |
else:
|
|
|
303 |
ds_item.retireDate = None
|
| 5217 |
amit.gupta |
304 |
|
|
|
305 |
if item.expectedArrivalDate:
|
|
|
306 |
ds_item.expectedArrivalDate = to_py_date(item.expectedArrivalDate)
|
|
|
307 |
else:
|
|
|
308 |
ds_item.expectedArrivalDate = None
|
| 7770 |
kshitij.so |
309 |
|
| 5217 |
amit.gupta |
310 |
if item.comingSoonStartDate:
|
|
|
311 |
ds_item.comingSoonStartDate = to_py_date(item.comingSoonStartDate)
|
| 6696 |
rajveer |
312 |
ds_item.comingSoonStartDate = ds_item.comingSoonStartDate.replace(hour=0,second=0,minute=0)
|
| 5217 |
amit.gupta |
313 |
else:
|
|
|
314 |
ds_item.comingSoonStartDate = None
|
| 7770 |
kshitij.so |
315 |
|
|
|
316 |
|
| 2497 |
ankur.sing |
317 |
ds_item.feature_id = item.featureId
|
|
|
318 |
ds_item.feature_description = item.featureDescription
|
| 7770 |
kshitij.so |
319 |
|
| 5047 |
amit.gupta |
320 |
if ds_item.bestDealText or item.bestDealText:
|
|
|
321 |
if item.bestDealText != ds_item.bestDealText:
|
| 5080 |
amit.gupta |
322 |
message += "Promotion text is changed from '{0}' to '{1}'.\n".format(ds_item.bestDealText, item.bestDealText)
|
| 2129 |
ankur.sing |
323 |
ds_item.bestDealText = item.bestDealText
|
|
|
324 |
ds_item.bestDealValue = item.bestDealValue
|
| 2065 |
ankur.sing |
325 |
ds_item.bestSellingRank = item.bestSellingRank
|
| 7770 |
kshitij.so |
326 |
|
| 6777 |
vikram.rag |
327 |
if ds_item.bestDealsDetailsText or item.bestDealsDetailsText:
|
|
|
328 |
if item.bestDealsDetailsText != ds_item.bestDealsDetailsText:
|
|
|
329 |
message += "Best deals details text is changed from '{0}' to '{1}'.\n".format(ds_item.bestDealsDetailsText, item.bestDealsDetailsText)
|
|
|
330 |
ds_item.bestDealsDetailsText = item.bestDealsDetailsText
|
| 7770 |
kshitij.so |
331 |
|
| 6777 |
vikram.rag |
332 |
if ds_item.bestDealsDetailsLink or item.bestDealsDetailsLink:
|
|
|
333 |
if item.bestDealsDetailsLink != ds_item.bestDealsDetailsLink:
|
|
|
334 |
message += "Best deals details link is changed from '{0}' to '{1}'.\n".format(ds_item.bestDealsDetailsLink, item.bestDealsDetailsLink)
|
|
|
335 |
ds_item.bestDealsDetailsLink = item.bestDealsDetailsLink
|
| 7770 |
kshitij.so |
336 |
|
|
|
337 |
|
| 2065 |
ankur.sing |
338 |
ds_item.defaultForEntity = item.defaultForEntity
|
| 7770 |
kshitij.so |
339 |
|
| 5047 |
amit.gupta |
340 |
if ds_item.risky or item.risky:
|
|
|
341 |
if ds_item.risky != item.risky:
|
| 5080 |
amit.gupta |
342 |
message += "Risky flag is changed to '{0}'.\n".format(set)
|
| 7770 |
kshitij.so |
343 |
|
| 2251 |
ankur.sing |
344 |
ds_item.risky = item.risky
|
| 7770 |
kshitij.so |
345 |
|
| 5385 |
phani.kuma |
346 |
ds_item.type = ItemType._VALUES_TO_NAMES[item.type]
|
|
|
347 |
ds_item.hasItemNo = item.hasItemNo
|
| 7770 |
kshitij.so |
348 |
|
| 3459 |
chandransh |
349 |
if item.expectedDelay is not None:
|
| 3359 |
chandransh |
350 |
ds_item.expectedDelay = item.expectedDelay
|
| 7770 |
kshitij.so |
351 |
|
| 4506 |
phani.kuma |
352 |
if item.preferredVendor:
|
| 5080 |
amit.gupta |
353 |
if item.preferredVendor != ds_item.preferredVendor:
|
| 5944 |
mandeep.dh |
354 |
inventoryClient = InventoryClient().get_client()
|
|
|
355 |
newPreferredVendorName = inventoryClient.getVendor(item.preferredVendor).name
|
| 5080 |
amit.gupta |
356 |
oldPreferredVendorName = 'None'
|
|
|
357 |
if ds_item.preferredVendor:
|
| 5944 |
mandeep.dh |
358 |
oldPreferredVendorName = inventoryClient.getVendor(ds_item.preferredVendor).name
|
| 7770 |
kshitij.so |
359 |
message += "Preferred vendor is changed from '{0}' to '{1}'.\n".format(oldPreferredVendorName, newPreferredVendorName)
|
| 4506 |
phani.kuma |
360 |
ds_item.preferredVendor = item.preferredVendor
|
| 7770 |
kshitij.so |
361 |
|
| 5080 |
amit.gupta |
362 |
if item.isWarehousePreferenceSticky != ds_item.isWarehousePreferenceSticky:
|
|
|
363 |
flag = "ON" if item.isWarehousePreferenceSticky else "OFF"
|
|
|
364 |
message += "Warehouse preference sticky is {0}.\n".format(flag)
|
|
|
365 |
|
| 4413 |
anupam.sin |
366 |
ds_item.isWarehousePreferenceSticky = item.isWarehousePreferenceSticky
|
| 7770 |
kshitij.so |
367 |
|
| 7296 |
amit.gupta |
368 |
ds_item.updatedOn = datetime.datetime.now()
|
| 7770 |
kshitij.so |
369 |
|
| 7382 |
rajveer |
370 |
|
| 7519 |
rajveer |
371 |
ds_item.activeOnStore = item.activeOnStore
|
| 18048 |
kshitij.so |
372 |
|
|
|
373 |
ds_item.packQuantity = item.packQuantity
|
| 18150 |
kshitij.so |
374 |
ds_item.quantityStep = item.quantityStep
|
|
|
375 |
ds_item.minimumBuyQuantity = item.minimumBuyQuantity
|
| 18414 |
kshitij.so |
376 |
ds_item.maximumBuyQuantity = item.maximumBuyQuantity
|
| 18048 |
kshitij.so |
377 |
|
| 122 |
ashish |
378 |
session.commit();
|
| 8867 |
rajveer |
379 |
|
| 11817 |
kshitij.so |
380 |
subject = "Item '{0}' is updated in Catalog. Id is {1}".format(__get_product_name(ds_item),ds_item.id)
|
|
|
381 |
if message:
|
|
|
382 |
__send_mail(subject, message)
|
|
|
383 |
if store_message:
|
|
|
384 |
__send_mail(subject, store_message, to_store_addresses)
|
| 8867 |
rajveer |
385 |
|
| 122 |
ashish |
386 |
return ds_item.id
|
| 94 |
ashish |
387 |
|
| 103 |
ashish |
388 |
def add_item(item):
|
|
|
389 |
if not item:
|
| 122 |
ashish |
390 |
raise InventoryServiceException(108, "Bad item in request")
|
| 635 |
rajveer |
391 |
if get_item(item.id):
|
| 15777 |
amit.gupta |
392 |
print item.id
|
| 122 |
ashish |
393 |
raise InventoryServiceException(101, "Item already exists")
|
| 7770 |
kshitij.so |
394 |
|
| 2120 |
ankur.sing |
395 |
validate_item_prices(item)
|
| 7770 |
kshitij.so |
396 |
|
| 103 |
ashish |
397 |
ds_item = Item()
|
| 12567 |
amit.gupta |
398 |
|
|
|
399 |
if item.id:
|
|
|
400 |
ds_item.id = item.id
|
| 963 |
chandransh |
401 |
if item.productGroup:
|
|
|
402 |
ds_item.product_group = item.productGroup
|
|
|
403 |
if item.brand:
|
|
|
404 |
ds_item.brand = item.brand
|
| 515 |
rajveer |
405 |
if item.modelName:
|
|
|
406 |
ds_item.model_name = item.modelName
|
|
|
407 |
if item.modelNumber:
|
|
|
408 |
ds_item.model_number = item.modelNumber
|
| 609 |
chandransh |
409 |
if item.color:
|
|
|
410 |
ds_item.color = item.color
|
| 483 |
rajveer |
411 |
if item.category:
|
|
|
412 |
ds_item.category = item.category
|
|
|
413 |
if item.comments:
|
|
|
414 |
ds_item.comments = item.comments
|
| 7291 |
vikram.rag |
415 |
if item.asin:
|
|
|
416 |
ds_item.asin = item.asin
|
|
|
417 |
ds_item.holdInventory = item.holdInventory
|
| 9841 |
rajveer |
418 |
ds_item.defaultInventory = item.defaultInventory
|
|
|
419 |
ds_item.holdOverride = item.holdOverride
|
| 7296 |
amit.gupta |
420 |
ds_item.addedOn = datetime.datetime.now()
|
|
|
421 |
ds_item.updatedOn = datetime.datetime.now()
|
| 2116 |
ankur.sing |
422 |
if item.startDate:
|
|
|
423 |
ds_item.startDate = to_py_date(item.startDate)
|
| 6696 |
rajveer |
424 |
ds_item.startDate = ds_item.startDate.replace(hour=0,second=0,minute=0)
|
| 2116 |
ankur.sing |
425 |
if item.retireDate:
|
|
|
426 |
ds_item.retireDate = to_py_date(item.retireDate)
|
| 5217 |
amit.gupta |
427 |
if item.comingSoonStartDate:
|
|
|
428 |
ds_item.comingSoonStartDate = to_py_date(item.comingSoonStartDate)
|
|
|
429 |
if item.expectedArrivalDate:
|
| 7770 |
kshitij.so |
430 |
ds_item.expectedArrivalDate = to_py_date(item.expectedArrivalDate)
|
| 483 |
rajveer |
431 |
if item.mrp:
|
|
|
432 |
ds_item.mrp = item.mrp
|
|
|
433 |
if item.sellingPrice:
|
|
|
434 |
ds_item.sellingPrice = item.sellingPrice
|
| 122 |
ashish |
435 |
if item.weight:
|
|
|
436 |
ds_item.weight = item.weight
|
| 7770 |
kshitij.so |
437 |
|
| 122 |
ashish |
438 |
if item.featureId:
|
|
|
439 |
ds_item.feature_id = item.featureId
|
|
|
440 |
if item.featureDescription:
|
|
|
441 |
ds_item.feature_description = item.featureDescription
|
| 7770 |
kshitij.so |
442 |
|
|
|
443 |
|
| 103 |
ashish |
444 |
#check if categories present. If yes, add them to system
|
| 7770 |
kshitij.so |
445 |
|
| 609 |
chandransh |
446 |
if item.bestDealValue:
|
|
|
447 |
ds_item.bestDealValue = item.bestDealValue
|
|
|
448 |
if item.bestDealText:
|
|
|
449 |
ds_item.bestDealText = item.bestDealText
|
| 6777 |
vikram.rag |
450 |
if item.bestDealsDetailsText:
|
|
|
451 |
ds_item.bestDealsDetailsText = item.bestDealsDetailsText
|
|
|
452 |
if item.bestDealsDetailsLink:
|
| 7770 |
kshitij.so |
453 |
ds_item.bestDealsDetailsLink = item.bestDealsDetailsLink
|
| 2116 |
ankur.sing |
454 |
if item.bestSellingRank:
|
|
|
455 |
ds_item.bestSellingRank = item.bestSellingRank
|
|
|
456 |
ds_item.defaultForEntity = item.defaultForEntity
|
| 2251 |
ankur.sing |
457 |
ds_item.risky = item.risky
|
| 7770 |
kshitij.so |
458 |
|
| 5385 |
phani.kuma |
459 |
ds_item.type = ItemType._VALUES_TO_NAMES[item.type]
|
|
|
460 |
ds_item.hasItemNo = item.hasItemNo
|
| 7256 |
rajveer |
461 |
ds_item.activeOnStore = item.activeOnStore
|
| 7770 |
kshitij.so |
462 |
|
| 3467 |
chandransh |
463 |
if item.expectedDelay is not None:
|
| 3359 |
chandransh |
464 |
ds_item.expectedDelay = item.expectedDelay
|
| 3467 |
chandransh |
465 |
else:
|
|
|
466 |
ds_item.expectedDelay = 0
|
| 18048 |
kshitij.so |
467 |
|
|
|
468 |
if item.packQuantity is None or item.packQuantity==0:
|
|
|
469 |
ds_item.packQuantity = 1
|
|
|
470 |
else:
|
|
|
471 |
ds_item.packQuantity = item.packQuantity
|
|
|
472 |
|
| 7770 |
kshitij.so |
473 |
|
| 5408 |
amit.gupta |
474 |
preferredVendorName = "None"
|
| 4881 |
phani.kuma |
475 |
if item.preferredVendor:
|
|
|
476 |
ds_item.preferredVendor = item.preferredVendor
|
| 5944 |
mandeep.dh |
477 |
inventoryClient = InventoryClient().get_client()
|
| 6838 |
vikram.rag |
478 |
preferredVendorName = inventoryClient.getVendor(item.preferredVendor).name
|
| 7770 |
kshitij.so |
479 |
|
| 6838 |
vikram.rag |
480 |
if item.preferredInsurer is not None:
|
| 7770 |
kshitij.so |
481 |
ds_item.preferredInsurer = item.preferredInsurer
|
|
|
482 |
|
| 5586 |
phani.kuma |
483 |
if item.catalogItemId:
|
|
|
484 |
catalog_client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
|
|
485 |
master_items = catalog_client.getItemsByCatalogId(item.catalogItemId)
|
|
|
486 |
itemStatus = status.IN_PROCESS
|
|
|
487 |
for masterItem in master_items:
|
|
|
488 |
if masterItem.itemStatus in [status.CONTENT_COMPLETE, status.COMING_SOON, status.ACTIVE, status.PAUSED]:
|
|
|
489 |
itemStatus = status.CONTENT_COMPLETE
|
|
|
490 |
ds_item.category = masterItem.category
|
|
|
491 |
break
|
|
|
492 |
ds_item.catalog_item_id = item.catalogItemId
|
|
|
493 |
ds_item.status = itemStatus
|
| 2116 |
ankur.sing |
494 |
ds_item.status_description = "This item is in process."
|
|
|
495 |
else:
|
| 5586 |
phani.kuma |
496 |
# Check if a similar item already exists in our database
|
|
|
497 |
similar_item = Item.query.filter_by(brand=item.brand, model_number=item.modelNumber, model_name=item.modelName).first()
|
| 7770 |
kshitij.so |
498 |
|
| 5586 |
phani.kuma |
499 |
if similar_item is None or similar_item.catalog_item_id is None:
|
|
|
500 |
# If there is no similar item in the database from before,
|
|
|
501 |
# use the entity_id_generator
|
|
|
502 |
entity_id = EntityIDGenerator.query.first()
|
|
|
503 |
ds_item.catalog_item_id = entity_id.id + 1
|
| 12641 |
amit.gupta |
504 |
if item.itemStatus:
|
|
|
505 |
ds_item.status = item.itemStatus
|
| 12648 |
amit.gupta |
506 |
ds_item.status_description = status._VALUES_TO_NAMES[item.itemStatus]
|
| 12640 |
amit.gupta |
507 |
else:
|
|
|
508 |
ds_item.status = status.IN_PROCESS
|
|
|
509 |
ds_item.status_description = "This item is in process."
|
| 5586 |
phani.kuma |
510 |
entity_id.id = entity_id.id + 1
|
|
|
511 |
if similar_item is not None and similar_item.catalog_item_id is None:
|
|
|
512 |
similar_item.catalog_item_id = entity_id.id
|
|
|
513 |
else:
|
| 12685 |
amit.gupta |
514 |
print "[SIMILAR ITEM FOUND:] FOR {0} {1} {2}".format(item.brand, item.modelNumber, item.modelName)
|
| 5586 |
phani.kuma |
515 |
#If a similar item already exists for a product group, brand and model_number, set it as same.
|
|
|
516 |
ds_item.catalog_item_id = similar_item.catalog_item_id
|
|
|
517 |
ds_item.category = similar_item.category
|
|
|
518 |
ds_item.product_group = similar_item.product_group
|
|
|
519 |
ds_item.status = similar_item.status
|
|
|
520 |
ds_item.status_description = similar_item.status_description
|
| 7770 |
kshitij.so |
521 |
|
| 103 |
ashish |
522 |
session.commit();
|
| 5052 |
amit.gupta |
523 |
subject = "New item is added. Id is {0}".format(str(ds_item.id))
|
| 6777 |
vikram.rag |
524 |
message = "Category : {6}, Brand : {0}, Model : {1}, Model Number : {2}\nColor : {3}, Selling Price : {4}, Mrp : {5}, \nPromotion Text : {7}, Preferred Vendor: {8}".format(item.brand, item.modelNumber, item.modelName, item.color, item.sellingPrice, item.mrp, item.category, item.bestDealText,item.bestDealsDetailsText,item.bestDealsDetailsLink, preferredVendorName)
|
| 15777 |
amit.gupta |
525 |
#__send_mail(subject, message)
|
| 3325 |
chandransh |
526 |
return ds_item.id
|
|
|
527 |
|
| 103 |
ashish |
528 |
def retire_item(item_id):
|
|
|
529 |
if not item_id:
|
| 122 |
ashish |
530 |
raise InventoryServiceException(101, "bad item id")
|
| 635 |
rajveer |
531 |
item = get_item(item_id)
|
| 103 |
ashish |
532 |
if not item:
|
| 122 |
ashish |
533 |
raise InventoryServiceException(108, "item id not present")
|
|
|
534 |
item.status = status.PHASED_OUT
|
|
|
535 |
item.retireDate = datetime.datetime.now()
|
| 103 |
ashish |
536 |
session.commit()
|
| 7770 |
kshitij.so |
537 |
|
| 122 |
ashish |
538 |
#need to implement threads based solution here
|
| 103 |
ashish |
539 |
def start_item_on(item_id, timestamp):
|
|
|
540 |
if not item_id:
|
| 122 |
ashish |
541 |
raise InventoryServiceException(101, "bad item id")
|
| 635 |
rajveer |
542 |
item = get_item(item_id)
|
| 103 |
ashish |
543 |
if not item:
|
| 122 |
ashish |
544 |
raise InventoryServiceException(108, "item id not present")
|
| 7770 |
kshitij.so |
545 |
|
| 122 |
ashish |
546 |
item.status = status.ACTIVE
|
|
|
547 |
item.startDate = datetime.datetime.fromtimestamp(to_py_date(timestamp))
|
|
|
548 |
add_status_change_log(item, status.ACTIVE)
|
| 103 |
ashish |
549 |
session.commit()
|
| 7770 |
kshitij.so |
550 |
|
| 122 |
ashish |
551 |
#need to implement threads here
|
| 103 |
ashish |
552 |
def retire_item_on(item_id, timestamp):
|
|
|
553 |
if not item_id:
|
| 122 |
ashish |
554 |
raise InventoryServiceException(101, "bad item id")
|
| 635 |
rajveer |
555 |
item = get_item(item_id)
|
| 103 |
ashish |
556 |
if not item:
|
| 122 |
ashish |
557 |
raise InventoryServiceException(108, "item id not present")
|
| 7770 |
kshitij.so |
558 |
|
| 122 |
ashish |
559 |
item.status = status.PHASED_OUT
|
|
|
560 |
item.retireDate = datetime.datetime.fromtimestamp(to_py_date(timestamp))
|
|
|
561 |
add_status_change_log(item, status.PHASED_OUT)
|
| 103 |
ashish |
562 |
session.commit()
|
| 7770 |
kshitij.so |
563 |
|
| 103 |
ashish |
564 |
def add_status_change_log(item, new_status):
|
|
|
565 |
item_change_log = ItemChangeLog()
|
|
|
566 |
item_change_log.new_status = new_status
|
|
|
567 |
item_change_log.old_status = item.status
|
|
|
568 |
item_change_log.timestamp = datetime.datetime.now()
|
|
|
569 |
item_change_log.item = item
|
|
|
570 |
session.commit()
|
| 7770 |
kshitij.so |
571 |
|
| 103 |
ashish |
572 |
def change_item_status(item_id, new_status):
|
|
|
573 |
if not item_id:
|
| 122 |
ashish |
574 |
raise InventoryServiceException(101, "bad item id")
|
| 635 |
rajveer |
575 |
item = get_item(item_id)
|
| 103 |
ashish |
576 |
if not item:
|
| 122 |
ashish |
577 |
raise InventoryServiceException(108, "item id not present")
|
| 2116 |
ankur.sing |
578 |
add_status_change_log(item, new_status)
|
| 122 |
ashish |
579 |
item.status = new_status
|
| 2251 |
ankur.sing |
580 |
if item.status == status.PHASED_OUT:
|
|
|
581 |
item.status_description = "This item has been phased out"
|
| 5047 |
amit.gupta |
582 |
__send_mail("Item '{0}' is Phased-Out. Item id is {1}".format(__get_product_name(item), item_id), "")
|
| 2251 |
ankur.sing |
583 |
elif item.status == status.DELETED:
|
|
|
584 |
item.status_description = "This item has been deleted"
|
| 3924 |
rajveer |
585 |
elif item.status == status.PAUSED:
|
| 7770 |
kshitij.so |
586 |
item.status_description = "This item is currently out of stock"
|
| 3924 |
rajveer |
587 |
elif item.status == status.PAUSED_BY_RISK:
|
|
|
588 |
item.status_description = "This item is currently out of stock"
|
|
|
589 |
#This will clear cache from tomcat
|
| 10223 |
amit.gupta |
590 |
#__clear_homepage_cache()
|
| 2251 |
ankur.sing |
591 |
elif item.status == status.ACTIVE:
|
|
|
592 |
item.status_description = "This item is active"
|
|
|
593 |
elif item.status == status.IN_PROCESS:
|
|
|
594 |
item.status_description = "This item is in process"
|
|
|
595 |
elif item.status == status.CONTENT_COMPLETE:
|
|
|
596 |
item.status_description = "This item is in process"
|
| 103 |
ashish |
597 |
session.commit()
|
| 12963 |
amit.gupta |
598 |
|
|
|
599 |
#Risky item is validated wheter in stock or not
|
| 5944 |
mandeep.dh |
600 |
def check_risky_item(item_id):
|
| 635 |
rajveer |
601 |
item = get_item(item_id)
|
| 2251 |
ankur.sing |
602 |
if not item.risky:
|
|
|
603 |
return
|
| 5944 |
mandeep.dh |
604 |
client = InventoryClient().get_client()
|
| 7770 |
kshitij.so |
605 |
itemInfo = client.getItemAvailabilityAtLocation(item.id, sourceId)
|
| 17782 |
amit.gupta |
606 |
availability = itemInfo[4]
|
| 5944 |
mandeep.dh |
607 |
if availability <= 0:
|
| 2251 |
ankur.sing |
608 |
if item.status == status.ACTIVE:
|
| 2984 |
rajveer |
609 |
change_item_status(item.id, status.PAUSED_BY_RISK)
|
| 4797 |
rajveer |
610 |
__send_mail_for_oos_item(item)
|
| 2251 |
ankur.sing |
611 |
else:
|
| 2984 |
rajveer |
612 |
if item.status == status.PAUSED_BY_RISK:
|
| 2251 |
ankur.sing |
613 |
change_item_status(item.id, status.ACTIVE)
|
| 6255 |
rajveer |
614 |
__send_mail_for_active_item(item.id, "Item '{0}' is Active. Item id is {1}".format(__get_product_name(item), item_id), "")
|
| 2368 |
ankur.sing |
615 |
session.commit()
|
| 7770 |
kshitij.so |
616 |
|
| 9253 |
rajveer |
617 |
def mark_item_as_content_complete(entity_id, category, brand, modelName, modelNumber, isAndroid):
|
| 2828 |
rajveer |
618 |
'''
|
|
|
619 |
Get all the items for this entityID and update category, brand, modelName and modelNumber for all.
|
|
|
620 |
Update Status for only IN_PROCESS items to CONTENT_COMPLETE
|
|
|
621 |
'''
|
| 723 |
chandransh |
622 |
content_complete_status = status.CONTENT_COMPLETE
|
| 2828 |
rajveer |
623 |
items = Item.query.filter_by(catalog_item_id=entity_id).all()
|
| 723 |
chandransh |
624 |
current_timestamp = datetime.datetime.now()
|
|
|
625 |
for item in items:
|
| 18569 |
amit.gupta |
626 |
if item.status == status.IN_PROCESS or item.status == status.PARTIALLY_ACTIVE:
|
| 2828 |
rajveer |
627 |
item.status = content_complete_status
|
| 18569 |
amit.gupta |
628 |
item.status_description = "CONTENT_COMPLETE"
|
| 2828 |
rajveer |
629 |
item_change_log = ItemChangeLog()
|
|
|
630 |
item_change_log.old_status = item.status
|
|
|
631 |
item_change_log.new_status = content_complete_status
|
|
|
632 |
item_change_log.timestamp = current_timestamp
|
|
|
633 |
item_change_log.item = item
|
| 17216 |
kshitij.so |
634 |
#if isAndroid:
|
|
|
635 |
# itemInsurerMapping = ItemInsurerMapping.query.filter(ItemInsurerMapping.itemId == item.id).filter(ItemInsurerMapping.insurerType == InsurerType._NAMES_TO_VALUES.get("DATA")).first()
|
|
|
636 |
# if itemInsurerMapping is None:
|
|
|
637 |
# itemInsurerMapping = ItemInsurerMapping()
|
|
|
638 |
# itemInsurerMapping.itemId = item.id
|
|
|
639 |
# itemInsurerMapping.insurerId = 2
|
|
|
640 |
# itemInsurerMapping.insurerType = 2
|
| 7770 |
kshitij.so |
641 |
|
| 4762 |
phani.kuma |
642 |
category_object = get_category(category)
|
|
|
643 |
if category_object is not None:
|
|
|
644 |
item.category = category
|
|
|
645 |
item.product_group = category_object.display_name
|
| 13034 |
amit.gupta |
646 |
else:
|
|
|
647 |
return False
|
| 2075 |
rajveer |
648 |
item.brand = brand
|
| 2081 |
rajveer |
649 |
item.model_name = modelName
|
|
|
650 |
item.model_number = modelNumber
|
| 723 |
chandransh |
651 |
item.updatedOn = current_timestamp
|
|
|
652 |
session.commit()
|
|
|
653 |
return True
|
| 1294 |
chandransh |
654 |
|
| 2404 |
chandransh |
655 |
def get_child_categories(category):
|
|
|
656 |
cm = CategoryManager()
|
| 2621 |
varun.gupt |
657 |
cat = cm.getCategory(category)
|
|
|
658 |
return cat.children_category_ids if cat else None
|
| 2404 |
chandransh |
659 |
|
| 626 |
chandransh |
660 |
def get_best_sellers(start_index, stop_index, category=-1):
|
| 2404 |
chandransh |
661 |
'''
|
|
|
662 |
Returns the Best Sellers between the start and the stop index in the given category
|
|
|
663 |
'''
|
| 1926 |
rajveer |
664 |
query = get_best_sellers_query(category, None)
|
| 1098 |
chandransh |
665 |
best_sellers = query.all()[start_index:stop_index]
|
| 621 |
chandransh |
666 |
return get_thrift_item_list(best_sellers)
|
|
|
667 |
|
| 2093 |
chandransh |
668 |
def get_best_sellers_count(category=-1):
|
| 2404 |
chandransh |
669 |
'''
|
|
|
670 |
Returns the number of best sellers in the given category
|
|
|
671 |
'''
|
| 1926 |
rajveer |
672 |
count = get_best_sellers_query(category, None).count()
|
| 1120 |
rajveer |
673 |
if count is None:
|
|
|
674 |
count = 0
|
| 766 |
rajveer |
675 |
return count
|
| 621 |
chandransh |
676 |
|
| 1926 |
rajveer |
677 |
def get_best_sellers_catalog_ids(start_index, stop_index, brand, category=-1):
|
| 2404 |
chandransh |
678 |
'''
|
|
|
679 |
Returns the Best sellers for the given brand and category between the start and the stop index.
|
| 7770 |
kshitij.so |
680 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
| 2404 |
chandransh |
681 |
'''
|
| 1926 |
rajveer |
682 |
query = get_best_sellers_query(category, brand)
|
| 1098 |
chandransh |
683 |
best_sellers = query.all()[start_index:stop_index]
|
| 621 |
chandransh |
684 |
return [item.catalog_item_id for item in best_sellers]
|
| 7770 |
kshitij.so |
685 |
|
| 1926 |
rajveer |
686 |
def get_best_sellers_query(category, brand):
|
| 2404 |
chandransh |
687 |
'''
|
|
|
688 |
Returns the query to be used for getting Best Sellers.
|
|
|
689 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
|
|
690 |
'''
|
| 1098 |
chandransh |
691 |
query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestSellingRank != None)
|
| 626 |
chandransh |
692 |
if category != -1:
|
| 1970 |
rajveer |
693 |
all_categories = [category]
|
|
|
694 |
child_categories = get_child_categories(category)
|
|
|
695 |
if child_categories is not None:
|
| 7770 |
kshitij.so |
696 |
all_categories = all_categories + child_categories
|
| 1970 |
rajveer |
697 |
query = query.filter(Item.category.in_(all_categories))
|
| 1926 |
rajveer |
698 |
if brand is not None:
|
|
|
699 |
query = query.filter_by(brand=brand)
|
| 7202 |
amit.gupta |
700 |
query = query.group_by(Item.catalog_item_id).order_by(asc(Item.bestSellingRank))
|
| 621 |
chandransh |
701 |
return query
|
| 609 |
chandransh |
702 |
|
| 1098 |
chandransh |
703 |
def get_best_deals(category=-1):
|
| 2404 |
chandransh |
704 |
'''
|
|
|
705 |
Returns the Best deals in the given category. Ignores the category if it's passed as -1.
|
|
|
706 |
'''
|
|
|
707 |
query = get_best_deals_query(Item, category, None)
|
| 1098 |
chandransh |
708 |
items = query.all()
|
| 609 |
chandransh |
709 |
return get_thrift_item_list(items)
|
|
|
710 |
|
| 1098 |
chandransh |
711 |
def get_best_deals_count(category=-1):
|
| 2404 |
chandransh |
712 |
'''
|
|
|
713 |
Returns the count of best deals in the given category.
|
|
|
714 |
Ignores the category if it's -1.
|
|
|
715 |
'''
|
|
|
716 |
count = get_best_deals_counting_query(func.count(distinct(Item.catalog_item_id)), category, None).scalar()
|
| 1120 |
rajveer |
717 |
if count is None:
|
|
|
718 |
count = 0
|
| 766 |
rajveer |
719 |
return count
|
| 7770 |
kshitij.so |
720 |
|
| 1926 |
rajveer |
721 |
def get_best_deals_catalog_ids(start_index, stop_index, brand, category=-1):
|
| 2404 |
chandransh |
722 |
'''
|
|
|
723 |
Returns the catalog_item_ids of best deal items for the given brand and category.
|
|
|
724 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
|
|
725 |
'''
|
|
|
726 |
query = get_best_deals_query(Item, category, brand)
|
| 1098 |
chandransh |
727 |
best_deal_items = query.all()[start_index:stop_index]
|
|
|
728 |
return [item.catalog_item_id for item in best_deal_items]
|
|
|
729 |
|
| 2404 |
chandransh |
730 |
def get_best_deals_counting_query(obj, category, brand):
|
|
|
731 |
'''
|
|
|
732 |
Returns the query to be used to select the best deals in the given brand and category.
|
| 7770 |
kshitij.so |
733 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
| 2404 |
chandransh |
734 |
'''
|
|
|
735 |
query = session.query(obj).filter_by(status=status.ACTIVE).filter(Item.bestDealValue != None)
|
| 626 |
chandransh |
736 |
if category != -1:
|
| 1970 |
rajveer |
737 |
all_categories = [category]
|
|
|
738 |
child_categories = get_child_categories(category)
|
|
|
739 |
if child_categories is not None:
|
| 7770 |
kshitij.so |
740 |
all_categories = all_categories + child_categories
|
| 1970 |
rajveer |
741 |
query = query.filter(Item.category.in_(all_categories))
|
| 1926 |
rajveer |
742 |
if brand is not None:
|
|
|
743 |
query = query.filter_by(brand=brand)
|
| 2404 |
chandransh |
744 |
return query
|
|
|
745 |
|
|
|
746 |
def get_best_deals_query(obj, category, brand):
|
|
|
747 |
'''
|
|
|
748 |
Returns the query to be used to get the best deals in the given category and brand.
|
|
|
749 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
|
|
750 |
'''
|
|
|
751 |
query = get_best_deals_counting_query(obj, category, brand)
|
| 1098 |
chandransh |
752 |
query = query.group_by(Item.catalog_item_id).order_by(desc(Item.bestDealValue))
|
|
|
753 |
return query
|
| 609 |
chandransh |
754 |
|
| 5217 |
amit.gupta |
755 |
def get_coming_soon(category=-1):
|
|
|
756 |
'''
|
|
|
757 |
Returns the Coming Soon items in the given category. Ignores the category if it's passed as -1.
|
|
|
758 |
'''
|
|
|
759 |
query = get_coming_soon_query(Item, category, None)
|
|
|
760 |
items = query.all()
|
|
|
761 |
return get_thrift_item_list(items)
|
|
|
762 |
|
|
|
763 |
def get_coming_soon_count(category=-1):
|
|
|
764 |
'''
|
|
|
765 |
Returns the count of coming in the given category.
|
|
|
766 |
Ignores the category if it's -1.
|
|
|
767 |
'''
|
|
|
768 |
count = get_coming_soon_counting_query(func.count(distinct(Item.catalog_item_id)), category, None).scalar()
|
|
|
769 |
if count is None:
|
|
|
770 |
count = 0
|
|
|
771 |
return count
|
|
|
772 |
|
|
|
773 |
def get_coming_soon_catalog_ids(start_index, stop_index, brand, category=-1):
|
|
|
774 |
'''
|
|
|
775 |
Returns the catalog_item_ids of coming soon items for the given brand and category.
|
|
|
776 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
|
|
777 |
'''
|
|
|
778 |
query = get_coming_soon_query(Item, category, brand)
|
|
|
779 |
coming_soon_items = query.all()[start_index:stop_index]
|
|
|
780 |
return [item.catalog_item_id for item in coming_soon_items]
|
|
|
781 |
|
|
|
782 |
def get_coming_soon_counting_query(obj, category, brand):
|
|
|
783 |
'''
|
|
|
784 |
Returns the query to be used to select the coming soon product in the given brand and category.
|
| 7770 |
kshitij.so |
785 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
| 5217 |
amit.gupta |
786 |
'''
|
|
|
787 |
query = session.query(obj).filter_by(status=status.COMING_SOON)
|
|
|
788 |
if category != -1:
|
|
|
789 |
all_categories = [category]
|
|
|
790 |
child_categories = get_child_categories(category)
|
|
|
791 |
if child_categories is not None:
|
| 7770 |
kshitij.so |
792 |
all_categories = all_categories + child_categories
|
| 5217 |
amit.gupta |
793 |
query = query.filter(Item.category.in_(all_categories))
|
|
|
794 |
if brand is not None:
|
|
|
795 |
query = query.filter_by(brand=brand)
|
|
|
796 |
return query
|
|
|
797 |
|
|
|
798 |
def get_coming_soon_query(obj, category, brand):
|
|
|
799 |
'''
|
|
|
800 |
Returns the query to be used to get the coming soon products in the given category and brand.
|
|
|
801 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
|
|
802 |
'''
|
|
|
803 |
query = get_coming_soon_counting_query(obj, category, brand)
|
|
|
804 |
query = query.group_by(Item.catalog_item_id).order_by(asc(Item.comingSoonStartDate))
|
|
|
805 |
return query
|
|
|
806 |
|
| 1098 |
chandransh |
807 |
def get_latest_arrivals(limit, category=-1):
|
| 2404 |
chandransh |
808 |
'''
|
|
|
809 |
Returns up to limit number of Latest Arrivals in the given category.
|
|
|
810 |
'''
|
| 2975 |
chandransh |
811 |
categories = []
|
|
|
812 |
if category != -1:
|
|
|
813 |
categories = [category]
|
|
|
814 |
query = get_latest_arrivals_query(Item, categories, None)
|
| 1098 |
chandransh |
815 |
items = query.all()[0:limit]
|
| 609 |
chandransh |
816 |
return get_thrift_item_list(items)
|
| 7770 |
kshitij.so |
817 |
|
| 1098 |
chandransh |
818 |
def get_latest_arrivals_count(limit, category=-1):
|
| 2404 |
chandransh |
819 |
'''
|
|
|
820 |
Returns the number of latest arrivals which will be displayed on the website.
|
| 3016 |
chandransh |
821 |
To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
|
| 2404 |
chandransh |
822 |
'''
|
| 2975 |
chandransh |
823 |
categories = []
|
|
|
824 |
if category != -1:
|
|
|
825 |
categories = [category]
|
|
|
826 |
count = get_latest_arrivals_counting_query(func.count(distinct(Item.catalog_item_id)), categories, None).scalar()
|
| 1120 |
rajveer |
827 |
if count is None:
|
|
|
828 |
count = 0
|
|
|
829 |
count = min(count, limit)
|
| 766 |
rajveer |
830 |
return count
|
| 7770 |
kshitij.so |
831 |
|
| 2975 |
chandransh |
832 |
def get_latest_arrivals_catalog_ids(start_index, stop_index, brand, categories=[]):
|
| 2404 |
chandransh |
833 |
'''
|
|
|
834 |
Returns the catalog_item_ids of the latest arrivals between the start and the stop index
|
| 3016 |
chandransh |
835 |
To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
|
| 2404 |
chandransh |
836 |
'''
|
| 2975 |
chandransh |
837 |
query = get_latest_arrivals_query(Item, categories, brand)
|
| 1098 |
chandransh |
838 |
latest_arrivals = query.all()[start_index:stop_index]
|
|
|
839 |
return [item.catalog_item_id for item in latest_arrivals]
|
|
|
840 |
|
| 2975 |
chandransh |
841 |
def get_latest_arrivals_counting_query(obj, categories, brand):
|
| 2404 |
chandransh |
842 |
'''
|
|
|
843 |
Returns the query to be used to count Latest arrivals.
|
| 3016 |
chandransh |
844 |
To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
|
| 2404 |
chandransh |
845 |
'''
|
|
|
846 |
query = session.query(obj).filter_by(status=status.ACTIVE)
|
| 7770 |
kshitij.so |
847 |
|
| 2975 |
chandransh |
848 |
all_categories = []
|
|
|
849 |
for category in categories:
|
|
|
850 |
all_categories.append(category)
|
| 1970 |
rajveer |
851 |
child_categories = get_child_categories(category)
|
| 2975 |
chandransh |
852 |
if child_categories:
|
|
|
853 |
all_categories = all_categories + child_categories
|
| 7770 |
kshitij.so |
854 |
if all_categories:
|
| 1970 |
rajveer |
855 |
query = query.filter(Item.category.in_(all_categories))
|
| 7770 |
kshitij.so |
856 |
|
| 1926 |
rajveer |
857 |
if brand is not None:
|
|
|
858 |
query = query.filter_by(brand=brand)
|
| 2404 |
chandransh |
859 |
return query
|
|
|
860 |
|
| 2975 |
chandransh |
861 |
def get_latest_arrivals_query(obj, categories, brand):
|
| 2404 |
chandransh |
862 |
'''
|
|
|
863 |
Returns the query to be used to retrieve Latest Arrivals.
|
|
|
864 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
|
|
865 |
'''
|
| 2975 |
chandransh |
866 |
query = get_latest_arrivals_counting_query(obj, categories, brand)
|
| 5167 |
rajveer |
867 |
query = query.group_by(Item.catalog_item_id).order_by(desc(Item.startDate)).order_by(Item.catalog_item_id)
|
| 1098 |
chandransh |
868 |
return query
|
| 609 |
chandransh |
869 |
|
|
|
870 |
def get_thrift_item_list(items):
|
| 1098 |
chandransh |
871 |
return [to_t_item(item) for item in items if item != None]
|
| 635 |
rajveer |
872 |
|
| 1155 |
rajveer |
873 |
def generate_new_entity_id():
|
|
|
874 |
generator = EntityIDGenerator.query.one()
|
|
|
875 |
id = generator.id + 1
|
|
|
876 |
generator.id = id
|
|
|
877 |
session.commit()
|
|
|
878 |
return id
|
|
|
879 |
|
| 635 |
rajveer |
880 |
def put_category_object(object):
|
|
|
881 |
category = Category.get_by(id=1)
|
|
|
882 |
if category is None:
|
|
|
883 |
category = Category()
|
| 7770 |
kshitij.so |
884 |
category.object = object
|
| 635 |
rajveer |
885 |
session.commit()
|
|
|
886 |
return True
|
|
|
887 |
|
|
|
888 |
def get_category_object():
|
| 766 |
rajveer |
889 |
object = Category.get_by(id=1).object
|
|
|
890 |
return object
|
|
|
891 |
|
| 1970 |
rajveer |
892 |
def add_category(t_category):
|
|
|
893 |
category = Category.get_by(id=t_category.id)
|
|
|
894 |
if category is None:
|
|
|
895 |
category = Category()
|
| 7770 |
kshitij.so |
896 |
category.id = t_category.id
|
| 1970 |
rajveer |
897 |
category.label = t_category.label
|
|
|
898 |
category.description = t_category.description
|
| 4762 |
phani.kuma |
899 |
category.display_name = t_category.display_name
|
| 7770 |
kshitij.so |
900 |
category.parent_category_id = t_category.parent_category_id
|
| 1970 |
rajveer |
901 |
session.commit()
|
|
|
902 |
return True
|
|
|
903 |
|
|
|
904 |
def get_category(id):
|
|
|
905 |
return Category.query.filter_by(id=id).first()
|
|
|
906 |
|
|
|
907 |
def get_all_categories():
|
|
|
908 |
return Category.query.all()
|
|
|
909 |
|
| 2120 |
ankur.sing |
910 |
def validate_item_prices(item):
|
| 2129 |
ankur.sing |
911 |
if item.mrp == None or item.sellingPrice == None or item.mrp == "" or item.sellingPrice == "":
|
|
|
912 |
return
|
|
|
913 |
if item.mrp < item.sellingPrice:
|
| 2120 |
ankur.sing |
914 |
print "[BAD MRP and SP:] for {0} {1} {2} {3}. MRP={4}, SP={5}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(item.sellingPrice))
|
|
|
915 |
raise InventoryServiceException(101, "[BAD MRP and SP:] for {0} {1} {2} {3}. MRP={4}, SP={5}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(item.sellingPrice)))
|
| 2065 |
ankur.sing |
916 |
return
|
| 7770 |
kshitij.so |
917 |
|
| 2120 |
ankur.sing |
918 |
def validate_vendor_prices(item, vendorPrices):
|
| 2129 |
ankur.sing |
919 |
if item.mrp != None and item.mrp != "" and vendorPrices.mop != "" and item.mrp < vendorPrices.mop:
|
| 2120 |
ankur.sing |
920 |
print "[BAD MRP and MOP:] for {0} {1} {2} {3}. MRP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(vendorPrices.mop), str(vendorPrices.vendorId))
|
|
|
921 |
raise InventoryServiceException(101, "[BAD MRP and MOP:] for {0} {1} {2} {3}. MRP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(vendorPrices.mop), str(vendorPrices.vendorId)))
|
|
|
922 |
if vendorPrices.mop != "" and vendorPrices.transferPrice != "" and vendorPrices.transferPrice > vendorPrices.mop:
|
|
|
923 |
print "[BAD MOP and TP:] for {0} {1} {2} {3}. TP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(vendorPrices.transferPrice), str(vendorPrices.mop), str(vendorPrices.vendorId))
|
|
|
924 |
raise InventoryServiceException(101, "[BAD MOP and TP:] for {0} {1} {2} {3}. TP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(vendorPrices.transferPrice), str(vendorPrices.mop), str(vendorPrices.vendorId)))
|
|
|
925 |
return
|
| 2065 |
ankur.sing |
926 |
|
| 4725 |
phani.kuma |
927 |
def check_color_valid(color):
|
|
|
928 |
if color is not None:
|
|
|
929 |
color = color.strip().lower()
|
|
|
930 |
if color != '' and color != 'na' and color != 'blank' and color != '(blank)':
|
|
|
931 |
return True
|
|
|
932 |
return False
|
|
|
933 |
|
|
|
934 |
def check_similar_item(brand, model_number, model_name, color):
|
| 2129 |
ankur.sing |
935 |
query = Item.query
|
| 2428 |
ankur.sing |
936 |
query = query.filter_by(brand=brand)
|
|
|
937 |
query = query.filter_by(model_number=model_number)
|
| 4725 |
phani.kuma |
938 |
query = query.filter_by(model_name=model_name)
|
|
|
939 |
similar_items = query.all()
|
|
|
940 |
item = None
|
|
|
941 |
# Check if a similar item already exists in our database
|
|
|
942 |
for old_item in similar_items:
|
|
|
943 |
if old_item.color != None and old_item.color.strip().lower() == color.strip().lower():
|
|
|
944 |
item = old_item
|
|
|
945 |
break
|
| 7770 |
kshitij.so |
946 |
|
| 4725 |
phani.kuma |
947 |
# Check if a similar item already exists in our database with out valid color if similar item with same color is not found
|
| 2116 |
ankur.sing |
948 |
if item is None:
|
| 4725 |
phani.kuma |
949 |
for old_item in similar_items:
|
|
|
950 |
if not check_color_valid(old_item.color):
|
|
|
951 |
item = old_item
|
|
|
952 |
break
|
|
|
953 |
i = 0
|
|
|
954 |
color_of_similar_item = None
|
|
|
955 |
# Check if a similar item already exists in our database to be used to get catalog_item_id
|
|
|
956 |
for old_item in similar_items:
|
|
|
957 |
# get a similar item already existing in our database with valid color
|
|
|
958 |
if check_color_valid(old_item.color):
|
|
|
959 |
similar_item = old_item
|
|
|
960 |
color_of_similar_item = similar_item.color
|
|
|
961 |
break
|
|
|
962 |
i = i + 1
|
|
|
963 |
# get a similar item already existing in our database if similar item with valid color is not found
|
|
|
964 |
if i == len(similar_items):
|
|
|
965 |
similar_item = old_item
|
|
|
966 |
color_of_similar_item = similar_item.color
|
| 7770 |
kshitij.so |
967 |
|
| 4725 |
phani.kuma |
968 |
# Check if a similar item that is obtained above is having a valid color
|
|
|
969 |
if check_color_valid(color_of_similar_item):
|
|
|
970 |
# 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.
|
|
|
971 |
# 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.
|
|
|
972 |
if item is None and not check_color_valid(color):
|
|
|
973 |
return similar_item.id
|
| 7770 |
kshitij.so |
974 |
|
| 4725 |
phani.kuma |
975 |
if item is None:
|
| 2116 |
ankur.sing |
976 |
return 0
|
|
|
977 |
else:
|
|
|
978 |
return item.id
|
| 7770 |
kshitij.so |
979 |
|
| 2286 |
ankur.sing |
980 |
def change_risky_flag(item_id, risky):
|
|
|
981 |
item = get_item(item_id)
|
|
|
982 |
if not item:
|
|
|
983 |
raise InventoryServiceException(101, "Item missing in our database")
|
|
|
984 |
try:
|
|
|
985 |
log_risky_flag(item_id, risky)
|
|
|
986 |
except:
|
|
|
987 |
print "Not able to log risky flag change"
|
|
|
988 |
item.risky = risky
|
| 4295 |
varun.gupt |
989 |
if not risky and item.status == status.PAUSED_BY_RISK:
|
| 2368 |
ankur.sing |
990 |
change_item_status(item.id, status.ACTIVE)
|
| 6255 |
rajveer |
991 |
__send_mail_for_active_item(item.id, "Item '{0}' is Active. Item id is {1}".format(__get_product_name(item), item_id), "")
|
| 2286 |
ankur.sing |
992 |
session.commit()
|
| 5047 |
amit.gupta |
993 |
flag = "ON" if risky else "OFF"
|
|
|
994 |
subject = "Risky flag is {0} for Item {1}.".format(flag, __get_product_name(item))
|
|
|
995 |
__send_mail(subject,"")
|
| 7770 |
kshitij.so |
996 |
|
| 4957 |
phani.kuma |
997 |
def get_items_for_mastersheet(categoryName, brand):
|
|
|
998 |
if not categoryName or not brand:
|
|
|
999 |
raise InventoryServiceException(101, "Invalid category or brand in request")
|
| 7770 |
kshitij.so |
1000 |
|
| 4762 |
phani.kuma |
1001 |
categories = ["Handsets", "Tablets", "Laptops"]
|
| 4957 |
phani.kuma |
1002 |
query = Item.query.filter(Item.status != status.PHASED_OUT)
|
|
|
1003 |
if categoryName == "ALL":
|
|
|
1004 |
pass
|
|
|
1005 |
elif categoryName == "ALL Accessories":
|
|
|
1006 |
query = query.filter(~Item.product_group.in_(categories))
|
|
|
1007 |
elif categoryName == "ALL Handsets":
|
|
|
1008 |
query = query.filter(Item.product_group.in_(categories))
|
|
|
1009 |
elif categoryName == "Mobile Accessories":
|
|
|
1010 |
child_categories = get_child_categories(10011)
|
|
|
1011 |
if child_categories is not None:
|
|
|
1012 |
child_categories.append(0)
|
|
|
1013 |
query = query.filter(Item.category.in_(child_categories))
|
|
|
1014 |
elif categoryName == "Laptop Accessories":
|
|
|
1015 |
child_categories = get_child_categories(10070)
|
|
|
1016 |
if child_categories is not None:
|
|
|
1017 |
child_categories.append(0)
|
|
|
1018 |
query = query.filter(Item.category.in_(child_categories))
|
|
|
1019 |
else:
|
|
|
1020 |
query = query.filter(Item.product_group == categoryName)
|
| 7770 |
kshitij.so |
1021 |
|
| 4957 |
phani.kuma |
1022 |
if brand == "ALL":
|
|
|
1023 |
pass
|
|
|
1024 |
else:
|
|
|
1025 |
query = query.filter(Item.brand == brand)
|
| 2358 |
ankur.sing |
1026 |
items = query.all()
|
|
|
1027 |
return items
|
| 2116 |
ankur.sing |
1028 |
|
| 2358 |
ankur.sing |
1029 |
def get_risky_items():
|
| 12963 |
amit.gupta |
1030 |
items = Item.query.filter(Item.risky==True).filter(or_(Item.status==status.ACTIVE, Item.status==status.PAUSED_BY_RISK)).all()
|
| 2358 |
ankur.sing |
1031 |
return items
|
| 3008 |
rajveer |
1032 |
|
| 2809 |
rajveer |
1033 |
def get_similar_items_catalog_ids(start_index, stop_index, itemId):
|
| 3008 |
rajveer |
1034 |
query = SimilarItems.query.filter_by(item_id=itemId).limit(stop_index-start_index)
|
|
|
1035 |
similar_items = query.all()
|
| 3289 |
rajveer |
1036 |
return_list = []
|
|
|
1037 |
for similar_item in similar_items:
|
|
|
1038 |
isActive = False
|
|
|
1039 |
try:
|
|
|
1040 |
all_items = Item.query.filter_by(catalog_item_id=similar_item.catalog_item_id).all()
|
|
|
1041 |
except:
|
|
|
1042 |
continue
|
|
|
1043 |
for item in all_items:
|
|
|
1044 |
isActive = isActive or item.status == status.ACTIVE
|
|
|
1045 |
if isActive:
|
|
|
1046 |
return_list.append(similar_item.catalog_item_id)
|
|
|
1047 |
return return_list
|
| 4423 |
phani.kuma |
1048 |
|
|
|
1049 |
def get_all_similar_items_catalog_ids(itemId):
|
|
|
1050 |
query = SimilarItems.query.filter_by(item_id=itemId)
|
|
|
1051 |
similar_items = query.all()
|
|
|
1052 |
return_list = []
|
|
|
1053 |
for similar_item in similar_items:
|
|
|
1054 |
item_query = Item.query.filter_by(catalog_item_id=similar_item.catalog_item_id).limit(1)
|
|
|
1055 |
item = item_query.one()
|
|
|
1056 |
return_list.append(item)
|
| 7770 |
kshitij.so |
1057 |
|
| 4423 |
phani.kuma |
1058 |
return get_thrift_item_list(return_list)
|
|
|
1059 |
|
|
|
1060 |
def add_similar_item_catalog_id(itemId, catalog_item_id):
|
|
|
1061 |
if not itemId or not catalog_item_id:
|
|
|
1062 |
raise InventoryServiceException(101, "Bad itemId or catalogItemId in request")
|
|
|
1063 |
items_for_entity = get_items_by_catalog_id(catalog_item_id)
|
|
|
1064 |
if not len(items_for_entity):
|
|
|
1065 |
raise InventoryServiceException(101, "catalogItemId does not exists in database")
|
| 7770 |
kshitij.so |
1066 |
|
| 4423 |
phani.kuma |
1067 |
s_items = SimilarItems.query.filter_by(item_id=itemId, catalog_item_id=catalog_item_id).all()
|
|
|
1068 |
if not len(s_items):
|
|
|
1069 |
s_item = SimilarItems()
|
|
|
1070 |
s_item.item_id=itemId
|
|
|
1071 |
s_item.catalog_item_id=catalog_item_id
|
|
|
1072 |
session.commit()
|
|
|
1073 |
return items_for_entity[0]
|
|
|
1074 |
else:
|
|
|
1075 |
raise InventoryServiceException(101, "Already exists")
|
| 7770 |
kshitij.so |
1076 |
|
| 4423 |
phani.kuma |
1077 |
def delete_similar_item_catalog_id(itemId, catalog_item_id):
|
|
|
1078 |
if not itemId or not catalog_item_id:
|
|
|
1079 |
raise InventoryServiceException(101, "Bad itemId or catalogItemId in request")
|
| 7770 |
kshitij.so |
1080 |
|
| 4423 |
phani.kuma |
1081 |
similar_item = SimilarItems.query.filter_by(item_id=itemId, catalog_item_id=catalog_item_id).all()
|
|
|
1082 |
if len(similar_item):
|
|
|
1083 |
similar_item[0].delete()
|
|
|
1084 |
session.commit()
|
|
|
1085 |
return True
|
| 5504 |
phani.kuma |
1086 |
|
|
|
1087 |
def get_all_vouchers_for_item(itemId):
|
|
|
1088 |
vouchers = VoucherItemMapping.query.filter_by(item_id=itemId).all()
|
|
|
1089 |
return vouchers
|
|
|
1090 |
|
|
|
1091 |
def get_voucher_amount(itemId, voucher_type):
|
|
|
1092 |
voucher = VoucherItemMapping.query.filter_by(item_id=itemId, voucherType=voucher_type).all()
|
|
|
1093 |
if len(voucher):
|
|
|
1094 |
return voucher[0].amount
|
|
|
1095 |
else:
|
| 5518 |
rajveer |
1096 |
return 0
|
| 5504 |
phani.kuma |
1097 |
|
|
|
1098 |
def add_update_voucher_for_item(catalog_item_id, voucher_type, voucher_amount):
|
|
|
1099 |
if not catalog_item_id or not voucher_type or not voucher_amount:
|
|
|
1100 |
raise InventoryServiceException(101, "Bad catalogItemId or voucherType or voucherAmount in request")
|
| 7770 |
kshitij.so |
1101 |
|
| 5504 |
phani.kuma |
1102 |
items_for_entity = get_items_by_catalog_id(catalog_item_id)
|
|
|
1103 |
if not len(items_for_entity):
|
|
|
1104 |
raise InventoryServiceException(101, "catalogItemId does not exists in database")
|
| 7770 |
kshitij.so |
1105 |
|
| 5504 |
phani.kuma |
1106 |
for item in items_for_entity:
|
|
|
1107 |
itemId = item.id
|
|
|
1108 |
voucher = VoucherItemMapping.query.filter_by(item_id=itemId, voucherType=voucher_type).all()
|
|
|
1109 |
if not len(voucher):
|
|
|
1110 |
voucher = VoucherItemMapping()
|
|
|
1111 |
voucher.item_id=itemId
|
|
|
1112 |
voucher.voucherType=voucher_type
|
|
|
1113 |
voucher.amount=voucher_amount
|
|
|
1114 |
else:
|
|
|
1115 |
voucher[0].amount=voucher_amount
|
|
|
1116 |
session.commit()
|
|
|
1117 |
return True
|
| 7770 |
kshitij.so |
1118 |
|
| 5504 |
phani.kuma |
1119 |
def delete_voucher_for_item(catalog_item_id, voucher_type):
|
|
|
1120 |
if not catalog_item_id or not voucher_type:
|
|
|
1121 |
raise InventoryServiceException(101, "Bad catalogItemId or voucherType in request")
|
| 7770 |
kshitij.so |
1122 |
|
| 5504 |
phani.kuma |
1123 |
items_for_entity = get_items_by_catalog_id(catalog_item_id)
|
|
|
1124 |
if not len(items_for_entity):
|
|
|
1125 |
raise InventoryServiceException(101, "catalogItemId does not exists in database")
|
| 7770 |
kshitij.so |
1126 |
|
| 5504 |
phani.kuma |
1127 |
for item in items_for_entity:
|
|
|
1128 |
itemId = item.id
|
|
|
1129 |
voucher = VoucherItemMapping.query.filter_by(item_id=itemId, voucherType=voucher_type).all()
|
|
|
1130 |
if len(voucher):
|
|
|
1131 |
voucher[0].delete()
|
|
|
1132 |
session.commit()
|
|
|
1133 |
return True
|
|
|
1134 |
|
| 3079 |
rajveer |
1135 |
def add_product_notification(itemId, email):
|
|
|
1136 |
try:
|
| 3470 |
rajveer |
1137 |
try:
|
|
|
1138 |
product_notification = ProductNotification.query.filter_by(item_id=itemId, email=email).one()
|
|
|
1139 |
except:
|
|
|
1140 |
product_notification = ProductNotification()
|
|
|
1141 |
product_notification.email = email
|
|
|
1142 |
product_notification.item_id = itemId
|
| 3079 |
rajveer |
1143 |
product_notification.addedOn = datetime.datetime.now()
|
|
|
1144 |
session.commit()
|
|
|
1145 |
return True
|
|
|
1146 |
except:
|
|
|
1147 |
return False
|
| 3086 |
rajveer |
1148 |
|
|
|
1149 |
|
|
|
1150 |
def send_product_notifications():
|
| 7134 |
rajveer |
1151 |
product_notifications = ProductNotification.query.order_by(ProductNotification.addedOn).all()
|
|
|
1152 |
itemcountmap = {}
|
|
|
1153 |
itemstatusmap = {}
|
| 8182 |
amar.kumar |
1154 |
#print "size of prduct notifications = " + str(len(product_notifications))
|
| 3086 |
rajveer |
1155 |
for product_notification in product_notifications:
|
|
|
1156 |
item = product_notification.item
|
| 7134 |
rajveer |
1157 |
if itemcountmap.has_key(item.id):
|
|
|
1158 |
itemcountmap[item.id] = itemcountmap.get(item.id) + 1
|
|
|
1159 |
else:
|
|
|
1160 |
client = InventoryClient().get_client()
|
|
|
1161 |
availability = client.getItemAvailabilityAtLocation(item.id, sourceId)[4]
|
| 8182 |
amar.kumar |
1162 |
#print "Item status " + str(item.status) + " item.risky " + str(item.risky) + " availability = " + str(availability)
|
|
|
1163 |
if item.status == status.ACTIVE and (not item.risky or availability > 0):
|
|
|
1164 |
#print "item status map has new entry " + str(item.id)
|
| 7134 |
rajveer |
1165 |
itemstatusmap[item.id] = True
|
|
|
1166 |
else:
|
|
|
1167 |
itemstatusmap[item.id] = False
|
|
|
1168 |
itemcountmap[item.id] = 1
|
|
|
1169 |
if itemcountmap[item.id] > 1000:
|
|
|
1170 |
continue
|
| 7770 |
kshitij.so |
1171 |
|
| 7134 |
rajveer |
1172 |
if itemstatusmap[item.id]:
|
| 8182 |
amar.kumar |
1173 |
#print product_notification.email, __get_product_name(item) , product_notification.addedOn, __get_product_url(item), item.id
|
| 3086 |
rajveer |
1174 |
__enque_product_notification_email(product_notification.email, __get_product_name(item) , product_notification.addedOn, __get_product_url(item), item.id)
|
|
|
1175 |
product_notification.delete()
|
|
|
1176 |
session.commit()
|
|
|
1177 |
return True
|
| 7770 |
kshitij.so |
1178 |
|
| 3086 |
rajveer |
1179 |
def __get_product_name(item):
|
|
|
1180 |
product_name = item.brand + " " + item.model_name + " " + item.model_number
|
|
|
1181 |
color = item.color
|
|
|
1182 |
if color is not None and color != 'NA':
|
|
|
1183 |
product_name = product_name + " (" + color + ")"
|
| 3201 |
rajveer |
1184 |
product_name = product_name.replace(" "," ")
|
| 3086 |
rajveer |
1185 |
return product_name
|
|
|
1186 |
|
|
|
1187 |
|
|
|
1188 |
def __get_product_url(item):
|
| 6029 |
rajveer |
1189 |
product_url = "http://" + source_url + "/mobile-phones/" + item.brand + "-" + item.model_name + "-" + item.model_number + "-" + str(item.catalog_item_id)
|
| 3086 |
rajveer |
1190 |
product_url = product_url.replace("--","-")
|
|
|
1191 |
product_url = product_url.replace(" ","")
|
|
|
1192 |
return product_url
|
|
|
1193 |
|
| 3348 |
varun.gupt |
1194 |
def get_all_brands_by_category(category_id):
|
|
|
1195 |
catm = CategoryManager()
|
|
|
1196 |
child_categories = catm.getCategory(category_id).children_category_ids
|
|
|
1197 |
brands = session.query(distinct(Item.brand)).filter(Item.category.in_(child_categories)).all()
|
| 7770 |
kshitij.so |
1198 |
|
| 3348 |
varun.gupt |
1199 |
return [brand[0] for brand in brands]
|
| 3086 |
rajveer |
1200 |
|
| 4957 |
phani.kuma |
1201 |
def get_all_brands():
|
|
|
1202 |
brands = session.query(distinct(Item.brand)).order_by(Item.brand).all()
|
| 7770 |
kshitij.so |
1203 |
|
| 4957 |
phani.kuma |
1204 |
return [brand[0] for brand in brands]
|
|
|
1205 |
|
| 3086 |
rajveer |
1206 |
def __enque_product_notification_email(email, product, date, url, itemId):
|
| 7770 |
kshitij.so |
1207 |
|
| 3086 |
rajveer |
1208 |
html = """
|
|
|
1209 |
<html>
|
|
|
1210 |
<body>
|
|
|
1211 |
<div>
|
|
|
1212 |
<p>
|
|
|
1213 |
Hi,<br /><br />
|
| 6029 |
rajveer |
1214 |
The product requested by you on $date is now available on $source_url.
|
| 7103 |
amar.kumar |
1215 |
<br />
|
|
|
1216 |
We have limited stocks of this model at this moment. If you don't want to miss out, please place your order as soon as possible.
|
| 3086 |
rajveer |
1217 |
</p>
|
| 7770 |
kshitij.so |
1218 |
|
|
|
1219 |
<p>
|
| 3086 |
rajveer |
1220 |
<strong>Product: $product </strong>
|
|
|
1221 |
</p>
|
| 7770 |
kshitij.so |
1222 |
|
| 3086 |
rajveer |
1223 |
<p>
|
| 7770 |
kshitij.so |
1224 |
Click the link below to visit the product:
|
| 3086 |
rajveer |
1225 |
<br/>
|
|
|
1226 |
$url
|
|
|
1227 |
</p>
|
|
|
1228 |
<p>
|
|
|
1229 |
Regards,<br/>
|
| 6029 |
rajveer |
1230 |
$source_name Customer Support Team<br/>
|
|
|
1231 |
$source_url<br/>
|
| 3086 |
rajveer |
1232 |
Email: help@saholic.com<br/>
|
|
|
1233 |
</p>
|
|
|
1234 |
</div>
|
|
|
1235 |
</body>
|
|
|
1236 |
</html>
|
|
|
1237 |
"""
|
|
|
1238 |
|
| 6029 |
rajveer |
1239 |
html = Template(html).substitute(dict(product=product,date=date,url=url,source_url=source_url,source_name=source_name))
|
| 7770 |
kshitij.so |
1240 |
|
| 3086 |
rajveer |
1241 |
try:
|
|
|
1242 |
helper_client = HelperClient().get_client()
|
| 8464 |
amar.kumar |
1243 |
helper_client.saveUserEmailForSending([email], "", "Product requested by you is available now.", html, str(itemId), "ProductNotification", [], [],sourceId)
|
| 3086 |
rajveer |
1244 |
except Exception as e:
|
|
|
1245 |
print e
|
| 8182 |
amar.kumar |
1246 |
print sys.exc_info()[0]
|
| 13709 |
manish.sha |
1247 |
|
|
|
1248 |
try:
|
|
|
1249 |
user_client = UserClient().get_client()
|
|
|
1250 |
user = user_client.getUserByEmail(email)
|
|
|
1251 |
if user is not None and user.id !=-1:
|
|
|
1252 |
if user.mobileNumber is not None:
|
|
|
1253 |
mobileNo = user.mobileNumber
|
|
|
1254 |
elif user.default_address_id is not None:
|
|
|
1255 |
defaultAddress = user_client.getAddressById(user.default_address_id)
|
|
|
1256 |
mobileNo = defaultAddress.mobileNumber
|
|
|
1257 |
else:
|
|
|
1258 |
print 'Sms not sent for email id- ', email
|
|
|
1259 |
mobileNo = None
|
|
|
1260 |
if mobileNo is not None:
|
|
|
1261 |
helper_client = HelperClient().get_client()
|
|
|
1262 |
helper_client.saveUserSmsForSending(user.id, mobileNo, "Dear, Customer, Product "+ product +" requested by you is now available at Saholic.com. Limited Stocks", SmsType.SERVICE_ALERT)
|
|
|
1263 |
userSmsInfo = helper_client.getUserSmsInfo(user.id);
|
|
|
1264 |
if userSmsInfo and mobileNo == userSmsInfo.mobileNo:
|
|
|
1265 |
userSmsInfo.dailyCount = userSmsInfo.dailyCount +1
|
|
|
1266 |
userSmsInfo.weeklyCount = userSmsInfo.weeklyCount +1
|
|
|
1267 |
helper_client.updateUserSmsInfo(userSmsInfo)
|
|
|
1268 |
elif userSmsInfo and mobileNo != userSmsInfo.mobileNo:
|
|
|
1269 |
userSmsInfo.updateTimestamp = to_java_date(datetime.datetime.now())
|
|
|
1270 |
userSmsInfo.mobileNo = mobileNo
|
|
|
1271 |
userSmsInfo.dailyCount = 1
|
|
|
1272 |
userSmsInfo.weeklyCount = 1
|
|
|
1273 |
helper_client.updateUserSmsInfo(userSmsInfo)
|
|
|
1274 |
else:
|
|
|
1275 |
userSmsInfo = UserSmsInfo()
|
|
|
1276 |
userSmsInfo.userId = user.id
|
|
|
1277 |
userSmsInfo.mobileNo = mobileNo
|
|
|
1278 |
userSmsInfo.createdTimestamp = to_java_date(datetime.datetime.now())
|
|
|
1279 |
userSmsInfo.updateTimestamp = to_java_date(datetime.datetime.now())
|
|
|
1280 |
helper_client.addUserSmsInfo(userSmsInfo);
|
|
|
1281 |
|
|
|
1282 |
except Exception as e:
|
|
|
1283 |
print e
|
|
|
1284 |
print sys.exc_info()[0]
|
| 3086 |
rajveer |
1285 |
|
| 3557 |
rajveer |
1286 |
def get_all_sources():
|
|
|
1287 |
sources = Source.query.all()
|
|
|
1288 |
return [to_t_source(source) for source in sources]
|
| 3086 |
rajveer |
1289 |
|
| 3557 |
rajveer |
1290 |
def get_item_pricing_by_source(itemId, sourceId):
|
|
|
1291 |
item = Item.query.filter_by(id=itemId).first()
|
|
|
1292 |
if item is None:
|
|
|
1293 |
raise InventoryServiceException(101, "Bad Item")
|
| 7770 |
kshitij.so |
1294 |
|
| 3557 |
rajveer |
1295 |
source = Source.query.filter_by(id=sourceId).first()
|
|
|
1296 |
if source is None:
|
|
|
1297 |
raise InventoryServiceException(101, "Source not found for sourceId " + str(sourceId))
|
| 7770 |
kshitij.so |
1298 |
|
| 3557 |
rajveer |
1299 |
item_pricing = SourceItemPricing.query.filter_by(source=source, item=item).first()
|
|
|
1300 |
if item_pricing is None:
|
|
|
1301 |
raise InventoryServiceException(101, "Pricing information not found for sourceId " + str(sourceId))
|
|
|
1302 |
return item_pricing
|
| 7770 |
kshitij.so |
1303 |
|
| 3557 |
rajveer |
1304 |
def add_source_item_pricing(sourceItemPricing):
|
|
|
1305 |
if not sourceItemPricing:
|
|
|
1306 |
raise InventoryServiceException(108, "Bad sourceItemPricing in request")
|
| 7770 |
kshitij.so |
1307 |
|
| 3557 |
rajveer |
1308 |
if not sourceItemPricing.sellingPrice:
|
| 4326 |
mandeep.dh |
1309 |
raise InventoryServiceException(101, "Selling Price is not defined for sourceId " + str(sourceItemPricing.sourceId))
|
| 7770 |
kshitij.so |
1310 |
|
| 3557 |
rajveer |
1311 |
sourceId = sourceItemPricing.sourceId
|
|
|
1312 |
itemId = sourceItemPricing.itemId
|
| 7770 |
kshitij.so |
1313 |
|
| 3557 |
rajveer |
1314 |
item = Item.query.filter_by(id=itemId).first()
|
|
|
1315 |
if item is None:
|
|
|
1316 |
raise InventoryServiceException(101, "Bad Item")
|
| 7770 |
kshitij.so |
1317 |
|
| 3557 |
rajveer |
1318 |
source = Source.query.filter_by(id=sourceId).first()
|
|
|
1319 |
if source is None:
|
|
|
1320 |
raise InventoryServiceException(101, "Source not found for sourceId " + str(sourceId))
|
| 7770 |
kshitij.so |
1321 |
|
| 3564 |
rajveer |
1322 |
ds_sourceItemPricing = SourceItemPricing.get_by(source=source, item=item)
|
| 3557 |
rajveer |
1323 |
if ds_sourceItemPricing is None:
|
|
|
1324 |
ds_sourceItemPricing = SourceItemPricing()
|
|
|
1325 |
ds_sourceItemPricing.source = source
|
|
|
1326 |
ds_sourceItemPricing.item = item
|
| 7770 |
kshitij.so |
1327 |
|
| 3557 |
rajveer |
1328 |
if sourceItemPricing.mrp:
|
|
|
1329 |
ds_sourceItemPricing.mrp = sourceItemPricing.mrp
|
|
|
1330 |
ds_sourceItemPricing.sellingPrice = sourceItemPricing.sellingPrice
|
|
|
1331 |
|
|
|
1332 |
session.commit()
|
|
|
1333 |
return
|
|
|
1334 |
|
|
|
1335 |
def get_all_source_pricing(itemId):
|
|
|
1336 |
item = Item.query.filter_by(id=itemId).first()
|
|
|
1337 |
if item is None:
|
|
|
1338 |
raise InventoryServiceException(101, "Bad Item")
|
|
|
1339 |
source_pricing = SourceItemPricing.query.filter_by(item=item).all()
|
|
|
1340 |
return source_pricing
|
| 7770 |
kshitij.so |
1341 |
|
| 3557 |
rajveer |
1342 |
|
|
|
1343 |
def get_item_for_source(item_id, sourceId):
|
|
|
1344 |
item = get_item(item_id)
|
|
|
1345 |
if sourceId == -1:
|
|
|
1346 |
return item
|
|
|
1347 |
try:
|
|
|
1348 |
sip = get_item_pricing_by_source(item_id, sourceId)
|
|
|
1349 |
item.sellingPrice = sip.sellingPrice
|
|
|
1350 |
if sip.mrp:
|
|
|
1351 |
item.mrp = sip.mrp
|
|
|
1352 |
except:
|
|
|
1353 |
print "No source pricing"
|
|
|
1354 |
return item
|
|
|
1355 |
|
| 3872 |
chandransh |
1356 |
def search_items(search_terms, offset, limit):
|
|
|
1357 |
query = Item.query
|
| 7770 |
kshitij.so |
1358 |
|
| 3872 |
chandransh |
1359 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
| 8139 |
kshitij.so |
1360 |
print search_terms
|
| 7770 |
kshitij.so |
1361 |
|
| 3872 |
chandransh |
1362 |
for search_term in search_terms:
|
| 6661 |
rajveer |
1363 |
query_clause = []
|
| 3872 |
chandransh |
1364 |
query_clause.append(Item.brand.like(search_term))
|
|
|
1365 |
query_clause.append(Item.model_number.like(search_term))
|
|
|
1366 |
query_clause.append(Item.model_name.like(search_term))
|
| 6661 |
rajveer |
1367 |
query = query.filter(or_(*query_clause))
|
| 8139 |
kshitij.so |
1368 |
|
|
|
1369 |
print query
|
| 3872 |
chandransh |
1370 |
query = query.order_by(Item.product_group, Item.brand, Item.model_number, Item.model_name).offset(offset)
|
|
|
1371 |
if limit:
|
|
|
1372 |
query = query.limit(limit)
|
|
|
1373 |
items = query.all()
|
|
|
1374 |
return items
|
|
|
1375 |
|
|
|
1376 |
def get_search_result_count(search_terms):
|
|
|
1377 |
query = Item.query
|
| 7770 |
kshitij.so |
1378 |
|
| 3872 |
chandransh |
1379 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
| 7770 |
kshitij.so |
1380 |
|
| 3872 |
chandransh |
1381 |
for search_term in search_terms:
|
| 6661 |
rajveer |
1382 |
query_clause = []
|
| 3872 |
chandransh |
1383 |
query_clause.append(Item.brand.like(search_term))
|
|
|
1384 |
query_clause.append(Item.model_number.like(search_term))
|
|
|
1385 |
query_clause.append(Item.model_name.like(search_term))
|
| 6661 |
rajveer |
1386 |
query = query.filter(or_(*query_clause))
|
| 7770 |
kshitij.so |
1387 |
|
| 3872 |
chandransh |
1388 |
return query.count()
|
|
|
1389 |
|
| 3924 |
rajveer |
1390 |
def __clear_homepage_cache():
|
|
|
1391 |
try:
|
|
|
1392 |
# create a password manager
|
|
|
1393 |
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
|
|
1394 |
# Add the username and password.
|
|
|
1395 |
configclient = ConfigClient()
|
| 4310 |
rajveer |
1396 |
ips = configclient.get_property("production_servers_private_ips");
|
| 3924 |
rajveer |
1397 |
ips = ips.split(" ")
|
| 7770 |
kshitij.so |
1398 |
|
| 3924 |
rajveer |
1399 |
for ip in ips:
|
| 4310 |
rajveer |
1400 |
try:
|
|
|
1401 |
top_level_url = "http://" + ip + ":8080/"
|
|
|
1402 |
password_mgr.add_password(None, top_level_url, "saholic", "shop2020")
|
|
|
1403 |
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
|
| 7770 |
kshitij.so |
1404 |
|
| 4310 |
rajveer |
1405 |
opener = urllib2.build_opener(handler)
|
| 7770 |
kshitij.so |
1406 |
|
| 4310 |
rajveer |
1407 |
# use the opener to fetch a URL
|
|
|
1408 |
res = opener.open(top_level_url + "cache-admin/HomePageSnippets?_method=delete")
|
|
|
1409 |
print "Successfully cleared home page cache" + res.read()
|
|
|
1410 |
except:
|
|
|
1411 |
print "Unable to clear home page cache" + res.read()
|
| 3924 |
rajveer |
1412 |
except:
|
|
|
1413 |
print "Unable to clear cache, still should continue with other operations"
|
| 7770 |
kshitij.so |
1414 |
|
| 4295 |
varun.gupt |
1415 |
def get_product_notifications(start_datetime):
|
|
|
1416 |
'''
|
|
|
1417 |
Returns a list of Product Notification objects each representing user requests for notification
|
|
|
1418 |
'''
|
|
|
1419 |
query = ProductNotification.query
|
| 7770 |
kshitij.so |
1420 |
|
| 4295 |
varun.gupt |
1421 |
if start_datetime:
|
|
|
1422 |
query = query.filter(ProductNotification.addedOn > start_datetime)
|
| 7770 |
kshitij.so |
1423 |
|
| 4295 |
varun.gupt |
1424 |
notifications = query.order_by(desc('addedOn')).all()
|
|
|
1425 |
return notifications
|
|
|
1426 |
|
| 7897 |
amar.kumar |
1427 |
def get_product_notification_request_count(start_datetime, categoryId):
|
| 4295 |
varun.gupt |
1428 |
'''
|
|
|
1429 |
Returns list of items and the counts of product notification requests
|
|
|
1430 |
'''
|
| 7897 |
amar.kumar |
1431 |
if categoryId:
|
|
|
1432 |
categories = get_child_categories(categoryId)
|
|
|
1433 |
items = Item.query.filter(Item.category.in_(categories)).all()
|
|
|
1434 |
item_ids = [item.id for item in items]
|
|
|
1435 |
|
| 4295 |
varun.gupt |
1436 |
print start_datetime
|
|
|
1437 |
query = session.query(ProductNotification, func.count(ProductNotification.email).label('count'))
|
| 7770 |
kshitij.so |
1438 |
|
| 4295 |
varun.gupt |
1439 |
if start_datetime:
|
|
|
1440 |
query = query.filter(ProductNotification.addedOn > start_datetime)
|
| 7897 |
amar.kumar |
1441 |
if categoryId:
|
|
|
1442 |
query = query.filter(ProductNotification.item_id.in_(item_ids))
|
| 4295 |
varun.gupt |
1443 |
counts = query.group_by(ProductNotification.item_id).order_by(desc('count')).all()
|
|
|
1444 |
return counts
|
|
|
1445 |
|
| 766 |
rajveer |
1446 |
def close_session():
|
|
|
1447 |
if session.is_active:
|
|
|
1448 |
print "session is active. closing it."
|
| 1399 |
rajveer |
1449 |
session.close()
|
| 3376 |
rajveer |
1450 |
|
|
|
1451 |
def is_alive():
|
|
|
1452 |
try:
|
|
|
1453 |
session.query(Item.id).limit(1).one()
|
|
|
1454 |
return True
|
|
|
1455 |
except:
|
|
|
1456 |
return False
|
| 4332 |
anupam.sin |
1457 |
|
| 4649 |
phani.kuma |
1458 |
def add_authorization_log_for_item(itemId, username, reason):
|
|
|
1459 |
if not itemId or not username:
|
|
|
1460 |
raise InventoryServiceException(101, "Bad itemId or Invalid username in request")
|
|
|
1461 |
authorize_log = AuthorizationLog()
|
|
|
1462 |
authorize_log.item_id = itemId
|
|
|
1463 |
authorize_log.username = username
|
|
|
1464 |
authorize_log.reason = reason
|
|
|
1465 |
session.commit()
|
| 4797 |
rajveer |
1466 |
return True
|
|
|
1467 |
|
| 6255 |
rajveer |
1468 |
def __send_mail_for_oos_item(item):
|
|
|
1469 |
oos = OOSTracker.get_by(itemId = item.id)
|
|
|
1470 |
if oos is None:
|
|
|
1471 |
oos = OOSTracker()
|
|
|
1472 |
oos.itemId = item.id
|
|
|
1473 |
session.commit()
|
|
|
1474 |
try:
|
| 6962 |
rajveer |
1475 |
EmailAttachmentSender.mail(mail_user, mail_password, to_addresses + ["pramit.singh@shop2020.in"], "Item is out of stock. ID: " + str(item.id) + " " + str(item.brand) + " " + str(item.model_name) + " " + str(item.model_number)+ " " + str(item.color), None)
|
| 6255 |
rajveer |
1476 |
except Exception as e:
|
|
|
1477 |
print e
|
| 4985 |
mandeep.dh |
1478 |
|
| 6255 |
rajveer |
1479 |
def __send_mail_for_active_item(itemId, subject, message):
|
|
|
1480 |
oos = OOSTracker.get_by(itemId = itemId)
|
|
|
1481 |
if oos is not None:
|
|
|
1482 |
oos.delete()
|
|
|
1483 |
session.commit()
|
|
|
1484 |
__send_mail(subject, message)
|
|
|
1485 |
|
| 7384 |
rajveer |
1486 |
def __send_mail(subject, message, send_to = to_addresses):
|
| 5080 |
amit.gupta |
1487 |
try:
|
| 7384 |
rajveer |
1488 |
thread = threading.Thread(target=partial(mail, mail_user, mail_password, send_to, subject, message))
|
| 5080 |
amit.gupta |
1489 |
thread.start()
|
| 15777 |
amit.gupta |
1490 |
except Exception:
|
|
|
1491 |
pass
|
| 5185 |
mandeep.dh |
1492 |
|
| 6039 |
amit.gupta |
1493 |
def get_vat_amount_for_item(itemId, price):
|
|
|
1494 |
item = Item.query.filter_by(id=itemId).first()
|
|
|
1495 |
vatPercentage = item.vatPercentage
|
|
|
1496 |
if vatPercentage is None:
|
|
|
1497 |
vatMaster = CategoryVatMaster.query.filter(and_(CategoryVatMaster.categoryId==item.category, CategoryVatMaster.minVal<=price, CategoryVatMaster.maxVal>=price)).first()
|
|
|
1498 |
vatPercentage = vatMaster.vatPercent
|
|
|
1499 |
if vatPercentage is None:
|
|
|
1500 |
vatPercentage = 0
|
|
|
1501 |
return (price*vatPercentage)/100
|
| 7770 |
kshitij.so |
1502 |
|
| 7340 |
amit.gupta |
1503 |
def get_vat_percentage_for_item(itemId, stateId, price):
|
| 7330 |
amit.gupta |
1504 |
itemVatMaster = ItemVatMaster.query.filter(and_(ItemVatMaster.itemId==itemId, ItemVatMaster.stateId==stateId)).first()
|
| 7340 |
amit.gupta |
1505 |
if itemVatMaster is None:
|
| 7330 |
amit.gupta |
1506 |
item = Item.query.filter_by(id=itemId).first()
|
| 7340 |
amit.gupta |
1507 |
if item is None:
|
|
|
1508 |
raise CatalogServiceException(itemId, "Could not find item in catalog")
|
|
|
1509 |
vatMaster = CategoryVatMaster.query.filter(and_(CategoryVatMaster.categoryId==item.category, CategoryVatMaster.minVal<=price, CategoryVatMaster.maxVal>=price, CategoryVatMaster.stateId == stateId)).first()
|
| 7330 |
amit.gupta |
1510 |
if vatMaster is None:
|
| 8589 |
amar.kumar |
1511 |
raise CatalogServiceException(stateId, "Could not find vat rate for this state." + str(stateId) + " for " + str(itemId))
|
| 7340 |
amit.gupta |
1512 |
return vatMaster.vatPercent
|
| 7330 |
amit.gupta |
1513 |
else:
|
| 7340 |
amit.gupta |
1514 |
return itemVatMaster.vatPercentage
|
| 6511 |
kshitij.so |
1515 |
|
| 12567 |
amit.gupta |
1516 |
def get_vat_percentage_for_item_category(itemId, stateId, price, categoryId):
|
|
|
1517 |
itemVatMaster = ItemVatMaster.query.filter(and_(ItemVatMaster.itemId==itemId, ItemVatMaster.stateId==stateId)).first()
|
|
|
1518 |
if itemVatMaster is None:
|
|
|
1519 |
vatMaster = CategoryVatMaster.query.filter(and_(CategoryVatMaster.categoryId==categoryId, CategoryVatMaster.minVal<=price, CategoryVatMaster.maxVal>=price, CategoryVatMaster.stateId == stateId)).first()
|
|
|
1520 |
if vatMaster is None:
|
|
|
1521 |
return -1
|
|
|
1522 |
return vatMaster.vatPercent
|
|
|
1523 |
else:
|
|
|
1524 |
return itemVatMaster.vatPercentage
|
|
|
1525 |
|
| 6531 |
vikram.rag |
1526 |
def get_all_ignored_inventoryupdate_items_list(offset,limit):
|
|
|
1527 |
client = InventoryClient().get_client()
|
|
|
1528 |
itemids = client.getIgnoredInventoryUpdateItemids(offset,limit)
|
| 6532 |
amit.gupta |
1529 |
result = []
|
|
|
1530 |
if itemids is not None and len(itemids)>0:
|
|
|
1531 |
query = Item.query.filter(Item.id.in_(itemids))
|
|
|
1532 |
query = query.order_by(Item.product_group, Item.brand, Item.model_number, Item.model_name)
|
|
|
1533 |
result = [to_t_item(item) for item in query.all()]
|
|
|
1534 |
return result
|
| 6531 |
vikram.rag |
1535 |
|
|
|
1536 |
|
| 6511 |
kshitij.so |
1537 |
def add_tag (displayName, catalogId):
|
|
|
1538 |
ent_tag = None
|
| 7770 |
kshitij.so |
1539 |
if catalogId is None or (not is_valid_catalog_id(catalogId)):
|
| 6511 |
kshitij.so |
1540 |
raise InventoryServiceException(id, "Invalid CatalogId")
|
|
|
1541 |
else:
|
|
|
1542 |
ent_tag = EntityTag()
|
|
|
1543 |
ent_tag.entityId = catalogId
|
|
|
1544 |
if displayName is None:
|
|
|
1545 |
raise InventoryServiceException(id, "Tag should not be empty")
|
| 7770 |
kshitij.so |
1546 |
else:
|
| 6511 |
kshitij.so |
1547 |
ent_tag.tag = displayName
|
|
|
1548 |
session.commit()
|
|
|
1549 |
return True
|
|
|
1550 |
|
| 8590 |
kshitij.so |
1551 |
def add_banner(bannerCongregate):
|
|
|
1552 |
banner = bannerCongregate.banner
|
| 9155 |
kshitij.so |
1553 |
antecedent = bannerCongregate.antecedent
|
| 8590 |
kshitij.so |
1554 |
t_bannerMaps = bannerCongregate.bannerMaps
|
|
|
1555 |
t_bannerUriMappings = bannerCongregate.bannerUriMappings
|
| 9178 |
kshitij.so |
1556 |
if antecedent.bannerName is not None :
|
|
|
1557 |
delete_banner(antecedent.bannerName,antecedent.bannerType)
|
| 9155 |
kshitij.so |
1558 |
try:
|
|
|
1559 |
banner_details=Banner()
|
|
|
1560 |
banner_details.bannerName=banner.bannerName
|
|
|
1561 |
banner_details.imageName=banner.imageName
|
|
|
1562 |
banner_details.link=banner.link
|
|
|
1563 |
banner_details.hasMap=banner.hasMap
|
|
|
1564 |
banner_details.priority = banner.priority
|
|
|
1565 |
banner_details.bannerType = banner.bannerType
|
| 10097 |
kshitij.so |
1566 |
add_banner_map(t_bannerMaps,banner.bannerType)
|
|
|
1567 |
add_banner_uri(t_bannerUriMappings,banner.bannerType)
|
| 9155 |
kshitij.so |
1568 |
session.commit()
|
| 10097 |
kshitij.so |
1569 |
return True
|
| 9155 |
kshitij.so |
1570 |
except:
|
| 10097 |
kshitij.so |
1571 |
return False
|
| 6848 |
kshitij.so |
1572 |
def get_all_banners():
|
| 8579 |
kshitij.so |
1573 |
return session.query(Banner).all()
|
| 6848 |
kshitij.so |
1574 |
|
| 9155 |
kshitij.so |
1575 |
def delete_banner(name,bType):
|
| 8579 |
kshitij.so |
1576 |
try:
|
| 9155 |
kshitij.so |
1577 |
session.query(Banner.bannerName).filter_by(bannerName=name).filter_by(bannerType=bType).delete()
|
|
|
1578 |
delete_banner_map(name,bType)
|
|
|
1579 |
delete_uri_mapping(name,bType)
|
| 10097 |
kshitij.so |
1580 |
session.commit()
|
| 8579 |
kshitij.so |
1581 |
return True
|
|
|
1582 |
except:
|
|
|
1583 |
return False
|
| 6848 |
kshitij.so |
1584 |
|
| 9155 |
kshitij.so |
1585 |
def get_banner_details(name,bType):
|
|
|
1586 |
banner = session.query(Banner).filter(Banner.bannerName==name).filter(Banner.bannerType==bType).one()
|
| 10097 |
kshitij.so |
1587 |
return banner
|
| 6848 |
kshitij.so |
1588 |
|
| 10494 |
kshitij.so |
1589 |
def __t_banner_details(banner,target):
|
| 10097 |
kshitij.so |
1590 |
bannerObj = t_banner()
|
|
|
1591 |
bannerObj.bannerName = banner.bannerName
|
|
|
1592 |
bannerObj.imageName = banner.imageName
|
|
|
1593 |
bannerObj.link = banner.link
|
|
|
1594 |
bannerObj.priority = banner.priority
|
|
|
1595 |
bannerObj.hasMap = banner.hasMap
|
|
|
1596 |
bannerObj.bannerType = banner.bannerType
|
|
|
1597 |
bannerObj.target = target
|
|
|
1598 |
return bannerObj
|
|
|
1599 |
|
|
|
1600 |
|
| 6848 |
kshitij.so |
1601 |
def get_active_banners():
|
| 8579 |
kshitij.so |
1602 |
bannerUriMap = {}
|
| 9155 |
kshitij.so |
1603 |
bannerType = [1,2]
|
|
|
1604 |
all_active = session.query(BannerUriMapping,Banner).filter(BannerUriMapping.bannerType.in_(bannerType)).filter(BannerUriMapping.isActive==True).filter(BannerUriMapping.bannerName==Banner.bannerName).filter(BannerUriMapping.bannerType==Banner.bannerType).order_by(desc(Banner.priority)).all()
|
| 8579 |
kshitij.so |
1605 |
for bannerUriMapping in all_active:
|
|
|
1606 |
bannerObj = []
|
| 9155 |
kshitij.so |
1607 |
if (bannerUriMapping[0].bannerType == BannerType.SIDE_BANNER):
|
|
|
1608 |
if 'side-banner' in bannerUriMap:
|
|
|
1609 |
for obj in bannerUriMap['side-banner']:
|
|
|
1610 |
bannerObj.append(obj)
|
| 10494 |
kshitij.so |
1611 |
bannerObj.append(__t_banner_details(bannerUriMapping[1],bannerUriMapping[0].target))
|
| 9155 |
kshitij.so |
1612 |
bannerUriMap['side-banner'] = bannerObj
|
|
|
1613 |
continue
|
| 8579 |
kshitij.so |
1614 |
if bannerUriMapping[0].uri not in bannerUriMap:
|
| 10494 |
kshitij.so |
1615 |
bannerObj.append(__t_banner_details(bannerUriMapping[1],bannerUriMapping[0].target))
|
| 8579 |
kshitij.so |
1616 |
bannerUriMap[bannerUriMapping[0].uri] = bannerObj
|
|
|
1617 |
else:
|
|
|
1618 |
for obj in bannerUriMap[bannerUriMapping[0].uri]:
|
|
|
1619 |
bannerObj.append(obj)
|
| 10494 |
kshitij.so |
1620 |
bannerObj.append(__t_banner_details(bannerUriMapping[1],bannerUriMapping[0].target))
|
| 8579 |
kshitij.so |
1621 |
bannerUriMap[bannerUriMapping[0].uri] = bannerObj
|
|
|
1622 |
return bannerUriMap
|
|
|
1623 |
|
| 6848 |
kshitij.so |
1624 |
|
| 9155 |
kshitij.so |
1625 |
def add_banner_map(bannerMaps,bannerType):
|
| 10097 |
kshitij.so |
1626 |
for bannerMap in bannerMaps:
|
|
|
1627 |
banner_map_details=BannerMap()
|
|
|
1628 |
banner_map_details.bannerName=bannerMap.bannerName
|
|
|
1629 |
banner_map_details.mapLink=bannerMap.mapLink
|
|
|
1630 |
banner_map_details.coordinates=bannerMap.coordinates
|
|
|
1631 |
banner_map_details.bannerType = bannerType
|
| 8579 |
kshitij.so |
1632 |
|
| 6848 |
kshitij.so |
1633 |
|
| 9155 |
kshitij.so |
1634 |
def delete_banner_map(name,bType):
|
| 10097 |
kshitij.so |
1635 |
session.query(BannerMap.bannerName).filter_by(bannerName=name).filter_by(bannerType=bType).delete()
|
| 6848 |
kshitij.so |
1636 |
|
| 9155 |
kshitij.so |
1637 |
def delete_uri_mapping(name,bType):
|
| 10097 |
kshitij.so |
1638 |
session.query(BannerUriMapping.bannerName).filter_by(bannerName=name).filter_by(bannerType=bType).delete()
|
| 8579 |
kshitij.so |
1639 |
|
| 9155 |
kshitij.so |
1640 |
def get_banner_map_details(name,bType):
|
| 6848 |
kshitij.so |
1641 |
query= session.query(BannerMap)
|
| 9155 |
kshitij.so |
1642 |
return query.filter_by(bannerName=name).filter_by(bannerType=bType).all()
|
| 8579 |
kshitij.so |
1643 |
|
|
|
1644 |
def update_banner(banner):
|
|
|
1645 |
banner_details = Banner.get_by(bannerName=banner.bannerName)
|
|
|
1646 |
try:
|
|
|
1647 |
if banner_details is not None:
|
|
|
1648 |
banner_details.imageName = banner.imageName
|
|
|
1649 |
banner_details.link = banner.link
|
|
|
1650 |
banner_details.priority = banner.priority
|
|
|
1651 |
banner_details.hasMap = banner.hasMap
|
|
|
1652 |
session.commit()
|
|
|
1653 |
return True
|
|
|
1654 |
else:
|
|
|
1655 |
return False
|
|
|
1656 |
except:
|
|
|
1657 |
return False
|
|
|
1658 |
|
| 9155 |
kshitij.so |
1659 |
def add_banner_uri(bannerUriMappings,bannerType):
|
| 8579 |
kshitij.so |
1660 |
for bannerUriMapping in bannerUriMappings:
|
|
|
1661 |
banner_uri = BannerUriMapping()
|
|
|
1662 |
banner_uri.bannerName = bannerUriMapping.bannerName
|
|
|
1663 |
banner_uri.uri = bannerUriMapping.uri
|
|
|
1664 |
banner_uri.isActive = bannerUriMapping.isActive
|
| 9155 |
kshitij.so |
1665 |
banner_uri.bannerType = bannerType
|
| 10097 |
kshitij.so |
1666 |
banner_uri.target = bannerUriMapping.target
|
| 8579 |
kshitij.so |
1667 |
|
| 9155 |
kshitij.so |
1668 |
def get_uri_mapping(name,bType):
|
| 8579 |
kshitij.so |
1669 |
query= session.query(BannerUriMapping)
|
| 9155 |
kshitij.so |
1670 |
return query.filter_by(bannerName=name).filter_by(bannerType=bType).all()
|
| 8579 |
kshitij.so |
1671 |
|
|
|
1672 |
def add_campaign(campaign):
|
|
|
1673 |
new_campaign = Campaign()
|
|
|
1674 |
new_campaign.campaignName = campaign.campaignName
|
|
|
1675 |
new_campaign.imageName = campaign.imageName
|
|
|
1676 |
session.commit()
|
|
|
1677 |
|
|
|
1678 |
def get_campaigns(name):
|
|
|
1679 |
query= session.query(Campaign)
|
|
|
1680 |
return query.filter_by(campaignName=name).all()
|
|
|
1681 |
|
|
|
1682 |
def delete_campaign(campaign_id):
|
|
|
1683 |
campaign = Campaign.get_by(id = campaign_id)
|
|
|
1684 |
if campaign is not None:
|
|
|
1685 |
campaign.delete()
|
|
|
1686 |
session.commit()
|
|
|
1687 |
|
|
|
1688 |
def get_all_campaigns():
|
|
|
1689 |
return session.query(distinct(Campaign.campaignName)).all()
|
|
|
1690 |
|
| 9155 |
kshitij.so |
1691 |
def get_active_banners_for_mobile_site():
|
|
|
1692 |
bannerType = [3]
|
|
|
1693 |
bannerMap = {}
|
|
|
1694 |
all_active = session.query(BannerUriMapping,Banner).filter(BannerUriMapping.bannerType.in_(bannerType)).filter(BannerUriMapping.isActive==True).filter(BannerUriMapping.bannerName==Banner.bannerName).filter(BannerUriMapping.bannerType==Banner.bannerType).order_by(desc(Banner.priority)).all()
|
|
|
1695 |
for bannerUriMapping in all_active:
|
|
|
1696 |
bannerObj = []
|
|
|
1697 |
if bannerUriMapping[0].uri not in bannerMap:
|
|
|
1698 |
bannerObj.append(get_banner_details(bannerUriMapping[0].bannerName,bannerUriMapping[0].bannerType))
|
|
|
1699 |
bannerMap[bannerUriMapping[0].uri] = bannerObj
|
|
|
1700 |
else:
|
|
|
1701 |
for obj in bannerMap[bannerUriMapping[0].uri]:
|
|
|
1702 |
bannerObj.append(obj)
|
|
|
1703 |
bannerObj.append(get_banner_details(bannerUriMapping[0].bannerName,bannerUriMapping[0].bannerType))
|
|
|
1704 |
bannerMap[bannerUriMapping[0].uri] = bannerObj
|
|
|
1705 |
return bannerMap
|
|
|
1706 |
|
|
|
1707 |
|
| 7770 |
kshitij.so |
1708 |
|
| 6511 |
kshitij.so |
1709 |
def get_all_tags ():
|
|
|
1710 |
return [tuple[0] for tuple in session.query(EntityTag.tag).distinct().all()]
|
|
|
1711 |
|
|
|
1712 |
def get_all_entities_by_tag_name(displayName):
|
|
|
1713 |
return [tuple[0] for tuple in session.query(EntityTag.entityId).filter_by(tag=displayName).all()]
|
| 7770 |
kshitij.so |
1714 |
|
| 6511 |
kshitij.so |
1715 |
def delete_tag(displayName):
|
|
|
1716 |
session.query(EntityTag.entityId).filter_by(tag=displayName).delete()
|
|
|
1717 |
session.commit()
|
|
|
1718 |
return True
|
| 6518 |
kshitij.so |
1719 |
|
|
|
1720 |
def delete_entity_tag(displayName, catalogId):
|
|
|
1721 |
session.query(EntityTag.tag).filter_by(tag=displayName,entityId=catalogId).delete()
|
|
|
1722 |
session.commit()
|
| 6805 |
anupam.sin |
1723 |
return True
|
|
|
1724 |
|
| 6921 |
anupam.sin |
1725 |
def get_insurance_amount(itemId, price, insurerId, quantity):
|
| 9299 |
kshitij.so |
1726 |
if insurerId ==1:
|
|
|
1727 |
#itemInsurerMapping = ItemInsurerMapping.query.filter(ItemInsurerMapping.itemId == itemId).filter(ItemInsurerMapping.insurerId == insurerId).first()
|
|
|
1728 |
#if itemInsurerMapping:
|
|
|
1729 |
#Default insurance premium is 1.5%
|
|
|
1730 |
# return round(price * (1.5/100) * quantity)
|
| 13183 |
amit.gupta |
1731 |
return round(price * (1.5/100) * quantity)
|
| 9299 |
kshitij.so |
1732 |
'''insuranceAmount = 0.0
|
|
|
1733 |
if itemInsurerMapping.premiumType == PremiumType._NAMES_TO_VALUES.get("PERCENT"):
|
|
|
1734 |
insuranceAmount = price * (itemInsurerMapping.premiumAmount/100) * quantity
|
|
|
1735 |
else :
|
|
|
1736 |
insuranceAmount = itemInsurerMapping.premiumAmount * quantity
|
|
|
1737 |
'''
|
|
|
1738 |
if insurerId ==2:
|
|
|
1739 |
return 0.0 #FOR PROMOTION PURPOSE
|
|
|
1740 |
#return 449.0 * quantity
|
| 7770 |
kshitij.so |
1741 |
|
| 9299 |
kshitij.so |
1742 |
return 0.0
|
|
|
1743 |
|
|
|
1744 |
def get_preffered_insurer_for_item(itemId, insurerType):
|
|
|
1745 |
itemInsurerMapping = ItemInsurerMapping.query.filter(ItemInsurerMapping.itemId == itemId).filter(ItemInsurerMapping.insurerType == insurerType).first()
|
|
|
1746 |
if not itemInsurerMapping:
|
|
|
1747 |
return 0
|
|
|
1748 |
else:
|
|
|
1749 |
return itemInsurerMapping.insurerId
|
|
|
1750 |
|
| 6805 |
anupam.sin |
1751 |
def get_insurer(insurerId):
|
| 6838 |
vikram.rag |
1752 |
return Insurer.get_by(id = insurerId)
|
| 7770 |
kshitij.so |
1753 |
|
| 6845 |
amit.gupta |
1754 |
def get_all_entity_tags():
|
|
|
1755 |
entitiesTag = EntityTag.query.all()
|
|
|
1756 |
entityMap = {}
|
|
|
1757 |
for e in entitiesTag:
|
|
|
1758 |
if not entityMap.has_key(e.entityId):
|
|
|
1759 |
entityMap[e.entityId] = []
|
| 7770 |
kshitij.so |
1760 |
entityMap[e.entityId].append(e.tag)
|
| 6845 |
amit.gupta |
1761 |
return entityMap
|
| 6838 |
vikram.rag |
1762 |
|
|
|
1763 |
|
|
|
1764 |
def get_all_insurers():
|
|
|
1765 |
return session.query(Insurer).all()
|
| 7770 |
kshitij.so |
1766 |
|
| 6962 |
rajveer |
1767 |
def update_insurance_declared_amount(insurerId, amount):
|
|
|
1768 |
insurer = Insurer.get_by(id = insurerId)
|
|
|
1769 |
insurer.declaredAmount += amount
|
|
|
1770 |
session.commit()
|
|
|
1771 |
if insurer.declaredAmount > 0.9*insurer.creditedAmount:
|
| 7770 |
kshitij.so |
1772 |
__send_mail("CRITICAL: Declared Insurance Amount is critical (Declared Amount - " + str(insurer.declaredAmount) + " and Credited Amount - " + str(insurer.creditedAmount) +")", "Please top up credited amount")
|
| 6962 |
rajveer |
1773 |
elif insurer.declaredAmount > 0.8*insurer.creditedAmount:
|
| 7770 |
kshitij.so |
1774 |
__send_mail("WARNING: Declared Insurance Amount is warning (Declared Amount - " + str(insurer.declaredAmount) + " and Credited Amount - " + str(insurer.creditedAmount) +")", "Please top up credited amount")
|
|
|
1775 |
|
| 7190 |
amar.kumar |
1776 |
def get_freebie_for_item(itemId):
|
|
|
1777 |
freebie = FreebieItem.get_by(itemId = itemId)
|
|
|
1778 |
if freebie is None:
|
|
|
1779 |
return 0
|
|
|
1780 |
else:
|
|
|
1781 |
return freebie.freebieItemId
|
| 7770 |
kshitij.so |
1782 |
|
| 7190 |
amar.kumar |
1783 |
def add_or_update_freebie_for_item(freebieItem):
|
|
|
1784 |
freebie = FreebieItem.get_by(itemId = freebieItem.itemId)
|
|
|
1785 |
if freebie is None:
|
|
|
1786 |
freebie = FreebieItem()
|
|
|
1787 |
freebie.itemId = freebieItem.itemId
|
|
|
1788 |
freebie.freebieItemId = freebieItem.freebieItemId
|
| 7256 |
rajveer |
1789 |
session.commit()
|
|
|
1790 |
|
| 7272 |
amit.gupta |
1791 |
|
|
|
1792 |
def add_or_update_brand_info(brandInfo):
|
|
|
1793 |
brandinfo = BrandInfo.get_by(name = brandInfo.name)
|
|
|
1794 |
if brandinfo is None:
|
|
|
1795 |
brandinfo = BrandInfo()
|
|
|
1796 |
brandinfo.itemId = brandInfo.itemId
|
|
|
1797 |
brandinfo.freebieItemId = brandInfo.freebieItemId
|
|
|
1798 |
session.commit()
|
| 7770 |
kshitij.so |
1799 |
|
| 7272 |
amit.gupta |
1800 |
def get_brand_info():
|
|
|
1801 |
brandInfoMap = dict()
|
| 8274 |
amit.gupta |
1802 |
brandInfoList = BrandInfo.query.all()
|
| 7272 |
amit.gupta |
1803 |
for brandInfo in brandInfoList:
|
|
|
1804 |
brandInfoMap[brandInfo.name] = to_t_brand_info(brandInfo)
|
|
|
1805 |
return brandInfoMap
|
|
|
1806 |
|
| 7382 |
rajveer |
1807 |
def update_store_pricing(tsp, allColors):
|
| 7306 |
rajveer |
1808 |
validate_store_pricing(tsp)
|
| 7382 |
rajveer |
1809 |
item = get_item(tsp.itemId)
|
| 7419 |
rajveer |
1810 |
activeOnStore = item.activeOnStore
|
| 7382 |
rajveer |
1811 |
if allColors:
|
|
|
1812 |
items = get_items_by_catalog_id(item.catalog_item_id)
|
|
|
1813 |
else:
|
|
|
1814 |
items = [item]
|
|
|
1815 |
for item in items:
|
|
|
1816 |
sp = StorePricing.get_by(item_id = item.id)
|
|
|
1817 |
if not sp:
|
|
|
1818 |
sp = StorePricing()
|
| 7419 |
rajveer |
1819 |
item.activeOnStore = activeOnStore
|
| 7382 |
rajveer |
1820 |
sp.recommendedPrice = tsp.recommendedPrice
|
|
|
1821 |
sp.minPrice = tsp.minPrice
|
|
|
1822 |
sp.minAdvancePrice = tsp.minAdvancePrice
|
|
|
1823 |
sp.maxPrice = tsp.maxPrice
|
|
|
1824 |
sp.item_id = item.id
|
|
|
1825 |
sp.freebieItemId = tsp.freebieItemId
|
|
|
1826 |
sp.bestDealText = tsp.bestDealText
|
|
|
1827 |
sp.absoluteMinPrice = tsp.absoluteMinPrice
|
| 7265 |
rajveer |
1828 |
session.commit()
|
| 7770 |
kshitij.so |
1829 |
|
|
|
1830 |
|
| 7306 |
rajveer |
1831 |
def validate_store_pricing(tsp):
|
|
|
1832 |
if tsp.minPrice > tsp.maxPrice:
|
| 7770 |
kshitij.so |
1833 |
raise InventoryServiceException(101, "DP is more than MRP")
|
|
|
1834 |
|
| 7306 |
rajveer |
1835 |
item = get_item(tsp.itemId)
|
| 7770 |
kshitij.so |
1836 |
|
| 7384 |
rajveer |
1837 |
if item.mrp and tsp.maxPrice > item.mrp:
|
|
|
1838 |
raise InventoryServiceException(101, "MRP is more than Saholic MRP")
|
| 7770 |
kshitij.so |
1839 |
|
| 7306 |
rajveer |
1840 |
if tsp.recommendedPrice < item.sellingPrice:
|
| 7770 |
kshitij.so |
1841 |
raise InventoryServiceException(101, "MOP is less than Saholic MOP.")
|
|
|
1842 |
|
| 7306 |
rajveer |
1843 |
if tsp.recommendedPrice < tsp.minPrice or tsp.recommendedPrice > tsp.maxPrice:
|
| 7770 |
kshitij.so |
1844 |
raise InventoryServiceException(101, "MOP price must be in the range")
|
| 8867 |
rajveer |
1845 |
|
|
|
1846 |
# if tsp.minPrice < item.sellingPrice:
|
|
|
1847 |
# store_message = "Saholic MOP Changed. DP {0} is less than Saholic MOP.\n".format(tsp.minPrice)
|
|
|
1848 |
# subject = "Item '{0}' is updated in Catalog. Id is {1}".format(__get_product_name(item),item.id)
|
|
|
1849 |
# __send_mail(subject, store_message, to_store_addresses)
|
| 7770 |
kshitij.so |
1850 |
|
| 7306 |
rajveer |
1851 |
return True
|
| 7770 |
kshitij.so |
1852 |
|
|
|
1853 |
|
| 7306 |
rajveer |
1854 |
|
|
|
1855 |
def get_defalut_store_pricing(itemId):
|
| 7256 |
rajveer |
1856 |
inventoryClient = InventoryClient().get_client()
|
| 7306 |
rajveer |
1857 |
pricings = inventoryClient.getAllItemPricing(itemId)
|
|
|
1858 |
item = get_item(itemId)
|
| 7382 |
rajveer |
1859 |
maxp = item.sellingPrice
|
|
|
1860 |
if item.mrp:
|
|
|
1861 |
maxp = item.mrp
|
| 7770 |
kshitij.so |
1862 |
|
| 7256 |
rajveer |
1863 |
minp = 0
|
| 7265 |
rajveer |
1864 |
rp = item.sellingPrice
|
| 7256 |
rajveer |
1865 |
for pricing in pricings:
|
| 7770 |
kshitij.so |
1866 |
if not minp or minp > pricing.dealerPrice:
|
| 7256 |
rajveer |
1867 |
minp = pricing.dealerPrice
|
|
|
1868 |
|
| 7770 |
kshitij.so |
1869 |
|
| 7426 |
anupam.sin |
1870 |
minap = math.ceil(min(max(500, rp*0.1),rp))
|
| 7306 |
rajveer |
1871 |
|
| 7431 |
rajveer |
1872 |
if minp > rp:
|
|
|
1873 |
minp = rp
|
| 7306 |
rajveer |
1874 |
sp = tStorePricing()
|
|
|
1875 |
sp.itemId = itemId
|
| 7256 |
rajveer |
1876 |
sp.recommendedPrice = rp
|
| 7351 |
rajveer |
1877 |
sp.absoluteMinPrice = minp
|
| 7256 |
rajveer |
1878 |
sp.minPrice = minp
|
|
|
1879 |
sp.minAdvancePrice = minap
|
|
|
1880 |
sp.maxPrice = maxp
|
| 7308 |
rajveer |
1881 |
sp.freebieItemId = 0
|
|
|
1882 |
sp.bestDealText = ""
|
| 7306 |
rajveer |
1883 |
return sp
|
| 7770 |
kshitij.so |
1884 |
|
|
|
1885 |
|
| 7256 |
rajveer |
1886 |
def get_store_pricing(itemId):
|
| 7270 |
rajveer |
1887 |
store = StorePricing.get_by(item_id = itemId)
|
| 7306 |
rajveer |
1888 |
if store is None:
|
|
|
1889 |
return get_defalut_store_pricing(itemId)
|
|
|
1890 |
|
| 7256 |
rajveer |
1891 |
sp = tStorePricing()
|
| 7770 |
kshitij.so |
1892 |
sp.itemId = itemId
|
| 7256 |
rajveer |
1893 |
sp.recommendedPrice = store.recommendedPrice
|
|
|
1894 |
sp.minPrice = store.minPrice
|
|
|
1895 |
sp.minAdvancePrice = store.minAdvancePrice
|
|
|
1896 |
sp.maxPrice = store.maxPrice
|
| 7351 |
rajveer |
1897 |
sp.absoluteMinPrice = store.absoluteMinPrice
|
| 7308 |
rajveer |
1898 |
sp.freebieItemId = store.freebieItemId
|
|
|
1899 |
sp.bestDealText = store.bestDealText
|
| 7281 |
kshitij.so |
1900 |
return sp
|
|
|
1901 |
|
|
|
1902 |
def get_all_amazon_listed_items():
|
|
|
1903 |
return session.query(Amazonlisted).all()
|
|
|
1904 |
|
|
|
1905 |
def get_amazon_item_details(amazonItemId):
|
|
|
1906 |
amazonlisted = Amazonlisted.get_by(itemId=amazonItemId)
|
| 15702 |
kshitij.so |
1907 |
fbaPromo, fbbPromo, fbgPromo, fbdPromo = __get_amazon_promotion_attributes_for_item(amazonItemId)
|
|
|
1908 |
return amazonlisted, fbaPromo, fbbPromo, fbgPromo, fbdPromo
|
| 7281 |
kshitij.so |
1909 |
|
| 12663 |
kshitij.so |
1910 |
|
| 8168 |
kshitij.so |
1911 |
def update_amazon_item_details(amazonlisted):
|
|
|
1912 |
amazon_listed = Amazonlisted.get_by(itemId = amazonlisted.itemid)
|
|
|
1913 |
amazon_listed.isFba=amazonlisted.isFba
|
| 10909 |
vikram.rag |
1914 |
amazon_listed.isFbb=amazonlisted.isFbb
|
| 12888 |
kshitij.so |
1915 |
amazon_listed.isFbg=amazonlisted.isFbg
|
| 15702 |
kshitij.so |
1916 |
amazon_listed.isFbd=amazonlisted.isFbd
|
| 8168 |
kshitij.so |
1917 |
amazon_listed.isNonFba=amazonlisted.isNonFba
|
|
|
1918 |
amazon_listed.isInventoryOverride=amazonlisted.isInventoryOverride
|
|
|
1919 |
amazon_listed.handlingTime=amazonlisted.handlingTime
|
|
|
1920 |
amazon_listed.isCustomTime=amazonlisted.isCustomTime
|
| 8619 |
kshitij.so |
1921 |
amazon_listed.taxCode=amazonlisted.taxCode
|
| 10909 |
vikram.rag |
1922 |
amazon_listed.fbbtaxCode=amazonlisted.fbbtaxCode
|
| 12888 |
kshitij.so |
1923 |
amazon_listed.fbgtaxCode=amazonlisted.fbgtaxCode
|
| 15702 |
kshitij.so |
1924 |
amazon_listed.fbdtaxCode=amazonlisted.fbdtaxCode
|
| 8619 |
kshitij.so |
1925 |
if (amazon_listed.sellingPrice != amazonlisted.sellingPrice) and amazonlisted.sellingPrice > 0:
|
| 8168 |
kshitij.so |
1926 |
amazon_listed.mfnPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
1927 |
amazon_listed.sellingPrice=amazonlisted.sellingPrice
|
| 8619 |
kshitij.so |
1928 |
if (amazon_listed.fbaPrice != amazonlisted.fbaPrice) and amazonlisted.fbaPrice > 0:
|
| 8168 |
kshitij.so |
1929 |
amazon_listed.fbaPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
1930 |
amazon_listed.fbaPrice=amazonlisted.fbaPrice
|
| 10909 |
vikram.rag |
1931 |
if (amazon_listed.fbbPrice != amazonlisted.fbbPrice) and amazonlisted.fbbPrice > 0:
|
|
|
1932 |
amazon_listed.fbbPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
1933 |
amazon_listed.fbbPrice=amazonlisted.fbbPrice
|
| 12888 |
kshitij.so |
1934 |
if (amazon_listed.fbgPrice != amazonlisted.fbgPrice) and amazonlisted.fbgPrice > 0:
|
|
|
1935 |
amazon_listed.fbgPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
1936 |
amazon_listed.fbgPrice=amazonlisted.fbgPrice
|
| 15702 |
kshitij.so |
1937 |
if (amazon_listed.fbdPrice != amazonlisted.fbdPrice) and amazonlisted.fbdPrice > 0:
|
|
|
1938 |
amazon_listed.fbdPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
1939 |
amazon_listed.fbdPrice=amazonlisted.fbdPrice
|
| 8168 |
kshitij.so |
1940 |
amazon_listed.suppressMfnPriceUpdate=amazonlisted.suppressMfnPriceUpdate
|
| 10909 |
vikram.rag |
1941 |
amazon_listed.suppressFbaPriceUpdate=amazonlisted.suppressFbaPriceUpdate
|
| 12363 |
kshitij.so |
1942 |
amazon_listed.suppressFbbPriceUpdate=amazonlisted.suppressFbbPriceUpdate
|
| 12888 |
kshitij.so |
1943 |
amazon_listed.suppressFbgPriceUpdate=amazonlisted.suppressFbgPriceUpdate
|
| 15702 |
kshitij.so |
1944 |
amazon_listed.suppressFbdPriceUpdate=amazonlisted.suppressFbdPriceUpdate
|
| 12363 |
kshitij.so |
1945 |
amazon_listed.overrrideWanlc = amazonlisted.overrrideWanlc
|
|
|
1946 |
amazon_listed.exceptionalWanlc = amazonlisted.exceptionalWanlc
|
| 12396 |
kshitij.so |
1947 |
amazon_listed.autoDecrement = amazonlisted.autoDecrement
|
|
|
1948 |
amazon_listed.autoIncrement = amazonlisted.autoIncrement
|
|
|
1949 |
amazon_listed.autoFavourite = amazonlisted.autoFavourite
|
|
|
1950 |
amazon_listed.manualFavourite = amazonlisted.manualFavourite
|
| 12448 |
kshitij.so |
1951 |
amazon_listed.otherCost = amazonlisted.otherCost
|
| 12663 |
kshitij.so |
1952 |
if amazon_listed.fbaPromoPrice != amazonlisted.fbaPromoPrice and amazonlisted.fbaPromoPrice > 0:
|
|
|
1953 |
amazon_listed.fbaPromoPrice = amazonlisted.fbaPromoPrice
|
|
|
1954 |
amazon_listed.fbaPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
1955 |
if amazon_listed.fbbPromoPrice != amazonlisted.fbbPromoPrice and amazonlisted.fbbPromoPrice > 0:
|
|
|
1956 |
amazon_listed.fbbPromoPrice = amazonlisted.fbbPromoPrice
|
|
|
1957 |
amazon_listed.fbbPriceLastUpdatedOn = datetime.datetime.now()
|
| 12888 |
kshitij.so |
1958 |
if amazon_listed.fbgPromoPrice != amazonlisted.fbgPromoPrice and amazonlisted.fbgPromoPrice > 0:
|
|
|
1959 |
amazon_listed.fbgPromoPrice = amazonlisted.fbgPromoPrice
|
|
|
1960 |
amazon_listed.fbgPriceLastUpdatedOn = datetime.datetime.now()
|
| 15702 |
kshitij.so |
1961 |
if amazon_listed.fbdPromoPrice != amazonlisted.fbdPromoPrice and amazonlisted.fbdPromoPrice > 0:
|
|
|
1962 |
amazon_listed.fbdPromoPrice = amazonlisted.fbdPromoPrice
|
|
|
1963 |
amazon_listed.fbdPriceLastUpdatedOn = datetime.datetime.now()
|
| 7281 |
kshitij.so |
1964 |
session.commit()
|
| 7770 |
kshitij.so |
1965 |
|
| 7281 |
kshitij.so |
1966 |
def add_amazon_item(amazonlisted):
|
|
|
1967 |
if (not amazonlisted) or (not amazonlisted.itemid) or (not amazonlisted.asin):
|
|
|
1968 |
return
|
| 7397 |
kshitij.so |
1969 |
amazonItem = Amazonlisted.get_by(itemId=amazonlisted.itemid)
|
|
|
1970 |
if amazonItem is None:
|
|
|
1971 |
amazon_item = Amazonlisted()
|
|
|
1972 |
if amazonlisted.itemid:
|
|
|
1973 |
amazon_item.itemId=amazonlisted.itemid
|
|
|
1974 |
if amazonlisted.asin:
|
|
|
1975 |
amazon_item.asin=amazonlisted.asin
|
|
|
1976 |
if amazonlisted.brand:
|
|
|
1977 |
amazon_item.brand=amazonlisted.brand
|
|
|
1978 |
else:
|
|
|
1979 |
amazon_item.brand=''
|
|
|
1980 |
if amazonlisted.model:
|
|
|
1981 |
amazon_item.model=amazonlisted.model
|
|
|
1982 |
else:
|
|
|
1983 |
amazon_item.model=''
|
|
|
1984 |
if amazonlisted.manufacturer_name:
|
|
|
1985 |
amazon_item.manufacturer_name=amazonlisted.manufacturer_name
|
|
|
1986 |
else:
|
|
|
1987 |
amazon_item.manufacturer_name=''
|
|
|
1988 |
if amazonlisted.name:
|
|
|
1989 |
amazon_item.name=amazonlisted.name
|
|
|
1990 |
else:
|
|
|
1991 |
amazon_item.name=''
|
|
|
1992 |
if amazonlisted.part_number:
|
|
|
1993 |
amazon_item.part_number=amazonlisted.part_number
|
|
|
1994 |
else:
|
|
|
1995 |
amazon_item.part_number=''
|
|
|
1996 |
if amazonlisted.ean:
|
|
|
1997 |
amazon_item.ean=amazonlisted.ean
|
|
|
1998 |
else:
|
|
|
1999 |
amazon_item.ean=''
|
|
|
2000 |
if amazonlisted.upc:
|
|
|
2001 |
amazon_item.upc=amazonlisted.upc
|
|
|
2002 |
else:
|
|
|
2003 |
amazon_item.upc=''
|
| 7770 |
kshitij.so |
2004 |
if amazonlisted.fbaPrice:
|
|
|
2005 |
amazon_item.fbaPrice=amazonlisted.fbaPrice
|
| 7782 |
kshitij.so |
2006 |
amazon_item.fbaPriceLastUpdatedOnSc = datetime.datetime.now()
|
| 7770 |
kshitij.so |
2007 |
amazon_item.fbaPriceLastUpdatedOn = datetime.datetime.now()
|
| 7397 |
kshitij.so |
2008 |
if amazonlisted.sellingPrice:
|
|
|
2009 |
amazon_item.sellingPrice=amazonlisted.sellingPrice
|
| 7782 |
kshitij.so |
2010 |
amazon_item.mfnPriceLastUpdatedOnSc = datetime.datetime.now()
|
| 7770 |
kshitij.so |
2011 |
amazon_item.mfnPriceLastUpdatedOn = datetime.datetime.now()
|
| 7397 |
kshitij.so |
2012 |
if amazonlisted.category:
|
|
|
2013 |
amazon_item.category=amazonlisted.category
|
|
|
2014 |
else:
|
|
|
2015 |
amazon_item.category=''
|
|
|
2016 |
if amazonlisted.color:
|
|
|
2017 |
amazon_item.color=amazonlisted.color
|
|
|
2018 |
else:
|
| 7404 |
kshitij.so |
2019 |
amazon_item.color=''
|
| 8139 |
kshitij.so |
2020 |
amazon_item.suppressMfnPriceUpdate=False
|
| 8140 |
kshitij.so |
2021 |
amazon_item.suppressFbaPriceUpdate=False
|
| 8379 |
vikram.rag |
2022 |
amazon_item.isFba = False
|
|
|
2023 |
amazon_item.isNonFba = False
|
|
|
2024 |
amazon_item.isInventoryOverride = False
|
| 10947 |
vikram.rag |
2025 |
if amazonlisted.fbbPrice:
|
|
|
2026 |
amazon_item.fbbPrice = amazonlisted.fbbPrice
|
|
|
2027 |
amazon_item.fbbPriceLastUpdatedOnSc = datetime.datetime.now()
|
|
|
2028 |
amazon_item.fbbPriceLastUpdatedOn = datetime.datetime.now()
|
| 10921 |
vikram.rag |
2029 |
amazon_item.isFbb = False
|
| 10909 |
vikram.rag |
2030 |
amazon_item.suppressFbbPriceUpdate = False
|
| 12888 |
kshitij.so |
2031 |
if amazonlisted.fbgPrice:
|
| 15702 |
kshitij.so |
2032 |
amazon_item.fbgPrice = amazonlisted.fbgPrice
|
| 12888 |
kshitij.so |
2033 |
amazon_item.fbgPriceLastUpdatedOnSc = datetime.datetime.now()
|
|
|
2034 |
amazon_item.fbgPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
2035 |
amazon_item.isFbg = False
|
|
|
2036 |
amazon_item.suppressFbgPriceUpdate = False
|
| 15702 |
kshitij.so |
2037 |
if amazonlisted.fbdPrice:
|
|
|
2038 |
amazon_item.fbdPrice = amazonlisted.fbdPrice
|
|
|
2039 |
amazon_item.fbdPriceLastUpdatedOnSc = datetime.datetime.now()
|
|
|
2040 |
amazon_item.fbdPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
2041 |
amazon_item.isFbd = False
|
|
|
2042 |
amazon_item.suppressFbdPriceUpdate = False
|
| 12773 |
kshitij.so |
2043 |
amazon_item.autoDecrement = True
|
|
|
2044 |
amazon_item.autoIncrement = True
|
| 15717 |
kshitij.so |
2045 |
amazon_item.packagingHeight = amazonlisted.packagingHeight
|
|
|
2046 |
amazon_item.packagingLength = amazonlisted.packagingLength
|
|
|
2047 |
amazon_item.packagingWidth = amazonlisted.packagingWidth
|
|
|
2048 |
amazon_item.packagingWeight = amazonlisted.packagingWeight
|
| 10909 |
vikram.rag |
2049 |
|
| 7397 |
kshitij.so |
2050 |
elif (amazonItem.asin!=amazonlisted.asin):
|
|
|
2051 |
if amazonlisted.asin:
|
|
|
2052 |
amazonItem.asin=amazonlisted.asin
|
|
|
2053 |
if amazonlisted.brand:
|
|
|
2054 |
amazonItem.brand=amazonlisted.brand
|
|
|
2055 |
else:
|
|
|
2056 |
amazonItem.brand=''
|
|
|
2057 |
if amazonlisted.model:
|
|
|
2058 |
amazonItem.model=amazonlisted.model
|
|
|
2059 |
else:
|
|
|
2060 |
amazonItem.model=''
|
|
|
2061 |
if amazonlisted.manufacturer_name:
|
|
|
2062 |
amazonItem.manufacturer_name=amazonlisted.manufacturer_name
|
|
|
2063 |
else:
|
|
|
2064 |
amazonItem.manufacturer_name=''
|
|
|
2065 |
if amazonlisted.name:
|
|
|
2066 |
amazonItem.name=amazonlisted.name
|
|
|
2067 |
else:
|
|
|
2068 |
amazonItem.name=''
|
|
|
2069 |
if amazonlisted.part_number:
|
|
|
2070 |
amazonItem.part_number=amazonlisted.part_number
|
|
|
2071 |
else:
|
|
|
2072 |
amazonItem.part_number=''
|
|
|
2073 |
if amazonlisted.ean:
|
|
|
2074 |
amazonItem.ean=amazonlisted.ean
|
|
|
2075 |
else:
|
|
|
2076 |
amazonItem.ean=''
|
|
|
2077 |
if amazonlisted.upc:
|
|
|
2078 |
amazonItem.upc=amazonlisted.upc
|
|
|
2079 |
else:
|
|
|
2080 |
amazonItem.upc=''
|
|
|
2081 |
if amazonlisted.sellingPrice:
|
| 8188 |
kshitij.so |
2082 |
amazonItem.sellingPrice=amazonlisted.sellingPrice
|
| 7397 |
kshitij.so |
2083 |
if amazonlisted.fbaPrice:
|
| 8188 |
kshitij.so |
2084 |
amazonItem.fbaPrice=amazonlisted.fbaPrice
|
| 7397 |
kshitij.so |
2085 |
if amazonlisted.isFba:
|
|
|
2086 |
amazonItem.isFba=amazonlisted.isFba
|
|
|
2087 |
if amazonlisted.isNonFba:
|
|
|
2088 |
amazonItem.isNonFba=amazonlisted.isNonFba
|
|
|
2089 |
if amazonlisted.isInventoryOverride:
|
|
|
2090 |
amazonItem.isInventoryOverride=amazonlisted.isInventoryOverride
|
|
|
2091 |
if amazonlisted.category:
|
|
|
2092 |
amazonItem.category=amazonlisted.category
|
|
|
2093 |
else:
|
|
|
2094 |
amazonItem.category=''
|
|
|
2095 |
if amazonlisted.color:
|
|
|
2096 |
amazonItem.color=amazonlisted.color
|
|
|
2097 |
else:
|
| 7404 |
kshitij.so |
2098 |
amazonItem.color=''
|
| 15717 |
kshitij.so |
2099 |
amazonItem.packagingHeight = amazonlisted.packagingHeight
|
|
|
2100 |
amazonItem.packagingLength = amazonlisted.packagingLength
|
|
|
2101 |
amazonItem.packagingWidth = amazonlisted.packagingWidth
|
|
|
2102 |
amazonItem.packagingWeight = amazonlisted.packagingWeight
|
| 7316 |
kshitij.so |
2103 |
else:
|
| 7397 |
kshitij.so |
2104 |
return
|
| 7281 |
kshitij.so |
2105 |
session.commit()
|
| 7770 |
kshitij.so |
2106 |
|
| 7291 |
vikram.rag |
2107 |
def get_asin_items():
|
| 7296 |
amit.gupta |
2108 |
from_date=datetime.datetime.now() - datetime.timedelta(days=10)
|
| 7291 |
vikram.rag |
2109 |
return Item.query.filter(Item.updatedOn > from_date).all()
|
| 7770 |
kshitij.so |
2110 |
|
| 7291 |
vikram.rag |
2111 |
def get_all_fba_listed_items():
|
|
|
2112 |
return Amazonlisted.query.filter(Amazonlisted.isFba==True).all()
|
| 7770 |
kshitij.so |
2113 |
|
| 7291 |
vikram.rag |
2114 |
def get_all_nonfba_listed_items():
|
|
|
2115 |
return Amazonlisted.query.filter(Amazonlisted.isNonFba==True).all()
|
| 7460 |
kshitij.so |
2116 |
|
|
|
2117 |
def update_item_inventory(itemId,holdInventory,defaultInventory):
|
|
|
2118 |
item = get_item(itemId)
|
|
|
2119 |
item.holdInventory = holdInventory
|
|
|
2120 |
item.defaultInventory = defaultInventory
|
|
|
2121 |
session.commit()
|
| 7770 |
kshitij.so |
2122 |
|
|
|
2123 |
def update_timestamp_for_amazon_feeds(feedType,skuList,timestamp):
|
|
|
2124 |
#amazonListed = get_all_amazon_listed_items()
|
| 7782 |
kshitij.so |
2125 |
#fbaItems = []
|
|
|
2126 |
#mfnItems = []
|
| 7770 |
kshitij.so |
2127 |
if feedType == 'NonFbaPricing':
|
| 7782 |
kshitij.so |
2128 |
for sku in skuList:
|
| 7770 |
kshitij.so |
2129 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
|
|
2130 |
amazonItem.mfnPriceLastUpdatedOnSc = to_py_date(timestamp)
|
| 12925 |
kshitij.so |
2131 |
session.commit()
|
| 7770 |
kshitij.so |
2132 |
return True
|
|
|
2133 |
elif feedType == 'FbaPricing':
|
| 7782 |
kshitij.so |
2134 |
for sku in skuList:
|
| 7770 |
kshitij.so |
2135 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
|
|
2136 |
amazonItem.fbaPriceLastUpdatedOnSc = to_py_date(timestamp)
|
| 12925 |
kshitij.so |
2137 |
session.commit()
|
| 7770 |
kshitij.so |
2138 |
return True
|
| 10924 |
vikram.rag |
2139 |
elif feedType == 'FbbPricing':
|
|
|
2140 |
for sku in skuList:
|
|
|
2141 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
|
|
2142 |
amazonItem.fbbPriceLastUpdatedOnSc = to_py_date(timestamp)
|
| 12925 |
kshitij.so |
2143 |
session.commit()
|
| 10924 |
vikram.rag |
2144 |
return True
|
| 12888 |
kshitij.so |
2145 |
elif feedType == 'FbgPricing':
|
|
|
2146 |
for sku in skuList:
|
|
|
2147 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
|
|
2148 |
amazonItem.fbgPriceLastUpdatedOnSc = to_py_date(timestamp)
|
| 12925 |
kshitij.so |
2149 |
session.commit()
|
| 12888 |
kshitij.so |
2150 |
return True
|
| 7770 |
kshitij.so |
2151 |
elif feedType== 'FullFbaPricing':
|
| 7782 |
kshitij.so |
2152 |
for sku in skuList:
|
| 7770 |
kshitij.so |
2153 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
|
|
2154 |
amazonItem.fbaPriceLastUpdatedOnSc = to_py_date(timestamp)
|
| 12925 |
kshitij.so |
2155 |
session.commit()
|
| 7770 |
kshitij.so |
2156 |
return True
|
|
|
2157 |
elif feedType== 'FullNonFbaPricing':
|
| 7782 |
kshitij.so |
2158 |
for sku in skuList:
|
| 7770 |
kshitij.so |
2159 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
|
|
2160 |
amazonItem.mfnPriceLastUpdatedOnSc = to_py_date(timestamp)
|
| 12925 |
kshitij.so |
2161 |
session.commit()
|
| 12701 |
kshitij.so |
2162 |
return True
|
| 8386 |
vikram.rag |
2163 |
elif (feedType=='FbaListingFeed'):
|
|
|
2164 |
for sku in skuList:
|
|
|
2165 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
|
|
2166 |
amazonItem.isFba = True
|
| 12925 |
kshitij.so |
2167 |
session.commit()
|
| 12701 |
kshitij.so |
2168 |
return True
|
| 12888 |
kshitij.so |
2169 |
elif (feedType=='FbgListingFeed'):
|
|
|
2170 |
for sku in skuList:
|
|
|
2171 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
|
|
2172 |
amazonItem.isFbg = True
|
| 12925 |
kshitij.so |
2173 |
session.commit()
|
| 12888 |
kshitij.so |
2174 |
return True
|
| 8386 |
vikram.rag |
2175 |
elif (feedType=='NonFbaListingFeed'):
|
|
|
2176 |
for sku in skuList:
|
|
|
2177 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
|
|
2178 |
amazonItem.isNonFba = True
|
| 12925 |
kshitij.so |
2179 |
session.commit()
|
| 12701 |
kshitij.so |
2180 |
return True
|
| 10920 |
vikram.rag |
2181 |
elif (feedType=='FbbListingFeed'):
|
|
|
2182 |
for sku in skuList:
|
|
|
2183 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
| 15702 |
kshitij.so |
2184 |
amazonItem.fbbListedOn = to_py_date(timestamp)
|
|
|
2185 |
amazonItem.isFbb = True
|
| 12925 |
kshitij.so |
2186 |
session.commit()
|
| 12701 |
kshitij.so |
2187 |
return True
|
| 15702 |
kshitij.so |
2188 |
elif (feedType=='FbdListingFeed'):
|
|
|
2189 |
for sku in skuList:
|
|
|
2190 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
|
|
2191 |
amazonItem.isFbd = True
|
|
|
2192 |
session.commit()
|
|
|
2193 |
return True
|
| 7770 |
kshitij.so |
2194 |
else:
|
|
|
2195 |
return False
|
| 7281 |
kshitij.so |
2196 |
|
| 7897 |
amar.kumar |
2197 |
def get_all_parent_categories():
|
|
|
2198 |
return Category.query.filter_by(parent_category_id=10000).all()
|
| 7977 |
kshitij.so |
2199 |
|
|
|
2200 |
def add_page_view_event(pageEvent):
|
|
|
2201 |
page_view_event = PageViewEvents()
|
|
|
2202 |
page_view_event.catalogId = pageEvent.catalogId
|
|
|
2203 |
page_view_event.url = pageEvent.url
|
|
|
2204 |
page_view_event.sellingPrice = pageEvent.sellingPrice
|
|
|
2205 |
page_view_event.ip = pageEvent.ip
|
|
|
2206 |
page_view_event.sessionId = pageEvent.sessionId
|
|
|
2207 |
page_view_event.comingSoon = pageEvent.comingSoon
|
|
|
2208 |
page_view_event.eventTimestamp = to_py_date(pageEvent.eventDate)
|
|
|
2209 |
session.commit()
|
|
|
2210 |
|
|
|
2211 |
def add_cart_event(cartEvent):
|
|
|
2212 |
cart_event = CartEvents()
|
|
|
2213 |
cart_event.catalogId = cartEvent.catalogId
|
|
|
2214 |
cart_event.itemId = cartEvent.itemId
|
|
|
2215 |
cart_event.inStock = cartEvent.inStock
|
|
|
2216 |
cart_event.ip = cartEvent.ip
|
|
|
2217 |
cart_event.sessionId = cartEvent.sessionId
|
|
|
2218 |
cart_event.comingSoon = cartEvent.comingSoon
|
|
|
2219 |
cart_event.sellingPrice = cartEvent.sellingPrice
|
|
|
2220 |
cart_event.eventTimestamp = to_py_date(cartEvent.eventDate)
|
|
|
2221 |
session.commit()
|
| 8168 |
kshitij.so |
2222 |
|
|
|
2223 |
def update_amazon_attributes_in_bulk(amazonlistedMap):
|
|
|
2224 |
for itemId,amazonlisted in amazonlistedMap.iteritems():
|
| 12407 |
kshitij.so |
2225 |
amazon_item = (get_amazon_item_details(itemId))[0]
|
| 8168 |
kshitij.so |
2226 |
if amazon_item is not None:
|
|
|
2227 |
if amazon_item.sellingPrice != amazonlisted.sellingPrice:
|
|
|
2228 |
amazon_item.mfnPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
2229 |
amazon_item.sellingPrice = amazonlisted.sellingPrice
|
|
|
2230 |
if amazon_item.fbaPrice != amazonlisted.fbaPrice:
|
|
|
2231 |
amazon_item.fbaPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
2232 |
amazon_item.fbaPrice = amazonlisted.fbaPrice
|
| 10909 |
vikram.rag |
2233 |
if amazon_item.fbbPrice != amazonlisted.fbbPrice:
|
|
|
2234 |
amazon_item.fbbPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
2235 |
amazon_item.fbbPrice = amazonlisted.fbbPrice
|
| 10929 |
vikram.rag |
2236 |
amazon_item.fbbtaxCode = amazonlisted.fbbtaxCode
|
| 8619 |
kshitij.so |
2237 |
amazon_item.taxCode = amazonlisted.taxCode
|
| 10909 |
vikram.rag |
2238 |
amazon_item.isFbb = amazonlisted.isFbb
|
| 8168 |
kshitij.so |
2239 |
amazon_item.isFba = amazonlisted.isFba
|
|
|
2240 |
amazon_item.isNonFba = amazonlisted.isNonFba
|
|
|
2241 |
amazon_item.isInventoryOverride = amazonlisted.isInventoryOverride
|
|
|
2242 |
amazon_item.suppressMfnPriceUpdate = amazonlisted.suppressMfnPriceUpdate
|
|
|
2243 |
amazon_item.suppressFbaPriceUpdate = amazonlisted.suppressFbaPriceUpdate
|
| 10909 |
vikram.rag |
2244 |
amazon_item.suppressFbbPriceUpdate = amazonlisted.suppressFbbPriceUpdate
|
| 12505 |
kshitij.so |
2245 |
amazon_item.otherCost = amazonlisted.otherCost
|
| 8168 |
kshitij.so |
2246 |
session.commit()
|
|
|
2247 |
return True
|
|
|
2248 |
|
| 7977 |
kshitij.so |
2249 |
|
| 8182 |
amar.kumar |
2250 |
def insert_ebay_item(ebayItem):
|
| 8241 |
amar.kumar |
2251 |
ebay_item = EbayItem.get_by(ebayListingId = ebayItem.ebayListingId)
|
|
|
2252 |
if ebay_item is None:
|
|
|
2253 |
ebay_item = EbayItem()
|
| 8182 |
amar.kumar |
2254 |
ebay_item.ebayListingId = ebayItem.ebayListingId
|
|
|
2255 |
ebay_item.itemId = ebayItem.itemId
|
|
|
2256 |
ebay_item.listingName = ebayItem.listingName
|
|
|
2257 |
ebay_item.listingPrice = ebayItem.listingPrice
|
| 8281 |
amar.kumar |
2258 |
ebay_item.listingExpiryDate = to_py_date(ebayItem.listingExpiryDate)
|
| 8182 |
amar.kumar |
2259 |
ebay_item.subsidy = ebayItem.subsidy
|
|
|
2260 |
ebay_item.defaultWarehouseId = ebayItem.defaultWarehouseId
|
|
|
2261 |
session.commit()
|
|
|
2262 |
|
| 7977 |
kshitij.so |
2263 |
|
| 8182 |
amar.kumar |
2264 |
def get_ebay_item(listing_id):
|
|
|
2265 |
ebay_item = EbayItem.get_by(ebayListingId = listing_id)
|
|
|
2266 |
return ebay_item
|
| 7977 |
kshitij.so |
2267 |
|
| 8182 |
amar.kumar |
2268 |
|
|
|
2269 |
def update_ebay_item(ebayItem):
|
|
|
2270 |
ebay_item = EbayItem.get_by(ebayListingId = ebayItem.ebayListingId)
|
|
|
2271 |
#if ebay_item.listingExpiryDate < datetime.datetime.now():
|
|
|
2272 |
ebay_item.listingName = ebayItem.listingName
|
|
|
2273 |
ebay_item.listingPrice = ebayItem.listingPrice
|
|
|
2274 |
ebay_item.listingExpiryDate = ebayItem.listingExpiryDate
|
|
|
2275 |
ebay_item.subsidy = ebayItem.subsidy
|
|
|
2276 |
ebay_item.defaultWarehouseId = ebayItem.defaultWarehouseId
|
|
|
2277 |
session.commit()
|
| 8379 |
vikram.rag |
2278 |
|
|
|
2279 |
def get_all_items_to_list_on_fba():
|
|
|
2280 |
return Amazonlisted.query.filter(Amazonlisted.isFba==False).all()
|
|
|
2281 |
|
|
|
2282 |
def get_all_items_to_list_on_nonfba():
|
|
|
2283 |
return Amazonlisted.query.filter(Amazonlisted.isNonFba==False).all()
|
| 8182 |
amar.kumar |
2284 |
|
| 8619 |
kshitij.so |
2285 |
def get_amazon_listed_items(offset,limit):
|
|
|
2286 |
return session.query(Amazonlisted).offset(offset).limit(limit).all()
|
|
|
2287 |
|
|
|
2288 |
def search_amazon_items(search_terms, offset, limit):
|
|
|
2289 |
query = Amazonlisted.query
|
|
|
2290 |
|
|
|
2291 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
|
|
2292 |
|
|
|
2293 |
for search_term in search_terms:
|
|
|
2294 |
query_clause = []
|
|
|
2295 |
query_clause.append(Amazonlisted.itemId.like(search_term))
|
|
|
2296 |
query_clause.append(Amazonlisted.brand.like(search_term))
|
|
|
2297 |
query_clause.append(Amazonlisted.model.like(search_term))
|
|
|
2298 |
query_clause.append(Amazonlisted.name.like(search_term))
|
|
|
2299 |
query_clause.append(Amazonlisted.asin.like(search_term))
|
|
|
2300 |
query = query.filter(or_(*query_clause))
|
|
|
2301 |
|
|
|
2302 |
query = query.offset(offset)
|
|
|
2303 |
if limit:
|
|
|
2304 |
query = query.limit(limit)
|
|
|
2305 |
amazon_items = query.all()
|
|
|
2306 |
return amazon_items
|
|
|
2307 |
|
|
|
2308 |
def get_amazon_search_result_count(search_terms):
|
|
|
2309 |
query = Amazonlisted.query
|
|
|
2310 |
|
|
|
2311 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
|
|
2312 |
|
|
|
2313 |
for search_term in search_terms:
|
|
|
2314 |
query_clause = []
|
|
|
2315 |
query_clause.append(Amazonlisted.itemId.like(search_term))
|
|
|
2316 |
query_clause.append(Amazonlisted.brand.like(search_term))
|
|
|
2317 |
query_clause.append(Amazonlisted.model.like(search_term))
|
|
|
2318 |
query_clause.append(Amazonlisted.name.like(search_term))
|
|
|
2319 |
query_clause.append(Amazonlisted.asin.like(search_term))
|
|
|
2320 |
query = query.filter(or_(*query_clause))
|
|
|
2321 |
|
|
|
2322 |
return query.count()
|
|
|
2323 |
|
|
|
2324 |
def get_count_for_amazonlisted_items():
|
|
|
2325 |
return session.query(func.count(Amazonlisted.itemId)).scalar()
|
|
|
2326 |
|
| 8739 |
vikram.rag |
2327 |
def add_or_update_snapdeal_item(snapdealitem):
|
|
|
2328 |
item = SnapdealItem.get_by(item_id=snapdealitem.item_id)
|
| 9779 |
kshitij.so |
2329 |
if not __validateSnapdealObject(snapdealitem):
|
|
|
2330 |
print "Bad object"
|
|
|
2331 |
return False
|
| 8739 |
vikram.rag |
2332 |
try:
|
|
|
2333 |
if item is not None:
|
| 10097 |
kshitij.so |
2334 |
itemHistory = MarketPlaceUpdateHistory()
|
| 9242 |
kshitij.so |
2335 |
itemHistory.item_id = snapdealitem.item_id
|
| 10097 |
kshitij.so |
2336 |
itemHistory.source = OrderSource.SNAPDEAL
|
| 9242 |
kshitij.so |
2337 |
itemHistory.exceptionPrice = item.exceptionPrice
|
|
|
2338 |
itemHistory.warehouseId = item.warehouseId
|
| 10097 |
kshitij.so |
2339 |
itemHistory.isListedOnSource = item.isListedOnSnapdeal
|
| 9242 |
kshitij.so |
2340 |
itemHistory.transferPrice = item.transferPrice
|
|
|
2341 |
itemHistory.sellingPrice = item.sellingPrice
|
|
|
2342 |
itemHistory.courierCost = item.courierCost
|
|
|
2343 |
itemHistory.commission = item.commission
|
|
|
2344 |
itemHistory.serviceTax = item.serviceTax
|
|
|
2345 |
itemHistory.suppressPriceFeed = item.suppressPriceFeed
|
|
|
2346 |
itemHistory.suppressInventoryFeed = item.suppressInventoryFeed
|
|
|
2347 |
itemHistory.updatedOn = item.updatedOn
|
| 9478 |
kshitij.so |
2348 |
itemHistory.maxNlc = item.maxNlc
|
| 10097 |
kshitij.so |
2349 |
itemHistory.skuAtSource = item.skuAtSnapdeal
|
|
|
2350 |
itemHistory.marketPlaceSerialNumber = item.supc
|
| 9779 |
kshitij.so |
2351 |
itemHistory.priceUpdatedBy = item.priceUpdatedBy
|
| 11095 |
kshitij.so |
2352 |
itemHistory.courierCostMarketplace = item.courierCostMarketplace
|
| 9242 |
kshitij.so |
2353 |
|
| 9779 |
kshitij.so |
2354 |
if (item.sellingPrice!=snapdealitem.sellingPrice):
|
|
|
2355 |
item.priceUpdatedBy = snapdealitem.updatedBy
|
|
|
2356 |
|
| 8739 |
vikram.rag |
2357 |
if snapdealitem.exceptionPrice is not None:
|
|
|
2358 |
item.exceptionPrice = snapdealitem.exceptionPrice
|
|
|
2359 |
if snapdealitem.warehouseId is not None:
|
|
|
2360 |
item.warehouseId = snapdealitem.warehouseId
|
|
|
2361 |
if snapdealitem.isListedOnSnapdeal is not None:
|
| 9242 |
kshitij.so |
2362 |
item.isListedOnSnapdeal = snapdealitem.isListedOnSnapdeal
|
|
|
2363 |
if snapdealitem.transferPrice is not None:
|
|
|
2364 |
item.transferPrice = snapdealitem.transferPrice
|
|
|
2365 |
if snapdealitem.sellingPrice is not None:
|
|
|
2366 |
item.sellingPrice = snapdealitem.sellingPrice
|
|
|
2367 |
if snapdealitem.courierCost is not None:
|
|
|
2368 |
item.courierCost = snapdealitem.courierCost
|
|
|
2369 |
if snapdealitem.commission is not None:
|
|
|
2370 |
item.commission = snapdealitem.commission
|
|
|
2371 |
if snapdealitem.serviceTax is not None:
|
|
|
2372 |
item.serviceTax = snapdealitem.serviceTax
|
|
|
2373 |
item.suppressPriceFeed =snapdealitem.suppressPriceFeed
|
| 9478 |
kshitij.so |
2374 |
item.suppressInventoryFeed =snapdealitem.suppressInventoryFeed
|
| 9581 |
kshitij.so |
2375 |
if snapdealitem.maxNlc is not None:
|
|
|
2376 |
item.maxNlc = snapdealitem.maxNlc
|
| 9478 |
kshitij.so |
2377 |
item.skuAtSnapdeal = snapdealitem.skuAtSnapdeal
|
| 9242 |
kshitij.so |
2378 |
item.updatedOn = datetime.datetime.now()
|
| 9568 |
kshitij.so |
2379 |
item.supc = snapdealitem.supc
|
| 11095 |
kshitij.so |
2380 |
item.courierCostMarketplace = snapdealitem.courierCostMarketplace
|
| 14780 |
manish.sha |
2381 |
if snapdealitem.isVoiListed is not None:
|
|
|
2382 |
item.isVoiListed = snapdealitem.isVoiListed
|
|
|
2383 |
if snapdealitem.voiSellingPrice is not None:
|
|
|
2384 |
item.voiSellingPrice = snapdealitem.voiSellingPrice
|
|
|
2385 |
if snapdealitem.voiSellingPrice is not None:
|
|
|
2386 |
item.voiPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
2387 |
if snapdealitem.voiSkuAtSnapdeal is not None:
|
|
|
2388 |
item.voiSkuAtSnapdeal = snapdealitem.voiSkuAtSnapdeal
|
|
|
2389 |
if snapdealitem.minimumPossibleSpVoi is not None:
|
|
|
2390 |
item.minimumPossibleSpVoi = snapdealitem.minimumPossibleSpVoi
|
|
|
2391 |
if snapdealitem.minimumPossibleTpVoi is not None:
|
|
|
2392 |
item.minimumPossibleTpVoi = snapdealitem.minimumPossibleTpVoi
|
|
|
2393 |
if snapdealitem.courierCostVoi is not None:
|
|
|
2394 |
item.courierCostVoi = snapdealitem.courierCostVoi
|
|
|
2395 |
if snapdealitem.serviceTaxVoi is not None:
|
|
|
2396 |
item.serviceTaxVoi = snapdealitem.serviceTaxVoi
|
|
|
2397 |
if snapdealitem.transferPriceVoi is not None:
|
|
|
2398 |
item.transferPriceVoi = snapdealitem.transferPriceVoi
|
|
|
2399 |
if snapdealitem.commissionVoi is not None:
|
|
|
2400 |
item.commissionVoi = snapdealitem.commissionVoi
|
| 14862 |
manish.sha |
2401 |
if snapdealitem.courierCostMarketplaceVoi is not None:
|
|
|
2402 |
item.courierCostMarketplaceVoi = snapdealitem.courierCostMarketplaceVoi
|
|
|
2403 |
if snapdealitem.commissionPercentageVoi is not None:
|
|
|
2404 |
item.commissionPercentageVoi = snapdealitem.commissionPercentageVoi
|
| 9779 |
kshitij.so |
2405 |
__markStatusForMarketplaceItems(snapdealitem,item)
|
|
|
2406 |
return update_marketplace_attributes_for_item(snapdealitem.marketplaceItems)
|
| 8739 |
vikram.rag |
2407 |
else:
|
|
|
2408 |
item = SnapdealItem()
|
|
|
2409 |
if snapdealitem.item_id is not None:
|
|
|
2410 |
item.item_id = snapdealitem.item_id
|
|
|
2411 |
if snapdealitem.exceptionPrice is not None:
|
|
|
2412 |
item.exceptionPrice = snapdealitem.exceptionPrice
|
|
|
2413 |
if snapdealitem.warehouseId is not None:
|
|
|
2414 |
item.warehouseId = snapdealitem.warehouseId
|
|
|
2415 |
if snapdealitem.isListedOnSnapdeal is not None:
|
| 9242 |
kshitij.so |
2416 |
item.isListedOnSnapdeal = snapdealitem.isListedOnSnapdeal
|
|
|
2417 |
if snapdealitem.transferPrice is not None:
|
|
|
2418 |
item.transferPrice = snapdealitem.transferPrice
|
|
|
2419 |
if snapdealitem.sellingPrice is not None:
|
|
|
2420 |
item.sellingPrice = snapdealitem.sellingPrice
|
|
|
2421 |
if snapdealitem.courierCost is not None:
|
|
|
2422 |
item.courierCost = snapdealitem.courierCost
|
|
|
2423 |
if snapdealitem.commission is not None:
|
|
|
2424 |
item.commission = snapdealitem.commission
|
|
|
2425 |
if snapdealitem.serviceTax is not None:
|
|
|
2426 |
item.serviceTax = snapdealitem.serviceTax
|
|
|
2427 |
item.suppressPriceFeed =snapdealitem.suppressPriceFeed
|
|
|
2428 |
item.suppressInventoryFeed =snapdealitem.suppressInventoryFeed
|
| 9595 |
kshitij.so |
2429 |
item.maxNlc = snapdealitem.maxNlc
|
| 9478 |
kshitij.so |
2430 |
item.skuAtSnapdeal = snapdealitem.skuAtSnapdeal
|
| 9568 |
kshitij.so |
2431 |
item.supc = snapdealitem.supc
|
| 9779 |
kshitij.so |
2432 |
item.updatedOn = datetime.datetime.now()
|
|
|
2433 |
item.priceUpdatedBy = snapdealitem.updatedBy
|
| 11095 |
kshitij.so |
2434 |
item.courierCostMarketplace = snapdealitem.courierCostMarketplace
|
| 14780 |
manish.sha |
2435 |
if snapdealitem.isVoiListed is not None:
|
|
|
2436 |
item.isVoiListed = snapdealitem.isVoiListed
|
|
|
2437 |
if snapdealitem.voiSellingPrice is not None:
|
|
|
2438 |
item.voiSellingPrice = snapdealitem.voiSellingPrice
|
|
|
2439 |
if snapdealitem.voiSellingPrice is not None:
|
|
|
2440 |
item.voiPriceLastUpdatedOn = datetime.datetime.now()
|
|
|
2441 |
if snapdealitem.voiSkuAtSnapdeal is not None:
|
|
|
2442 |
item.voiSkuAtSnapdeal = snapdealitem.voiSkuAtSnapdeal
|
|
|
2443 |
if snapdealitem.minimumPossibleSpVoi is not None:
|
|
|
2444 |
item.minimumPossibleSpVoi = snapdealitem.minimumPossibleSpVoi
|
|
|
2445 |
if snapdealitem.minimumPossibleTpVoi is not None:
|
|
|
2446 |
item.minimumPossibleTpVoi = snapdealitem.minimumPossibleTpVoi
|
|
|
2447 |
if snapdealitem.courierCostVoi is not None:
|
|
|
2448 |
item.courierCostVoi = snapdealitem.courierCostVoi
|
|
|
2449 |
if snapdealitem.serviceTaxVoi is not None:
|
|
|
2450 |
item.serviceTaxVoi = snapdealitem.serviceTaxVoi
|
|
|
2451 |
if snapdealitem.transferPriceVoi is not None:
|
|
|
2452 |
item.transferPriceVoi = snapdealitem.transferPriceVoi
|
|
|
2453 |
if snapdealitem.commissionVoi is not None:
|
|
|
2454 |
item.commissionVoi = snapdealitem.commissionVoi
|
| 14862 |
manish.sha |
2455 |
if snapdealitem.courierCostMarketplaceVoi is not None:
|
|
|
2456 |
item.courierCostMarketplaceVoi = snapdealitem.courierCostMarketplaceVoi
|
|
|
2457 |
if snapdealitem.commissionPercentageVoi is not None:
|
|
|
2458 |
item.commissionPercentageVoi = snapdealitem.commissionPercentageVoi
|
| 9779 |
kshitij.so |
2459 |
__markStatusForMarketplaceItems(snapdealitem,item)
|
|
|
2460 |
return update_marketplace_attributes_for_item(snapdealitem.marketplaceItems)
|
|
|
2461 |
except Exception as ex:
|
|
|
2462 |
print "Unable to addOrupdate snapdealItem"
|
|
|
2463 |
print ex
|
| 9242 |
kshitij.so |
2464 |
return False
|
| 8739 |
vikram.rag |
2465 |
|
|
|
2466 |
def get_snapdeal_item(itemid):
|
| 8755 |
vikram.rag |
2467 |
item = session.query(SnapdealItem,Item).join((Item,SnapdealItem.item_id==Item.id)).filter(SnapdealItem.item_id==itemid).first()
|
| 8747 |
vikram.rag |
2468 |
return item
|
| 9724 |
kshitij.so |
2469 |
|
|
|
2470 |
def get_snapdeal_item_detail(itemid):
|
|
|
2471 |
item = session.query(SnapdealItem,Item).join((Item,SnapdealItem.item_id==Item.id)).filter(SnapdealItem.item_id==itemid).first()
|
|
|
2472 |
try:
|
|
|
2473 |
client = InventoryClient().get_client()
|
|
|
2474 |
SnapdealInventoryItem = client.getSnapdealInventoryForItem(itemid)
|
|
|
2475 |
return item, SnapdealInventoryItem
|
|
|
2476 |
except Exception as e:
|
|
|
2477 |
print e
|
|
|
2478 |
return item,None
|
| 8739 |
vikram.rag |
2479 |
|
|
|
2480 |
def get_all_snapdeal_items():
|
| 8754 |
vikram.rag |
2481 |
items = session.query(SnapdealItem,Item).join((Item,SnapdealItem.item_id==Item.id)).all()
|
| 8739 |
vikram.rag |
2482 |
return items
|
|
|
2483 |
|
| 9242 |
kshitij.so |
2484 |
def get_snapdeal_items(offset,limit):
|
|
|
2485 |
return session.query(SnapdealItem,Item).join((Item,SnapdealItem.item_id==Item.id)).offset(offset).limit(limit).all()
|
|
|
2486 |
|
| 8619 |
kshitij.so |
2487 |
def update_asin(amazonAsinMap):
|
|
|
2488 |
for item_id,t_item in amazonAsinMap.iteritems():
|
|
|
2489 |
item = get_item(item_id)
|
|
|
2490 |
item.asin=t_item.asin
|
|
|
2491 |
item.defaultInventory = t_item.defaultInventory
|
|
|
2492 |
item.holdInventory = t_item.holdInventory
|
|
|
2493 |
item.updatedOn = datetime.datetime.now()
|
|
|
2494 |
session.commit()
|
| 9242 |
kshitij.so |
2495 |
|
|
|
2496 |
def search_snapdeal_items(search_terms,offset,limit):
|
|
|
2497 |
query = session.query(SnapdealItem,Item).join((Item,SnapdealItem.item_id==Item.id))
|
|
|
2498 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
|
|
2499 |
for search_term in search_terms:
|
|
|
2500 |
query_clause = []
|
|
|
2501 |
query_clause.append(Item.id.like(search_term))
|
|
|
2502 |
query_clause.append(Item.brand.like(search_term))
|
|
|
2503 |
query_clause.append(Item.model_name.like(search_term))
|
|
|
2504 |
query_clause.append(Item.model_number.like(search_term))
|
|
|
2505 |
query_clause.append(Item.color.like(search_term))
|
|
|
2506 |
query = query.filter(or_(*query_clause))
|
|
|
2507 |
|
|
|
2508 |
query = query.offset(offset)
|
|
|
2509 |
if limit:
|
|
|
2510 |
query = query.limit(limit)
|
|
|
2511 |
snapdeal_items = query.all()
|
|
|
2512 |
return snapdeal_items
|
|
|
2513 |
|
|
|
2514 |
def get_snapdeal_search_result_count(search_terms):
|
|
|
2515 |
query = session.query(SnapdealItem,Item).join((Item,SnapdealItem.item_id==Item.id))
|
|
|
2516 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
|
|
2517 |
for search_term in search_terms:
|
|
|
2518 |
query_clause = []
|
|
|
2519 |
query_clause.append(Item.id.like(search_term))
|
|
|
2520 |
query_clause.append(Item.brand.like(search_term))
|
|
|
2521 |
query_clause.append(Item.model_name.like(search_term))
|
|
|
2522 |
query_clause.append(Item.model_number.like(search_term))
|
|
|
2523 |
query_clause.append(Item.color.like(search_term))
|
|
|
2524 |
query = query.filter(or_(*query_clause))
|
|
|
2525 |
return query.count()
|
|
|
2526 |
|
|
|
2527 |
def get_count_for_snapdeal_items():
|
|
|
2528 |
return session.query(func.count(SnapdealItem.item_id)).scalar()
|
|
|
2529 |
|
| 9456 |
vikram.rag |
2530 |
def get_snapdealitem_by_skuatsnapdeal(sku):
|
|
|
2531 |
snapdeal_item = SnapdealItem.get_by(skuAtSnapdeal=sku)
|
|
|
2532 |
if snapdeal_item is not None:
|
|
|
2533 |
item = session.query(SnapdealItem,Item).join((Item,SnapdealItem.item_id==Item.id)).filter(SnapdealItem.item_id==snapdeal_item.item_id).first()
|
|
|
2534 |
else:
|
|
|
2535 |
return None
|
|
|
2536 |
return item
|
| 9242 |
kshitij.so |
2537 |
|
| 9621 |
manish.sha |
2538 |
def get_product_feed_submit(catalog_itemId):
|
|
|
2539 |
product_feedsubmit = ProductFeedSubmit.get_by(catalogItemId=catalog_itemId)
|
|
|
2540 |
return product_feedsubmit
|
| 9456 |
vikram.rag |
2541 |
|
| 9621 |
manish.sha |
2542 |
def add_product_feed_submit(productFeedSubmit):
|
|
|
2543 |
feedSubmit = ProductFeedSubmit()
|
|
|
2544 |
feedSubmit.catalogItemId = productFeedSubmit.catalogItemId
|
|
|
2545 |
feedSubmit.stockLinkedFeed = productFeedSubmit.stockLinkedFeed
|
|
|
2546 |
session.commit()
|
|
|
2547 |
return True
|
|
|
2548 |
|
|
|
2549 |
def update_product_feed_submit(productFeedSubmit):
|
|
|
2550 |
feedSubmit = get_product_feed_submit(productFeedSubmit.catalogItemId)
|
|
|
2551 |
if feedSubmit:
|
|
|
2552 |
feedSubmit.catalogItemId = productFeedSubmit.catalogItemId
|
|
|
2553 |
feedSubmit.stockLinkedFeed = productFeedSubmit.stockLinkedFeed
|
|
|
2554 |
session.commit()
|
|
|
2555 |
return True
|
|
|
2556 |
return False
|
|
|
2557 |
|
|
|
2558 |
def delete_product_feed_submit(catalog_itemId):
|
|
|
2559 |
feedSubmit = get_product_feed_submit(catalog_itemId)
|
|
|
2560 |
if feedSubmit:
|
|
|
2561 |
feedSubmit.delete()
|
|
|
2562 |
session.commit()
|
|
|
2563 |
return True
|
|
|
2564 |
return False
|
|
|
2565 |
|
|
|
2566 |
def get_all_product_feed_submit():
|
|
|
2567 |
print session.query(ProductFeedSubmit).all()
|
|
|
2568 |
return session.query(ProductFeedSubmit).all()
|
|
|
2569 |
|
| 9724 |
kshitij.so |
2570 |
def get_marketplace_details_for_item(item_id, sourceId):
|
|
|
2571 |
return MarketplaceItems.get_by(itemId=item_id,source=sourceId)
|
|
|
2572 |
|
|
|
2573 |
def update_marketplace_attributes_for_item(t_marketplaceItem):
|
|
|
2574 |
if t_marketplaceItem.source is None or t_marketplaceItem.itemId is None:
|
|
|
2575 |
return False
|
|
|
2576 |
try:
|
|
|
2577 |
marketplaceItem = get_marketplace_details_for_item(t_marketplaceItem.itemId,t_marketplaceItem.source)
|
|
|
2578 |
if marketplaceItem is None:
|
|
|
2579 |
marketplaceItem = MarketplaceItems()
|
|
|
2580 |
marketplaceItem.itemId = t_marketplaceItem.itemId
|
|
|
2581 |
marketplaceItem.source = t_marketplaceItem.source
|
| 9779 |
kshitij.so |
2582 |
marketplaceItem.emiFee = t_marketplaceItem.emiFee
|
|
|
2583 |
marketplaceItem.closingFee = t_marketplaceItem.closingFee
|
|
|
2584 |
marketplaceItem.returnProvision = t_marketplaceItem.returnProvision
|
|
|
2585 |
marketplaceItem.commission = t_marketplaceItem.commission
|
| 9724 |
kshitij.so |
2586 |
marketplaceItem.vat = t_marketplaceItem.vat
|
| 12133 |
kshitij.so |
2587 |
if marketplaceItem.source == OrderSource.SNAPDEAL:
|
|
|
2588 |
marketplaceItem.packagingCost = t_marketplaceItem.packagingCost
|
|
|
2589 |
else:
|
|
|
2590 |
marketplaceItem.packagingCost = 15.0
|
| 9779 |
kshitij.so |
2591 |
marketplaceItem.serviceTax = t_marketplaceItem.serviceTax
|
| 9724 |
kshitij.so |
2592 |
marketplaceItem.courierCost = t_marketplaceItem.courierCost
|
|
|
2593 |
marketplaceItem.otherCost = t_marketplaceItem.otherCost
|
|
|
2594 |
marketplaceItem.autoIncrement = t_marketplaceItem.autoIncrement
|
|
|
2595 |
marketplaceItem.autoDecrement = t_marketplaceItem.autoDecrement
|
|
|
2596 |
marketplaceItem.manualFavourite = t_marketplaceItem.manualFavourite
|
|
|
2597 |
marketplaceItem.currentSp = t_marketplaceItem.currentSp
|
|
|
2598 |
marketplaceItem.currentTp = t_marketplaceItem.currentTp
|
|
|
2599 |
marketplaceItem.minimumPossibleSp = t_marketplaceItem.minimumPossibleSp
|
|
|
2600 |
marketplaceItem.minimumPossibleTp = t_marketplaceItem.minimumPossibleTp
|
| 9923 |
kshitij.so |
2601 |
marketplaceItem.maximumSellingPrice = t_marketplaceItem.maximumSellingPrice
|
| 10287 |
kshitij.so |
2602 |
marketplaceItem.pgFee = t_marketplaceItem.pgFee
|
| 11095 |
kshitij.so |
2603 |
marketplaceItem.courierCostMarketplace = t_marketplaceItem.courierCostMarketplace
|
| 9724 |
kshitij.so |
2604 |
else:
|
|
|
2605 |
marketplaceItem.courierCost = t_marketplaceItem.courierCost
|
|
|
2606 |
marketplaceItem.otherCost = t_marketplaceItem.otherCost
|
|
|
2607 |
marketplaceItem.autoIncrement = t_marketplaceItem.autoIncrement
|
|
|
2608 |
marketplaceItem.autoDecrement = t_marketplaceItem.autoDecrement
|
|
|
2609 |
marketplaceItem.manualFavourite = t_marketplaceItem.manualFavourite
|
|
|
2610 |
marketplaceItem.currentSp = t_marketplaceItem.currentSp
|
|
|
2611 |
marketplaceItem.currentTp = t_marketplaceItem.currentTp
|
|
|
2612 |
marketplaceItem.minimumPossibleSp = t_marketplaceItem.minimumPossibleSp
|
|
|
2613 |
marketplaceItem.minimumPossibleTp = t_marketplaceItem.minimumPossibleTp
|
| 9779 |
kshitij.so |
2614 |
marketplaceItem.emiFee = t_marketplaceItem.emiFee
|
|
|
2615 |
marketplaceItem.closingFee = t_marketplaceItem.closingFee
|
|
|
2616 |
marketplaceItem.returnProvision = t_marketplaceItem.returnProvision
|
|
|
2617 |
marketplaceItem.commission = t_marketplaceItem.commission
|
| 12133 |
kshitij.so |
2618 |
if marketplaceItem.source == OrderSource.SNAPDEAL:
|
|
|
2619 |
marketplaceItem.packagingCost = t_marketplaceItem.packagingCost
|
|
|
2620 |
else:
|
|
|
2621 |
marketplaceItem.packagingCost = 15.0
|
| 9779 |
kshitij.so |
2622 |
marketplaceItem.vat = t_marketplaceItem.vat
|
|
|
2623 |
marketplaceItem.serviceTax = t_marketplaceItem.serviceTax
|
| 9923 |
kshitij.so |
2624 |
marketplaceItem.maximumSellingPrice = t_marketplaceItem.maximumSellingPrice
|
| 10287 |
kshitij.so |
2625 |
marketplaceItem.pgFee = t_marketplaceItem.pgFee
|
| 11095 |
kshitij.so |
2626 |
marketplaceItem.courierCostMarketplace = t_marketplaceItem.courierCostMarketplace
|
| 9724 |
kshitij.so |
2627 |
session.commit()
|
|
|
2628 |
return True
|
|
|
2629 |
except Exception as ex:
|
| 9779 |
kshitij.so |
2630 |
print "Unable to addOrupdate MarketplaceItem"
|
| 9724 |
kshitij.so |
2631 |
print ex
|
|
|
2632 |
return False
|
| 9779 |
kshitij.so |
2633 |
|
|
|
2634 |
def __markStatusForMarketplaceItems(snapdealItem,item):
|
|
|
2635 |
try:
|
|
|
2636 |
marketplaceItem = snapdealItem.marketplaceItems
|
|
|
2637 |
markUpdatedItem = MarketPlaceItemPrice.query.filter(MarketPlaceItemPrice.item_id==snapdealItem.item_id).filter(MarketPlaceItemPrice.source==marketplaceItem.source).first()
|
|
|
2638 |
if markUpdatedItem is None:
|
|
|
2639 |
marketPlaceItemPrice = MarketPlaceItemPrice()
|
|
|
2640 |
marketPlaceItemPrice.item_id = snapdealItem.item_id
|
|
|
2641 |
marketPlaceItemPrice.source = marketplaceItem.source
|
|
|
2642 |
marketPlaceItemPrice.lastUpdatedOn = item.updatedOn
|
|
|
2643 |
marketPlaceItemPrice.sellingPrice = item.sellingPrice
|
|
|
2644 |
marketPlaceItemPrice.suppressPriceFeed = item.suppressPriceFeed
|
|
|
2645 |
marketPlaceItemPrice.isListedOnSource = item.isListedOnSnapdeal
|
|
|
2646 |
else:
|
|
|
2647 |
if (markUpdatedItem.sellingPrice!=snapdealItem.sellingPrice or markUpdatedItem.suppressPriceFeed!=item.suppressPriceFeed or markUpdatedItem.isListedOnSource!=item.isListedOnSnapdeal):
|
|
|
2648 |
markUpdatedItem.lastUpdatedOn = item.updatedOn
|
|
|
2649 |
markUpdatedItem.sellingPrice = snapdealItem.sellingPrice
|
|
|
2650 |
markUpdatedItem.suppressPriceFeed = item.suppressPriceFeed
|
|
|
2651 |
markUpdatedItem.isListedOnSource = item.isListedOnSnapdeal
|
|
|
2652 |
return True
|
|
|
2653 |
except Exception as e:
|
|
|
2654 |
print e
|
|
|
2655 |
return False
|
| 9724 |
kshitij.so |
2656 |
|
| 10097 |
kshitij.so |
2657 |
def __markStatusForFlipkartItems(flipkartItem,item):
|
|
|
2658 |
try:
|
|
|
2659 |
marketplaceItem = flipkartItem.marketplaceItems
|
|
|
2660 |
markUpdatedItem = MarketPlaceItemPrice.query.filter(MarketPlaceItemPrice.item_id==flipkartItem.item_id).filter(MarketPlaceItemPrice.source==marketplaceItem.source).first()
|
|
|
2661 |
if markUpdatedItem is None:
|
|
|
2662 |
marketPlaceItemPrice = MarketPlaceItemPrice()
|
|
|
2663 |
marketPlaceItemPrice.item_id = flipkartItem.item_id
|
|
|
2664 |
marketPlaceItemPrice.source = marketplaceItem.source
|
|
|
2665 |
marketPlaceItemPrice.lastUpdatedOn = item.updatedOn
|
|
|
2666 |
marketPlaceItemPrice.sellingPrice = marketplaceItem.currentSp
|
|
|
2667 |
marketPlaceItemPrice.suppressPriceFeed = item.suppressPriceFeed
|
|
|
2668 |
marketPlaceItemPrice.isListedOnSource = item.isListedOnFlipkart
|
|
|
2669 |
else:
|
|
|
2670 |
if (markUpdatedItem.sellingPrice!=marketplaceItem.currentSp or markUpdatedItem.suppressPriceFeed!=item.suppressPriceFeed or markUpdatedItem.isListedOnSource!=item.isListedOnFlipkart):
|
|
|
2671 |
markUpdatedItem.lastUpdatedOn = item.updatedOn
|
|
|
2672 |
markUpdatedItem.sellingPrice = marketplaceItem.currentSp
|
|
|
2673 |
markUpdatedItem.suppressPriceFeed = item.suppressPriceFeed
|
|
|
2674 |
markUpdatedItem.isListedOnSource = item.isListedOnFlipkart
|
|
|
2675 |
return True
|
|
|
2676 |
except Exception as e:
|
|
|
2677 |
print e
|
|
|
2678 |
return False
|
|
|
2679 |
|
|
|
2680 |
|
| 9779 |
kshitij.so |
2681 |
def get_costing_for_marketplace(source_id,itemId):
|
| 12133 |
kshitij.so |
2682 |
d_item = get_item(itemId)
|
| 10097 |
kshitij.so |
2683 |
time = datetime.datetime.now()
|
|
|
2684 |
sip = SourceItemPercentage.query.filter(SourceItemPercentage.item_id==itemId).filter(SourceItemPercentage.source==source_id).filter(SourceItemPercentage.startDate<=time).filter(SourceItemPercentage.expiryDate>=time).first()
|
| 12133 |
kshitij.so |
2685 |
srm = SourceReturnPercentage.get_by(source=source_id,brand=d_item.brand,category_id=d_item.category)
|
| 10097 |
kshitij.so |
2686 |
if sip is not None:
|
| 12133 |
kshitij.so |
2687 |
sip.returnProvision = srm.returnProvision
|
| 10097 |
kshitij.so |
2688 |
return sip
|
| 9779 |
kshitij.so |
2689 |
else:
|
| 10097 |
kshitij.so |
2690 |
item = get_item(itemId)
|
|
|
2691 |
scp = SourceCategoryPercentage.query.filter(SourceCategoryPercentage.category_id==item.category).filter(SourceCategoryPercentage.source==source_id).filter(SourceCategoryPercentage.startDate<=time).filter(SourceCategoryPercentage.expiryDate>=time).first()
|
|
|
2692 |
if scp is not None:
|
| 12133 |
kshitij.so |
2693 |
scp.returnProvision = srm.returnProvision
|
| 10097 |
kshitij.so |
2694 |
return scp
|
|
|
2695 |
else:
|
|
|
2696 |
spm = SourcePercentageMaster.get_by(source=source_id)
|
| 12133 |
kshitij.so |
2697 |
spm.returnProvision = srm.returnProvision
|
| 10097 |
kshitij.so |
2698 |
return spm
|
| 9779 |
kshitij.so |
2699 |
|
|
|
2700 |
def __validateSnapdealObject(snapdealItem):
|
|
|
2701 |
if len(snapdealItem.supc)==0 or snapdealItem.supc is None or len(snapdealItem.skuAtSnapdeal)==0 or snapdealItem.skuAtSnapdeal is None or snapdealItem.sellingPrice==0 or snapdealItem.maxNlc==0:
|
|
|
2702 |
return False
|
|
|
2703 |
else:
|
|
|
2704 |
return True
|
| 10097 |
kshitij.so |
2705 |
|
|
|
2706 |
def __validateFlipkartObject(flipkartitem):
|
|
|
2707 |
mpItem = flipkartitem.marketplaceItems
|
|
|
2708 |
print mpItem
|
| 10116 |
kshitij.so |
2709 |
if mpItem.currentSp==0 or flipkartitem.maxNlc==0 or len(flipkartitem.flipkartSerialNumber)==0 or flipkartitem.flipkartSerialNumber is None or len(flipkartitem.skuAtFlipkart)==0 or flipkartitem.skuAtFlipkart is None:
|
| 10097 |
kshitij.so |
2710 |
return False
|
|
|
2711 |
else:
|
|
|
2712 |
return True
|
| 9779 |
kshitij.so |
2713 |
|
|
|
2714 |
|
| 9776 |
vikram.rag |
2715 |
def get_all_marketplace_items_for_priceupdate(source):
|
|
|
2716 |
marketPlaceItemsPrices = MarketPlaceItemPrice.query.filter(MarketPlaceItemPrice.source == source).filter(MarketPlaceItemPrice.lastUpdatedOn > MarketPlaceItemPrice.lastUpdatedOnMarketplace).all()
|
|
|
2717 |
return marketPlaceItemsPrices
|
| 9724 |
kshitij.so |
2718 |
|
| 9816 |
kshitij.so |
2719 |
def update_marketplace_priceupdate_status(skuList,timestamp,source_id):
|
| 9776 |
vikram.rag |
2720 |
for sku in skuList:
|
| 9816 |
kshitij.so |
2721 |
item = MarketPlaceItemPrice.get_by(item_id=sku,source=source_id)
|
| 9776 |
vikram.rag |
2722 |
if item is not None:
|
|
|
2723 |
item.lastUpdatedOnMarketplace = to_py_date(timestamp)
|
| 9816 |
kshitij.so |
2724 |
mp_item = get_marketplace_details_for_item(sku,source_id)
|
|
|
2725 |
if mp_item is not None:
|
|
|
2726 |
mp_item.lastCheckedTimestamp = to_py_date(timestamp)
|
| 9776 |
vikram.rag |
2727 |
session.commit()
|
| 9895 |
vikram.rag |
2728 |
|
| 9907 |
vikram.rag |
2729 |
def update_item_hold_inventory(itemHoldMap):
|
|
|
2730 |
items = get_all_alive_items()
|
|
|
2731 |
for item in items:
|
|
|
2732 |
if item.holdOverride:
|
|
|
2733 |
continue
|
|
|
2734 |
if itemHoldMap.__contains__(item.id):
|
|
|
2735 |
item.holdInventory = itemHoldMap[item.id]
|
|
|
2736 |
else:
|
|
|
2737 |
item.holdInventory = 1
|
|
|
2738 |
session.commit()
|
|
|
2739 |
|
| 9895 |
vikram.rag |
2740 |
def update_nlc_at_marketplaces(itemid,vendor_id,nlc):
|
|
|
2741 |
try:
|
|
|
2742 |
item = SnapdealItem.get_by(item_id=itemid)
|
|
|
2743 |
if item is not None:
|
|
|
2744 |
marketplaceitem = MarketplaceItems.get_by(itemId=itemid,source=7)
|
|
|
2745 |
ic = InventoryClient().get_client()
|
|
|
2746 |
warehouse = ic.getWarehouse(item.warehouseId)
|
|
|
2747 |
if(warehouse.vendor.id==vendor_id):
|
|
|
2748 |
item.maxNlc = nlc
|
|
|
2749 |
vat = (item.sellingPrice/(1+(marketplaceitem.vat/100))-(nlc/(1+(marketplaceitem.vat/100))))*(marketplaceitem.vat/100)
|
| 12133 |
kshitij.so |
2750 |
inHouseCost = marketplaceitem.packagingCost + vat + (marketplaceitem.returnProvision/100)*item.sellingPrice + marketplaceitem.otherCost
|
| 9895 |
vikram.rag |
2751 |
marketplaceitem.minimumPossibleTp = nlc + inHouseCost
|
| 10287 |
kshitij.so |
2752 |
if (marketplaceitem.pgFee/100)*item.sellingPrice>=20:
|
| 12133 |
kshitij.so |
2753 |
marketplaceitem.minimumPossibleSp = (nlc+(item.courierCostMarketplace+marketplaceitem.closingFee)*(1+(marketplaceitem.serviceTax/100))*(1+(marketplaceitem.vat/100))+(marketplaceitem.packagingCost+marketplaceitem.otherCost)*(1+(marketplaceitem.vat)/100))/(1-(marketplaceitem.commission/100+marketplaceitem.emiFee/100+marketplaceitem.pgFee/100)*(1+(marketplaceitem.serviceTax/100))*(1+(marketplaceitem.vat)/100)-(marketplaceitem.returnProvision/100)*(1+(marketplaceitem.vat)/100))
|
| 10287 |
kshitij.so |
2754 |
else:
|
| 12133 |
kshitij.so |
2755 |
marketplaceitem.minimumPossibleSp = (nlc+(item.courierCostMarketplace+marketplaceitem.closingFee+20)*(1+(marketplaceitem.serviceTax/100))*(1+(marketplaceitem.vat/100))+(marketplaceitem.packagingCost+marketplaceitem.otherCost)*(1+(marketplaceitem.vat)/100))/(1-(marketplaceitem.commission/100+marketplaceitem.emiFee/100)*(1+(marketplaceitem.serviceTax/100))*(1+(marketplaceitem.vat)/100)-(marketplaceitem.returnProvision/100)*(1+(marketplaceitem.vat)/100))
|
| 9895 |
vikram.rag |
2756 |
session.commit()
|
| 10287 |
kshitij.so |
2757 |
flipkartitem = FlipkartItem.get_by(item_id=itemid)
|
|
|
2758 |
if flipkartitem is not None:
|
|
|
2759 |
ic = InventoryClient().get_client()
|
|
|
2760 |
fmarketplaceitem = MarketplaceItems.get_by(itemId=itemid,source=8)
|
|
|
2761 |
warehouse = ic.getWarehouse(flipkartitem.warehouseId)
|
|
|
2762 |
if(warehouse.vendor.id==vendor_id):
|
|
|
2763 |
print 'Inside Flipkart maxnlc change'
|
|
|
2764 |
flipkartitem.maxNlc = nlc
|
|
|
2765 |
vat = (fmarketplaceitem.currentSp/(1+(fmarketplaceitem.vat/100))-(nlc/(1+(fmarketplaceitem.vat/100))))*(fmarketplaceitem.vat/100)
|
|
|
2766 |
inHouseCost = 15 + vat + (fmarketplaceitem.returnProvision/100)*fmarketplaceitem.currentSp + fmarketplaceitem.otherCost
|
|
|
2767 |
fmarketplaceitem.minimumPossibleTp = nlc + inHouseCost
|
|
|
2768 |
fmarketplaceitem.minimumPossibleSp = (nlc+(fmarketplaceitem.courierCost+fmarketplaceitem.closingFee)*(1+(fmarketplaceitem.serviceTax/100))*(1+(fmarketplaceitem.vat/100))+(15+fmarketplaceitem.otherCost)*(1+(fmarketplaceitem.vat)/100))/(1-(fmarketplaceitem.commission/100+fmarketplaceitem.emiFee/100)*(1+(fmarketplaceitem.serviceTax/100))*(1+(fmarketplaceitem.vat)/100)-(fmarketplaceitem.returnProvision/100)*(1+(fmarketplaceitem.vat)/100))
|
|
|
2769 |
session.commit()
|
| 9895 |
vikram.rag |
2770 |
finally:
|
| 9945 |
vikram.rag |
2771 |
close_session()
|
|
|
2772 |
|
|
|
2773 |
def get_all_flipkart_items():
|
| 10103 |
kshitij.so |
2774 |
return session.query(FlipkartItem,Item).join((Item,FlipkartItem.item_id==Item.id)).all()
|
| 10097 |
kshitij.so |
2775 |
|
|
|
2776 |
def get_flipkart_item(itemid):
|
|
|
2777 |
item = session.query(FlipkartItem,Item).join((Item,FlipkartItem.item_id==Item.id)).filter(FlipkartItem.item_id==itemid).first()
|
|
|
2778 |
return item
|
|
|
2779 |
|
|
|
2780 |
def add_or_update_flipkart_item(flipkartitem):
|
|
|
2781 |
item = FlipkartItem.get_by(item_id=flipkartitem.item_id)
|
|
|
2782 |
mpItem = get_marketplace_details_for_item(flipkartitem.item_id,OrderSource.FLIPKART)
|
|
|
2783 |
t_mpItem = flipkartitem.marketplaceItems
|
|
|
2784 |
if not __validateFlipkartObject(flipkartitem):
|
|
|
2785 |
return False
|
|
|
2786 |
try:
|
|
|
2787 |
if item is not None:
|
|
|
2788 |
itemHistory = MarketPlaceUpdateHistory()
|
|
|
2789 |
itemHistory.item_id = flipkartitem.item_id
|
|
|
2790 |
itemHistory.source = OrderSource.FLIPKART
|
|
|
2791 |
itemHistory.exceptionPrice = item.exceptionPrice
|
|
|
2792 |
itemHistory.warehouseId = item.warehouseId
|
|
|
2793 |
itemHistory.isListedOnSource = item.isListedOnFlipkart
|
|
|
2794 |
itemHistory.transferPrice = mpItem.currentTp
|
|
|
2795 |
itemHistory.sellingPrice = mpItem.currentSp
|
|
|
2796 |
itemHistory.courierCost = mpItem.courierCost
|
|
|
2797 |
itemHistory.commission = item.commissionValue
|
|
|
2798 |
itemHistory.serviceTax = item.serviceTaxValue
|
|
|
2799 |
itemHistory.suppressPriceFeed = item.suppressPriceFeed
|
|
|
2800 |
itemHistory.suppressInventoryFeed = item.suppressInventoryFeed
|
|
|
2801 |
itemHistory.updatedOn = item.updatedOn
|
|
|
2802 |
itemHistory.maxNlc = item.maxNlc
|
|
|
2803 |
itemHistory.skuAtSource = item. skuAtFlipkart
|
|
|
2804 |
itemHistory.marketPlaceSerialNumber = item.flipkartSerialNumber
|
|
|
2805 |
itemHistory.priceUpdatedBy = item.updatedBy
|
|
|
2806 |
if (mpItem.currentSp!=t_mpItem.currentSp):
|
|
|
2807 |
item.updatedBy = flipkartitem.updatedBy
|
|
|
2808 |
item.exceptionPrice = flipkartitem.exceptionPrice
|
|
|
2809 |
item.warehouseId = flipkartitem.warehouseId
|
| 14780 |
manish.sha |
2810 |
if flipkartitem.isListedOnFlipkart:
|
|
|
2811 |
item.isListedOnFlipkart = flipkartitem.isListedOnFlipkart
|
|
|
2812 |
item.isFaListed = False
|
|
|
2813 |
else:
|
|
|
2814 |
item.isFaListed = flipkartitem.isFaListed
|
|
|
2815 |
item.isListedOnFlipkart = flipkartitem.isListedOnFlipkart
|
| 10097 |
kshitij.so |
2816 |
item.commissionValue = flipkartitem.commissionValue
|
|
|
2817 |
item.serviceTaxValue = flipkartitem.serviceTaxValue
|
|
|
2818 |
item.suppressPriceFeed =flipkartitem.suppressPriceFeed
|
|
|
2819 |
item.suppressInventoryFeed =flipkartitem.suppressInventoryFeed
|
|
|
2820 |
item.maxNlc = flipkartitem.maxNlc
|
|
|
2821 |
item.skuAtFlipkart = flipkartitem.skuAtFlipkart
|
|
|
2822 |
item.flipkartSerialNumber = flipkartitem.flipkartSerialNumber
|
|
|
2823 |
item.updatedOn = datetime.datetime.now()
|
| 14780 |
manish.sha |
2824 |
if flipkartitem.isFaListed:
|
|
|
2825 |
item.isListedOnFlipkart = False
|
|
|
2826 |
item.isFaListed = flipkartitem.isFaListed
|
|
|
2827 |
else:
|
|
|
2828 |
item.isFaListed = flipkartitem.isFaListed
|
|
|
2829 |
item.isListedOnFlipkart = flipkartitem.isListedOnFlipkart
|
| 10097 |
kshitij.so |
2830 |
__markStatusForFlipkartItems(flipkartitem,item)
|
|
|
2831 |
return update_marketplace_attributes_for_item(flipkartitem.marketplaceItems)
|
|
|
2832 |
else:
|
|
|
2833 |
item = FlipkartItem()
|
|
|
2834 |
if flipkartitem.item_id is not None:
|
|
|
2835 |
item.item_id = flipkartitem.item_id
|
|
|
2836 |
item.exceptionPrice = flipkartitem.exceptionPrice
|
|
|
2837 |
item.warehouseId = flipkartitem.warehouseId
|
| 14780 |
manish.sha |
2838 |
if flipkartitem.isListedOnFlipkart:
|
|
|
2839 |
item.isListedOnFlipkart = flipkartitem.isListedOnFlipkart
|
|
|
2840 |
item.isFaListed = False
|
|
|
2841 |
else:
|
|
|
2842 |
item.isFaListed = flipkartitem.isFaListed
|
|
|
2843 |
item.isListedOnFlipkart = flipkartitem.isListedOnFlipkart
|
| 10097 |
kshitij.so |
2844 |
item.commissionValue = flipkartitem.commissionValue
|
|
|
2845 |
item.serviceTaxValue = flipkartitem.serviceTaxValue
|
|
|
2846 |
item.suppressPriceFeed =flipkartitem.suppressPriceFeed
|
|
|
2847 |
item.suppressInventoryFeed =flipkartitem.suppressInventoryFeed
|
|
|
2848 |
item.maxNlc = flipkartitem.maxNlc
|
|
|
2849 |
item.skuAtFlipkart = flipkartitem.skuAtFlipkart
|
|
|
2850 |
item.flipkartSerialNumber = flipkartitem.flipkartSerialNumber
|
|
|
2851 |
item.updatedOn = datetime.datetime.now()
|
|
|
2852 |
item.updatedBy = flipkartitem.updatedBy
|
| 14780 |
manish.sha |
2853 |
if flipkartitem.isFaListed:
|
|
|
2854 |
item.isListedOnFlipkart = False
|
|
|
2855 |
item.isFaListed = flipkartitem.isFaListed
|
|
|
2856 |
else:
|
|
|
2857 |
item.isFaListed = flipkartitem.isFaListed
|
|
|
2858 |
item.isListedOnFlipkart = flipkartitem.isListedOnFlipkart
|
| 10097 |
kshitij.so |
2859 |
__markStatusForFlipkartItems(flipkartitem,item)
|
|
|
2860 |
return update_marketplace_attributes_for_item(flipkartitem.marketplaceItems)
|
|
|
2861 |
except Exception as ex:
|
|
|
2862 |
print "Unable to addOrupdate flipkart"
|
|
|
2863 |
print ex
|
|
|
2864 |
return False
|
|
|
2865 |
|
|
|
2866 |
def get_flipkart_item_detail(itemid):
|
|
|
2867 |
item = session.query(FlipkartItem,Item).join((Item,FlipkartItem.item_id==Item.id)).filter(FlipkartItem.item_id==itemid).first()
|
|
|
2868 |
try:
|
|
|
2869 |
client = InventoryClient().get_client()
|
|
|
2870 |
FlipkartInventoryItem = client.getFlipkartlInventoryForItem(itemid)
|
|
|
2871 |
return item, FlipkartInventoryItem
|
|
|
2872 |
except Exception as e:
|
|
|
2873 |
print e
|
|
|
2874 |
return item,None
|
|
|
2875 |
|
|
|
2876 |
def get_flipkart_items(offset,limit):
|
|
|
2877 |
return session.query(FlipkartItem,Item).join((Item,FlipkartItem.item_id==Item.id)).offset(offset).limit(limit).all()
|
|
|
2878 |
|
|
|
2879 |
def search_flipkart_items(search_terms,offset,limit):
|
|
|
2880 |
query = session.query(FlipkartItem,Item).join((Item,FlipkartItem.item_id==Item.id))
|
|
|
2881 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
|
|
2882 |
for search_term in search_terms:
|
|
|
2883 |
query_clause = []
|
|
|
2884 |
query_clause.append(Item.id.like(search_term))
|
|
|
2885 |
query_clause.append(Item.brand.like(search_term))
|
|
|
2886 |
query_clause.append(Item.model_name.like(search_term))
|
|
|
2887 |
query_clause.append(Item.model_number.like(search_term))
|
|
|
2888 |
query_clause.append(Item.color.like(search_term))
|
|
|
2889 |
query = query.filter(or_(*query_clause))
|
|
|
2890 |
|
|
|
2891 |
query = query.offset(offset)
|
|
|
2892 |
if limit:
|
|
|
2893 |
query = query.limit(limit)
|
|
|
2894 |
flipkart_items = query.all()
|
|
|
2895 |
return flipkart_items
|
|
|
2896 |
|
|
|
2897 |
def get_flipkart_search_result_count(search_terms):
|
|
|
2898 |
query = session.query(FlipkartItem,Item).join((Item,FlipkartItem.item_id==Item.id))
|
|
|
2899 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
|
|
2900 |
for search_term in search_terms:
|
|
|
2901 |
query_clause = []
|
|
|
2902 |
query_clause.append(Item.id.like(search_term))
|
|
|
2903 |
query_clause.append(Item.brand.like(search_term))
|
|
|
2904 |
query_clause.append(Item.model_name.like(search_term))
|
|
|
2905 |
query_clause.append(Item.model_number.like(search_term))
|
|
|
2906 |
query_clause.append(Item.color.like(search_term))
|
|
|
2907 |
query = query.filter(or_(*query_clause))
|
|
|
2908 |
return query.count()
|
|
|
2909 |
|
|
|
2910 |
def get_count_for_flipkart_items():
|
|
|
2911 |
return session.query(func.count(FlipkartItem.item_id)).scalar()
|
|
|
2912 |
|
|
|
2913 |
def get_all_fk_items():
|
|
|
2914 |
return session.query(FlipkartItem,Item).join((Item,FlipkartItem.item_id==Item.id)).all()
|
|
|
2915 |
|
| 10140 |
vikram.rag |
2916 |
def get_flipkart_item_by_sku_at_flipkart(sku):
|
| 10141 |
vikram.rag |
2917 |
return session.query(FlipkartItem,Item).join((Item,FlipkartItem.item_id==Item.id)).filter(FlipkartItem.skuAtFlipkart==sku).first()
|
| 10909 |
vikram.rag |
2918 |
|
| 11015 |
kshitij.so |
2919 |
def get_marketplace_history(source,offset,itemId):
|
|
|
2920 |
return session.query(MarketPlaceHistory).filter(MarketPlaceHistory.item_id==itemId).filter(MarketPlaceHistory.source==source).filter(or_(MarketPlaceHistory.toGroup==True,MarketPlaceHistory.toGroup==None)).order_by(desc(MarketPlaceHistory.timestamp)).limit(11).offset(offset).all()
|
|
|
2921 |
|
| 10909 |
vikram.rag |
2922 |
def get_all_fbb_listed_items():
|
| 15702 |
kshitij.so |
2923 |
return Amazonlisted.query.filter(Amazonlisted.isFbb==False).filter(or_(Amazonlisted.fbdtaxCode!=None,Amazonlisted.fbdtaxCode!="")).all()
|
| 11015 |
kshitij.so |
2924 |
|
| 10924 |
vikram.rag |
2925 |
def get_all_fbb_pricing_items():
|
| 12949 |
kshitij.so |
2926 |
#Removing fbbListedOn from query.Will have to fix this.(2014-10-17)
|
|
|
2927 |
#return Amazonlisted.query.filter(Amazonlisted.isFbb==True).filter(Amazonlisted.suppressFbbPriceUpdate==False).filter(Amazonlisted.fbbListedOn != None).all()
|
|
|
2928 |
return Amazonlisted.query.filter(Amazonlisted.isFbb==True).filter(Amazonlisted.suppressFbbPriceUpdate==False).all()
|
| 11015 |
kshitij.so |
2929 |
def get_count_for_marketplaceHistory(source,itemId):
|
|
|
2930 |
return len(session.query(MarketPlaceHistory).filter(MarketPlaceHistory.item_id==itemId).filter(MarketPlaceHistory.source==source).filter(or_(MarketPlaceHistory.toGroup==True,MarketPlaceHistory.toGroup==None)).all())
|
|
|
2931 |
|
|
|
2932 |
def get_marketplace_history_by_date(source,startDate,endDate,offset,limit,itemId):
|
|
|
2933 |
return session.query(MarketPlaceHistory).filter(MarketPlaceHistory.item_id==itemId).filter(MarketPlaceHistory.source==source).filter(MarketPlaceHistory.timestamp > to_py_date(startDate)).filter(MarketPlaceHistory.timestamp < to_py_date(endDate)).order_by(desc(MarketPlaceHistory.timestamp)).all()
|
|
|
2934 |
|
| 11531 |
vikram.rag |
2935 |
def get_private_deal_details(itemid):
|
|
|
2936 |
return PrivateDeals.get_by(item_id=itemid)
|
|
|
2937 |
|
|
|
2938 |
def get_private_deal_items(offset,limit):
|
| 12124 |
kshitij.so |
2939 |
if offset==0 and limit==0:
|
|
|
2940 |
return session.query(Item).join((PrivateDeals,Item.id==PrivateDeals.item_id)).filter(PrivateDeals.isActive==True).all()
|
| 11614 |
vikram.rag |
2941 |
return session.query(Item).join((PrivateDeals,Item.id==PrivateDeals.item_id)).filter(PrivateDeals.isActive==True).offset(offset).limit(limit).all()
|
| 11531 |
vikram.rag |
2942 |
|
| 11653 |
amit.gupta |
2943 |
def get_all_active_private_deals(itemIds, daysDelta):
|
|
|
2944 |
dealsMap = dict()
|
|
|
2945 |
all_active_items_query = session.query(PrivateDeals).filter(PrivateDeals.isActive==True).filter(now().between(PrivateDeals.startDate, PrivateDeals.endDate + datetime.timedelta(days=daysDelta)))
|
|
|
2946 |
if itemIds is not None:
|
| 11667 |
amit.gupta |
2947 |
all_active_items_query = all_active_items_query.filter(PrivateDeals.item_id.in_(itemIds))
|
| 11653 |
amit.gupta |
2948 |
|
|
|
2949 |
all_active_private_deals = all_active_items_query.all()
|
|
|
2950 |
if all_active_private_deals is not None or all_active_private_deals!=[]:
|
| 11592 |
amit.gupta |
2951 |
for active_private_deal in all_active_private_deals:
|
| 13183 |
amit.gupta |
2952 |
item = get_item(active_private_deal.item_id)
|
|
|
2953 |
if item.sellingPrice > active_private_deal.dealPrice:
|
|
|
2954 |
dealsMap[active_private_deal.item_id] = to_t_private_deal(active_private_deal)
|
|
|
2955 |
return dealsMap
|
| 11592 |
amit.gupta |
2956 |
|
| 11531 |
vikram.rag |
2957 |
def add_or_update_private_deal(privatedeal):
|
| 11606 |
vikram.rag |
2958 |
print 'Inside update private deals'
|
| 11531 |
vikram.rag |
2959 |
try:
|
|
|
2960 |
deal = PrivateDeals.get_by(item_id=privatedeal.item_id)
|
|
|
2961 |
if deal is None:
|
|
|
2962 |
deal = PrivateDeals()
|
|
|
2963 |
deal.item_id = privatedeal.item_id
|
|
|
2964 |
deal.dealFreebieItemId = privatedeal.dealFreebieItemId
|
|
|
2965 |
deal.dealPrice = privatedeal.dealPrice
|
| 11838 |
amit.gupta |
2966 |
deal.startDate = to_py_date(privatedeal.startDate).replace(hour=0,second=0,minute=0)
|
|
|
2967 |
deal.endDate = to_py_date(privatedeal.endDate).replace(hour=0,second=0,minute=0)
|
| 11566 |
vikram.rag |
2968 |
deal.dealTextOption = privatedeal.dealTextOption
|
| 11531 |
vikram.rag |
2969 |
deal.dealText = privatedeal.dealText
|
|
|
2970 |
deal.isCod = privatedeal.isCod
|
|
|
2971 |
deal.rank = privatedeal.rank
|
| 11566 |
vikram.rag |
2972 |
deal.dealFreebieOption = privatedeal.dealFreebieOption
|
| 11606 |
vikram.rag |
2973 |
deal.isActive = privatedeal.isActive
|
| 11531 |
vikram.rag |
2974 |
else:
|
|
|
2975 |
deal.dealFreebieItemId = privatedeal.dealFreebieItemId
|
|
|
2976 |
deal.dealPrice = privatedeal.dealPrice
|
| 11896 |
amit.gupta |
2977 |
deal.startDate = to_py_date(privatedeal.startDate).replace(hour=0,second=0,minute=0)
|
|
|
2978 |
deal.endDate = to_py_date(privatedeal.endDate).replace(hour=0,second=0,minute=0)
|
| 11606 |
vikram.rag |
2979 |
deal.dealTextOption = privatedeal.dealTextOption
|
| 11531 |
vikram.rag |
2980 |
deal.dealText = privatedeal.dealText
|
|
|
2981 |
deal.isCod = privatedeal.isCod
|
|
|
2982 |
deal.rank = privatedeal.rank
|
| 11566 |
vikram.rag |
2983 |
deal.dealFreebieOption = privatedeal.dealFreebieOption
|
| 11606 |
vikram.rag |
2984 |
deal.isActive = privatedeal.isActive
|
| 11531 |
vikram.rag |
2985 |
session.commit()
|
|
|
2986 |
return True
|
|
|
2987 |
except Exception as e:
|
| 11606 |
vikram.rag |
2988 |
print 'Exception in updating private deals'
|
| 11531 |
vikram.rag |
2989 |
print e
|
| 11606 |
vikram.rag |
2990 |
return False
|
| 11645 |
amit.gupta |
2991 |
|
|
|
2992 |
def get_private_deals_query():
|
| 13076 |
amit.gupta |
2993 |
return session.query(Item).join((PrivateDeals,Item.id==PrivateDeals.item_id)).filter(Item.status==status.ACTIVE).filter(PrivateDeals.isActive==True).filter(now().between(PrivateDeals.startDate, PrivateDeals.endDate)).group_by(Item.catalog_item_id).order_by(desc(PrivateDeals.rank))
|
| 11635 |
vikram.rag |
2994 |
|
| 11645 |
amit.gupta |
2995 |
def get_private_deals_count():
|
| 11857 |
amit.gupta |
2996 |
return session.query(func.count(distinct(Item.catalog_item_id))).join((PrivateDeals,Item.id==PrivateDeals.item_id)).filter(Item.status==status.ACTIVE).filter(PrivateDeals.isActive==True).filter(now().between(PrivateDeals.startDate, PrivateDeals.endDate)).scalar()
|
| 11645 |
amit.gupta |
2997 |
|
| 11635 |
vikram.rag |
2998 |
def get_private_deals_catalog_ids(offset,limit):
|
| 11645 |
amit.gupta |
2999 |
private_deal_items = get_private_deals_query().offset(offset).limit(limit).all()
|
| 11635 |
vikram.rag |
3000 |
if private_deal_items is None:
|
| 11645 |
amit.gupta |
3001 |
return []
|
| 11635 |
vikram.rag |
3002 |
else:
|
| 11908 |
kshitij.so |
3003 |
return [item.catalog_item_id for item in private_deal_items]
|
|
|
3004 |
|
|
|
3005 |
def get_amazon_out_of_sync(itemId):
|
|
|
3006 |
return AmazonOutOfSync.get_by(item_id=itemId)
|
|
|
3007 |
|
|
|
3008 |
def get_all_private_deals_comparison():
|
| 12133 |
kshitij.so |
3009 |
return session.query(PrivateDealsPriceComparison,Item).join((Item,PrivateDealsPriceComparison.item_id==Item.id)).all()
|
|
|
3010 |
|
| 13709 |
manish.sha |
3011 |
'''
|
|
|
3012 |
def get_all_deal_tags():
|
|
|
3013 |
return session.query(DealTag).all()
|
|
|
3014 |
|
|
|
3015 |
def get_active_tags_for_item(itemId):
|
|
|
3016 |
return session.query(ItemTag).filter(ItemTag.itemId == itemId).filter(ItemTag.status == True).all()
|
|
|
3017 |
|
|
|
3018 |
def get_item_tag_for_item(itemId, tagId):
|
|
|
3019 |
tag = session.query(ItemTag).filter(ItemTag.itemId == itemId).filter(ItemTag.tagId == tagId).first()
|
|
|
3020 |
if tag:
|
|
|
3021 |
return tag
|
|
|
3022 |
else:
|
|
|
3023 |
return None
|
|
|
3024 |
|
|
|
3025 |
def get_all_item_tags_by_item_id(itemId):
|
|
|
3026 |
tag_list = []
|
|
|
3027 |
tag_list.append(session.query(ItemTag).filter(ItemTag.itemId == itemId).filter(ItemTag.status == True).first())
|
|
|
3028 |
return tag_list
|
|
|
3029 |
|
|
|
3030 |
def add_update_item_tag(itemTag, makeStatusInactive):
|
|
|
3031 |
if itemTag is None:
|
|
|
3032 |
raise CatalogServiceException(109, "Item Tag not found")
|
|
|
3033 |
|
|
|
3034 |
exist_tag = get_item_tag_for_item(itemTag.itemId, itemTag.tagId)
|
|
|
3035 |
if makeStatusInactive :
|
|
|
3036 |
for tag in get_active_tags_for_item(itemTag.itemId):
|
|
|
3037 |
tag.status = False
|
|
|
3038 |
session.commit()
|
|
|
3039 |
return True
|
|
|
3040 |
else:
|
|
|
3041 |
if exist_tag:
|
|
|
3042 |
exist_tag.startDate = to_py_date(itemTag.startDate)
|
|
|
3043 |
if itemTag.endDate:
|
|
|
3044 |
exist_tag.endDate = to_py_date(itemTag.endDate)
|
|
|
3045 |
else:
|
|
|
3046 |
exist_tag.endDate = None
|
|
|
3047 |
exist_tag.status = True
|
|
|
3048 |
session.commit()
|
|
|
3049 |
return True
|
|
|
3050 |
else:
|
|
|
3051 |
tag = ItemTag()
|
|
|
3052 |
tag.itemId = itemTag.itemId
|
|
|
3053 |
tag.tagId = itemTag.tagId
|
|
|
3054 |
tag.startDate = to_py_date(itemTag.startDate)
|
|
|
3055 |
if itemTag.endDate:
|
|
|
3056 |
tag.endDate = to_py_date(itemTag.endDate)
|
|
|
3057 |
tag.status = True
|
|
|
3058 |
session.commit()
|
|
|
3059 |
return True
|
|
|
3060 |
|
|
|
3061 |
return False
|
|
|
3062 |
'''
|
|
|
3063 |
|
| 12133 |
kshitij.so |
3064 |
def get_all_snapdeal_marketplaceItem():
|
|
|
3065 |
return session.query(SnapdealItem,MarketplaceItems,Item).join((MarketplaceItems,SnapdealItem.item_id==MarketplaceItems.itemId)).join((Item,SnapdealItem.item_id==Item.id)).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
|
|
|
3066 |
|
|
|
3067 |
def get_all_flipkart_marketplaceItem():
|
|
|
3068 |
return session.query(FlipkartItem,MarketplaceItems,Item).join((MarketplaceItems,FlipkartItem.item_id==MarketplaceItems.itemId)).join((Item,FlipkartItem.item_id==Item.id)).filter(MarketplaceItems.source==OrderSource.FLIPKART).all()
|
|
|
3069 |
|
| 12243 |
kshitij.so |
3070 |
def add_competitor_scraping(competitorScrapingMap):
|
| 12256 |
kshitij.so |
3071 |
cpr = __add_request_competitor_scraping(competitorScrapingMap.itervalues().next())
|
| 12243 |
kshitij.so |
3072 |
for competitorScraping in competitorScrapingMap.itervalues():
|
|
|
3073 |
cp = CompetitorPricing()
|
|
|
3074 |
cp.item_id = competitorScraping.item_id
|
|
|
3075 |
cp.snapdealScraping = competitorScraping.isSnapdeal
|
|
|
3076 |
cp.flipkartScraping = competitorScraping.isFlipkart
|
|
|
3077 |
cp.amazonScraping = competitorScraping.isAmazon
|
| 12256 |
kshitij.so |
3078 |
cp.competitorPricing = cpr
|
| 12243 |
kshitij.so |
3079 |
session.commit()
|
| 12133 |
kshitij.so |
3080 |
|
| 12256 |
kshitij.so |
3081 |
def __add_request_competitor_scraping(data):
|
|
|
3082 |
cpr = CompetitorPricingRequest()
|
|
|
3083 |
cpr.requestId = data.uploadId
|
|
|
3084 |
cpr.user = data.userEmail
|
|
|
3085 |
return cpr
|
|
|
3086 |
|
|
|
3087 |
|
| 12243 |
kshitij.so |
3088 |
def get_previous_competitor_scraping(delta):
|
|
|
3089 |
result = []
|
| 12256 |
kshitij.so |
3090 |
items = session.query(func.count(CompetitorPricing.item_id),CompetitorPricing.competitorPricing_requestId,CompetitorPricingRequest.isProcessed,CompetitorPricingRequest.user).join((CompetitorPricingRequest,CompetitorPricingRequest.requestId==CompetitorPricing.competitorPricing_requestId)).group_by(CompetitorPricing.competitorPricing_requestId).order_by(desc(CompetitorPricing.competitorPricing_requestId)).limit(delta).all()
|
| 12243 |
kshitij.so |
3091 |
for item in items:
|
|
|
3092 |
t_competitorPricing = TCompetitorPricing()
|
|
|
3093 |
t_competitorPricing.item_id = item[0]
|
|
|
3094 |
t_competitorPricing.uploadId = item[1]
|
|
|
3095 |
t_competitorPricing.processed = item[2]
|
| 12256 |
kshitij.so |
3096 |
t_competitorPricing.userEmail = item[3]
|
| 12243 |
kshitij.so |
3097 |
result.append(t_competitorPricing)
|
|
|
3098 |
return result
|
| 12256 |
kshitij.so |
3099 |
|
|
|
3100 |
def get_upload_result_by_id(uploadId):
|
|
|
3101 |
return session.query(CompetitorPricing,Item).join((Item,CompetitorPricing.item_id==Item.id)).filter(CompetitorPricing.competitorPricing_requestId==uploadId).all()
|
| 12363 |
kshitij.so |
3102 |
|
|
|
3103 |
def add_amazon_promotion(amazonPromotions):
|
| 12947 |
kshitij.so |
3104 |
notAdded = []
|
| 12363 |
kshitij.so |
3105 |
for sku, amazonPromotion in amazonPromotions.iteritems():
|
| 12947 |
kshitij.so |
3106 |
amazonSku = sku.strip().upper()
|
|
|
3107 |
if amazonSku.startswith('FBA'):
|
|
|
3108 |
stateId = 1
|
|
|
3109 |
elif amazonSku.startswith('FBB'):
|
|
|
3110 |
stateId = 2
|
|
|
3111 |
elif amazonSku.startswith('FBG'):
|
|
|
3112 |
stateId = 3
|
| 15702 |
kshitij.so |
3113 |
elif amazonSku.startswith('FBD'):
|
|
|
3114 |
stateId = 0
|
| 12947 |
kshitij.so |
3115 |
else:
|
|
|
3116 |
notAdded.append(amazonSku)
|
|
|
3117 |
continue
|
|
|
3118 |
amazonItem = get_amazon_item_details(int(amazonSku[3:]))
|
|
|
3119 |
if amazonItem[0] is None:
|
|
|
3120 |
notAdded.append(amazonSku)
|
|
|
3121 |
continue
|
| 12363 |
kshitij.so |
3122 |
d_amazonPromotion = AmazonPromotion()
|
| 12947 |
kshitij.so |
3123 |
d_amazonPromotion.sku = amazonSku
|
| 12363 |
kshitij.so |
3124 |
d_amazonPromotion.standardPrice = amazonPromotion.standardPrice
|
|
|
3125 |
d_amazonPromotion.salePrice = amazonPromotion.salePrice
|
| 12464 |
kshitij.so |
3126 |
d_amazonPromotion.subsidy = amazonPromotion.subsidyAmount
|
| 12363 |
kshitij.so |
3127 |
d_amazonPromotion.startDate = to_py_date(amazonPromotion.startDate)
|
|
|
3128 |
d_amazonPromotion.endDate = to_py_date(amazonPromotion.endDate)
|
| 12663 |
kshitij.so |
3129 |
d_amazonPromotion.addedOn = to_py_date(amazonPromotion.addedOn)
|
|
|
3130 |
d_amazonPromotion.promotionActive = False
|
| 12363 |
kshitij.so |
3131 |
d_amazonPromotion.promotionType = amazonPromotion.promotionType
|
| 12947 |
kshitij.so |
3132 |
d_amazonPromotion.stateId = stateId
|
| 12663 |
kshitij.so |
3133 |
if d_amazonPromotion.promotionType == AmazonPromotionType._NAMES_TO_VALUES.get('LONGTERM'):
|
|
|
3134 |
if d_amazonPromotion.stateId == 1:
|
|
|
3135 |
amazonItem[0].fbaPromoPrice = amazonPromotion.salePrice
|
|
|
3136 |
amazonItem[0].fbaPromoStartDate = to_py_date(amazonPromotion.startDate)
|
|
|
3137 |
amazonItem[0].fbaPromoEndDate = to_py_date(amazonPromotion.endDate)
|
|
|
3138 |
amazonItem[0].fbaPromoActive = False
|
| 12888 |
kshitij.so |
3139 |
elif d_amazonPromotion.stateId == 2:
|
| 12663 |
kshitij.so |
3140 |
amazonItem[0].fbbPromoPrice = amazonPromotion.salePrice
|
|
|
3141 |
amazonItem[0].fbbPromoStartDate = to_py_date(amazonPromotion.startDate)
|
|
|
3142 |
amazonItem[0].fbbPromoEndDate = to_py_date(amazonPromotion.endDate)
|
|
|
3143 |
amazonItem[0].fbbPromoActive = False
|
| 15702 |
kshitij.so |
3144 |
elif d_amazonPromotion.stateId == 3:
|
| 12888 |
kshitij.so |
3145 |
amazonItem[0].fbgPromoPrice = amazonPromotion.salePrice
|
|
|
3146 |
amazonItem[0].fbgPromoStartDate = to_py_date(amazonPromotion.startDate)
|
|
|
3147 |
amazonItem[0].fbgPromoEndDate = to_py_date(amazonPromotion.endDate)
|
|
|
3148 |
amazonItem[0].fbgPromoActive = False
|
| 15702 |
kshitij.so |
3149 |
else:
|
|
|
3150 |
amazonItem[0].fbdPromoPrice = amazonPromotion.salePrice
|
|
|
3151 |
amazonItem[0].fbdPromoStartDate = to_py_date(amazonPromotion.startDate)
|
|
|
3152 |
amazonItem[0].fbdPromoEndDate = to_py_date(amazonPromotion.endDate)
|
|
|
3153 |
amazonItem[0].fbdPromoActive = False
|
| 12663 |
kshitij.so |
3154 |
else:
|
|
|
3155 |
d_amazonPromotion.promotionActive = True
|
| 12363 |
kshitij.so |
3156 |
session.commit()
|
| 12947 |
kshitij.so |
3157 |
return notAdded
|
| 12363 |
kshitij.so |
3158 |
|
|
|
3159 |
|
| 12567 |
amit.gupta |
3160 |
def get_vat_rates(itemId, categoryId):
|
|
|
3161 |
vatRates = {}
|
|
|
3162 |
item = get_item(itemId)
|
|
|
3163 |
for stateinfo in fetchStateMaster().values():
|
|
|
3164 |
price = item.sellingPrice
|
|
|
3165 |
if VatType.MRP == stateinfo.vatType:
|
|
|
3166 |
price = item.mrp
|
|
|
3167 |
vatRates[stateinfo.id] = get_vat_percentage_for_item_category(itemId, stateinfo.id, price, categoryId)
|
|
|
3168 |
return vatRates
|
|
|
3169 |
|
|
|
3170 |
def update_item_state_vat(itemId, stateVat):
|
|
|
3171 |
for k,v in stateVat.iteritems():
|
|
|
3172 |
itemVat = ItemVatMaster.query.filter(and_(ItemVatMaster.itemId==itemId, ItemVatMaster.stateId==k)).first()
|
|
|
3173 |
if itemVat:
|
|
|
3174 |
itemVat.vatPercentage = v
|
|
|
3175 |
else:
|
|
|
3176 |
itemVat = ItemVatMaster()
|
|
|
3177 |
itemVat.itemId = itemId
|
|
|
3178 |
itemVat.stateId = k
|
|
|
3179 |
itemVat.vatPercentage = v
|
|
|
3180 |
session.commit()
|
|
|
3181 |
return True
|
|
|
3182 |
|
|
|
3183 |
def mark_partially_active(itemId, categoryId):
|
|
|
3184 |
item = get_item(itemId)
|
|
|
3185 |
item.category = categoryId
|
|
|
3186 |
item.status = 8
|
|
|
3187 |
item.status_description = 'Partially Active'
|
|
|
3188 |
session.commit()
|
|
|
3189 |
return True
|
|
|
3190 |
|
| 12363 |
kshitij.so |
3191 |
def get_amazon_promotion(startDate,endDate):
|
|
|
3192 |
return AmazonPromotion.query.filter(AmazonPromotion.startDate>=(to_py_date(startDate))).filter(AmazonPromotion.endDate<=(to_py_date(endDate))).all()
|
|
|
3193 |
|
|
|
3194 |
def update_amazon_promotion(amazonPromotions):
|
|
|
3195 |
for amazonPromotion in amazonPromotions:
|
| 12666 |
kshitij.so |
3196 |
amp = AmazonPromotion.get_by(sku=amazonPromotion.sku,addedOn=to_py_date(amazonPromotion.addedOn), promotionType = amazonPromotion.promotionType )
|
| 12663 |
kshitij.so |
3197 |
amp.promotionActive = True
|
|
|
3198 |
amp.updatedOnMarketplace = datetime.datetime.now()
|
| 12670 |
kshitij.so |
3199 |
if amp.promotionType == 1:
|
| 12663 |
kshitij.so |
3200 |
amazonItem = get_amazon_item_details(int(amp.sku[3:]))
|
|
|
3201 |
if amp.stateId == 1:
|
| 12670 |
kshitij.so |
3202 |
amazonItem[0].fbaPromotionActive = True
|
| 12888 |
kshitij.so |
3203 |
elif amp.stateId == 2:
|
|
|
3204 |
amazonItem[0].fbbPromotionActive = True
|
| 15702 |
kshitij.so |
3205 |
elif amp.stateId == 3:
|
|
|
3206 |
amazonItem[0].fbgPromotionActive = True
|
| 12663 |
kshitij.so |
3207 |
else:
|
| 15702 |
kshitij.so |
3208 |
amazonItem[0].fbdPromotionActive = True
|
| 12363 |
kshitij.so |
3209 |
session.commit()
|
| 12668 |
kshitij.so |
3210 |
return True
|
| 12363 |
kshitij.so |
3211 |
|
| 13136 |
amit.gupta |
3212 |
def check_services(map_lines):
|
|
|
3213 |
for key in map_lines.keys():
|
|
|
3214 |
line = map_lines[key]
|
|
|
3215 |
if line['insurer'] > 0 :
|
|
|
3216 |
insurerId = get_preffered_insurer_for_item(key,InsurerType.DEVICE)
|
|
|
3217 |
line['insurer'] = insurerId
|
|
|
3218 |
line['insureramount'] = get_insurance_amount(key, line['amount'], insurerId, line['quantity'])
|
|
|
3219 |
if line['dpinsurer'] > 0:
|
|
|
3220 |
insurerId = get_preffered_insurer_for_item(key,InsurerType.DATA)
|
|
|
3221 |
line['dpinsurer'] = insurerId
|
|
|
3222 |
line['dpinsureramount'] = get_insurance_amount(key, line['amount'], insurerId, line['quantity'])
|
|
|
3223 |
return map_lines
|
|
|
3224 |
|
| 12363 |
kshitij.so |
3225 |
def __get_amazon_promotion_attributes_for_item(item_id):
|
|
|
3226 |
timestamp = datetime.datetime.now()
|
| 12665 |
kshitij.so |
3227 |
fbaPromo = AmazonPromotion.query.filter(AmazonPromotion.sku=='FBA'+str(item_id)).filter(AmazonPromotion.startDate<=timestamp).filter(AmazonPromotion.endDate>=timestamp).filter(AmazonPromotion.updatedOnMarketplace>to_py_date(0)).order_by(desc(AmazonPromotion.updatedOnMarketplace)).limit(1).all()
|
|
|
3228 |
fbbPromo = AmazonPromotion.query.filter(AmazonPromotion.sku=='FBB'+str(item_id)).filter(AmazonPromotion.startDate<=timestamp).filter(AmazonPromotion.endDate>=timestamp).filter(AmazonPromotion.updatedOnMarketplace>to_py_date(0)).order_by(desc(AmazonPromotion.updatedOnMarketplace)).limit(1).all()
|
| 12888 |
kshitij.so |
3229 |
fbgPromo = AmazonPromotion.query.filter(AmazonPromotion.sku=='FBG'+str(item_id)).filter(AmazonPromotion.startDate<=timestamp).filter(AmazonPromotion.endDate>=timestamp).filter(AmazonPromotion.updatedOnMarketplace>to_py_date(0)).order_by(desc(AmazonPromotion.updatedOnMarketplace)).limit(1).all()
|
| 15702 |
kshitij.so |
3230 |
fbdPromo = AmazonPromotion.query.filter(AmazonPromotion.sku=='FBD'+str(item_id)).filter(AmazonPromotion.startDate<=timestamp).filter(AmazonPromotion.endDate>=timestamp).filter(AmazonPromotion.updatedOnMarketplace>to_py_date(0)).order_by(desc(AmazonPromotion.updatedOnMarketplace)).limit(1).all()
|
|
|
3231 |
return fbaPromo, fbbPromo, fbgPromo, fbdPromo
|
| 12665 |
kshitij.so |
3232 |
|
|
|
3233 |
def get_ex_affiliate_item_info():
|
|
|
3234 |
query = session.query(ExclusiveAffiliateItemInfo, OutboundAffiliateMaster.name).join((OutboundAffiliateMaster, ExclusiveAffiliateItemInfo.affiliateId==OutboundAffiliateMaster.id)).filter(ExclusiveAffiliateItemInfo.isActive == True).all()
|
|
|
3235 |
close_session()
|
|
|
3236 |
map = {}
|
|
|
3237 |
for q in query:
|
|
|
3238 |
map[q[0].itemId]=to_t_exclusive_affiliate_item_info(q)
|
| 12888 |
kshitij.so |
3239 |
return map
|
|
|
3240 |
|
|
|
3241 |
def get_all_items_to_list_on_fbg():
|
|
|
3242 |
return Amazonlisted.query.filter(Amazonlisted.isFbg==False).filter(or_(Amazonlisted.fbgtaxCode!=None,Amazonlisted.fbgtaxCode!="")).all()
|
|
|
3243 |
|
|
|
3244 |
def get_all_fbg_listed_items():
|
|
|
3245 |
return Amazonlisted.query.filter(Amazonlisted.isFbg==True).all()
|
| 13709 |
manish.sha |
3246 |
|
|
|
3247 |
def add_hs_item(hsItems):
|
|
|
3248 |
for hsItem in hsItems:
|
|
|
3249 |
hs_item = HsItem.get_by(hsItemId = hsItem.hsItemId)
|
|
|
3250 |
if hs_item is None:
|
|
|
3251 |
hs_item = HsItem()
|
|
|
3252 |
hs_item.addedBy = hsItem.addedBy
|
|
|
3253 |
hs_item.addedTimestamp = to_py_date(hsItem.addedTimestamp)
|
|
|
3254 |
hs_item.defaultWarehouseId = hsItem.defaultWarehouseId
|
|
|
3255 |
hs_item.hsItemId = hsItem.hsItemId
|
|
|
3256 |
hs_item.hsProductId = hsItem.hsProductId
|
|
|
3257 |
hs_item.itemId = hsItem.itemId
|
|
|
3258 |
hs_item.listingPrice = hsItem.listingPrice
|
|
|
3259 |
session.commit()
|
|
|
3260 |
|
|
|
3261 |
def update_hs_item(hsItem):
|
|
|
3262 |
hs_item = HsItem.get_by(hsItemId = hsItem.hsItemId)
|
|
|
3263 |
hs_item.addedBy = hsItem.addedBy
|
|
|
3264 |
hs_item.addedTimestamp = to_py_date(hsItem.addedTimestamp)
|
|
|
3265 |
hs_item.defaultWarehouseId = hsItem.defaultWarehouseId
|
|
|
3266 |
hs_item.itemId = hsItem.itemId
|
|
|
3267 |
hs_item.listingPrice = hsItem.listingPrice
|
|
|
3268 |
session.commit()
|
|
|
3269 |
|
|
|
3270 |
def get_hs_item(hs_ItemId):
|
|
|
3271 |
hsItem = HsItem.get_by(hsItemId = hs_ItemId)
|
| 14182 |
kshitij.so |
3272 |
return hsItem
|
|
|
3273 |
|
|
|
3274 |
def get_pricing_for_dtr(catalogItemId):
|
|
|
3275 |
d_item = None
|
| 18719 |
kshitij.so |
3276 |
bulkPricingMap = {}
|
| 14182 |
kshitij.so |
3277 |
now = datetime.datetime.now()
|
|
|
3278 |
items = Item.query.filter(Item.catalog_item_id == catalogItemId).all()
|
|
|
3279 |
if items:
|
|
|
3280 |
for item in items:
|
|
|
3281 |
if item.status !=3 :
|
|
|
3282 |
continue
|
|
|
3283 |
pvt_deal_item = get_private_deal_details(item.id)
|
|
|
3284 |
if pvt_deal_item is not None and pvt_deal_item.isActive ==1 and pvt_deal_item.startDate < now and pvt_deal_item.endDate > now:
|
|
|
3285 |
item.sellingPrice = pvt_deal_item.dealPrice
|
|
|
3286 |
d_item = item
|
|
|
3287 |
break
|
|
|
3288 |
else:
|
|
|
3289 |
d_item = item
|
| 18719 |
kshitij.so |
3290 |
if d_item is not None:
|
|
|
3291 |
bulkPricingList = get_bulk_pricing_by_item_id(d_item.id)
|
|
|
3292 |
for bulkPricing in bulkPricingList:
|
|
|
3293 |
bulkPricingMap[bulkPricing.quantity] = bulkPricing.price
|
|
|
3294 |
|
|
|
3295 |
return d_item, bulkPricingMap
|
| 15702 |
kshitij.so |
3296 |
|
|
|
3297 |
def get_all_items_to_list_on_fbd():
|
|
|
3298 |
return Amazonlisted.query.filter(Amazonlisted.isFbd==False).filter(or_(Amazonlisted.fbdtaxCode!=None,Amazonlisted.fbdtaxCode!="")).all()
|
|
|
3299 |
|
|
|
3300 |
def get_all_fbd_listed_items():
|
|
|
3301 |
return Amazonlisted.query.filter(Amazonlisted.isFbd==True).all()
|
|
|
3302 |
|
| 18150 |
kshitij.so |
3303 |
def get_bulk_pricing_for_items(itemIds):
|
|
|
3304 |
itemMap = {}
|
| 18450 |
kshitij.so |
3305 |
if len(itemIds) ==0:
|
|
|
3306 |
items = BulkItemPricing.query.all()
|
|
|
3307 |
else:
|
|
|
3308 |
items = BulkItemPricing.query.filter(BulkItemPricing.item_id.in_(itemIds)).all()
|
| 18150 |
kshitij.so |
3309 |
for item in items:
|
|
|
3310 |
if not itemMap.has_key(item.item_id):
|
|
|
3311 |
itemMap[item.item_id] = [to_t_bulk_pricing(item)]
|
|
|
3312 |
else:
|
|
|
3313 |
(itemMap.get(item.item_id)).append(to_t_bulk_pricing(item))
|
|
|
3314 |
return itemMap
|
|
|
3315 |
|
|
|
3316 |
def add_bulk_pricing_for_item(bulkItemPricing):
|
|
|
3317 |
exist = BulkItemPricing.query.filter(BulkItemPricing.item_id==bulkItemPricing.item_id).filter(BulkItemPricing.quantity==bulkItemPricing.quantity).all()
|
|
|
3318 |
if len(exist) > 0:
|
|
|
3319 |
raise
|
|
|
3320 |
d_BulkItemPricing = BulkItemPricing()
|
|
|
3321 |
d_BulkItemPricing.item_id = bulkItemPricing.item_id
|
|
|
3322 |
d_BulkItemPricing.quantity = bulkItemPricing.quantity
|
|
|
3323 |
d_BulkItemPricing.price = bulkItemPricing.price
|
|
|
3324 |
session.commit()
|
|
|
3325 |
return d_BulkItemPricing
|
|
|
3326 |
|
|
|
3327 |
def get_bulk_pricing_by_item_id(itemId):
|
| 18719 |
kshitij.so |
3328 |
bulkPricingItems = BulkItemPricing.query.filter(BulkItemPricing.item_id==itemId).order_by(asc(BulkItemPricing.quantity)).all()
|
| 18150 |
kshitij.so |
3329 |
return bulkPricingItems
|
|
|
3330 |
|
|
|
3331 |
def delete_bulk_pricing_for_item_by_id(id):
|
|
|
3332 |
bulkPricingItems = BulkItemPricing.query.filter(BulkItemPricing.id==id).all()
|
|
|
3333 |
if len(bulkPricingItems) > 0:
|
|
|
3334 |
bulkPricingItems[0].delete()
|
|
|
3335 |
session.commit()
|
|
|
3336 |
return True
|
|
|
3337 |
else:
|
|
|
3338 |
return False
|
|
|
3339 |
|
|
|
3340 |
def delete_bulk_pricing_for_item(itemId):
|
|
|
3341 |
session.query(BulkItemPricing).filter_by(item_id=itemId).delete()
|
|
|
3342 |
session.commit()
|
|
|
3343 |
return True
|
|
|
3344 |
|
| 18450 |
kshitij.so |
3345 |
def update_bulk_prices_on_production(itemId, bulkItemPricingList):
|
|
|
3346 |
session.query(BulkItemPricing).filter_by(item_id=itemId).delete()
|
|
|
3347 |
session.commit()
|
|
|
3348 |
for bulkItem in bulkItemPricingList:
|
|
|
3349 |
d_bulkItem = BulkItemPricing()
|
|
|
3350 |
d_bulkItem.id = bulkItem.id
|
|
|
3351 |
d_bulkItem.price = bulkItem.price
|
|
|
3352 |
d_bulkItem.quantity = bulkItem.quantity
|
|
|
3353 |
d_bulkItem.item_id = bulkItem.item_id
|
| 18595 |
kshitij.so |
3354 |
session.commit()
|
| 18764 |
kshitij.so |
3355 |
return True
|
| 18450 |
kshitij.so |
3356 |
|
| 18764 |
kshitij.so |
3357 |
def get_cart_by_value(cartIds):
|
|
|
3358 |
itemList = []
|
|
|
3359 |
uc = UserClient().get_client()
|
|
|
3360 |
returnMap = uc.getCartByValue(cartIds)
|
|
|
3361 |
cartMap = {}
|
|
|
3362 |
for lines in returnMap.itervalues():
|
|
|
3363 |
for line in lines:
|
|
|
3364 |
if not line.itemId in itemList:
|
|
|
3365 |
itemList.append(line.itemId)
|
|
|
3366 |
items = session.query(Category.parent_category_id,Item.id).join((Item,Category.id==Item.category)).filter(Item.id.in_(itemList)).all()
|
|
|
3367 |
for item in items:
|
| 18814 |
kshitij.so |
3368 |
if item[0] in (10001, 10009, 10049, 11001):
|
|
|
3369 |
try:
|
|
|
3370 |
itemList.remove(item[1])
|
|
|
3371 |
except:
|
|
|
3372 |
pass
|
| 18764 |
kshitij.so |
3373 |
for cart_id, lines in returnMap.iteritems():
|
|
|
3374 |
actual_price = 0
|
|
|
3375 |
for line in lines:
|
|
|
3376 |
if line.itemId in itemList:
|
| 18813 |
kshitij.so |
3377 |
actual_price = actual_price + line.quantity*line.actualPrice
|
| 18764 |
kshitij.so |
3378 |
cartMap[cart_id] = actual_price
|
| 18815 |
kshitij.so |
3379 |
sorted_x = sorted(cartMap.items(), key=operator.itemgetter(1),reverse=True)
|
| 18765 |
kshitij.so |
3380 |
return [cart_id[0] for cart_id in sorted_x]
|
| 18764 |
kshitij.so |
3381 |
|
| 15702 |
kshitij.so |
3382 |
if __name__=='__main__':
|
|
|
3383 |
DataService.initialize()
|
| 18450 |
kshitij.so |
3384 |
#update_bulk_prices_on_production(21053,[])
|
| 18765 |
kshitij.so |
3385 |
print get_cart_by_value([1005394,46868158])
|
| 18150 |
kshitij.so |
3386 |
|