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