| Line 61... |
Line 61... |
| 61 |
from shop2020.thriftpy.alert.ttypes import MonitoredEntity, EntityType
|
61 |
from shop2020.thriftpy.alert.ttypes import MonitoredEntity, EntityType
|
| 62 |
from shop2020.thriftpy.crm.ttypes import *
|
62 |
from shop2020.thriftpy.crm.ttypes import *
|
| 63 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType, PickUpType
|
63 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType, PickUpType
|
| 64 |
from shop2020.thriftpy.model.v1.catalog.ttypes import ItemType
|
64 |
from shop2020.thriftpy.model.v1.catalog.ttypes import ItemType
|
| 65 |
from shop2020.thriftpy.model.v1.inventory.ttypes import BillingType, \
|
65 |
from shop2020.thriftpy.model.v1.inventory.ttypes import BillingType, \
|
| 66 |
InventoryServiceException, WarehouseType, InventoryType, VatType
|
66 |
InventoryServiceException, WarehouseType, InventoryType, VatType, ItemInventory
|
| 67 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
67 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
| 68 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
68 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
| 69 |
HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType, RechargeOrderStatus, \
|
69 |
HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType, RechargeOrderStatus, \
|
| 70 |
RechargeType, RechargeStatistics, DeviceNumberInfo, EmiChargeType, PayMethod, \
|
70 |
RechargeType, RechargeStatistics, DeviceNumberInfo, EmiChargeType, PayMethod, \
|
| 71 |
OrderSource, StorePaymentStatus, ProductCondition, TaxType, \
|
71 |
OrderSource, StorePaymentStatus, ProductCondition, TaxType, \
|
| Line 97... |
Line 97... |
| 97 |
import re
|
97 |
import re
|
| 98 |
import sys
|
98 |
import sys
|
| 99 |
import time
|
99 |
import time
|
| 100 |
import traceback
|
100 |
import traceback
|
| 101 |
import urllib
|
101 |
import urllib
|
| - |
|
102 |
import MySQLdb
|
| 102 |
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
103 |
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
| 103 |
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
104 |
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
| 104 |
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
105 |
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
| 105 |
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
106 |
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
| 106 |
|
107 |
|
| Line 154... |
Line 155... |
| 154 |
'110087','110088','110089','110091','110092','110093','110094','110095','110096','110101','110103','110104','110105','110106','110107',\
|
155 |
'110087','110088','110089','110091','110092','110093','110094','110095','110096','110101','110103','110104','110105','110106','110107',\
|
| 155 |
'110108','110109','110110','110112','110113','110114','110115','110116','110117','110118','110119','110120','110122','110124','110125',\
|
156 |
'110108','110109','110110','110112','110113','110114','110115','110116','110117','110118','110119','110120','110122','110124','110125',\
|
| 156 |
'110301','110302','110501','110502','110503','110504','110505','110510','110511','110512','110601','110602','110603','110604','110605',\
|
157 |
'110301','110302','110501','110502','110503','110504','110505','110510','110511','110512','110601','110602','110603','110604','110605',\
|
| 157 |
'110606','110607','110608','110609']
|
158 |
'110606','110607','110608','110609']
|
| 158 |
|
159 |
|
| - |
|
160 |
def getDbConnection(db_host, db_user, db_password, db_name):
|
| - |
|
161 |
return MySQLdb.connect(db_host, db_user, db_password, db_name)
|
| - |
|
162 |
|
| - |
|
163 |
def closeConnection(conn):
|
| - |
|
164 |
conn.close()
|
| - |
|
165 |
|
| 159 |
def get_store_account_client():
|
166 |
def get_store_account_client():
|
| 160 |
global aclient
|
167 |
global aclient
|
| 161 |
if aclient is None:
|
168 |
if aclient is None:
|
| 162 |
aclient = Client(hotspot_store_url, timeout=70)
|
169 |
aclient = Client(hotspot_store_url, timeout=70)
|
| 163 |
return aclient
|
170 |
return aclient
|
| Line 6525... |
Line 6532... |
| 6525 |
|
6532 |
|
| 6526 |
#Start:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
6533 |
#Start:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
| 6527 |
def update_order_AWB(orderId, airwayBillNo):
|
6534 |
def update_order_AWB(orderId, airwayBillNo):
|
| 6528 |
order = Order.get_by(id = orderId)
|
6535 |
order = Order.get_by(id = orderId)
|
| 6529 |
order.airwaybill_no=airwayBillNo
|
6536 |
order.airwaybill_no=airwayBillNo
|
| 6530 |
order.tracking_id = airwayBillNo
|
6537 |
order.tracking_id=airwayBillNo
|
| - |
|
6538 |
order.logisticsTransactionId = str(order.transaction_id)+airwayBillNo
|
| 6531 |
session.commit()
|
6539 |
session.commit()
|
| 6532 |
return order
|
6540 |
return order
|
| 6533 |
#End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
6541 |
#End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
| 6534 |
|
6542 |
|
| 6535 |
def get_hotspot_service_matrices():
|
6543 |
def get_hotspot_service_matrices():
|
| Line 7415... |
Line 7423... |
| 7415 |
session.commit()
|
7423 |
session.commit()
|
| 7416 |
finally:
|
7424 |
finally:
|
| 7417 |
return get_recharge_transaction(rechargeTransactionId)
|
7425 |
return get_recharge_transaction(rechargeTransactionId)
|
| 7418 |
else:
|
7426 |
else:
|
| 7419 |
return d_rechargeTransaction
|
7427 |
return d_rechargeTransaction
|
| - |
|
7428 |
|
| - |
|
7429 |
def accept_package_orders(orders):
|
| - |
|
7430 |
totalWeight = 0.0
|
| - |
|
7431 |
totalOrdersAmount = 0.0
|
| - |
|
7432 |
ordersList = []
|
| - |
|
7433 |
totalOrderQuantity = 0
|
| - |
|
7434 |
|
| - |
|
7435 |
for orderId in orders:
|
| - |
|
7436 |
orderObj = Order.get_by(id=orderId)
|
| - |
|
7437 |
totalOrderQuantity = totalOrderQuantity + long(orderObj.lineitems[0].quantity)
|
| - |
|
7438 |
ordersList.append(orderObj)
|
| - |
|
7439 |
|
| - |
|
7440 |
print orders
|
| - |
|
7441 |
|
| - |
|
7442 |
user_client = UserClient().get_client()
|
| - |
|
7443 |
isPrivateDealUser = user_client.isPrivateDealUser(ordersList[0].customer_id)
|
| - |
|
7444 |
privateDealUser = None
|
| - |
|
7445 |
if isPrivateDealUser:
|
| - |
|
7446 |
privateDealUser = user_client.getPrivateDealUser(ordersList[0].customer_id)
|
| - |
|
7447 |
logistics_client = LogisticsClient().get_client()
|
| - |
|
7448 |
provider = logistics_client.getProvider(ordersList[0].logistics_provider_id)
|
| - |
|
7449 |
providerLimits = logistics_client.getProviderLimitDetailsForPincode(provider.id, ordersList[0].customer_pincode)
|
| - |
|
7450 |
print 'Accpet Order Process Started'
|
| - |
|
7451 |
|
| - |
|
7452 |
'''
|
| - |
|
7453 |
Check For Pre Conditions
|
| - |
|
7454 |
'''
|
| - |
|
7455 |
for order in ordersList:
|
| - |
|
7456 |
totalWeight = totalWeight + order.total_weight
|
| - |
|
7457 |
#if order.cod:
|
| - |
|
7458 |
totalOrdersAmount = totalOrdersAmount + order.total_amount
|
| - |
|
7459 |
|
| - |
|
7460 |
if isPrivateDealUser:
|
| - |
|
7461 |
if totalOrdersAmount > privateDealUser.bulkShipmentAmountLimit:
|
| - |
|
7462 |
raise TransactionServiceException(208, "Private Deal Counter "+privateDealUser.counter_id+ " Group Shipment Weight Limit Violated")
|
| - |
|
7463 |
|
| - |
|
7464 |
print 'totalWeight',totalWeight
|
| - |
|
7465 |
if totalWeight > provider.bundleWeightLimit:
|
| - |
|
7466 |
raise TransactionServiceException(210, "Logistics Partner "+provider.name+ " Group Shipment Weight Limit Violated")
|
| - |
|
7467 |
|
| - |
|
7468 |
if order.cod:
|
| - |
|
7469 |
if totalOrdersAmount > provider.maxCodLimit:
|
| - |
|
7470 |
raise TransactionServiceException(210, "Logistics Partner "+provider.name+ " Max Cod Amount Collection Limit Violated")
|
| - |
|
7471 |
|
| - |
|
7472 |
websiteCodLimit = float(providerLimits.get("websiteCodLimit"))
|
| - |
|
7473 |
providerPrepaidLimit = float(providerLimits.get("providerPrepaidLimit"))
|
| - |
|
7474 |
|
| - |
|
7475 |
if order.cod:
|
| - |
|
7476 |
if totalOrdersAmount > websiteCodLimit:
|
| - |
|
7477 |
raise TransactionServiceException(212, "Website Maximum COD Limit Violated")
|
| - |
|
7478 |
|
| - |
|
7479 |
if not order.cod:
|
| - |
|
7480 |
if totalOrdersAmount > providerPrepaidLimit:
|
| - |
|
7481 |
raise TransactionServiceException(212, "Logistics Partner "+provider.name+ " Max Cod Amount Collection Limit Violated")
|
| - |
|
7482 |
|
| - |
|
7483 |
for order in ordersList:
|
| - |
|
7484 |
if order.status 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]:
|
| - |
|
7485 |
if not order.cod:
|
| - |
|
7486 |
if order.transaction.status == TransactionStatus.AUTHORIZED:
|
| - |
|
7487 |
__capture_txn(order)
|
| - |
|
7488 |
break
|
| - |
|
7489 |
|
| - |
|
7490 |
conn = getDbConnection("192.168.190.114","root", "shop2020", "inventory")
|
| - |
|
7491 |
#conn = getDbConnection("localhost","root","shop2020","inventory")
|
| - |
|
7492 |
print 'Connected to Inventory DB'
|
| - |
|
7493 |
|
| - |
|
7494 |
for order in ordersList:
|
| - |
|
7495 |
if order.status 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]:
|
| - |
|
7496 |
order.status = OrderStatus.ACCEPTED
|
| - |
|
7497 |
order.statusDescription = "Order Accepted"
|
| - |
|
7498 |
order.accepted_timestamp = datetime.datetime.now()
|
| - |
|
7499 |
if order.source == 6 or order.source == 7 or order.source == 8:
|
| - |
|
7500 |
if order.source == 8 and order.cod:
|
| - |
|
7501 |
order.cod = False
|
| - |
|
7502 |
continue
|
| - |
|
7503 |
|
| - |
|
7504 |
itemId = order.lineitems[0].item_id
|
| - |
|
7505 |
|
| - |
|
7506 |
selectSql = "select warehouse_id, availability, reserved, held from currentinventorysnapshot where item_id = %d"%(itemId)
|
| - |
|
7507 |
avalibilityResult = None
|
| - |
|
7508 |
|
| - |
|
7509 |
try:
|
| - |
|
7510 |
cursor = conn.cursor()
|
| - |
|
7511 |
cursor.execute(selectSql)
|
| - |
|
7512 |
avalibilityResult = cursor.fetchall()
|
| - |
|
7513 |
except Exception as e:
|
| - |
|
7514 |
print "Error: unable to fetch data"
|
| - |
|
7515 |
|
| - |
|
7516 |
wrongFulFillmentWh = False
|
| - |
|
7517 |
|
| - |
|
7518 |
itemAvailibility = ItemInventory()
|
| - |
|
7519 |
availability = {}
|
| - |
|
7520 |
reserved = {}
|
| - |
|
7521 |
held = {}
|
| - |
|
7522 |
|
| - |
|
7523 |
if avalibilityResult is not None:
|
| - |
|
7524 |
for avalibilityRecord in avalibilityResult:
|
| - |
|
7525 |
if order.fulfilmentWarehouseId == avalibilityRecord[0]:
|
| - |
|
7526 |
wrongFulFillmentWh = False
|
| - |
|
7527 |
break
|
| - |
|
7528 |
else:
|
| - |
|
7529 |
wrongFulFillmentWh = True
|
| - |
|
7530 |
availability[avalibilityRecord[0]] = avalibilityRecord[1]
|
| - |
|
7531 |
reserved[avalibilityRecord[0]] = avalibilityRecord[2]
|
| - |
|
7532 |
held[avalibilityRecord[0]] = avalibilityRecord[3]
|
| - |
|
7533 |
continue
|
| - |
|
7534 |
|
| - |
|
7535 |
itemAvailibility.id = itemId
|
| - |
|
7536 |
itemAvailibility.availability = availability
|
| - |
|
7537 |
itemAvailibility.reserved = reserved
|
| - |
|
7538 |
itemAvailibility.held = held
|
| - |
|
7539 |
|
| - |
|
7540 |
warehousesResult = None
|
| - |
|
7541 |
if wrongFulFillmentWh:
|
| - |
|
7542 |
selectSql = "SELECT * from warehouse where warehouseType ='OURS' and inventoryType='GOOD' and billingWarehouseId=%d"%(order.warehouse_id)
|
| - |
|
7543 |
try:
|
| - |
|
7544 |
cursor = conn.cursor()
|
| - |
|
7545 |
cursor.execute(selectSql)
|
| - |
|
7546 |
warehousesResult = cursor.fetchall()
|
| - |
|
7547 |
except Exception as e:
|
| - |
|
7548 |
print "Error: unable to fetch data 1"
|
| - |
|
7549 |
|
| - |
|
7550 |
newFulfillWh = None
|
| - |
|
7551 |
if warehousesResult is not None:
|
| - |
|
7552 |
for warehouse in warehousesResult:
|
| - |
|
7553 |
if itemAvailibility.availability.has_key(warehouse[0]) and itemAvailibility.availability[warehouse[0]] >= itemAvailibility.reserved[warehouse[0]] + order.lineitems[0].quantity:
|
| - |
|
7554 |
sql_update = "update currentinventorysnapshot set reserved = reserved -%d where item_id = %d and warehouse_id = %d"%(int(order.lineitems[0].quantity),itemId,order.fulfilmentWarehouseId)
|
| - |
|
7555 |
sql_delete = "delete from currentreservationsnapshot where order_id = %d and item_id = %d and warehouse_id = %d and source_id= %d"%(order.id,itemId,order.fulfilmentWarehouseId,sourceId)
|
| - |
|
7556 |
|
| - |
|
7557 |
print sql_update
|
| - |
|
7558 |
try:
|
| - |
|
7559 |
cursor = conn.cursor()
|
| - |
|
7560 |
cursor.execute(sql_update)
|
| - |
|
7561 |
cursor.execute(sql_delete)
|
| - |
|
7562 |
except:
|
| - |
|
7563 |
conn.rollback()
|
| - |
|
7564 |
|
| - |
|
7565 |
sql_get = "select * from currentinventorysnapshot where item_id=%d and warehouse_id=%d"%(itemId,warehouse[0])
|
| - |
|
7566 |
|
| - |
|
7567 |
try:
|
| - |
|
7568 |
cursor = conn.cursor()
|
| - |
|
7569 |
cursor.execute(sql_get)
|
| - |
|
7570 |
invsnapshot = cursor.fetchone()
|
| - |
|
7571 |
if invsnapshot is not None:
|
| - |
|
7572 |
sql_update = "update currentinventorysnapshot set reserved = reserved +%d where item_id = %d and warehouse_id = %d"%(int(order.lineitems[0].quantity),itemId,warehouse[0])
|
| - |
|
7573 |
cursor.execute(sql_update)
|
| - |
|
7574 |
else:
|
| - |
|
7575 |
sql_insert = "insert into currentinventorysnapshot values(%d,%d,%d,%d,%d)"%(itemId,warehouse[0],0,int(order.lineitems[0].quantity),0)
|
| - |
|
7576 |
cursor.execute(sql_insert)
|
| - |
|
7577 |
sql_res_insert = "insert into currentreservationsnapshot values(%d,%d,%d,%d,'%s','%s',%d)"%(itemId,warehouse[0],sourceId,order.id,str(order.created_timestamp), str(order.promised_shipping_time), int(order.lineitems[0].quantity))
|
| - |
|
7578 |
cursor.execute(sql_res_insert)
|
| - |
|
7579 |
except:
|
| - |
|
7580 |
conn.rollback()
|
| - |
|
7581 |
order.fulfilmentWarehouseId = warehouse[0]
|
| - |
|
7582 |
newFulfillWh = warehouse[0]
|
| - |
|
7583 |
break
|
| - |
|
7584 |
|
| - |
|
7585 |
orderFulfillmentWarehouse = None
|
| - |
|
7586 |
try:
|
| - |
|
7587 |
cursor = conn.cursor()
|
| - |
|
7588 |
if wrongFulFillmentWh:
|
| - |
|
7589 |
selectSql = "select id, displayName, vendor_id from warehouse where id = %d"%(newFulfillWh)
|
| - |
|
7590 |
cursor.execute(selectSql)
|
| - |
|
7591 |
else:
|
| - |
|
7592 |
selectSql = "select id, displayName, vendor_id from warehouse where id = %d"%(order.fulfilmentWarehouseId)
|
| - |
|
7593 |
cursor.execute(selectSql)
|
| - |
|
7594 |
orderFulfillmentWarehouse = cursor.fetchone()
|
| - |
|
7595 |
except Exception as e:
|
| - |
|
7596 |
print "Error: unable to fetch data 2"
|
| - |
|
7597 |
|
| - |
|
7598 |
|
| - |
|
7599 |
if orderFulfillmentWarehouse is not None:
|
| - |
|
7600 |
itemPricing = None
|
| - |
|
7601 |
selectSql = "select * from vendoritempricing where item_id = %d and vendor_id = %d"%(itemId,orderFulfillmentWarehouse[2])
|
| - |
|
7602 |
try:
|
| - |
|
7603 |
cursor = conn.cursor()
|
| - |
|
7604 |
cursor.execute(selectSql)
|
| - |
|
7605 |
itemPricing = cursor.fetchone()
|
| - |
|
7606 |
except Exception as e:
|
| - |
|
7607 |
print "Error: unable to fetch data 3"
|
| - |
|
7608 |
|
| - |
|
7609 |
if itemPricing is None:
|
| - |
|
7610 |
raise TransactionServiceException(214, "Vendor Item Pricing Missing For Item Id "+itemId+ " and Fulfillment Warehouse "+ orderFulfillmentWarehouse[1])
|
| - |
|
7611 |
else:
|
| - |
|
7612 |
order.lineitems[0].transfer_price = itemPricing[4]
|
| - |
|
7613 |
order.lineitems[0].nlc = itemPricing[5]
|
| - |
|
7614 |
|
| - |
|
7615 |
try:
|
| - |
|
7616 |
conn.commit()
|
| - |
|
7617 |
except:
|
| - |
|
7618 |
conn.close()
|
| 7420 |
|
7619 |
|
| - |
|
7620 |
conn.close()
|
| - |
|
7621 |
|
| - |
|
7622 |
print 'Process completed'
|
| - |
|
7623 |
deltype = DeliveryType.PREPAID
|
| - |
|
7624 |
if ordersList[0].cod:
|
| - |
|
7625 |
deltype = DeliveryType.COD
|
| - |
|
7626 |
if not logistics_client.isAlive():
|
| - |
|
7627 |
logistics_client = LogisticsClient().get_client()
|
| - |
|
7628 |
awbNumber = logistics_client.getNewEmptyAwb(provider.id, deltype, totalOrderQuantity)
|
| 7421 |
|
7629 |
|
| - |
|
7630 |
session.commit()
|
| - |
|
7631 |
|
| - |
|
7632 |
for order in ordersList:
|
| - |
|
7633 |
update_order_AWB(order.id, awbNumber)
|
| - |
|
7634 |
|
| - |
|
7635 |
return True
|
| - |
|
7636 |
|
| - |
|
7637 |
def get_group_orders_by_logistics_txn_id(logisticsTxnId):
|
| - |
|
7638 |
orders = Order.query.filter(Order.logisticsTransactionId==logisticsTxnId).all()
|
| - |
|
7639 |
if not orders:
|
| - |
|
7640 |
orders = []
|
| - |
|
7641 |
return orders
|
| - |
|
7642 |
|
| - |
|
7643 |
def add_billing_details_for_groupped_orders(orderIds, invoice_number, itemNumbersMap, serialNumbersMap, freebieWarehouseIdMap, billed_by, jacketNumber, billingType, authorize):
|
| - |
|
7644 |
''' Check for Biller'''
|
| - |
|
7645 |
if billed_by is None or billed_by.strip() == "":
|
| - |
|
7646 |
raise TransactionServiceException(110, "Invalid Biller")
|
| - |
|
7647 |
|
| - |
|
7648 |
ordersList = []
|
| - |
|
7649 |
|
| - |
|
7650 |
''' Check for Order'''
|
| - |
|
7651 |
for orderId in orderIds:
|
| - |
|
7652 |
order = Order.get_by(id=orderId)
|
| - |
|
7653 |
if not order:
|
| - |
|
7654 |
raise TransactionServiceException(301, "No order found for the given order id" + str(orderId))
|
| - |
|
7655 |
else:
|
| - |
|
7656 |
ordersList.append(order)
|
| - |
|
7657 |
|
| - |
|
7658 |
|
| - |
|
7659 |
#inventoryDbConnection = getDbConnection("192.168.190.114","root", "shop2020", "inventory")
|
| - |
|
7660 |
warehouseDbConnection = getDbConnection("localhost","root", "shop2020", "warehouse")
|
| - |
|
7661 |
inventory_client = InventoryClient().get_client()
|
| - |
|
7662 |
warehouse_client = WarehouseClient().get_client()
|
| - |
|
7663 |
catalog_client = CatalogClient().get_client()
|
| - |
|
7664 |
whStateId = None
|
| - |
|
7665 |
for order in ordersList:
|
| - |
|
7666 |
newTaxType = __getOrderTaxType(order)
|
| - |
|
7667 |
if order.taxType == 2:
|
| - |
|
7668 |
if newTaxType == 0:
|
| - |
|
7669 |
raise TransactionServiceException(302, "C-Form billing is not allowed for same state for Order" + str(order.id))
|
| - |
|
7670 |
else:
|
| - |
|
7671 |
order.taxType = newTaxType
|
| - |
|
7672 |
|
| - |
|
7673 |
if jacketNumber is None or jacketNumber <= 0:
|
| - |
|
7674 |
if order.source == OrderSource.EBAY or order.source == OrderSource.SNAPDEAL or order.source == OrderSource.FLIPKART:
|
| - |
|
7675 |
print "Skipping Jacket Number field for OrderId " + str(orderId)
|
| - |
|
7676 |
else:
|
| - |
|
7677 |
raise TransactionServiceException(303, "Invalid jacket number")
|
| - |
|
7678 |
|
| - |
|
7679 |
'''
|
| - |
|
7680 |
First checking whether freebie can be billed or not otherwise wont proceed.
|
| - |
|
7681 |
'''
|
| - |
|
7682 |
if order.freebieItemId:
|
| - |
|
7683 |
if billingType == BillingType.OURS or billingType == BillingType.OURS_EXTERNAL:
|
| - |
|
7684 |
freebieWarehouseId = freebieWarehouseIdMap.get(order.id)[0]
|
| - |
|
7685 |
if freebieWarehouseId:
|
| - |
|
7686 |
if not inventory_client.isAlive():
|
| - |
|
7687 |
inventory_client = InventoryClient().get_client()
|
| - |
|
7688 |
warehouse = inventory_client.getWarehouse(freebieWarehouseId)
|
| - |
|
7689 |
if warehouse.warehouseType!= WarehouseType.OURS or warehouse.inventoryType != InventoryType.GOOD:
|
| - |
|
7690 |
raise TransactionServiceException(304,'Billing of Freebie is only allowed from OURS_GOOD warehouses. Order Id:- '+str(order.id))
|
| - |
|
7691 |
if not warehouse_client.isAlive():
|
| - |
|
7692 |
warehouse_client = WarehouseClient().get_client()
|
| - |
|
7693 |
isItemAvailable = warehouse_client.isItemAvailableForSale(order.freebieItemId, "", freebieWarehouseId)
|
| - |
|
7694 |
if isItemAvailable == False:
|
| - |
|
7695 |
raise TransactionServiceException(305,'No Freebie Item available. Order Id- '+str(order.id))
|
| - |
|
7696 |
else:
|
| - |
|
7697 |
raise TransactionServiceException(306,'No warehouseId provided for billing of freebie. Order Id-'+str(order.id))
|
| - |
|
7698 |
|
| - |
|
7699 |
lineitem = order.lineitems[0]
|
| - |
|
7700 |
item_id = lineitem.item_id
|
| - |
|
7701 |
|
| - |
|
7702 |
'''
|
| - |
|
7703 |
Checking if order is a freebie split-order and if the order is cod and if the original order is marked as delivered.
|
| - |
|
7704 |
'''
|
| - |
|
7705 |
freebie_order_info_text = "Freebie Order for Order ID"
|
| - |
|
7706 |
if lineitem.extra_info and freebie_order_info_text in lineitem.extra_info:
|
| - |
|
7707 |
canbillOrder = __isFreebieOrderBillable(order)
|
| - |
|
7708 |
if canbillOrder == False:
|
| - |
|
7709 |
raise TransactionServiceException(307,'Parent order for this is COD and is still undelivered')
|
| - |
|
7710 |
|
| - |
|
7711 |
if not catalog_client.isAlive():
|
| - |
|
7712 |
catalog_client = CatalogClient().get_client()
|
| - |
|
7713 |
item = catalog_client.getItem(item_id)
|
| - |
|
7714 |
if order.status == OrderStatus.ACCEPTED:
|
| - |
|
7715 |
if order.source == 6:
|
| - |
|
7716 |
order.jacket_number = "600"+str(orderId)
|
| - |
|
7717 |
elif order.source == 7:
|
| - |
|
7718 |
order.jacket_number = "700"+str(orderId)
|
| - |
|
7719 |
elif order.source == 8:
|
| - |
|
7720 |
order.jacket_number = "800"+str(orderId)
|
| - |
|
7721 |
else:
|
| - |
|
7722 |
order.jacket_number = jacketNumber
|
| - |
|
7723 |
|
| - |
|
7724 |
itemNumbers = itemNumbersMap.get(order.id)
|
| - |
|
7725 |
|
| - |
|
7726 |
lineitem.item_number = itemNumbers[0]
|
| - |
|
7727 |
serialNumbers = serialNumbersMap.get(order.id)
|
| - |
|
7728 |
|
| - |
|
7729 |
if serialNumbers:
|
| - |
|
7730 |
finalSerialNo =''
|
| - |
|
7731 |
for serialNumber in serialNumbers:
|
| - |
|
7732 |
finalSerialNo = finalSerialNo +','+ serialNumber
|
| - |
|
7733 |
|
| - |
|
7734 |
finalSerialNo = finalSerialNo[1:]
|
| - |
|
7735 |
|
| - |
|
7736 |
if lineitem.serial_number is None:
|
| - |
|
7737 |
lineitem.serial_number = finalSerialNo
|
| - |
|
7738 |
else:
|
| - |
|
7739 |
lineitem.serial_number = lineitem.serial_number + ',' + finalSerialNo
|
| - |
|
7740 |
order.status = OrderStatus.BILLED
|
| - |
|
7741 |
order.statusDescription = "Order Billed"
|
| - |
|
7742 |
order.billing_timestamp = datetime.datetime.now()
|
| - |
|
7743 |
order.billed_by = billed_by
|
| - |
|
7744 |
|
| - |
|
7745 |
# Letting the billing process fail in cases where we are unable to
|
| - |
|
7746 |
# fill in transfer price
|
| - |
|
7747 |
try:
|
| - |
|
7748 |
if not inventory_client.isAlive():
|
| - |
|
7749 |
inventory_client = InventoryClient().get_client()
|
| - |
|
7750 |
warehouse = inventory_client.getWarehouse(order.fulfilmentWarehouseId)
|
| - |
|
7751 |
item_pricing = inventory_client.getItemPricing(item_id, warehouse.vendor.id)
|
| - |
|
7752 |
lineitem.transfer_price = item_pricing.transferPrice
|
| - |
|
7753 |
lineitem.nlc = item_pricing.nlc
|
| - |
|
7754 |
if order.taxType == TaxType.CFORM:
|
| - |
|
7755 |
lineitem.vatRate = 2
|
| - |
|
7756 |
else:
|
| - |
|
7757 |
if not catalog_client.isAlive():
|
| - |
|
7758 |
catalog_client = CatalogClient().get_client()
|
| - |
|
7759 |
if fetchStateMaster()[warehouse.stateId].vatType==VatType.MRP:
|
| - |
|
7760 |
lineitem.vatRate = catalog_client.getVatPercentageForItem(lineitem.item_id, warehouse.stateId, lineitem.mrp)
|
| - |
|
7761 |
else:
|
| - |
|
7762 |
lineitem.vatRate = catalog_client.getVatPercentageForItem(lineitem.item_id, warehouse.stateId, lineitem.unit_price)
|
| - |
|
7763 |
order.vendorId = warehouse.vendor.id
|
| - |
|
7764 |
whStateId = warehouse.stateId
|
| - |
|
7765 |
except InventoryServiceException as e:
|
| - |
|
7766 |
print sys.exc_info()[0]
|
| - |
|
7767 |
print e.message
|
| - |
|
7768 |
raise TransactionServiceException(110, 'Transfer price missing for itemId: ' + str(item_id) + ' and vendor: ' + str(warehouse.vendor.id))
|
| - |
|
7769 |
|
| - |
|
7770 |
if order.orderType == OrderType.B2B:
|
| - |
|
7771 |
tinNumber = Attribute.query.filter(Attribute.orderId == order.id).filter(Attribute.name == "tinNumber").first()
|
| - |
|
7772 |
if tinNumber is None:
|
| - |
|
7773 |
raise TransactionServiceException(308, "Tin Number is Missing for B2B Order. Please contact engineering Team" + str(orderId))
|
| - |
|
7774 |
if newTaxType != 0:
|
| - |
|
7775 |
order.orderType = OrderType.B2C
|
| - |
|
7776 |
|
| - |
|
7777 |
if billingType == BillingType.OURS:
|
| - |
|
7778 |
if order.productCondition == ProductCondition.GOOD:
|
| - |
|
7779 |
# Fetching GOOD w/h corresponding to the virtual one here
|
| - |
|
7780 |
if not warehouse.billingWarehouseId:
|
| - |
|
7781 |
if not inventory_client.isAlive():
|
| - |
|
7782 |
inventory_client = InventoryClient().get_client()
|
| - |
|
7783 |
warehouse = inventory_client.getWarehouses(None, InventoryType.GOOD, warehouse.vendor.id, order.warehouse_id, 0)[0]
|
| - |
|
7784 |
|
| - |
|
7785 |
whCursor = warehouseDbConnection.cursor()
|
| - |
|
7786 |
''' Good Serialized'''
|
| - |
|
7787 |
if ItemType.SERIALIZED == item.type:
|
| - |
|
7788 |
for serialNumber in serialNumbers:
|
| - |
|
7789 |
invItemSql = "select i.id, i.itemId, i.itemNumber, i.serialNumber, i.initialQuantity, i.currentQuantity, i.purchaseId, i.purchaseReturnId, i.currentWarehouseId, i.lastScanType, i.transferStatus, physicalWarehouseId, po.supplierId, l.unitPrice, l.nlc from inventoryItem i join purchase p on i.purchaseId = p.id join purchaseorder po on p.purchaseOrder_id = po.id join lineitem l on (i.itemId = l.itemId and po.id =l.purchaseOrder_id) where i.serialNumber ='%s' order by i.id desc limit 1"%(serialNumber)
|
| - |
|
7790 |
whCursor.execute(invItemSql)
|
| - |
|
7791 |
invItem = whCursor.fetchone()
|
| - |
|
7792 |
if invItem is None:
|
| - |
|
7793 |
raise TransactionServiceException(309, "No Item in the inventory with this serial number " + serialNumber+" and Order Id:- "+str(order.id))
|
| - |
|
7794 |
if item.id!=invItem[1]:
|
| - |
|
7795 |
if not catalog_client.isAlive():
|
| - |
|
7796 |
catalog_client = CatalogClient().get_client()
|
| - |
|
7797 |
sritem = catalog_client.getItem(invItem[1])
|
| - |
|
7798 |
scanItemString = " ".join([str(sritem.brand), str(sritem.modelName), str(sritem.modelNumber), str(sritem.color)])
|
| - |
|
7799 |
lineItemString = " ".join([str(lineitem.brand), str(lineitem.model_name), str(lineitem.model_number), str(lineitem.color)])
|
| - |
|
7800 |
raise TransactionServiceException(310, "Trying to scan " + scanItemString + " instead of " + lineItemString+" Order Id- "+order.id)
|
| - |
|
7801 |
if order.warehouse_id!= invItem[11]:
|
| - |
|
7802 |
raise TransactionServiceException(311, "No Item residing in Billing Warehouse with this serial number " + serialNumber+" and Order Id:- "+str(order.id))
|
| - |
|
7803 |
if invItem[10] is not None and invItem[10]=='IN_TRANSIT':
|
| - |
|
7804 |
raise TransactionServiceException(312, "Trying to Scan In-Transit Inventory " + serialNumber+" and Order Id:- "+str(order.id))
|
| - |
|
7805 |
if invItem[9]=='MARKED_BAD' or invItem[9]=='DOA_IN' or invItem[9]=='DOA_OUT' or invItem[9]=='DOA_REJECTED' or invItem[9]=='SALE_RET_UNUSABLE' or invItem[9]=='BAD_SALE':
|
| - |
|
7806 |
raise TransactionServiceException(313, "Trying to Scan Bad Inventory Serial Number:- " + serialNumber+" and Order Id:- "+str(order.id))
|
| - |
|
7807 |
scanSql = "select * from scanNew where inventoryItemId =%d"%(invItem[0])
|
| - |
|
7808 |
whCursor.execute(scanSql)
|
| - |
|
7809 |
scans = whCursor.fetchall()
|
| - |
|
7810 |
if scans is None:
|
| - |
|
7811 |
raise TransactionServiceException(314, "Item with Serial Number:- " + serialNumber+" never scanned in the system")
|
| - |
|
7812 |
lastScan = scans[len(scans)-1]
|
| - |
|
7813 |
if lastScan[3]=='SALE':
|
| - |
|
7814 |
raise TransactionServiceException(315, "Inventory Item with serial number- "+ serialNumber+" already scanned against order id- "+str(lastScan[6]))
|
| - |
|
7815 |
if warehouse.id!=invItem[8]:
|
| - |
|
7816 |
raise TransactionServiceException(316, "Inventory Item scanning from vendor warehouse "+str(invItem[8])+" instead of order fulfillment warehouse "+str(warehouse.id)+" order id- "+str(order.id))
|
| - |
|
7817 |
|
| - |
|
7818 |
current_time = datetime.datetime.now()
|
| - |
|
7819 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),1,order.id)
|
| - |
|
7820 |
whCursor.execute(insertScanSql)
|
| - |
|
7821 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-1, lastScanType='SALE' where id=%d and serialnumber ='%s'"%(invItem[0],serialNumber)
|
| - |
|
7822 |
whCursor.execute(updateInvItemSql)
|
| - |
|
7823 |
|
| - |
|
7824 |
|
| - |
|
7825 |
lineitem.transfer_price = invItem[13]
|
| - |
|
7826 |
lineitem.nlc = invItem[14]
|
| - |
|
7827 |
order.vendorId = invItem[12]
|
| - |
|
7828 |
|
| - |
|
7829 |
if warehouse.billingType == BillingType.OURS:
|
| - |
|
7830 |
if not inventory_client.isAlive():
|
| - |
|
7831 |
inventory_client = InventoryClient().get_client()
|
| - |
|
7832 |
inventory_client.addInventory(item.id, warehouse.id, -1)
|
| - |
|
7833 |
|
| - |
|
7834 |
else:
|
| - |
|
7835 |
invItemSql = "select i.id, i.itemId, i.itemNumber, i.serialNumber, i.initialQuantity, i.currentQuantity, i.purchaseId, i.purchaseReturnId, i.currentWarehouseId, i.lastScanType, i.transferStatus, physicalWarehouseId, po.supplierId, l.unitPrice, l.nlc from inventoryItem i join purchase p on i.purchaseId = p.id join purchaseorder po on p.purchaseOrder_id = po.id join lineitem l on (i.itemId = l.itemId and po.id =l.purchaseOrder_id) where i.itemId = %d AND i.currentQuantity > 0 AND i.currentWarehouseId = %d AND i.physicalWarehouseId = %d AND i.lastScanType not in ('MARKED_BAD','DOA_IN','DOA_REJECTED','DOA_REPLACED') AND (i.transferStatus is NULL or i.transferStatus != 'IN_TRANSIT') AND i.itemNumber ='%s'"%(item.id,order.fulfilmentWarehouseId,order.warehouse_id,itemNumbers[0])
|
| - |
|
7836 |
whCursor.execute(invItemSql)
|
| - |
|
7837 |
invItems = whCursor.fetchall()
|
| - |
|
7838 |
if invItems is None:
|
| - |
|
7839 |
raise TransactionServiceException(317, "No Item in the inventory with this item number " + itemNumbers[0]+" in Vendor Warehouse Id- "+str(warehouse.id)+" Order Id:- "+str(order.id))
|
| - |
|
7840 |
totalCurrentQuantity =0
|
| - |
|
7841 |
for invItem in invItems:
|
| - |
|
7842 |
totalCurrentQuantity = totalCurrentQuantity + invItem[5]
|
| - |
|
7843 |
|
| - |
|
7844 |
orderQuantity = lineitem.quantity
|
| - |
|
7845 |
if totalCurrentQuantity < lineitem.quantity:
|
| - |
|
7846 |
raise TransactionServiceException(318, "Unsufficient Quantity with this item number " + itemNumbers[0]+" in Vendor Warehouse Id- "+str(warehouse.id)+" Order Id:- "+str(order.id))
|
| - |
|
7847 |
|
| - |
|
7848 |
for invItem in invItems:
|
| - |
|
7849 |
scanSql = "select * from scanNew where inventoryItemId =%d"%(invItem[0])
|
| - |
|
7850 |
whCursor.execute(scanSql)
|
| - |
|
7851 |
scans = whCursor.fetchall()
|
| - |
|
7852 |
|
| - |
|
7853 |
if scans is None:
|
| - |
|
7854 |
raise TransactionServiceException(319, "Item with Item Number:- " + itemNumbers[0]+" never scanned in the system")
|
| - |
|
7855 |
|
| - |
|
7856 |
|
| - |
|
7857 |
currentQuantity = invItem[5]
|
| - |
|
7858 |
scanQuantity = 0
|
| - |
|
7859 |
if orderQuantity >0:
|
| - |
|
7860 |
if currentQuantity < orderQuantity:
|
| - |
|
7861 |
scanQuantity = currentQuantity
|
| - |
|
7862 |
orderQuantity = orderQuantity - currentQuantity
|
| - |
|
7863 |
elif currentQuantity > orderQuantity:
|
| - |
|
7864 |
scanQuantity = currentQuantity - orderQuantity
|
| - |
|
7865 |
orderQuantity = 0
|
| - |
|
7866 |
else:
|
| - |
|
7867 |
scanQuantity = currentQuantity
|
| - |
|
7868 |
orderQuantity = 0
|
| - |
|
7869 |
else:
|
| - |
|
7870 |
break
|
| - |
|
7871 |
|
| - |
|
7872 |
current_time = datetime.datetime.now()
|
| - |
|
7873 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),scanQuantity,order.id)
|
| - |
|
7874 |
whCursor.execute(insertScanSql)
|
| - |
|
7875 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-%d, lastScanType='SALE' where id=%d "%(scanQuantity,invItem[0])
|
| - |
|
7876 |
whCursor.execute(updateInvItemSql)
|
| - |
|
7877 |
|
| - |
|
7878 |
lineitem.transfer_price = invItem[13]
|
| - |
|
7879 |
lineitem.nlc = invItem[14]
|
| - |
|
7880 |
order.vendorId = invItem[12]
|
| - |
|
7881 |
|
| - |
|
7882 |
if warehouse.billingType == BillingType.OURS:
|
| - |
|
7883 |
if not inventory_client.isAlive():
|
| - |
|
7884 |
inventory_client = InventoryClient().get_client()
|
| - |
|
7885 |
inventory_client.addInventory(item.id, warehouse.id, long(-1.0*lineitem.quantity))
|
| - |
|
7886 |
|
| - |
|
7887 |
else:
|
| - |
|
7888 |
''' Bad Serialized '''
|
| - |
|
7889 |
if not warehouse.billingWarehouseId:
|
| - |
|
7890 |
if not inventory_client.isAlive():
|
| - |
|
7891 |
inventory_client = InventoryClient().get_client()
|
| - |
|
7892 |
warehouse = inventory_client.getWarehouses(None, InventoryType.GOOD, warehouse.vendor.id, order.warehouse_id, 0)[0]
|
| - |
|
7893 |
|
| - |
|
7894 |
whCursor = warehouseDbConnection.cursor()
|
| - |
|
7895 |
if ItemType.SERIALIZED == item.type:
|
| - |
|
7896 |
for serialNumber in serialNumbers:
|
| - |
|
7897 |
invItemSql = "select i.id, i.itemId, i.itemNumber, i.serialNumber, i.initialQuantity, i.currentQuantity, i.purchaseId, i.purchaseReturnId, i.currentWarehouseId, i.lastScanType, i.transferStatus, physicalWarehouseId, po.supplierId, l.unitPrice, l.nlc from inventoryItem i join purchase p on i.purchaseId = p.id join purchaseorder po on p.purchaseOrder_id = po.id join lineitem l on (i.itemId = l.itemId and po.id =l.purchaseOrder_id) where i.serialNumber ='%s' order by i.id desc limit 1"%(serialNumber)
|
| - |
|
7898 |
whCursor.execute(invItemSql)
|
| - |
|
7899 |
invItem = whCursor.fetchone()
|
| - |
|
7900 |
if invItem is None:
|
| - |
|
7901 |
raise TransactionServiceException(110, "No Item in the inventory with this serial number " + serialNumber+" and Order Id:- "+str(order.id))
|
| - |
|
7902 |
if item.id!=invItem[1]:
|
| - |
|
7903 |
if not catalog_client.isAlive():
|
| - |
|
7904 |
catalog_client = CatalogClient().get_client()
|
| - |
|
7905 |
sritem = catalog_client.getItem(invItem[1])
|
| - |
|
7906 |
scanItemString = " ".join([str(sritem.brand), str(sritem.modelName), str(sritem.modelNumber), str(sritem.color)])
|
| - |
|
7907 |
lineItemString = " ".join([str(lineitem.brand), str(lineitem.model_name), str(lineitem.model_number), str(lineitem.color)])
|
| - |
|
7908 |
raise TransactionServiceException(110, "Trying to scan " + scanItemString + " instead of " + lineItemString+" Order Id- "+order.id)
|
| - |
|
7909 |
if order.warehouse_id!= invItem[11]:
|
| - |
|
7910 |
raise TransactionServiceException(110, "No Item residing in Billing Warehouse with this serial number " + serialNumber+" and Order Id:- "+str(order.id))
|
| - |
|
7911 |
if invItem[10] is not None and invItem[10]=='IN_TRANSIT':
|
| - |
|
7912 |
raise TransactionServiceException(110, "Trying to Scan In-Transit Inventory " + serialNumber+" and Order Id:- "+str(order.id))
|
| - |
|
7913 |
if invItem[9]!='MARKED_BAD' or invItem[9]!='DOA_IN' or invItem[9]!='DOA_REJECTED' or invItem[9]!='SALE_RET_UNUSABLE':
|
| - |
|
7914 |
raise TransactionServiceException(110, "Trying to Scan Good Inventory Serial Number:- " + serialNumber+" and Order Id:- "+str(order.id))
|
| - |
|
7915 |
scanSql = "select * from scanNew where inventoryItemId =%d"%(invItem[0])
|
| - |
|
7916 |
whCursor.execute(scanSql)
|
| - |
|
7917 |
scans = whCursor.fetchall()
|
| - |
|
7918 |
if scans is None:
|
| - |
|
7919 |
raise TransactionServiceException(110, "Item with Serial Number:- " + serialNumber+" never scanned in the system")
|
| - |
|
7920 |
lastScan = scans[len(scans)-1]
|
| - |
|
7921 |
if lastScan[3]=='BAD_SALE':
|
| - |
|
7922 |
raise TransactionServiceException(110, "Inventory Item with serial number- "+ serialNumber+" already scanned against order id- "+str(lastScan[6]))
|
| - |
|
7923 |
if warehouse.id!=invItem[8]:
|
| - |
|
7924 |
raise TransactionServiceException(110, "Inventory Item scanning from vendor warehouse "+str(invItem[8])+" instead of order fulfillment warehouse "+str(warehouse.id)+" order id- "+str(order.id))
|
| - |
|
7925 |
current_time = datetime.datetime.now()
|
| - |
|
7926 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'BAD_SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),1,order.id)
|
| - |
|
7927 |
whCursor.execute(insertScanSql)
|
| - |
|
7928 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-1, lastScanType='BAD_SALE' where id=%d and serialnumber ='%s'"%(invItem[0],serialNumber)
|
| - |
|
7929 |
whCursor.execute(updateInvItemSql)
|
| - |
|
7930 |
|
| - |
|
7931 |
|
| - |
|
7932 |
lineitem.transfer_price = invItem[13]
|
| - |
|
7933 |
lineitem.nlc = invItem[14]
|
| - |
|
7934 |
order.vendorId = invItem[12]
|
| - |
|
7935 |
else:
|
| - |
|
7936 |
invItemSql = "select i.id, i.itemId, i.itemNumber, i.serialNumber, i.initialQuantity, i.currentQuantity, i.purchaseId, i.purchaseReturnId, i.currentWarehouseId, i.lastScanType, i.transferStatus, physicalWarehouseId, po.supplierId, l.unitPrice, l.nlc from inventoryItem i join purchase p on i.purchaseId = p.id join purchaseorder po on p.purchaseOrder_id = po.id join lineitem l on (i.itemId = l.itemId and po.id =l.purchaseOrder_id) where i.itemNumber = '%s' AND itemId = %d AND i.physicalWarehouseId = %d AND i.currentWarehouseId =%d AND lastScanType in ('BAD_SALE', 'MARKED_BAD', 'SALE_RET_UNUSABLE', 'DOA_REJECTED', 'DOA_IN') AND (i.transferStatus is NULL or i.transferStatus != 'IN_TRANSIT')"%(itemNumbers[0],item.id,order.warehouse_id,order.fulfilmentWarehouseId)
|
| - |
|
7937 |
whCursor.execute(invItemSql)
|
| - |
|
7938 |
invItems = whCursor.fetchall()
|
| - |
|
7939 |
if invItems is None:
|
| - |
|
7940 |
raise TransactionServiceException(110, "No Item in the inventory with this item number " + itemNumbers[0]+" in Vendor Warehouse Id- "+str(warehouse.id)+" Order Id:- "+str(order.id))
|
| - |
|
7941 |
totalCurrentQuantity =0
|
| - |
|
7942 |
for invItem in invItems:
|
| - |
|
7943 |
totalCurrentQuantity = totalCurrentQuantity + invItem[5]
|
| - |
|
7944 |
|
| - |
|
7945 |
orderQuantity = lineitem.quantity
|
| - |
|
7946 |
if totalCurrentQuantity < lineitem.quantity:
|
| - |
|
7947 |
raise TransactionServiceException(110, "Unsufficient Quantity with this item number " + itemNumbers[0]+" in Vendor Warehouse Id- "+str(warehouse.id)+" Order Id:- "+str(order.id))
|
| - |
|
7948 |
|
| - |
|
7949 |
for invItem in invItems:
|
| - |
|
7950 |
scanSql = "select * from scanNew where inventoryItemId =%d"%(invItem[0])
|
| - |
|
7951 |
whCursor.execute(scanSql)
|
| - |
|
7952 |
scans = whCursor.fetchall()
|
| - |
|
7953 |
|
| - |
|
7954 |
if scans is None:
|
| - |
|
7955 |
raise TransactionServiceException(110, "Item with Item Number:- " + itemNumbers[0]+" never scanned in the system")
|
| - |
|
7956 |
if warehouse.billingType == BillingType.OURS:
|
| - |
|
7957 |
if not inventory_client.isAlive():
|
| - |
|
7958 |
inventory_client = InventoryClient().get_client()
|
| - |
|
7959 |
inventory_client.addInventory(item.id, warehouse.id, long(-1.0*lineitem.quantity))
|
| - |
|
7960 |
|
| - |
|
7961 |
currentQuantity = invItem[5]
|
| - |
|
7962 |
scanQuantity = 0
|
| - |
|
7963 |
if orderQuantity >0:
|
| - |
|
7964 |
if currentQuantity < orderQuantity:
|
| - |
|
7965 |
scanQuantity = currentQuantity
|
| - |
|
7966 |
orderQuantity = orderQuantity - currentQuantity
|
| - |
|
7967 |
elif currentQuantity > orderQuantity:
|
| - |
|
7968 |
scanQuantity = currentQuantity - orderQuantity
|
| - |
|
7969 |
orderQuantity = 0
|
| - |
|
7970 |
else:
|
| - |
|
7971 |
scanQuantity = currentQuantity
|
| - |
|
7972 |
orderQuantity = 0
|
| - |
|
7973 |
else:
|
| - |
|
7974 |
break
|
| - |
|
7975 |
|
| - |
|
7976 |
current_time = datetime.datetime.now()
|
| - |
|
7977 |
insertScanSql = "insert into scanNew(inventoryItemId, warehouseId, type, scannedAt, quantity, orderId) values(%d,%d,'%s','%s',%d,%d)"%(invItem[0],warehouse.id,'BAD_SALE',current_time.strftime('%Y-%m-%d %H:%M:%S'),scanQuantity,order.id)
|
| - |
|
7978 |
whCursor.execute(insertScanSql)
|
| - |
|
7979 |
updateInvItemSql = "update inventoryItem set currentQuantity = currentQuantity-%d, lastScanType='BAD_SALE' where id=%d "%(scanQuantity,invItem[0])
|
| - |
|
7980 |
whCursor.execute(updateInvItemSql)
|
| - |
|
7981 |
|
| - |
|
7982 |
lineitem.transfer_price = invItem[13]
|
| - |
|
7983 |
lineitem.nlc = invItem[14]
|
| - |
|
7984 |
order.vendorId = invItem[12]
|
| - |
|
7985 |
|
| - |
|
7986 |
elif billingType == BillingType.OURS_EXTERNAL:
|
| - |
|
7987 |
try:
|
| - |
|
7988 |
if ItemType.SERIALIZED == item.type:
|
| - |
|
7989 |
serialNumber = serialNumbers[0]
|
| - |
|
7990 |
else:
|
| - |
|
7991 |
serialNumber = ""
|
| - |
|
7992 |
if not warehouse_client.isAlive():
|
| - |
|
7993 |
warehouse_client = WarehouseClient().get_client()
|
| - |
|
7994 |
inventoryItem = warehouse_client.scanForOursExternalSale(lineitem.item_id, serialNumber, lineitem.item_number, invoice_number, order.fulfilmentWarehouseId, lineitem.transfer_price, lineitem.nlc, order.id)
|
| - |
|
7995 |
lineitem.transfer_price = inventoryItem.unitPrice
|
| - |
|
7996 |
lineitem.nlc = inventoryItem.nlc
|
| - |
|
7997 |
order.vendorId = inventoryItem.supplierId
|
| - |
|
7998 |
except WarehouseServiceException as e:
|
| - |
|
7999 |
print sys.exc_info()[0]
|
| - |
|
8000 |
print 'Could not scan out orders due to: ' + e.message
|
| - |
|
8001 |
raise TransactionServiceException(110, e.message)
|
| - |
|
8002 |
else:
|
| - |
|
8003 |
if not warehouse.isAvailabilityMonitored:
|
| - |
|
8004 |
if not inventory_client.isAlive():
|
| - |
|
8005 |
inventory_client = InventoryClient().get_client()
|
| - |
|
8006 |
inventory_client.addInventory(item.id, warehouse.id, -1 * lineitem.quantity)
|
| - |
|
8007 |
if order.freebieItemId:
|
| - |
|
8008 |
inventoryItem = None
|
| - |
|
8009 |
for freebieWhId in freebieWarehouseIdMap.get(order.id):
|
| - |
|
8010 |
try:
|
| - |
|
8011 |
warehouse_client = WarehouseClient().get_client()
|
| - |
|
8012 |
inventoryItem = warehouse_client.scanfreebie(orderId, order.freebieItemId, freebieWhId, ScanType.SALE);
|
| - |
|
8013 |
except Exception as e:
|
| - |
|
8014 |
print e.message
|
| - |
|
8015 |
raise TransactionServiceException(110,'Error in billing freebie for warehouseId ' + str(freebieWarehouseId))
|
| - |
|
8016 |
|
| - |
|
8017 |
attr = Attribute()
|
| - |
|
8018 |
attr.orderId = orderId
|
| - |
|
8019 |
attr.name = "freebie_tp"
|
| - |
|
8020 |
attr.value = str(inventoryItem.unitPrice)
|
| - |
|
8021 |
|
| - |
|
8022 |
attr1 = Attribute()
|
| - |
|
8023 |
attr1.orderId = orderId
|
| - |
|
8024 |
attr1.name = "freebie_vendor"
|
| - |
|
8025 |
attr1.value = str(inventoryItem.supplierId)
|
| - |
|
8026 |
|
| - |
|
8027 |
attr2 = Attribute()
|
| - |
|
8028 |
attr2.orderId = orderId
|
| - |
|
8029 |
attr2.name = "freebie_nlc"
|
| - |
|
8030 |
attr2.value = str(inventoryItem.nlc)
|
| - |
|
8031 |
if order.productCondition != ProductCondition.BAD:
|
| - |
|
8032 |
'''
|
| - |
|
8033 |
Reduce the reservation count for all line items of the given order.
|
| - |
|
8034 |
'''
|
| - |
|
8035 |
try:
|
| - |
|
8036 |
if not inventory_client.isAlive():
|
| - |
|
8037 |
inventory_client = InventoryClient().get_client()
|
| - |
|
8038 |
for lineitem in order.lineitems:
|
| - |
|
8039 |
inventory_client.reduceReservationCount(lineitem.item_id, order.fulfilmentWarehouseId, sourceId, order.id, lineitem.quantity)
|
| - |
|
8040 |
except:
|
| - |
|
8041 |
print "Unable to reduce reservation count"
|
| - |
|
8042 |
|
| - |
|
8043 |
warehouseDbConnection.commit()
|
| - |
|
8044 |
warehouseDbConnection.close()
|
| - |
|
8045 |
session.commit()
|
| - |
|
8046 |
|
| - |
|
8047 |
if billingType == BillingType.OURS or billingType == BillingType.OURS_EXTERNAL:
|
| - |
|
8048 |
invoiceNumber = get_next_invoice_counter(ordersList[0].orderType, whStateId)
|
| - |
|
8049 |
|
| - |
|
8050 |
for order in ordersList:
|
| - |
|
8051 |
order.invoice_number = invoiceNumber
|
| - |
|
8052 |
session.commit()
|
| - |
|
8053 |
|
| - |
|
8054 |
return True
|
| 7422 |
|
8055 |
|
| 7423 |
if __name__ == '__main__':
|
8056 |
if __name__ == '__main__':
|
| 7424 |
print get_orders_by_mobile_number("9650889334")
|
8057 |
print get_orders_by_mobile_number("9650889334")
|