| 20644 |
amit.gupta |
1 |
# -*- coding: utf-8 -*-
|
|
|
2 |
|
|
|
3 |
'''
|
|
|
4 |
Created on 29-Mar-2010
|
|
|
5 |
|
|
|
6 |
@author: Chandranshu
|
|
|
7 |
'''
|
|
|
8 |
|
|
|
9 |
from datetime import date, timedelta
|
|
|
10 |
from decimal import Decimal
|
|
|
11 |
from elixir import *
|
|
|
12 |
from math import ceil
|
|
|
13 |
from random import randrange
|
|
|
14 |
from reportlab.lib import colors
|
|
|
15 |
from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY
|
|
|
16 |
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
|
|
|
17 |
from reportlab.lib.units import inch, mm
|
|
|
18 |
from reportlab.pdfgen.canvas import Canvas
|
|
|
19 |
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, \
|
|
|
20 |
BaseDocTemplate, Frame, PageTemplate, Table, TableStyle
|
|
|
21 |
from shop2020.clients.AlertClient import AlertClient
|
|
|
22 |
from shop2020.clients.CRMClient import CRMClient
|
|
|
23 |
from shop2020.clients.CatalogClient import CatalogClient
|
|
|
24 |
from shop2020.clients.HelperClient import HelperClient
|
|
|
25 |
from shop2020.clients.InventoryClient import InventoryClient
|
|
|
26 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
|
|
27 |
from shop2020.clients.PaymentClient import PaymentClient
|
|
|
28 |
from shop2020.clients.PromotionClient import PromotionClient
|
|
|
29 |
from shop2020.clients.UserClient import UserClient
|
|
|
30 |
from shop2020.clients.WarehouseClient import WarehouseClient
|
|
|
31 |
from shop2020.config.client.ConfigClient import ConfigClient
|
|
|
32 |
from shop2020.model.v1 import order
|
|
|
33 |
from shop2020.model.v1.order.impl import DataService, RechargeService
|
|
|
34 |
from shop2020.model.v1.order.impl.Convertors import to_t_emi_scheme, to_t_order, \
|
|
|
35 |
cutoff_date, to_t_warehouse_address
|
|
|
36 |
from shop2020.model.v1.order.impl.DataAccessors import get_order, \
|
|
|
37 |
get_transaction, get_orders_by_mobile_number, __clone_order, delhi_pincodes, \
|
|
|
38 |
__create_recharge_voucher_tracker, __push_store_collection_to_hotspot, \
|
|
|
39 |
get_hotspot_store, get_source_detail
|
|
|
40 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
|
|
|
41 |
Order, BatchNoGenerator, InvoiceIDGenerator, TransactionRequiringExtraProcessing, \
|
|
|
42 |
OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary, \
|
|
|
43 |
CodVerificationAgent, Attribute, RechargeVoucherTracker, EmiScheme, MiscCharges, \
|
|
|
44 |
BlockedIpRange, DeniedIpAddress, InsuranceDetailForOrder, DocumentStore, \
|
|
|
45 |
RechargeTransaction, HotspotStore, WalletForCompany, WalletHistoryForCompany, \
|
|
|
46 |
FRC, OperatorSeries, SourceDetail, Company, EbayOrder, AmazonFbaSalesSnapshot, \
|
|
|
47 |
AmazonOrder, StoreOrderDetail, EdcBank, StoreOrderCollection, \
|
|
|
48 |
HotspotServiceMatrix, SnapdealOrder, FlipkartOrder, DataInsuranceDetailForOrder, \
|
|
|
49 |
AmazonFbaOrderReturns, FlipkartAdvantageOrder, InvoiceCounterGenerator, \
|
|
|
50 |
TransactionShipmentSequence, HsOrder, Creditor, UserSanction, CreditHistory, \
|
|
|
51 |
LoanHistory, ShipmentLogisticsCostDetail, ReturnOrderInfo, ReturnTransaction, \
|
|
|
52 |
ReturnPickupRequest, SellerWarehouse, Seller, Organisation, \
|
|
|
53 |
WarehouseAddressMapping, WarehouseAddressMaster
|
|
|
54 |
from shop2020.model.v1.order.impl.model.BaseOrder import BaseOrder
|
|
|
55 |
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
|
|
|
56 |
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import \
|
|
|
57 |
MobileRechargeOrder
|
|
|
58 |
from shop2020.model.v1.order.impl.model.RechargeDenomination import \
|
|
|
59 |
RechargeDenomination
|
|
|
60 |
from shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrder
|
|
|
61 |
from shop2020.model.v1.order.impl.model.RechargePlan import RechargePlan
|
|
|
62 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
|
|
63 |
from shop2020.model.v1.order.impl.model.ServiceAvailability import \
|
|
|
64 |
ServiceAvailability
|
|
|
65 |
from shop2020.model.v1.order.impl.model.ServiceProvider import ServiceProvider
|
|
|
66 |
from shop2020.model.v1.order.impl.model.TelecomCircle import TelecomCircle
|
|
|
67 |
from shop2020.model.v1.order.impl.model.UserWallet import UserWallet
|
|
|
68 |
from shop2020.model.v1.order.impl.model.UserWalletHistory import \
|
|
|
69 |
UserWalletHistory
|
|
|
70 |
from shop2020.model.v1.user.impl.Converters import to_t_address
|
|
|
71 |
from shop2020.thriftpy.alert.ttypes import MonitoredEntity, EntityType
|
|
|
72 |
from shop2020.thriftpy.crm.ttypes import *
|
|
|
73 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType, PickUpType
|
|
|
74 |
from shop2020.thriftpy.model.v1.catalog.ttypes import ItemType, ItemCondition
|
|
|
75 |
from shop2020.thriftpy.model.v1.inventory.ttypes import BillingType, \
|
|
|
76 |
InventoryServiceException, WarehouseType, InventoryType, VatType, ItemInventory
|
|
|
77 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
|
|
78 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
|
|
79 |
HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType, RechargeOrderStatus, \
|
|
|
80 |
RechargeType, RechargeStatistics, DeviceNumberInfo, EmiChargeType, PayMethod, \
|
|
|
81 |
OrderSource, StorePaymentStatus, ProductCondition, TaxType, \
|
|
|
82 |
AmazonFCWarehouseLocation, RechargeMode, CreditTxnType, \
|
|
|
83 |
CreditHistory as TCreditHistory, LoanHistory as TLoanHistory, \
|
|
|
84 |
ShipmentLogisticsCostDetail as TShipmentLogisticsCostDetail, \
|
|
|
85 |
ReturnTransactionStatus, ReturnAction, ReturnTxnResolutionStatus, \
|
|
|
86 |
ReplacementShippingType, ReturnTxnPickupStatus, ReceivedReturnType, \
|
|
|
87 |
ReturnPickupType, RefundType, SellerInfo, BuyerInfo
|
|
|
88 |
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType, CouponCategory, \
|
|
|
89 |
User, Sex
|
|
|
90 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
|
|
91 |
from shop2020.thriftpy.utils.ttypes import UserSmsInfo, SmsType
|
|
|
92 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
|
|
|
93 |
WarehouseServiceException
|
|
|
94 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part, \
|
|
|
95 |
mail_html
|
|
|
96 |
from shop2020.utils.Utils import to_py_date, to_java_date, \
|
|
|
97 |
getSyncOperatorsForRecharge
|
|
|
98 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
|
|
99 |
from sqlalchemy.sql import func
|
|
|
100 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, \
|
|
|
101 |
between
|
|
|
102 |
from string import Template
|
|
|
103 |
from suds.client import Client
|
|
|
104 |
from textwrap import dedent
|
|
|
105 |
from xml.dom.minidom import parseString
|
|
|
106 |
import MySQLdb
|
|
|
107 |
import base64
|
|
|
108 |
import datetime
|
|
|
109 |
import httplib
|
|
|
110 |
import logging
|
|
|
111 |
import math
|
|
|
112 |
import os
|
|
|
113 |
import re
|
|
|
114 |
import sys
|
|
|
115 |
import time
|
|
|
116 |
import traceback
|
|
|
117 |
import urllib
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
|
|
122 |
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
|
|
123 |
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
|
|
124 |
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
|
|
125 |
logging.basicConfig(level=logging.DEBUG)
|
|
|
126 |
|
|
|
127 |
sourceId = int(ConfigClient().get_property("sourceid"))
|
|
|
128 |
capitalFloatPayMethod = 456789
|
|
|
129 |
SaholicHelpEmailId = "Saholic <help@saholic.com>"
|
|
|
130 |
mail_user = 'cnc.center@shop2020.in'
|
|
|
131 |
mail_password = '5h0p2o2o'
|
|
|
132 |
help_user = 'help@shop2020.in'
|
|
|
133 |
help_password = '5h0p2o2o'
|
|
|
134 |
source_url = 'www.saholic.com'
|
|
|
135 |
source_name = 'Saholic'
|
|
|
136 |
hotspot_store_url ='http://125.19.98.100/loaddetect/service.asmx?WSDL'
|
|
|
137 |
aclient = None
|
|
|
138 |
|
|
|
139 |
PREPAID_SHIPPING_CUTOFF_TIME = 15
|
|
|
140 |
COD_SHIPPING_CUTOFF_TIME = 12
|
|
|
141 |
|
|
|
142 |
billedOrdersColorMap = {}
|
|
|
143 |
|
|
|
144 |
ORDER_STATUS_TO_USER_TRUST_LEVEL_DELTA_DICT = {
|
|
|
145 |
OrderStatus.RTO_RESHIPPED : 3,
|
|
|
146 |
OrderStatus.RTO_IN_TRANSIT : -5,
|
|
|
147 |
OrderStatus.DELIVERY_SUCCESS : 1,
|
|
|
148 |
OrderStatus.DOA_CERT_INVALID : -5
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
creditTxnMultiplierMap = {
|
|
|
152 |
CreditTxnType.BLOCKED : 1,
|
|
|
153 |
CreditTxnType.BLOCKED_REVERSED : -1,
|
|
|
154 |
CreditTxnType.LOAN : -1,
|
|
|
155 |
CreditTxnType.CORRECTION : 1
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
loanTxnMultplierMap = {
|
|
|
159 |
CreditTxnType.LOAN : 1,
|
|
|
160 |
CreditTxnType.LOAN_CANCELLED : -1,
|
|
|
161 |
CreditTxnType.PAID : -1,
|
|
|
162 |
CreditTxnType.CORRECTION : -1
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
refund_status_transition = { OrderStatus.LOST_IN_TRANSIT : OrderStatus.LOST_IN_TRANSIT_REFUNDED,
|
|
|
166 |
OrderStatus.RTO_RECEIVED_PRESTINE : OrderStatus.RTO_REFUNDED,
|
|
|
167 |
OrderStatus.RTO_RECEIVED_DAMAGED : OrderStatus.RTO_DAMAGED_REFUNDED,
|
|
|
168 |
OrderStatus.RTO_LOST_IN_TRANSIT : OrderStatus.RTO_LOST_IN_TRANSIT_REFUNDED,
|
|
|
169 |
OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
|
|
|
170 |
OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
|
|
|
171 |
OrderStatus.DOA_RECEIVED_DAMAGED : OrderStatus.DOA_REFUNDED_RCVD_DAMAGED,
|
|
|
172 |
OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
|
|
|
173 |
OrderStatus.RET_PRODUCT_UNUSABLE : OrderStatus.RET_PRODUCT_UNUSABLE_REFUNDED,
|
|
|
174 |
OrderStatus.RET_PRODUCT_USABLE : OrderStatus.RET_PRODUCT_USABLE_REFUNDED,
|
|
|
175 |
OrderStatus.RET_RECEIVED_DAMAGED : OrderStatus.RET_REFUNDED_RCVD_DAMAGED,
|
|
|
176 |
OrderStatus.RET_LOST_IN_TRANSIT : OrderStatus.RET_REFUNDED_LOST_IN_TRANSIT,
|
|
|
177 |
OrderStatus.COD_VERIFICATION_PENDING : OrderStatus.COD_VERIFICATION_FAILED,
|
|
|
178 |
OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
|
|
179 |
OrderStatus.INVENTORY_LOW : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
|
|
180 |
OrderStatus.LOW_INV_PO_RAISED : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
|
|
181 |
OrderStatus.LOW_INV_REVERSAL_IN_PROCESS : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
|
|
182 |
OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
|
|
183 |
OrderStatus.ACCEPTED : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
|
|
184 |
OrderStatus.BILLED : OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST,
|
|
|
185 |
OrderStatus.CANCEL_REQUEST_CONFIRMED : OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
creditorTicketSizeMap = {}
|
|
|
189 |
creditorDueDateMap = {}
|
|
|
190 |
|
|
|
191 |
stateIdMap = {}
|
|
|
192 |
|
|
|
193 |
def create_ebay_order(ebay_order):
|
|
|
194 |
ebayOrder = EbayOrder()
|
|
|
195 |
ebayOrder.orderId = ebay_order.orderId
|
|
|
196 |
ebayOrder.paisaPayId = ebay_order.paisaPayId
|
|
|
197 |
ebayOrder.salesRecordNumber = ebay_order.salesRecordNumber
|
|
|
198 |
ebayOrder.ebayListingId = ebay_order.ebayListingId
|
|
|
199 |
ebayOrder.subsidyAmount = ebay_order.subsidyAmount
|
|
|
200 |
ebayOrder.ebayTxnDate = to_py_date(ebay_order.ebayTxnDate)
|
|
|
201 |
ebayOrder.transactionId = ebay_order.transactionId
|
|
|
202 |
ebayOrder.listingName = ebay_order.listingName
|
|
|
203 |
ebayOrder.listingPrice = ebay_order.listingPrice
|
|
|
204 |
session.commit()
|
|
|
205 |
|
|
|
206 |
def get_ebay_order_by_sales_rec_number(sales_rec_number):
|
|
|
207 |
return EbayOrder.query.filter(EbayOrder.salesRecordNumber == sales_rec_number).one()
|
|
|
208 |
|
|
|
209 |
def get_ebay_order(sales_rec_number, listingId, paisa_pay_id):
|
|
|
210 |
query = EbayOrder.query
|
|
|
211 |
if sales_rec_number:
|
|
|
212 |
query = query.filter(EbayOrder.salesRecordNumber == sales_rec_number)
|
|
|
213 |
if listingId:
|
|
|
214 |
query = query.filter(EbayOrder.ebayListingId == listingId)
|
|
|
215 |
if paisa_pay_id:
|
|
|
216 |
query = query.filter(EbayOrder.paisaPayId == paisa_pay_id)
|
|
|
217 |
return query.all()
|
|
|
218 |
#return EbayOrder.query.filter(EbayOrder.salesRecordNumber == sales_rec_number).filter(EbayOrder.ebayListingId == listingId).one()
|
|
|
219 |
|
|
|
220 |
def get_ebay_order_by_orderId(order_id):
|
|
|
221 |
return EbayOrder.query.filter(EbayOrder.orderId == order_id).one()
|
|
|
222 |
|
|
|
223 |
def update_ebay_order(ebay_order):
|
|
|
224 |
ebayOrder = get_ebay_order_by_orderId(ebay_order.orderId)
|
|
|
225 |
ebayOrder.subsidyAmount = ebay_order.subsidyAmount
|
|
|
226 |
ebayOrder.transactionId = ebay_order.transactionId
|
|
|
227 |
ebayOrder.ebayTxnDate = to_py_date(ebay_order.ebayTxnDate)
|
|
|
228 |
ebayOrder.bluedartPaisaPayRef = ebay_order.bluedartPaisaPayRef
|
|
|
229 |
ebayOrder.listingPrice = ebay_order.listingPrice
|
|
|
230 |
session.commit()
|
|
|
231 |
|
|
|
232 |
def ebay_order_exists(sales_rec_number, ebay_listing_id):
|
|
|
233 |
try:
|
|
|
234 |
ebayOrder = get_ebay_order_by_sales_rec_number(sales_rec_number)
|
|
|
235 |
if ebayOrder.ebayListingId == ebay_listing_id:
|
|
|
236 |
return True
|
|
|
237 |
else:
|
|
|
238 |
return False
|
|
|
239 |
except Exception as e:
|
|
|
240 |
return False
|
|
|
241 |
def update_order_for_ebay(t_order):
|
|
|
242 |
order = get_order(t_order.id)
|
|
|
243 |
order.customer_id = t_order.customer_id
|
|
|
244 |
order.customer_name = t_order.customer_name
|
|
|
245 |
order.customer_city = t_order.customer_city
|
|
|
246 |
order.customer_state = t_order.customer_state
|
|
|
247 |
order.customer_mobilenumber = t_order.customer_mobilenumber
|
|
|
248 |
order.customer_pincode = t_order.customer_pincode
|
|
|
249 |
order.customer_address1 = t_order.customer_address1
|
|
|
250 |
order.customer_address2 = t_order.customer_address2
|
|
|
251 |
order.customer_email = t_order.customer_email
|
|
|
252 |
order.logistics_provider_id = t_order.logistics_provider_id
|
|
|
253 |
order.airwaybill_no = t_order.airwaybill_no
|
|
|
254 |
order.tracking_id = t_order.tracking_id
|
|
|
255 |
order.status = t_order.status
|
|
|
256 |
order.statusDescription = t_order.statusDescription
|
|
|
257 |
order.cod = 0
|
|
|
258 |
order.otg = False
|
|
|
259 |
order.freebieItemId = 0
|
|
|
260 |
order.orderType = OrderType.B2C
|
|
|
261 |
order.source = 6
|
|
|
262 |
|
|
|
263 |
transaction = get_transaction(order.transaction_id)
|
|
|
264 |
transaction.status = TransactionStatus.AUTHORIZED
|
|
|
265 |
transaction.customer_id = t_order.customer_id
|
|
|
266 |
session.commit()
|
|
|
267 |
def split_ebay_order(order_id, split_order_qty, split_order_item_id, use_power_ship):
|
|
|
268 |
#In case of split now order is always assigned based on the website logic...Also itemId won't work for now
|
|
|
269 |
order = get_order(order_id)
|
|
|
270 |
if split_order_qty >=order.lineitems[0].quantity:
|
|
|
271 |
raise TransactionServiceException(108, "Split Quantity is greater than or equal to order quantity")
|
|
|
272 |
if order.status not in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.CAPTURE_IN_PROCESS, OrderStatus.REJECTED, OrderStatus.ACCEPTED]:
|
|
|
273 |
raise TransactionServiceException(108, "Order not allowed to be split")
|
|
|
274 |
new_order = __clone_order(order, False, False)
|
|
|
275 |
new_order.expected_delivery_time = order.expected_delivery_time
|
|
|
276 |
new_order.promised_delivery_time = order.promised_delivery_time
|
|
|
277 |
new_order.expected_shipping_time = order.expected_shipping_time
|
|
|
278 |
new_order.promised_shipping_time = order.promised_shipping_time
|
|
|
279 |
if use_power_ship:
|
|
|
280 |
new_order.logistics_provider_id = order.logistics_provider_id
|
|
|
281 |
new_order.airwaybill_no = order.airwaybill_no
|
|
|
282 |
new_order.tracking_id = order.tracking_id
|
|
|
283 |
|
|
|
284 |
new_order.lineitems[0].quantity = split_order_qty
|
|
|
285 |
new_order.lineitems[0].total_price = new_order.lineitems[0].unit_price*split_order_qty
|
|
|
286 |
new_order.total_amount = new_order.lineitems[0].total_price
|
|
|
287 |
|
|
|
288 |
order.lineitems[0].quantity = order.lineitems[0].quantity - split_order_qty
|
|
|
289 |
order.lineitems[0].total_price = order.lineitems[0].unit_price * order.lineitems[0].quantity
|
|
|
290 |
order.total_amount = order.lineitems[0].total_price
|
|
|
291 |
|
|
|
292 |
session.commit()
|
|
|
293 |
return new_order
|
|
|
294 |
|
|
|
295 |
def add_or_update_amazon_fba_sales_snapshot(amazonfbasalessnapshot):
|
|
|
296 |
salesnapshotfordate = AmazonFbaSalesSnapshot.get_by(item_id = amazonfbasalessnapshot.item_id,dateOfSale=to_py_date(amazonfbasalessnapshot.dateOfSale).date(),fcLocation=amazonfbasalessnapshot.fcLocation)
|
|
|
297 |
if salesnapshotfordate is None:
|
|
|
298 |
amazon_fba_sales_snapshot = AmazonFbaSalesSnapshot()
|
|
|
299 |
amazon_fba_sales_snapshot.dateOfSale = to_py_date(amazonfbasalessnapshot.dateOfSale).date()
|
|
|
300 |
amazon_fba_sales_snapshot.item_id = amazonfbasalessnapshot.item_id
|
|
|
301 |
amazon_fba_sales_snapshot.totalOrderCount = amazonfbasalessnapshot.totalOrderCount
|
|
|
302 |
amazon_fba_sales_snapshot.amazonFbaInventory = amazonfbasalessnapshot.amazonFbaInventory
|
|
|
303 |
amazon_fba_sales_snapshot.isOutOfStock = amazonfbasalessnapshot.isOutOfStock
|
|
|
304 |
amazon_fba_sales_snapshot.promotionOrderCount = amazonfbasalessnapshot.promotionOrderCount
|
|
|
305 |
amazon_fba_sales_snapshot.totalSale = amazonfbasalessnapshot.totalSale
|
|
|
306 |
amazon_fba_sales_snapshot.promotionSale = amazonfbasalessnapshot.promotionSale
|
|
|
307 |
#if amazonfbasalessnapshot.ourPrice is not None:
|
|
|
308 |
amazon_fba_sales_snapshot.ourPriceSnapshotDate = to_py_date(amazonfbasalessnapshot.ourPriceSnapshotDate)
|
|
|
309 |
amazon_fba_sales_snapshot.ourPrice = amazonfbasalessnapshot.ourPrice
|
|
|
310 |
#if amazonfbasalessnapshot.salePrice is not None:
|
|
|
311 |
amazon_fba_sales_snapshot.salePriceSnapshotDate = to_py_date(amazonfbasalessnapshot.salePriceSnapshotDate)
|
|
|
312 |
amazon_fba_sales_snapshot.salePrice = amazonfbasalessnapshot.salePrice
|
|
|
313 |
#if amazonfbasalessnapshot.minFbaPrice is not None:
|
|
|
314 |
amazon_fba_sales_snapshot.minFbaPriceSnapshotDate = to_py_date(amazonfbasalessnapshot.minFbaPriceSnapshotDate)
|
|
|
315 |
amazon_fba_sales_snapshot.minFbaPrice = amazonfbasalessnapshot.minFbaPrice
|
|
|
316 |
#if amazonfbasalessnapshot.minMfnPrice is not None:
|
|
|
317 |
amazon_fba_sales_snapshot.minMfnPriceSnapshotDate = to_py_date(amazonfbasalessnapshot.minMfnPriceSnapshotDate)
|
|
|
318 |
amazon_fba_sales_snapshot.minMfnPrice = amazonfbasalessnapshot.minMfnPrice
|
|
|
319 |
amazon_fba_sales_snapshot.fcLocation = amazonfbasalessnapshot.fcLocation
|
|
|
320 |
|
|
|
321 |
else:
|
|
|
322 |
if(amazonfbasalessnapshot.totalOrderCount > 0):
|
|
|
323 |
salesnapshotfordate.isOutOfStock = 0
|
|
|
324 |
salesnapshotfordate.promotionOrderCount = amazonfbasalessnapshot.promotionOrderCount
|
|
|
325 |
salesnapshotfordate.totalSale = amazonfbasalessnapshot.totalSale
|
|
|
326 |
salesnapshotfordate.promotionSale = amazonfbasalessnapshot.promotionSale
|
|
|
327 |
salesnapshotfordate.totalOrderCount = amazonfbasalessnapshot.totalOrderCount
|
|
|
328 |
salesnapshotfordate.fcLocation = amazonfbasalessnapshot.fcLocation
|
|
|
329 |
session.commit()
|
|
|
330 |
|
|
|
331 |
def get_amazon_fba_sales_snapshot_for_days(interval):
|
|
|
332 |
query = session.query(Order.status, func.count(Order.id)).group_by(Order.status)
|
|
|
333 |
date = datetime.datetime.now()
|
|
|
334 |
toDate = date-timedelta(days = 1)
|
|
|
335 |
fromDate = toDate-timedelta(days = interval)
|
|
|
336 |
fbasalessnapshot = AmazonFbaSalesSnapshot.query.filter(AmazonFbaSalesSnapshot.dateOfSale.between (fromDate.date(),toDate.date())).order_by(AmazonFbaSalesSnapshot.dateOfSale).all()
|
|
|
337 |
return fbasalessnapshot
|
|
|
338 |
|
|
|
339 |
def create_snapdeal_order(t_snapdeal_order):
|
|
|
340 |
snapdealOrder = SnapdealOrder()
|
|
|
341 |
snapdealOrder.orderId = t_snapdeal_order.orderId
|
|
|
342 |
snapdealOrder.subOrderId = t_snapdeal_order.subOrderId
|
|
|
343 |
snapdealOrder.referenceCode = t_snapdeal_order.referenceCode
|
|
|
344 |
snapdealOrder.productName = t_snapdeal_order.productName
|
|
|
345 |
snapdealOrder.listingPrice = t_snapdeal_order.listingPrice
|
|
|
346 |
snapdealOrder.snapdealTxnDate = to_py_date(t_snapdeal_order.snapdealTxnDate)
|
|
|
347 |
snapdealOrder.maxNlc = t_snapdeal_order.maxNlc
|
|
|
348 |
order = Order.get_by(id=t_snapdeal_order.orderId)
|
|
|
349 |
order.status = OrderStatus.ACCEPTED
|
|
|
350 |
user = None
|
|
|
351 |
try:
|
|
|
352 |
user_client = UserClient().get_client()
|
|
|
353 |
user_to_add = User()
|
|
|
354 |
user_to_add.email = 'SD.'+ str(t_snapdeal_order.orderId) + '@mailinator.com'
|
|
|
355 |
user_to_add.password = 'hSp5gvCsrrhZcceE6mzzOQ'
|
|
|
356 |
user_to_add.communicationEmail = user_to_add.email
|
|
|
357 |
user_to_add.sourceStartTime = int(round(time.time() * 1000))
|
|
|
358 |
user_to_add.sourceId = OrderSource.SNAPDEAL
|
|
|
359 |
user_to_add.sex = Sex.WONT_SAY
|
|
|
360 |
user_to_add = user_client.createUser(user_to_add)
|
|
|
361 |
user = user_to_add
|
|
|
362 |
except:
|
|
|
363 |
pass
|
|
|
364 |
|
|
|
365 |
if user:
|
|
|
366 |
order.customer_id = user.userId
|
|
|
367 |
order.customer_email = user.email
|
|
|
368 |
session.commit()
|
|
|
369 |
|
|
|
370 |
def get_snapdeal_order(order_id, reference_code, subOrder_id):
|
|
|
371 |
query = SnapdealOrder.query
|
|
|
372 |
if order_id:
|
|
|
373 |
query = query.filter(SnapdealOrder.orderId == order_id)
|
|
|
374 |
elif reference_code==subOrder_id:
|
|
|
375 |
if reference_code is None:
|
|
|
376 |
reference_code=''
|
|
|
377 |
query = query.filter(or_(SnapdealOrder.referenceCode == reference_code, SnapdealOrder.subOrderId== subOrder_id))
|
|
|
378 |
else:
|
|
|
379 |
query = query.filter(and_(SnapdealOrder.referenceCode == reference_code, SnapdealOrder.subOrderId== subOrder_id))
|
|
|
380 |
return query.one()
|
|
|
381 |
return query.all()
|
|
|
382 |
|
|
|
383 |
def snapdeal_order_exists(suborder_id, reference_code):
|
|
|
384 |
exists = SnapdealOrder.query.filter_by(subOrderId=suborder_id,referenceCode=reference_code).first()
|
|
|
385 |
if exists is not None:
|
|
|
386 |
return True
|
|
|
387 |
else:
|
|
|
388 |
return False
|
|
|
389 |
|
|
|
390 |
def get_amazon_fba_sales_latest_snapshot_for_item(item_id):
|
|
|
391 |
return AmazonFbaSalesSnapshot.query.filter(AmazonFbaSalesSnapshot.item_id==item_id).filter(AmazonFbaSalesSnapshot.dateOfSale!=datetime.datetime.now().date()).order_by(desc(AmazonFbaSalesSnapshot.dateOfSale)).first()
|
|
|
392 |
|
|
|
393 |
def update_latest_fba_prices_for_item(fbaitemprices):
|
|
|
394 |
fbasalessnapshot = AmazonFbaSalesSnapshot.query.filter(AmazonFbaSalesSnapshot.item_id==fbaitemprices.item_id).order_by(desc(AmazonFbaSalesSnapshot.dateOfSale)).first()
|
|
|
395 |
if(fbasalessnapshot.ourPriceSnapshotDate < to_java_date(fbaitemprices.ourPriceSnapshotDate) and fbaitemprices.ourPrice is not None):
|
|
|
396 |
fbasalessnapshot.ourPriceSnapshotDate = to_py_date(fbaitemprices.ourPriceSnapshotDate)
|
|
|
397 |
fbasalessnapshot.ourPrice = fbaitemprices.ourPrice
|
|
|
398 |
if(fbasalessnapshot.salePriceSnapshotDate < to_java_date(fbaitemprices.salePriceSnapshotDate) and fbaitemprices.salePrice is not None):
|
|
|
399 |
fbasalessnapshot.salePriceSnapshotDate = to_py_date(fbaitemprices.salePriceSnapshotDate)
|
|
|
400 |
fbasalessnapshot.salePrice = fbaitemprices.salePrice
|
|
|
401 |
if(fbasalessnapshot.minFbaPriceSnapshotDate < to_java_date(fbaitemprices.minFbaPriceSnapshotDate) and fbaitemprices.minFbaPrice is not None):
|
|
|
402 |
fbasalessnapshot.minFbaPriceSnapshotDate = to_py_date(fbaitemprices.minFbaPriceSnapshotDate)
|
|
|
403 |
fbasalessnapshot.minFbaPrice = fbaitemprices.minFbaPrice
|
|
|
404 |
if(fbasalessnapshot.minMfnPriceSnapshotDate < to_java_date(fbaitemprices.minMfnPriceSnapshotDate) and fbaitemprices.minMfnPrice is not None):
|
|
|
405 |
fbasalessnapshot.minMfnPriceSnapshotDate = to_py_date(fbaitemprices.minMfnPriceSnapshotDate)
|
|
|
406 |
fbasalessnapshot.minMfnPrice = fbaitemprices.minMfnPrice
|
|
|
407 |
session.commit()
|
|
|
408 |
|
|
|
409 |
def flipkart_order_exists(orderid,suborderid):
|
|
|
410 |
exists = FlipkartOrder.query.filter_by(flipkartOrderId=orderid,flipkartSubOrderId=suborderid).first()
|
|
|
411 |
if exists is not None:
|
|
|
412 |
return True
|
|
|
413 |
else:
|
|
|
414 |
return False
|
|
|
415 |
|
|
|
416 |
def create_flipkart_order(flipkartorder):
|
|
|
417 |
order = FlipkartOrder()
|
|
|
418 |
order.orderId = flipkartorder.orderId
|
|
|
419 |
order.flipkartSubOrderId = flipkartorder.flipkartSubOrderId
|
|
|
420 |
order.flipkartOrderId = flipkartorder.flipkartOrderId
|
|
|
421 |
order.flipkartTxnDate = to_py_date(flipkartorder.flipkartTxnDate)
|
|
|
422 |
order.shippingPrice = flipkartorder.shippingPrice
|
|
|
423 |
order.octroiFee = flipkartorder.octroiFee
|
|
|
424 |
order.emiFee = flipkartorder.emiFee
|
|
|
425 |
order.maxNlc = flipkartorder.maxNlc
|
|
|
426 |
s_order = Order.get_by(id=flipkartorder.orderId)
|
|
|
427 |
if s_order.cod:
|
|
|
428 |
s_order.status = OrderStatus.COD_VERIFICATION_PENDING
|
|
|
429 |
else:
|
|
|
430 |
s_order.status = OrderStatus.ACCEPTED
|
|
|
431 |
s_order.accepted_timetsmap = datetime.datetime.now()
|
|
|
432 |
user = None
|
|
|
433 |
try:
|
|
|
434 |
user_client = UserClient().get_client()
|
|
|
435 |
user_to_add = User()
|
|
|
436 |
user_to_add.email = 'FK.'+ str(flipkartorder.orderId) + '@mailinator.com'
|
|
|
437 |
user_to_add.password = 'gR9zF-Ish2im6tbYFNivgA'
|
|
|
438 |
user_to_add.communicationEmail = user_to_add.email
|
|
|
439 |
user_to_add.sourceStartTime = int(round(time.time() * 1000))
|
|
|
440 |
user_to_add.sourceId = OrderSource.FLIPKART
|
|
|
441 |
user_to_add.sex = Sex.WONT_SAY
|
|
|
442 |
user_to_add = user_client.createUser(user_to_add)
|
|
|
443 |
user = user_to_add
|
|
|
444 |
except:
|
|
|
445 |
pass
|
|
|
446 |
|
|
|
447 |
if user:
|
|
|
448 |
s_order.customer_id = user.userId
|
|
|
449 |
s_order.customer_email = user.email
|
|
|
450 |
|
|
|
451 |
session.commit()
|
|
|
452 |
|
|
|
453 |
def get_flipkart_order(orderid):
|
|
|
454 |
flipkartorder = FlipkartOrder.query.filter_by(orderId=orderid).first()
|
|
|
455 |
if not flipkartorder:
|
|
|
456 |
print "No found order for orderid " + str(orderid)
|
|
|
457 |
raise TransactionServiceException(108, "no such order")
|
|
|
458 |
return flipkartorder
|
|
|
459 |
|
|
|
460 |
def get_flipkart_order_by_subOrderId(flipkartOrderItemId):
|
|
|
461 |
flipkartorder = FlipkartOrder.query.filter_by(flipkartSubOrderId=flipkartOrderItemId).first()
|
|
|
462 |
if not flipkartorder:
|
|
|
463 |
raise TransactionServiceException(108, "no such flipkart order " + str(flipkartOrderItemId))
|
|
|
464 |
return flipkartorder
|
|
|
465 |
|
|
|
466 |
def update_flipkart_order_dates_and_awb(orderid,suborderid,date,awb):
|
|
|
467 |
flipkartorder = FlipkartOrder.query.filter_by(flipkartOrderId=orderid,flipkartSubOrderId=suborderid).first()
|
|
|
468 |
print flipkartorder
|
|
|
469 |
order = get_order(flipkartorder.orderId)
|
|
|
470 |
if not order:
|
|
|
471 |
print "No found order for orderid " + str(orderid)
|
|
|
472 |
raise TransactionServiceException(108, "no such order")
|
|
|
473 |
order.tracking_id = awb
|
|
|
474 |
order.expected_delivery_time = to_py_date(date + 4*24*60*60*1000)
|
|
|
475 |
order.promised_delivery_time = to_py_date(date + 4*24*60*60*1000)
|
|
|
476 |
order.expected_shipping_time = to_py_date(date)
|
|
|
477 |
order.promised_shipping_time = to_py_date(date)
|
|
|
478 |
session.commit()
|
|
|
479 |
|
|
|
480 |
def update_snapdeal_orders_status(orders):
|
|
|
481 |
for statusString, orderList in orders.iteritems():
|
|
|
482 |
if statusString == "Cancelled":
|
|
|
483 |
try:
|
|
|
484 |
for cancel_order in orderList:
|
|
|
485 |
ref_code = cancel_order[0]
|
|
|
486 |
sub_order_code = cancel_order[1]
|
|
|
487 |
snapdeal_order = None
|
|
|
488 |
try:
|
|
|
489 |
snapdeal_order = get_snapdeal_order(None, ref_code, sub_order_code)
|
|
|
490 |
except Exception as e:
|
|
|
491 |
print 'Caught in Updation of Cancelled Orders Getting Snapdeal Order'
|
|
|
492 |
pass
|
|
|
493 |
if snapdeal_order:
|
|
|
494 |
order = get_order(snapdeal_order.orderId)
|
|
|
495 |
if order.status == OrderStatus.SHIPPED_FROM_WH:
|
|
|
496 |
order.status = OrderStatus.SHIPPED_TO_LOGST
|
|
|
497 |
session.commit()
|
|
|
498 |
except Exception as e:
|
|
|
499 |
print 'Caught in Updation of Cancelled Orders'
|
|
|
500 |
print e
|
|
|
501 |
print sys.exc_info()
|
|
|
502 |
|
|
|
503 |
|
|
|
504 |
if statusString == "Delivered":
|
|
|
505 |
try:
|
|
|
506 |
for del_order in orderList:
|
|
|
507 |
ref_code = del_order[0]
|
|
|
508 |
sub_order_code = del_order[1]
|
|
|
509 |
dlvry_timestamp = del_order[2]
|
|
|
510 |
snapdeal_order = None
|
|
|
511 |
try:
|
|
|
512 |
snapdeal_order = get_snapdeal_order(None, ref_code, sub_order_code)
|
|
|
513 |
except Exception as e:
|
|
|
514 |
print 'Caught in Updation of Delivered Orders Getting Snapdeal Order'
|
|
|
515 |
pass
|
|
|
516 |
if snapdeal_order:
|
|
|
517 |
order = get_order(snapdeal_order.orderId)
|
|
|
518 |
if order.status == OrderStatus.SHIPPED_FROM_WH:
|
|
|
519 |
order.delivery_timestamp = datetime.datetime.strptime(dlvry_timestamp, "%Y-%m-%d %H:%M:%S")
|
|
|
520 |
order.receiver = order.customer_name
|
|
|
521 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
|
|
522 |
order.statusDescription = "Order delivered"
|
|
|
523 |
session.commit()
|
|
|
524 |
except Exception as e:
|
|
|
525 |
print 'Caught in Updation of Delivered Orders'
|
|
|
526 |
print e
|
|
|
527 |
print sys.exc_info()
|
|
|
528 |
'''
|
|
|
529 |
try:
|
|
|
530 |
for del_order in delivered_orders:
|
|
|
531 |
ref_code = del_order[0]
|
|
|
532 |
sub_order_code = del_order[1]
|
|
|
533 |
dlvry_timestamp = del_order[2]
|
|
|
534 |
|
|
|
535 |
if snapdeal_order_exists(sub_order_code, ref_code):
|
|
|
536 |
snapdeal_order = get_snapdeal_order(None, None, sub_order_code)
|
|
|
537 |
if snapdeal_order:
|
|
|
538 |
order = get_order(snapdeal_order.orderId)
|
|
|
539 |
if order.status == OrderStatus.SHIPPED_FROM_WH:
|
|
|
540 |
order.delivery_timestamp = datetime.datetime.strptime(dlvry_timestamp, "%Y-%m-%d %H:%M:%S")
|
|
|
541 |
order.receiver = order.customer_name
|
|
|
542 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
|
|
543 |
order.statusDescription = "Order delivered"
|
|
|
544 |
session.commit()
|
|
|
545 |
except Exception as e:
|
|
|
546 |
print e
|
|
|
547 |
print sys.exc_info()
|
|
|
548 |
'''
|
|
|
549 |
|
|
|
550 |
def update_flipkart_orders_status(delivered_orders):
|
|
|
551 |
try:
|
|
|
552 |
for del_order in delivered_orders:
|
|
|
553 |
flipkart_order_id = del_order[0]
|
|
|
554 |
sub_order_code = del_order[1]
|
|
|
555 |
dlvry_timestamp = del_order[2]
|
|
|
556 |
|
|
|
557 |
if flipkart_order_exists(flipkart_order_id,sub_order_code):
|
|
|
558 |
flipkart_order = get_flipkart_order_by_subOrderId(sub_order_code)
|
|
|
559 |
if flipkart_order:
|
|
|
560 |
order = get_order(flipkart_order.orderId)
|
|
|
561 |
if order.status == OrderStatus.SHIPPED_FROM_WH:
|
|
|
562 |
order.delivery_timestamp = datetime.datetime.strptime(dlvry_timestamp, "%Y-%m-%d %H:%M:%S")
|
|
|
563 |
order.receiver = order.customer_name
|
|
|
564 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
|
|
565 |
order.statusDescription = "Order delivered"
|
|
|
566 |
session.commit()
|
|
|
567 |
except Exception as e:
|
|
|
568 |
print e
|
|
|
569 |
print sys.exc_info()
|
|
|
570 |
|
|
|
571 |
'''
|
|
|
572 |
order_ids = delivered_orders.keys()
|
|
|
573 |
for orderId in order_ids:
|
|
|
574 |
order = Order.query.filter(Order.id == orderId).first()
|
|
|
575 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
|
|
576 |
order.statusDescription = "Order delivered"
|
|
|
577 |
order.delivery_timestamp = datetime.datetime.strptime(delivered_orders.get(orderId), "%Y-%m-%d %H:%M:%S")
|
|
|
578 |
session.commit()
|
|
|
579 |
'''
|
|
|
580 |
|
|
|
581 |
def bulk_add_or_update_amazon_fba_sales_snapshot(amazonfbasalessnapshotlist):
|
|
|
582 |
for amazonfbasalessnapshot in amazonfbasalessnapshotlist:
|
|
|
583 |
salesnapshotfordate = AmazonFbaSalesSnapshot.get_by(item_id = amazonfbasalessnapshot.item_id,dateOfSale=to_py_date(amazonfbasalessnapshot.dateOfSale).date(),fcLocation=amazonfbasalessnapshot.fcLocation)
|
|
|
584 |
if salesnapshotfordate is None:
|
|
|
585 |
amazon_fba_sales_snapshot = AmazonFbaSalesSnapshot()
|
|
|
586 |
amazon_fba_sales_snapshot.dateOfSale = to_py_date(amazonfbasalessnapshot.dateOfSale).date()
|
|
|
587 |
amazon_fba_sales_snapshot.item_id = amazonfbasalessnapshot.item_id
|
|
|
588 |
amazon_fba_sales_snapshot.totalOrderCount = amazonfbasalessnapshot.totalOrderCount
|
|
|
589 |
amazon_fba_sales_snapshot.amazonFbaInventory = amazonfbasalessnapshot.amazonFbaInventory
|
|
|
590 |
amazon_fba_sales_snapshot.isOutOfStock = amazonfbasalessnapshot.isOutOfStock
|
|
|
591 |
amazon_fba_sales_snapshot.promotionOrderCount = amazonfbasalessnapshot.promotionOrderCount
|
|
|
592 |
amazon_fba_sales_snapshot.totalSale = amazonfbasalessnapshot.totalSale
|
|
|
593 |
amazon_fba_sales_snapshot.promotionSale = amazonfbasalessnapshot.promotionSale
|
|
|
594 |
#if amazonfbasalessnapshot.ourPrice is not None:
|
|
|
595 |
amazon_fba_sales_snapshot.ourPriceSnapshotDate = to_py_date(amazonfbasalessnapshot.ourPriceSnapshotDate)
|
|
|
596 |
amazon_fba_sales_snapshot.ourPrice = amazonfbasalessnapshot.ourPrice
|
|
|
597 |
#if amazonfbasalessnapshot.salePrice is not None:
|
|
|
598 |
amazon_fba_sales_snapshot.salePriceSnapshotDate = to_py_date(amazonfbasalessnapshot.salePriceSnapshotDate)
|
|
|
599 |
amazon_fba_sales_snapshot.salePrice = amazonfbasalessnapshot.salePrice
|
|
|
600 |
#if amazonfbasalessnapshot.minFbaPrice is not None:
|
|
|
601 |
amazon_fba_sales_snapshot.minFbaPriceSnapshotDate = to_py_date(amazonfbasalessnapshot.minFbaPriceSnapshotDate)
|
|
|
602 |
amazon_fba_sales_snapshot.minFbaPrice = amazonfbasalessnapshot.minFbaPrice
|
|
|
603 |
#if amazonfbasalessnapshot.minMfnPrice is not None:
|
|
|
604 |
amazon_fba_sales_snapshot.minMfnPriceSnapshotDate = to_py_date(amazonfbasalessnapshot.minMfnPriceSnapshotDate)
|
|
|
605 |
amazon_fba_sales_snapshot.minMfnPrice = amazonfbasalessnapshot.minMfnPrice
|
|
|
606 |
amazon_fba_sales_snapshot.fcLocation = amazonfbasalessnapshot.fcLocation
|
|
|
607 |
else:
|
|
|
608 |
if(amazonfbasalessnapshot.totalOrderCount > 0):
|
|
|
609 |
salesnapshotfordate.isOutOfStock = 0
|
|
|
610 |
salesnapshotfordate.promotionOrderCount = amazonfbasalessnapshot.promotionOrderCount
|
|
|
611 |
salesnapshotfordate.totalSale = amazonfbasalessnapshot.totalSale
|
|
|
612 |
salesnapshotfordate.promotionSale = amazonfbasalessnapshot.promotionSale
|
|
|
613 |
salesnapshotfordate.totalOrderCount = amazonfbasalessnapshot.totalOrderCount
|
|
|
614 |
salesnapshotfordate.fcLocation = amazonfbasalessnapshot.fcLocation
|
|
|
615 |
session.commit()
|
|
|
616 |
|
|
|
617 |
def get_created_orders_for_flipkart(flipkartorderids):
|
|
|
618 |
item_ordercount = dict()
|
|
|
619 |
orders = []
|
|
|
620 |
flipkart_orders = session.query(FlipkartOrder).filter(FlipkartOrder.flipkartOrderId.in_(tuple(flipkartorderids))).all()
|
|
|
621 |
print flipkart_orders
|
|
|
622 |
if len(flipkart_orders)!=0:
|
|
|
623 |
for order in flipkart_orders:
|
|
|
624 |
print order.orderId
|
|
|
625 |
orders.append(order.orderId)
|
|
|
626 |
items =session.query(LineItem.item_id,func.count(LineItem.quantity)).join((Order,LineItem.order_id==Order.id)).filter(Order.id.in_(tuple(orders))).filter(Order.status >=3).filter(Order.shipping_timestamp==None).group_by(LineItem.item_id).all()
|
|
|
627 |
else:
|
|
|
628 |
return item_ordercount
|
|
|
629 |
print "items map after query"
|
|
|
630 |
print items
|
|
|
631 |
for item in items:
|
|
|
632 |
print "item id"
|
|
|
633 |
print item[0]
|
|
|
634 |
print "order count"
|
|
|
635 |
print item[1]
|
|
|
636 |
item_ordercount[item[0]] = item[1]
|
|
|
637 |
print item_ordercount
|
|
|
638 |
return item_ordercount
|
|
|
639 |
|
|
|
640 |
def change_easyship_mfn_order_txn_status(transaction_id, new_status, description, pickUp, orderType, source, shipTimestamp, deliveryTimeStamp):
|
|
|
641 |
transaction = get_transaction(transaction_id)
|
|
|
642 |
transaction.status = new_status
|
|
|
643 |
transaction.status_message = description
|
|
|
644 |
## Assign runner in case of delhi pincodes
|
|
|
645 |
if transaction.orders[0].pickupStoreId:
|
|
|
646 |
logistics_client = LogisticsClient().get_client()
|
|
|
647 |
store = logistics_client.getPickupStore(transaction.orders[0].pickupStoreId)
|
|
|
648 |
if delhi_pincodes.__contains__(store.pin):
|
|
|
649 |
pickUp = PickUpType.RUNNER
|
|
|
650 |
|
|
|
651 |
if new_status == TransactionStatus.FAILED:
|
|
|
652 |
for order in transaction.orders:
|
|
|
653 |
order.status = OrderStatus.PAYMENT_FAILED
|
|
|
654 |
order.statusDescription = "Payment Failed"
|
|
|
655 |
elif new_status == TransactionStatus.AUTHORIZED or new_status == TransactionStatus.FLAGGED:
|
|
|
656 |
for order in transaction.orders:
|
|
|
657 |
if new_status == TransactionStatus.AUTHORIZED:
|
|
|
658 |
order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
|
|
|
659 |
order.statusDescription = "Submitted to warehouse"
|
|
|
660 |
elif new_status == TransactionStatus.FLAGGED:
|
|
|
661 |
order.status = OrderStatus.PAYMENT_FLAGGED
|
|
|
662 |
order.statusDescription = "Payment flagged by gateway"
|
|
|
663 |
order.cod = False
|
|
|
664 |
order.orderType = orderType
|
|
|
665 |
#After we got payment success, we will set logistics info also
|
|
|
666 |
logistics_client = LogisticsClient().get_client()
|
|
|
667 |
#FIXME line item is only one now. If multiple will come, need to fix.
|
|
|
668 |
item_id = order.lineitems[0].item_id
|
|
|
669 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID, pickUp)
|
|
|
670 |
|
|
|
671 |
#current_time = datetime.datetime.now()
|
|
|
672 |
|
|
|
673 |
#logistics_info.deliveryTime = adjust_delivery_time(to_py_date(deliveryTimeStamp), 0)
|
|
|
674 |
#logistics_info.shippingTime = adjust_delivery_time(to_py_date(shipTimestamp), 0)
|
|
|
675 |
#logistics_info.deliveryDelay = 0
|
|
|
676 |
|
|
|
677 |
|
|
|
678 |
order.otg = logistics_info.otgAvailable
|
|
|
679 |
order.warehouse_id = logistics_info.warehouseId
|
|
|
680 |
order.fulfilmentWarehouseId = logistics_info.fulfilmentWarehouseId
|
|
|
681 |
order.logistics_provider_id = 45
|
|
|
682 |
#Start:- Added by Manish Sharma for FedEx Integration - Shipment Creation on 31-Jul-2013
|
|
|
683 |
#order.airwaybill_no = logistics_info.airway_billno
|
|
|
684 |
#order.tracking_id = order.airwaybill_no
|
|
|
685 |
#End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
|
|
686 |
|
|
|
687 |
order.courier_delivery_time = to_py_date(deliveryTimeStamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
|
|
688 |
order.expected_shipping_time = to_py_date(shipTimestamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
|
|
689 |
order.promised_shipping_time = order.expected_shipping_time
|
|
|
690 |
order.expected_delivery_time = to_py_date(deliveryTimeStamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
|
|
691 |
order.promised_delivery_time = order.expected_delivery_time
|
|
|
692 |
|
|
|
693 |
if order.pickupStoreId:
|
|
|
694 |
order.otg = False
|
|
|
695 |
|
|
|
696 |
inventory_client = InventoryClient().get_client()
|
|
|
697 |
if order.productCondition != ProductCondition.BAD:
|
|
|
698 |
inventory_client.reserveItemInWarehouse(item_id, logistics_info.fulfilmentWarehouseId, sourceId, order.id, to_java_date(order.created_timestamp), to_java_date(order.promised_shipping_time), order.lineitems[0].quantity)
|
|
|
699 |
|
|
|
700 |
try:
|
|
|
701 |
item_pricing = inventory_client.getItemPricing(item_id, -1)
|
|
|
702 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
|
|
703 |
order.lineitems[0].nlc = item_pricing.nlc
|
|
|
704 |
except:
|
|
|
705 |
print "Not able to get transfer price. Skipping"
|
|
|
706 |
|
|
|
707 |
catalog_client = CatalogClient().get_client()
|
|
|
708 |
voucherAmount = catalog_client.getVoucherAmount(item_id, VoucherType.SPICEDECK_MOBILE)
|
|
|
709 |
if voucherAmount:
|
|
|
710 |
__create_recharge_voucher_tracker(order, voucherAmount, VoucherType.SPICEDECK_MOBILE)
|
|
|
711 |
#Note 2 Buy back Offer
|
|
|
712 |
if item_id in (7974, 7558) and transaction.coupon_code is not None and transaction.coupon_code.lower() == "note2buyback":
|
|
|
713 |
order.status = OrderStatus.COD_VERIFICATION_PENDING
|
|
|
714 |
order.statusDescription = "Note 2 Buy Back Offer - Approval Pending from CRM Team"
|
|
|
715 |
order.otg = False
|
|
|
716 |
|
|
|
717 |
elif new_status == TransactionStatus.COD_IN_PROCESS:
|
|
|
718 |
for order in transaction.orders:
|
|
|
719 |
order.status = OrderStatus.COD_VERIFICATION_PENDING
|
|
|
720 |
order.statusDescription = "Verification Pending"
|
|
|
721 |
order.cod = True
|
|
|
722 |
order.orderType = orderType
|
|
|
723 |
#After we got payment success, we will set logistics info also
|
|
|
724 |
logistics_client = LogisticsClient().get_client()
|
|
|
725 |
#FIXME line item is only one now. If multiple will come, need to fix.
|
|
|
726 |
item_id = order.lineitems[0].item_id
|
|
|
727 |
if order.pickupStoreId:
|
|
|
728 |
# Need to send prepaid awb number for store pick up orders
|
|
|
729 |
logistics_info = logistics_client.getLogisticsEstimation(item_id, order.customer_pincode, DeliveryType.COD)
|
|
|
730 |
#//Start:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
|
|
731 |
#prepaid_logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID, pickUp)
|
|
|
732 |
#logistics_info.airway_billno = prepaid_logistics_info.airway_billno
|
|
|
733 |
#logistics_info.providerId = prepaid_logistics_info.providerId
|
|
|
734 |
#End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
|
|
735 |
# Will not provide OTG in pickup store
|
|
|
736 |
order.otg = False
|
|
|
737 |
else:
|
|
|
738 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.COD, pickUp)
|
|
|
739 |
order.otg = logistics_info.otgAvailable
|
|
|
740 |
|
|
|
741 |
|
|
|
742 |
#current_time = datetime.datetime.now()
|
|
|
743 |
#logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
|
|
744 |
#logistics_info.shippingTime = adjust_delivery_time(current_time, logistics_info.shippingTime)
|
|
|
745 |
#logistics_info.deliveryDelay = adjust_delivery_time(current_time, (logistics_info.shippingTime+logistics_info.deliveryDelay))
|
|
|
746 |
|
|
|
747 |
|
|
|
748 |
order.warehouse_id = logistics_info.warehouseId
|
|
|
749 |
order.fulfilmentWarehouseId = logistics_info.fulfilmentWarehouseId
|
|
|
750 |
order.logistics_provider_id = 45
|
|
|
751 |
#Start:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
|
|
752 |
#order.airwaybill_no = logistics_info.airway_billno
|
|
|
753 |
#order.tracking_id = order.airwaybill_no
|
|
|
754 |
#End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
|
|
755 |
order.courier_delivery_time = to_py_date(deliveryTimeStamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
|
|
756 |
order.expected_shipping_time = to_py_date(shipTimestamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
|
|
757 |
order.promised_shipping_time = order.expected_shipping_time
|
|
|
758 |
order.expected_delivery_time = to_py_date(deliveryTimeStamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
|
|
759 |
order.promised_delivery_time = order.expected_delivery_time
|
|
|
760 |
|
|
|
761 |
inventory_client = InventoryClient().get_client()
|
|
|
762 |
if order.productCondition != ProductCondition.BAD:
|
|
|
763 |
inventory_client.reserveItemInWarehouse(item_id, logistics_info.fulfilmentWarehouseId, sourceId, order.id, to_java_date(order.created_timestamp), to_java_date(order.promised_shipping_time), order.lineitems[0].quantity)
|
|
|
764 |
|
|
|
765 |
try:
|
|
|
766 |
item_pricing = inventory_client.getItemPricing(item_id, -1)
|
|
|
767 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
|
|
768 |
order.lineitems[0].nlc = item_pricing.nlc
|
|
|
769 |
except:
|
|
|
770 |
print "Not able to get transfer price. Skipping"
|
|
|
771 |
|
|
|
772 |
catalog_client = CatalogClient().get_client()
|
|
|
773 |
voucherAmount = catalog_client.getVoucherAmount(item_id, VoucherType.SPICEDECK_MOBILE)
|
|
|
774 |
if voucherAmount:
|
|
|
775 |
__create_recharge_voucher_tracker(order, voucherAmount, VoucherType.SPICEDECK_MOBILE)
|
|
|
776 |
|
|
|
777 |
|
|
|
778 |
session.commit()
|
|
|
779 |
|
|
|
780 |
if new_status in (TransactionStatus.AUTHORIZED, TransactionStatus.FLAGGED, TransactionStatus.COD_IN_PROCESS):
|
|
|
781 |
try:
|
|
|
782 |
if order.source == OrderSource.WEBSITE:
|
|
|
783 |
if new_status == TransactionStatus.COD_IN_PROCESS:
|
|
|
784 |
transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
|
|
|
785 |
transaction_requiring_extra_processing.category = 'COD_VERIFICATION'
|
|
|
786 |
transaction_requiring_extra_processing.transaction_id = transaction_id
|
|
|
787 |
session.commit()
|
|
|
788 |
elif new_status == TransactionStatus.FLAGGED:
|
|
|
789 |
transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
|
|
|
790 |
transaction_requiring_extra_processing.category = 'PAYMENT_FLAGGED'
|
|
|
791 |
transaction_requiring_extra_processing.transaction_id = transaction_id
|
|
|
792 |
session.commit()
|
|
|
793 |
elif order.source == OrderSource.STORE:
|
|
|
794 |
order.otg = False
|
|
|
795 |
session.commit()
|
|
|
796 |
catalog_client = CatalogClient().get_client()
|
|
|
797 |
sourcePricing = catalog_client.getStorePricing(order.lineitems[0].item_id)
|
|
|
798 |
if order.total_amount >= sourcePricing.minPrice:
|
|
|
799 |
order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
|
|
|
800 |
order.statusDescription = "Order Accepted"
|
|
|
801 |
session.commit()
|
|
|
802 |
sod = StoreOrderDetail.get_by(orderId = order.id)
|
|
|
803 |
__push_store_collection_to_hotspot(order, "advance", sod.cashAmount, sod.cardAmount)
|
|
|
804 |
|
|
|
805 |
else:
|
|
|
806 |
order.status = OrderStatus.COD_VERIFICATION_PENDING
|
|
|
807 |
order.statusDescription = "Approval Pending"
|
|
|
808 |
content = "<html><body>"
|
|
|
809 |
content += "<h4>Order Id: " + str(order.id) + "</h4>"
|
|
|
810 |
content += "<h4>Product: " + str(order.lineitems[0]) + "</h4>"
|
|
|
811 |
content += "<h4>Min Price: " + str(sourcePricing.minPrice) + "</h4>"
|
|
|
812 |
content += "<h4>Recommended Price: " + str(sourcePricing.recommendedPrice) + "</h4>"
|
|
|
813 |
content += "<h2>Approval Requested for Price: " + str(order.total_amount) + "</h2>"
|
|
|
814 |
content += "<h2>Note 1: If this discount price is approved then reply 'Approved' otherwise 'Not Approved' without changing anythig in the Mail.</h2>"
|
|
|
815 |
content += "<h2>Note 2: For Quick approval using browser <a href='http://support.shop2020.in:8080/Support/price-approval?xszbg=" + base64.b64encode(str(order.id)) + "'>Click Here</a></h2>"
|
|
|
816 |
content += "<br><br></body></html>"
|
|
|
817 |
store = get_hotspot_store(order.storeId, "")
|
|
|
818 |
helper_client = HelperClient().get_client()
|
|
|
819 |
helper_client.saveUserEmailForSending(store.approvalEmail.split(';'), SaholicHelpEmailId, "Price approval requested for " + str(order.lineitems[0]) + " order Id " + str(order.id) + " in store " + store.hotspotId , content, str(transaction_id), "PriceApproval", [], [], order.source)
|
|
|
820 |
session.commit()
|
|
|
821 |
else:
|
|
|
822 |
order.otg = False
|
|
|
823 |
session.commit()
|
|
|
824 |
except Exception as e:
|
|
|
825 |
print "Error inserting transaction Id: " + str(transaction_id) + " due to " + str(e)
|
|
|
826 |
|
|
|
827 |
return True
|
|
|
828 |
|
|
|
829 |
def update_amazon_fba_order_returns(fbaOrderReturns):
|
|
|
830 |
for order_return in fbaOrderReturns:
|
|
|
831 |
orderReturn = AmazonFbaOrderReturns.query.filter(AmazonFbaOrderReturns.amazonOrderId==order_return.amazonOrderId).filter(AmazonFbaOrderReturns.insertionTimestamp == to_py_date(order_return.insertionTimestamp)).filter(AmazonFbaOrderReturns.sku==order_return.sku).first()
|
|
|
832 |
if orderReturn:
|
|
|
833 |
orderReturn.sellableReturnQuantity = order_return.sellableReturnQuantity
|
|
|
834 |
orderReturn.nonSellableReturnQuantity = order_return.nonSellableReturnQuantity
|
|
|
835 |
session.commit()
|
|
|
836 |
else:
|
|
|
837 |
orderReturn = AmazonFbaOrderReturns()
|
|
|
838 |
orderReturn.amazonOrderId = order_return.amazonOrderId
|
|
|
839 |
orderReturn.insertionTimestamp = to_py_date(order_return.insertionTimestamp)
|
|
|
840 |
orderReturn.sku = order_return.sku
|
|
|
841 |
orderReturn.creationTimestamp = to_py_date(order_return.creationTimestamp)
|
|
|
842 |
orderReturn.shippedQuantity = order_return.shippedQuantity
|
|
|
843 |
orderReturn.sellableReturnQuantity = order_return.sellableReturnQuantity
|
|
|
844 |
orderReturn.nonSellableReturnQuantity = order_return.nonSellableReturnQuantity
|
|
|
845 |
session.commit()
|
|
|
846 |
|
|
|
847 |
def get_all_amazon_fba_order_returns(insertionTimestamp):
|
|
|
848 |
returns = AmazonFbaOrderReturns.query.filter(AmazonFbaOrderReturns.insertionTimestamp==to_py_date(insertionTimestamp)).all()
|
|
|
849 |
if not returns:
|
|
|
850 |
returns = []
|
|
|
851 |
return returns
|
|
|
852 |
|
|
|
853 |
def get_total_sale_returns_fba_skus_curent_time(insertionTimestamp):
|
|
|
854 |
allFbaSkuDetails = session.query(AmazonFbaOrderReturns.sku, func.sum(AmazonFbaOrderReturns.shippedQuantity), func.sum(AmazonFbaOrderReturns.sellableReturnQuantity), func.sum(AmazonFbaOrderReturns.nonSellableReturnQuantity)).group_by(AmazonFbaOrderReturns.sku).filter(AmazonFbaOrderReturns.insertionTimestamp == to_py_date(insertionTimestamp)).all()
|
|
|
855 |
|
|
|
856 |
returnAllFbaSkuDetails = {}
|
|
|
857 |
|
|
|
858 |
for fbaSkuDetail in allFbaSkuDetails:
|
|
|
859 |
saleReturnDetail = {}
|
|
|
860 |
saleReturnDetail['Sale'] = fbaSkuDetail[1]
|
|
|
861 |
saleReturnDetail['SaleableReturn'] = fbaSkuDetail[2]
|
|
|
862 |
saleReturnDetail['NonSaleableReturn'] = fbaSkuDetail[3]
|
|
|
863 |
returnAllFbaSkuDetails[fbaSkuDetail[0]]= saleReturnDetail
|
|
|
864 |
|
|
|
865 |
return returnAllFbaSkuDetails
|
|
|
866 |
|
|
|
867 |
def get_amazon_fba_sales_latest_snapshot_for_item_location_wise(item_id,location):
|
|
|
868 |
return AmazonFbaSalesSnapshot.query.filter(AmazonFbaSalesSnapshot.item_id==item_id).filter(AmazonFbaSalesSnapshot.fcLocation==location).filter(AmazonFbaSalesSnapshot.dateOfSale!=datetime.datetime.now().date()).order_by(desc(AmazonFbaSalesSnapshot.dateOfSale)).first()
|
|
|
869 |
|
|
|
870 |
def get_verification_pending_orders_fk():
|
|
|
871 |
retOrders = Order.query.filter(Order.source==OrderSource.FLIPKART).filter(Order.status==OrderStatus.COD_VERIFICATION_PENDING).all()
|
|
|
872 |
retFkOrders = []
|
|
|
873 |
order_ids = []
|
|
|
874 |
if not retOrders:
|
|
|
875 |
return retFkOrders
|
|
|
876 |
else:
|
|
|
877 |
for order in retOrders:
|
|
|
878 |
order_ids.append(order.id)
|
|
|
879 |
retFkOrders = FlipkartOrder.query.filter(FlipkartOrder.orderId.in_(tuple(order_ids)))
|
|
|
880 |
if not retFkOrders:
|
|
|
881 |
retFkOrders = []
|
|
|
882 |
return retFkOrders
|
|
|
883 |
|
|
|
884 |
def get_fa_order_by_fk_order_id(fk_OrderId,fk_OrderItemId):
|
|
|
885 |
faOrder = FlipkartAdvantageOrder.query.filter_by(fkOrderId=fk_OrderId,fkOrderItemId=fk_OrderItemId).first()
|
|
|
886 |
if not faOrder:
|
|
|
887 |
print "Not found order for orderId " + str(fk_OrderId)
|
|
|
888 |
raise TransactionServiceException(108, "no such order")
|
|
|
889 |
|
|
|
890 |
return faOrder
|
|
|
891 |
|
|
|
892 |
def flipkart_fa_order_exists(fk_OrderId,fk_OrderItemId):
|
|
|
893 |
faOrder = FlipkartAdvantageOrder.query.filter_by(fkOrderId=fk_OrderId,fkOrderItemId=fk_OrderItemId).first()
|
|
|
894 |
if not faOrder:
|
|
|
895 |
return False
|
|
|
896 |
else:
|
|
|
897 |
return True
|
|
|
898 |
|
|
|
899 |
def get_all_fa_orders_list(status):
|
|
|
900 |
faOrders = None
|
|
|
901 |
if status == 'all':
|
|
|
902 |
faOrders = FlipkartAdvantageOrder.query.all()
|
|
|
903 |
else:
|
|
|
904 |
faOrders = FlipkartAdvantageOrder.query.filter(FlipkartAdvantageOrder.status==status).all()
|
|
|
905 |
if not faOrders:
|
|
|
906 |
faOrders = []
|
|
|
907 |
return faOrders
|
|
|
908 |
|
|
|
909 |
def add_update_fa_orders_bulk(faOrdersList):
|
|
|
910 |
for faOrder in faOrdersList:
|
|
|
911 |
if faOrder.status == 'approved':
|
|
|
912 |
fa_Order = FlipkartAdvantageOrder()
|
|
|
913 |
fa_Order.fkOrderId = faOrder.fkOrderId
|
|
|
914 |
fa_Order.fkOrderItemId = faOrder.fkOrderItemId
|
|
|
915 |
fa_Order.sku = faOrder.sku
|
|
|
916 |
fa_Order.creationTimestamp = to_py_date(faOrder.creationTimestamp)
|
|
|
917 |
fa_Order.customerName = faOrder.customerName
|
|
|
918 |
fa_Order.customerAddress = faOrder.customerAddress
|
|
|
919 |
fa_Order.pincode = faOrder.pincode
|
|
|
920 |
fa_Order.customerCity = faOrder.customerCity
|
|
|
921 |
fa_Order.customerState = faOrder.customerState
|
|
|
922 |
fa_Order.customerPhone = faOrder.customerPhone
|
|
|
923 |
fa_Order.status = faOrder.status
|
|
|
924 |
fa_Order.quantity = faOrder.quantity
|
|
|
925 |
fa_Order.totalPrice = faOrder.totalPrice
|
|
|
926 |
fa_Order.listPrice = faOrder.listPrice
|
|
|
927 |
fa_Order.modifiedDate = to_py_date(faOrder.modifiedDate)
|
|
|
928 |
fa_Order.listingId = faOrder.listingId
|
|
|
929 |
fa_Order.cancelReason = faOrder.cancelReason
|
|
|
930 |
fa_Order.returnReason = faOrder.returnReason
|
|
|
931 |
fa_Order.freebieItemId = faOrder.freebieItemId
|
|
|
932 |
fa_Order.productTitle = faOrder.productTitle
|
|
|
933 |
else:
|
|
|
934 |
fa_Order = FlipkartAdvantageOrder.query.filter_by(fkOrderId=faOrder.fkOrderId,fkOrderItemId=faOrder.fkOrderItemId).first()
|
|
|
935 |
if fa_Order:
|
|
|
936 |
if fa_Order.status !=faOrder.status:
|
|
|
937 |
fa_Order.status = faOrder.status
|
|
|
938 |
fa_Order.cancelReason = faOrder.cancelReason
|
|
|
939 |
fa_Order.returnReason = faOrder.returnReason
|
|
|
940 |
fa_Order.modifiedDate = to_py_date(faOrder.modifiedDate)
|
|
|
941 |
else:
|
|
|
942 |
fa_Order = FlipkartAdvantageOrder()
|
|
|
943 |
fa_Order.fkOrderId = faOrder.fkOrderId
|
|
|
944 |
fa_Order.fkOrderItemId = faOrder.fkOrderItemId
|
|
|
945 |
fa_Order.sku = faOrder.sku
|
|
|
946 |
fa_Order.creationTimestamp = to_py_date(faOrder.creationTimestamp)
|
|
|
947 |
fa_Order.customerName = faOrder.customerName
|
|
|
948 |
fa_Order.customerAddress = faOrder.customerAddress
|
|
|
949 |
fa_Order.pincode = faOrder.pincode
|
|
|
950 |
fa_Order.customerCity = faOrder.customerCity
|
|
|
951 |
fa_Order.customerState = faOrder.customerState
|
|
|
952 |
fa_Order.customerPhone = faOrder.customerPhone
|
|
|
953 |
fa_Order.status = faOrder.status
|
|
|
954 |
fa_Order.quantity = faOrder.quantity
|
|
|
955 |
fa_Order.totalPrice = faOrder.totalPrice
|
|
|
956 |
fa_Order.listPrice = faOrder.listPrice
|
|
|
957 |
fa_Order.modifiedDate = to_py_date(faOrder.modifiedDate)
|
|
|
958 |
fa_Order.listingId = faOrder.listingId
|
|
|
959 |
fa_Order.cancelReason = faOrder.cancelReason
|
|
|
960 |
fa_Order.returnReason = faOrder.returnReason
|
|
|
961 |
fa_Order.freebieItemId = faOrder.freebieItemId
|
|
|
962 |
fa_Order.productTitle = faOrder.productTitle
|
|
|
963 |
session.commit()
|
|
|
964 |
|
|
|
965 |
def create_homeshop_order(hsOrder):
|
|
|
966 |
hs_Order = HsOrder()
|
|
|
967 |
hs_Order.orderId = hsOrder.orderId
|
|
|
968 |
hs_Order.catalogueName = hsOrder.catalogueName
|
|
|
969 |
hs_Order.courierName = hsOrder.courierName
|
|
|
970 |
hs_Order.hsItemId = hsOrder.hsItemId
|
|
|
971 |
hs_Order.hsOrderDate = to_py_date(hsOrder.hsOrderDate)
|
|
|
972 |
hs_Order.hsOrderNo = hsOrder.hsOrderNo
|
|
|
973 |
hs_Order.hsProductId = hsOrder.hsProductId
|
|
|
974 |
hs_Order.hsSubOrderNo = hsOrder.hsSubOrderNo
|
|
|
975 |
hs_Order.paymentMode = hsOrder.paymentMode
|
|
|
976 |
hs_Order.sellerSku = hsOrder.sellerSku
|
|
|
977 |
hs_Order.slaDays = hsOrder.slaDays
|
|
|
978 |
hs_Order.shippingName = hsOrder.shippingName
|
|
|
979 |
order = Order.get_by(id=hsOrder.orderId)
|
|
|
980 |
order.status = OrderStatus.ACCEPTED
|
|
|
981 |
order.accepted_timestamp = datetime.datetime.now()
|
|
|
982 |
user = None
|
|
|
983 |
try:
|
|
|
984 |
user_client = UserClient().get_client()
|
|
|
985 |
user_to_add = User()
|
|
|
986 |
user_to_add.email = 'HS.'+ str(hsOrder.orderId) + '@mailinator.com'
|
|
|
987 |
user_to_add.password = 'ouBPONyDYWfeAFtXeaYRkQ'
|
|
|
988 |
user_to_add.communicationEmail = user_to_add.email
|
|
|
989 |
user_to_add.sourceStartTime = int(round(time.time() * 1000))
|
|
|
990 |
user_to_add.sourceId = OrderSource.HOMESHOP18
|
|
|
991 |
user_to_add.sex = Sex.WONT_SAY
|
|
|
992 |
user_to_add = user_client.createUser(user_to_add)
|
|
|
993 |
user = user_to_add
|
|
|
994 |
except:
|
|
|
995 |
pass
|
|
|
996 |
|
|
|
997 |
if user:
|
|
|
998 |
order.customer_id = user.userId
|
|
|
999 |
order.customer_email = user.email
|
|
|
1000 |
session.commit()
|
|
|
1001 |
|
|
|
1002 |
def get_homeshop_order(order_id, hsOrderNo, hsSubOrderNo):
|
|
|
1003 |
query = HsOrder.query
|
|
|
1004 |
if order_id:
|
|
|
1005 |
query = query.filter(HsOrder.orderId == order_id)
|
|
|
1006 |
if hsOrderNo:
|
|
|
1007 |
query = query.filter(HsOrder.hsOrderNo == hsOrderNo)
|
|
|
1008 |
if hsSubOrderNo:
|
|
|
1009 |
query = query.filter(HsOrder.hsSubOrderNo == hsSubOrderNo)
|
|
|
1010 |
return query.all()
|
|
|
1011 |
|
|
|
1012 |
def homeshop_order_exists(hs_OrderNo, hs_SubOrderNo):
|
|
|
1013 |
exists = HsOrder.query.filter_by(hsOrderNo=hs_OrderNo,hsSubOrderNo=hs_SubOrderNo).first()
|
|
|
1014 |
if exists is not None:
|
|
|
1015 |
return True
|
|
|
1016 |
else:
|
|
|
1017 |
return False
|
|
|
1018 |
|
|
|
1019 |
def update_timestamp_for_amazon_order(orderDeliveryMap):
|
|
|
1020 |
for orderId,dateMap in orderDeliveryMap.iteritems():
|
|
|
1021 |
order = get_order(orderId)
|
|
|
1022 |
order.expected_delivery_time = datetime.datetime.strptime(dateMap.values()[0]+' 15:00:00', '%d-%m-%Y %H:%M:%S')
|
|
|
1023 |
order.promised_delivery_time = datetime.datetime.strptime(dateMap.values()[0]+' 15:00:00', '%d-%m-%Y %H:%M:%S')
|
|
|
1024 |
promisedShipping = datetime.datetime.strptime(dateMap.keys()[0]+' 15:00:00', '%d-%m-%Y %H:%M:%S')
|
|
|
1025 |
order.expected_shipping_time = promisedShipping
|
|
|
1026 |
order.promised_shipping_time = promisedShipping
|
|
|
1027 |
session.commit()
|
|
|
1028 |
return True
|
|
|
1029 |
|
|
|
1030 |
def update_source_detail_timestamp(id,lastUpdatedOn):
|
|
|
1031 |
detail = get_source_detail(id)
|
|
|
1032 |
detail.lastUpdatedOn = to_py_date(lastUpdatedOn)
|
|
|
1033 |
session.commit()
|
|
|
1034 |
return True
|