Subversion Repositories SmartDukaan

Rev

Rev 19960 | Rev 19980 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19960 Rev 19973
Line 4... Line 4...
4
Created on 29-Mar-2010
4
Created on 29-Mar-2010
5
 
5
 
6
@author: Chandranshu
6
@author: Chandranshu
7
'''
7
'''
8
 
8
 
-
 
9
import MySQLdb
-
 
10
import base64
9
from datetime import date, timedelta
11
from datetime import date, timedelta
-
 
12
import datetime
10
from decimal import Decimal
13
from decimal import Decimal
11
from elixir import *
14
from elixir import *
-
 
15
import httplib
-
 
16
import logging
12
from math import ceil
17
from math import ceil
-
 
18
import math
-
 
19
import os
13
from random import randrange
20
from random import randrange
-
 
21
import re
-
 
22
from reportlab.lib import colors
14
from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY
23
from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY
15
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
24
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
16
from reportlab.lib.units import inch, mm
25
from reportlab.lib.units import inch, mm
17
from reportlab.pdfgen.canvas import Canvas
26
from reportlab.pdfgen.canvas import Canvas
18
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, \
27
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, \
19
    BaseDocTemplate, Frame, PageTemplate
28
    BaseDocTemplate, Frame, PageTemplate, Table, TableStyle
20
from reportlab.rl_config import defaultPageSize
29
from reportlab.rl_config import defaultPageSize
-
 
30
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
-
 
31
from sqlalchemy.sql import func
-
 
32
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, \
-
 
33
    between
-
 
34
from string import Template
-
 
35
import sys
21
from reportlab.lib import colors
36
from textwrap import dedent
-
 
37
import time
-
 
38
import traceback
-
 
39
import urllib
22
from reportlab.platypus import Table, TableStyle
40
from xml.dom.minidom import parseString
-
 
41
 
23
from shop2020.clients.AlertClient import AlertClient
42
from shop2020.clients.AlertClient import AlertClient
24
from shop2020.clients.CRMClient import CRMClient
43
from shop2020.clients.CRMClient import CRMClient
25
from shop2020.clients.CatalogClient import CatalogClient
44
from shop2020.clients.CatalogClient import CatalogClient
26
from shop2020.clients.HelperClient import HelperClient
45
from shop2020.clients.HelperClient import HelperClient
27
from shop2020.clients.InventoryClient import InventoryClient
46
from shop2020.clients.InventoryClient import InventoryClient
Line 31... Line 50...
31
from shop2020.clients.UserClient import UserClient
50
from shop2020.clients.UserClient import UserClient
32
from shop2020.clients.WarehouseClient import WarehouseClient
51
from shop2020.clients.WarehouseClient import WarehouseClient
33
from shop2020.config.client.ConfigClient import ConfigClient
52
from shop2020.config.client.ConfigClient import ConfigClient
34
from shop2020.model.v1 import order
53
from shop2020.model.v1 import order
35
from shop2020.model.v1.order.impl import DataService, RechargeService
54
from shop2020.model.v1.order.impl import DataService, RechargeService
36
from shop2020.model.v1.order.impl.Convertors import to_t_emi_scheme, to_t_order,\
55
from shop2020.model.v1.order.impl.Convertors import to_t_emi_scheme, to_t_order, \
37
    cutoff_date
56
    cutoff_date
38
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
57
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
39
    Order, BatchNoGenerator, InvoiceIDGenerator, TransactionRequiringExtraProcessing, \
58
    Order, BatchNoGenerator, InvoiceIDGenerator, TransactionRequiringExtraProcessing, \
40
    OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary, \
59
    OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary, \
41
    CodVerificationAgent, Attribute, RechargeVoucherTracker, EmiScheme, MiscCharges, \
60
    CodVerificationAgent, Attribute, RechargeVoucherTracker, EmiScheme, MiscCharges, \
Line 43... Line 62...
43
    RechargeTransaction, HotspotStore, WalletForCompany, WalletHistoryForCompany, \
62
    RechargeTransaction, HotspotStore, WalletForCompany, WalletHistoryForCompany, \
44
    FRC, OperatorSeries, SourceDetail, Company, EbayOrder, AmazonFbaSalesSnapshot, \
63
    FRC, OperatorSeries, SourceDetail, Company, EbayOrder, AmazonFbaSalesSnapshot, \
45
    AmazonOrder, StoreOrderDetail, EdcBank, StoreOrderCollection, \
64
    AmazonOrder, StoreOrderDetail, EdcBank, StoreOrderCollection, \
46
    HotspotServiceMatrix, SnapdealOrder, FlipkartOrder, DataInsuranceDetailForOrder, \
