| Line 6... |
Line 6... |
| 6 |
from elixir import *
|
6 |
from elixir import *
|
| 7 |
from shop2020.model.v1.catalog.impl import DataService
|
7 |
from shop2020.model.v1.catalog.impl import DataService
|
| 8 |
from shop2020.model.v1.catalog.impl.DataService import Item, \
|
8 |
from shop2020.model.v1.catalog.impl.DataService import Item, \
|
| 9 |
Warehouse, ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo,\
|
9 |
Warehouse, ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo,\
|
| 10 |
ItemChangeLog, Category, EntityIDGenerator, VendorItemPricing,\
|
10 |
ItemChangeLog, Category, EntityIDGenerator, VendorItemPricing,\
|
| 11 |
VendorItemMapping, Vendor, SimilarItems, ProductNotification
|
11 |
VendorItemMapping, Vendor, SimilarItems, ProductNotification, Source, SourceItemPricing
|
| 12 |
from shop2020.thriftpy.model.v1.catalog.ttypes import \
|
12 |
from shop2020.thriftpy.model.v1.catalog.ttypes import \
|
| 13 |
InventoryServiceException, status, ItemShippingInfo
|
13 |
InventoryServiceException, status, ItemShippingInfo
|
| 14 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item,\
|
14 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item,\
|
| 15 |
to_t_vendor_item_pricing
|
15 |
to_t_vendor_item_pricing, to_t_source
|
| 16 |
import datetime
|
16 |
import datetime
|
| 17 |
import sys
|
17 |
import sys
|
| 18 |
from shop2020.utils.Utils import log_entry, to_py_date, log_risky_flag
|
18 |
from shop2020.utils.Utils import log_entry, to_py_date, log_risky_flag
|
| 19 |
from sqlalchemy import desc, asc
|
19 |
from sqlalchemy import desc, asc
|
| 20 |
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
20 |
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
| Line 1070... |
Line 1070... |
| 1070 |
helper_client = HelperClient().get_client()
|
1070 |
helper_client = HelperClient().get_client()
|
| 1071 |
helper_client.saveUserEmailForSending(email, "", "Product requested by you is available now.", html, str(itemId), "ProductNotification")
|
1071 |
helper_client.saveUserEmailForSending(email, "", "Product requested by you is available now.", html, str(itemId), "ProductNotification")
|
| 1072 |
except Exception as e:
|
1072 |
except Exception as e:
|
| 1073 |
print e
|
1073 |
print e
|
| 1074 |
|
1074 |
|
| - |
|
1075 |
def get_all_sources():
|
| - |
|
1076 |
sources = Source.query.all()
|
| - |
|
1077 |
return [to_t_source(source) for source in sources]
|
| - |
|
1078 |
|
| - |
|
1079 |
def get_item_pricing_by_source(itemId, sourceId):
|
| - |
|
1080 |
item = Item.query.filter_by(id=itemId).first()
|
| - |
|
1081 |
if item is None:
|
| - |
|
1082 |
raise InventoryServiceException(101, "Bad Item")
|
| - |
|
1083 |
|
| - |
|
1084 |
source = Source.query.filter_by(id=sourceId).first()
|
| - |
|
1085 |
if source is None:
|
| - |
|
1086 |
raise InventoryServiceException(101, "Source not found for sourceId " + str(sourceId))
|
| - |
|
1087 |
|
| - |
|
1088 |
item_pricing = SourceItemPricing.query.filter_by(source=source, item=item).first()
|
| - |
|
1089 |
if item_pricing is None:
|
| - |
|
1090 |
raise InventoryServiceException(101, "Pricing information not found for sourceId " + str(sourceId))
|
| - |
|
1091 |
return item_pricing
|
| - |
|
1092 |
|
| - |
|
1093 |
def add_source_item_pricing(sourceItemPricing):
|
| - |
|
1094 |
if not sourceItemPricing:
|
| - |
|
1095 |
raise InventoryServiceException(108, "Bad sourceItemPricing in request")
|
| - |
|
1096 |
|
| - |
|
1097 |
if not sourceItemPricing.sellingPrice:
|
| - |
|
1098 |
raise InventoryServiceException(101, "Selling Price is not defined for sourceId " + str(sourceId))
|
| - |
|
1099 |
|
| - |
|
1100 |
sourceId = sourceItemPricing.sourceId
|
| - |
|
1101 |
itemId = sourceItemPricing.itemId
|
| - |
|
1102 |
|
| - |
|
1103 |
item = Item.query.filter_by(id=itemId).first()
|
| - |
|
1104 |
if item is None:
|
| - |
|
1105 |
raise InventoryServiceException(101, "Bad Item")
|
| - |
|
1106 |
|
| - |
|
1107 |
source = Source.query.filter_by(id=sourceId).first()
|
| - |
|
1108 |
if source is None:
|
| - |
|
1109 |
raise InventoryServiceException(101, "Source not found for sourceId " + str(sourceId))
|
| - |
|
1110 |
|
| - |
|
1111 |
ds_sourceItemPricing = SourceItemPricing.query.get_by(SourceItemPricing.source==source, SourceItemPricing.item==item)
|
| - |
|
1112 |
if ds_sourceItemPricing is None:
|
| - |
|
1113 |
ds_sourceItemPricing = SourceItemPricing()
|
| - |
|
1114 |
ds_sourceItemPricing.source = source
|
| - |
|
1115 |
ds_sourceItemPricing.item = item
|
| - |
|
1116 |
|
| - |
|
1117 |
if sourceItemPricing.mrp:
|
| - |
|
1118 |
ds_sourceItemPricing.mrp = sourceItemPricing.mrp
|
| - |
|
1119 |
ds_sourceItemPricing.sellingPrice = sourceItemPricing.sellingPrice
|
| - |
|
1120 |
|
| - |
|
1121 |
session.commit()
|
| - |
|
1122 |
return
|
| - |
|
1123 |
|
| - |
|
1124 |
def get_all_source_pricing(itemId):
|
| - |
|
1125 |
item = Item.query.filter_by(id=itemId).first()
|
| - |
|
1126 |
if item is None:
|
| - |
|
1127 |
raise InventoryServiceException(101, "Bad Item")
|
| - |
|
1128 |
source_pricing = SourceItemPricing.query.filter_by(item=item).all()
|
| - |
|
1129 |
return source_pricing
|
| - |
|
1130 |
|
| - |
|
1131 |
|
| - |
|
1132 |
def get_item_for_source(item_id, sourceId):
|
| - |
|
1133 |
item = get_item(item_id)
|
| - |
|
1134 |
if sourceId == -1:
|
| - |
|
1135 |
return item
|
| - |
|
1136 |
try:
|
| - |
|
1137 |
sip = get_item_pricing_by_source(item_id, sourceId)
|
| - |
|
1138 |
item.sellingPrice = sip.sellingPrice
|
| - |
|
1139 |
if sip.mrp:
|
| - |
|
1140 |
item.mrp = sip.mrp
|
| - |
|
1141 |
except:
|
| - |
|
1142 |
print "No source pricing"
|
| - |
|
1143 |
return item
|
| 1075 |
|
1144 |
|
| 1076 |
def close_session():
|
1145 |
def close_session():
|
| 1077 |
if session.is_active:
|
1146 |
if session.is_active:
|
| 1078 |
print "session is active. closing it."
|
1147 |
print "session is active. closing it."
|
| 1079 |
session.close()
|
1148 |
session.close()
|