65
    HotspotServiceMatrix, SnapdealOrder, FlipkartOrder, DataInsuranceDetailForOrder, \
47
    AmazonFbaOrderReturns, FlipkartAdvantageOrder, InvoiceCounterGenerator, \
66
    AmazonFbaOrderReturns, FlipkartAdvantageOrder, InvoiceCounterGenerator, \
48
    TransactionShipmentSequence, HsOrder, Creditor, UserSanction, CreditHistory, LoanHistory, \
67
    TransactionShipmentSequence, HsOrder, Creditor, UserSanction, CreditHistory, \
49
    ShipmentLogisticsCostDetail, ReturnOrderInfo, ReturnTransaction , ReturnPickupRequest
68
    LoanHistory, ShipmentLogisticsCostDetail, ReturnOrderInfo, ReturnTransaction, \
-
 
69
    ReturnPickupRequest, SellerWarehouse, Seller, Organisation
50
from shop2020.model.v1.order.impl.model.BaseOrder import BaseOrder
70
from shop2020.model.v1.order.impl.model.BaseOrder import BaseOrder
51
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
71
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
52
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import \
72
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import \
53
    MobileRechargeOrder
73
    MobileRechargeOrder
54
from shop2020.model.v1.order.impl.model.RechargeDenomination import \
74
from shop2020.model.v1.order.impl.model.RechargeDenomination import \
Line 72... Line 92...
72
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
92
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
73
    TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
93
    TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
74
    HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType, RechargeOrderStatus, \
94
    HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType, RechargeOrderStatus, \
75
    RechargeType, RechargeStatistics, DeviceNumberInfo, EmiChargeType, PayMethod, \
95
    RechargeType, RechargeStatistics, DeviceNumberInfo, EmiChargeType, PayMethod, \
76
    OrderSource, StorePaymentStatus, ProductCondition, TaxType, \
96
    OrderSource, StorePaymentStatus, ProductCondition, TaxType, \
77
    AmazonFCWarehouseLocation, RechargeMode, CreditTxnType, CreditHistory as TCreditHistory, \
97
    AmazonFCWarehouseLocation, RechargeMode, CreditTxnType, \
-
 
98
    CreditHistory as TCreditHistory, LoanHistory as TLoanHistory, \
78
    LoanHistory as TLoanHistory, ShipmentLogisticsCostDetail as TShipmentLogisticsCostDetail, \
99
    ShipmentLogisticsCostDetail as TShipmentLogisticsCostDetail, \
79
    ReturnTransactionStatus, ReturnAction, ReturnTxnResolutionStatus, ReplacementShippingType, \
100
    ReturnTransactionStatus, ReturnAction, ReturnTxnResolutionStatus, \
-
 
101
    ReplacementShippingType, ReturnTxnPickupStatus, ReceivedReturnType, \
80
    ReturnTxnPickupStatus, ReceivedReturnType, ReturnPickupType, RefundType
102
    ReturnPickupType, RefundType, SellerInfo
81
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType, CouponCategory, \
103
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType, CouponCategory, \
82
    User, Sex
104
    User, Sex
83
from shop2020.thriftpy.payments.ttypes import PaymentException
105
from shop2020.thriftpy.payments.ttypes import PaymentException
84
from shop2020.thriftpy.utils.ttypes import UserSmsInfo, SmsType
106
from shop2020.thriftpy.utils.ttypes import UserSmsInfo, SmsType
85
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
107
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
86
    WarehouseServiceException
108
    WarehouseServiceException
87
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part, \
109
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part, \
88
    mail_html
110
    mail_html
89
from shop2020.utils.Utils import to_py_date, to_java_date, \
111
from shop2020.utils.Utils import to_py_date, to_java_date, \
90
    getSyncOperatorsForRecharge
112
    getSyncOperatorsForRecharge
91
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
-
 
92
from sqlalchemy.sql import func
-
 
93
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, \
-
 
94
    between
-
 
95
from string import Template
-
 
96
from suds.client import Client
113
from suds.client import Client
97
from textwrap import dedent
-
 
98
from xml.dom.minidom import parseString
-
 
99
import base64
-
 
100
import datetime
-
 
101
import httplib
-
 
102
import logging
-
 
103
import os
114
 
104
import re
115
 
105
import sys
-
 
106
import time
-
 
107
import traceback
-
 
108
import urllib
-
 
109
import MySQLdb
-
 
110
import math
-
 
111
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
116
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
112
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
117
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
113
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
118
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
114
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
119
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
115
 
-
 
116
 
-
 
117
logging.basicConfig(level=logging.DEBUG)
120
logging.basicConfig(level=logging.DEBUG)
118
 
121
 
119
sourceId = int(ConfigClient().get_property("sourceid"))
122
sourceId = int(ConfigClient().get_property("sourceid"))
120
capitalFloatPayMethod = 456789 
123
capitalFloatPayMethod = 456789 
121
SaholicHelpEmailId = "Saholic <help@saholic.com>"
124
SaholicHelpEmailId = "Saholic <help@saholic.com>"
Line 2396... Line 2399...
2396
                session.commit()
2399
                session.commit()
2397
                return True
2400
                return True
2398
        if billingType == BillingType.OURS or billingType == BillingType.OURS_EXTERNAL:
2401
        if billingType == BillingType.OURS or billingType == BillingType.OURS_EXTERNAL:
2399
            #as of now only company 2 - SORPL, 3-New company is operating and cutoff config will decide the company to be used to bill
2402
            #as of now only company 2 - SORPL, 3-New company is operating and cutoff config will decide the company to be used to bill
2400
            #until further change - Amit Gupta
2403
            #until further change - Amit Gupta
2401
            companyId = 2
2404
            seller_id = __get_seller()
2402
            if cutoff_date <= datetime.datetime.now():
2405
            order.invoice_number = get_next_invoice_counter(seller_id, order.warehouse_id, order.orderType)
2403
                companyId = 3
2406
            order.seller_id = seller_id
2404
            order.invoice_number = get_next_invoice_counter(companyId, order.orderType, whStateId)
-
 
2405
        session.commit()
2407
        session.commit()
2406
        return True
2408
        return True
2407
    else:
2409
    else:
2408
        return False
2410
        return False
2409
 
2411
 
Line 3195... Line 3197...
3195
    entity_id = InvoiceIDGenerator.query.filter(InvoiceIDGenerator.orderType == orderType).with_lockmode("update").one()
3197
    entity_id = InvoiceIDGenerator.query.filter(InvoiceIDGenerator.orderType == orderType).with_lockmode("update").one()
3196
    invoice_number = entity_id.id + 1
3198
    invoice_number = entity_id.id + 1
3197
    entity_id.id = invoice_number
3199
    entity_id.id = invoice_number
3198
    return invoice_number
3200
    return invoice_number
3199
 
3201
 
3200
def get_next_invoice_counter(companyId, orderType, stateId):
3202
def get_next_invoice_counter(seller_id, warehouse_id, orderType):
3201
    if OrderType.B2Cbulk == orderType:
3203
    if OrderType.B2Cbulk == orderType:
3202
        orderType = OrderType.B2C
3204
        orderType = OrderType.B2C
3203
    entity_id = InvoiceCounterGenerator.query.filter(InvoiceCounterGenerator.orderType == orderType).filter(InvoiceCounterGenerator.stateId == stateId).filter(InvoiceCounterGenerator.companyId==companyId).with_lockmode("update").one()
3205
    #entity_id = InvoiceCounterGenerator.query.filter(InvoiceCounterGenerator.orderType == orderType).filter(InvoiceCounterGenerator.stateId == stateId).filter(InvoiceCounterGenerator.companyId==companyId).with_lockmode("update").one()
-
 
3206
    entity_id = SellerWarehouse.query.filter(SellerWarehouse.orderType == orderType).filter(SellerWarehouse.warehouse_id == warehouse_id).filter(SellerWarehouse.seller_id==seller_id).with_lockmode("update").one()
3204
    invoice_number = entity_id.id + 1
3207
    invoice_number = entity_id.id + 1
3205
    entity_id.id = invoice_number 
3208
    entity_id.id = invoice_number 
3206
    ret_invoiceNo = entity_id.prefix + str(invoice_number) 
3209
    ret_invoiceNo = entity_id.prefix + str(invoice_number) 
3207
    return ret_invoiceNo
3210
    return ret_invoiceNo
3208
 
3211
 
Line 9327... Line 9330...
9327
    if warehouseDbConnection.open:
9330
    if warehouseDbConnection.open:
9328
        warehouseDbConnection.close()
9331
        warehouseDbConnection.close()
9329
    session.commit()
9332
    session.commit()
9330
    
9333
    
9331
    if billingType == BillingType.OURS or billingType == BillingType.OURS_EXTERNAL:
9334
    if billingType == BillingType.OURS or billingType == BillingType.OURS_EXTERNAL:
9332
        #as of now only company 1 - SORPL, 3-New company is operating and cutoff config will decide the company to be used to bill
-
 
9333
        #until further change - Amit Gupta
9335
        #get seller for current warehouse id
9334
        companyId = 2
-
 
9335
        if cutoff_date <= datetime.datetime.now():
9336
        seller_id  = __get_seller()
9336
            companyId = 3
-
 
9337
        
-
 
9338
        invoiceNumber = get_next_invoice_counter(companyId, ordersList[0].orderType, whStateId)
9337
        invoiceNumber = get_next_invoice_counter(seller_id, ordersList[0].warehouse_id, ordersList[0].orderType)
9339
            
9338
            
9340
            
9339
            
9341
    
9340
    
9342
    invoiceTypeVal = 1
9341
    invoiceTypeVal = 1
9343
    if not individualInvoice:
9342
    if not individualInvoice:
Line 9352... Line 9351...
9352
        txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==int(transactionShipSeqValues[0])).filter(TransactionShipmentSequence.sequence==int(transactionShipSeqValues[1])).order_by(desc(TransactionShipmentSequence.id)).first()
9351
        txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==int(transactionShipSeqValues[0])).filter(TransactionShipmentSequence.sequence==int(transactionShipSeqValues[1])).order_by(desc(TransactionShipmentSequence.id)).first()
9353
        txnShipSeq.invoiceFormat = invoiceTypeVal
9352
        txnShipSeq.invoiceFormat = invoiceTypeVal
9354
 
9353
 
9355
    for order in ordersList:
9354
    for order in ordersList:
9356
        order.invoice_number = invoiceNumber
9355
        order.invoice_number = invoiceNumber
-
 
9356
        order.seller_id = seller_id
9357
    session.commit()
9357
    session.commit()
9358
                            
9358
                            
9359
    return True
9359
    return True
9360
 
9360
 
9361
def get_invoice_format_logistics_txn_id(transactionId, shipementSeq):
9361
def get_invoice_format_logistics_txn_id(transactionId, shipementSeq):
Line 10966... Line 10966...
10966
    returnOrderInfo.masterOrderId = order.logisticsTransactionId
10966
    returnOrderInfo.masterOrderId = order.logisticsTransactionId
10967
    returnOrderInfo.warehouse_id = order.warehouse_id
10967
    returnOrderInfo.warehouse_id = order.warehouse_id
10968
    returnOrderInfo.returnAction = returnInfo.returnAction
10968
    returnOrderInfo.returnAction = returnInfo.returnAction
10969
    returnOrderInfo.freebieItemId = order.freebieItemId
10969
    returnOrderInfo.freebieItemId = order.freebieItemId
10970
    returnOrderInfo.returnTxnResolutionStatus = ReturnTxnResolutionStatus._VALUES_TO_NAMES[ReturnTxnResolutionStatus.PENDING]
10970
    returnOrderInfo.returnTxnResolutionStatus = ReturnTxnResolutionStatus._VALUES_TO_NAMES[ReturnTxnResolutionStatus.PENDING]
-
 
10971
    
-
 
10972
def get_seller_info(sellerId):
-
 
10973
    sellerInfo = SellerInfo()
-
 
10974
    seller = Seller.get_by(id=sellerId)
-
 
10975
    if seller is None:
-
 
10976
        return None
-
 
10977
    else:
-
 
10978
        sellerInfo.tin = seller.tin
-
 
10979
        org = Organisation.get_by(id=seller.organisation_id)
-
 
10980
        if org is None:
-
 
10981
            return None
-
 
10982
        else:
-
 
10983
            org = Organisation()
-
 
10984
            sellerInfo.organisationName = org.name
-
 
10985
            sellerInfo.regId = org.registered_id
-
 
10986
            sellerInfo.registeredAddress =  org.address
-
 
10987
            if org.type == 'company':
-
 
10988
                sellerInfo.cinNumber = org.registered_id
-
 
10989
            return sellerInfo
-
 
10990
            
-
 
10991
        
-
 
10992
        return "1"
10971
 
10993
 
10972
def split_return_order_info(returnOrderId, splitReturnOrderQty):
10994
def split_return_order_info(returnOrderId, splitReturnOrderQty):
10973
    returnOrder = ReturnOrderInfo.get_by(id=returnOrderId)
10995
    returnOrder = ReturnOrderInfo.get_by(id=returnOrderId)
10974
    if returnOrder is None:
10996
    if returnOrder is None:
10975
        raise TransactionServiceException(101, "No Return Order is there with this Order Id")
10997
        raise TransactionServiceException(101, "No Return Order is there with this Order Id")
-
 
10998
 
-
 
10999
#Seller would be used to get tin number
-
 
11000
def __get_seller():
-
 
11001
        #As of now we should hardcode the seller
-
 
11002
        return 5
10976
    
11003
    
10977
if __name__ == '__main__':
11004
if __name__ == '__main__':
10978
    print get_orders_by_mobile_number("9650889334")
11005
    print get_orders_by_mobile_number("9650889334")