Subversion Repositories SmartDukaan

Rev

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

Rev 16201 Rev 16300
Line 1... Line 1...
1
import os
1
import os
2
import re
2
import re
3
import smtplib
3
import smtplib
4
import csv
4
import csv
5
import MySQLdb
5
import MySQLdb
6
from dtr.storage import DataService
6
from dtr.storage import DataService, Mongo
7
from dtr.storage.DataService import MerchantSubOrders
7
from dtr.storage.DataService import MerchantSubOrders
8
from elixir import *
8
from elixir import *
9
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
9
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
10
from sqlalchemy.sql import func
10
from sqlalchemy.sql import func
11
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, \
11
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, \
12
    between
12
    between
13
import datetime
13
import datetime
14
from pymongo.mongo_client import MongoClient
14
from pymongo.mongo_client import MongoClient
-
 
15
 
15
import optparse
16
import optparse
16
    
17
    
17
db = MySQLdb.connect('localhost',"root","shop2020","dtr" )
18
db = MySQLdb.connect('localhost',"root","shop2020","dtr" )
18
 
19
 
19
DataService.initialize(db_hostname="localhost")
20
DataService.initialize(db_hostname="localhost")
Line 30... Line 31...
30
    storeId = None
31
    storeId = None
31
    userId = None
32
    userId = None
32
    productCode = None
33
    productCode = None
33
    brand = None
34
    brand = None
34
    productName = None
35
    productName = None
-
 
36
    category_id=None
35
    amountPaid = None
37
    amountPaid = None
36
    quantity = None
38
    quantity = None
37
    unitPrice = None
39
    unitPrice = None
38
    status = None
40
    status = None
39
    createdTime = None
41
    createdTime = None
40
    
42
    
41
    def __init__(self,orderId, merchantOrderId, merchantSubOrderId, storeId, userId, productCode, productName, amountPaid, quantity,unitPrice, status, createdTime):
43
    def __init__(self,orderId, merchantOrderId, merchantSubOrderId, storeId, userId, productCode, productName,category_id, amountPaid, quantity,unitPrice, status, createdTime):
42
        self.orderId = orderId
44
        self.orderId = orderId
43
        self.merchantOrderId = merchantOrderId
45
        self.merchantOrderId = merchantOrderId
44
        self.merchantSubOrderId = merchantSubOrderId
46
        self.merchantSubOrderId = merchantSubOrderId
45
        self.storeId = storeId
47
        self.storeId = storeId
46
        self.userId = userId 
48
        self.userId = userId 
47
        self.productCode = productCode
49
        self.productCode = productCode
48
        self.productName= productName
50
        self.productName= productName
-
 
51
        self.category_id= category_id
49
        self.amountPaid = amountPaid
52
        self.amountPaid = amountPaid
50
        self.quantity = quantity
53
        self.quantity = quantity
51
        self.unitPrice = unitPrice
54
        self.unitPrice = unitPrice
52
        self.status = status
55
        self.status = status
53
        if createdTime is not None:
56
        if createdTime is not None:
54
            self.createdTime = to_py_date(createdTime)
57
            self.createdTime = to_py_date(createdTime)
55
        else:
58
        else:
56
            self.createdTime = None
59
            self.createdTime = None
57
        self.userId = userId
60
        self.userId = userId
58
        
61
        
-
 
62
 
59
def getAndStoreMerchantSubOrders():
63
def getAndStoreMerchantSubOrders():
60
    existingMaxOrderId = session.query(func.max(MerchantSubOrders.orderId)).one()
64
    existingMaxOrderId = session.query(func.max(MerchantSubOrders.orderId)).one()
61
    db = client.Dtr
65
    db = client.Dtr
62
    collection = db.merchantOrder
66
    collection = db.merchantOrder
63
    orders = collection.find({'orderId':{'$gt':int(existingMaxOrderId[0])}})
67
    orders = collection.find({'orderId':{'$gt':int(existingMaxOrderId[0])}})
Line 88... Line 92...
88
                    product = list(masterDataCollection.find({'secondaryIdentifier':productCode.strip(), 'source_id':storeId}))
92
                    product = list(masterDataCollection.find({'secondaryIdentifier':productCode.strip(), 'source_id':storeId}))
89
                if product is not None and len(product)>0:
93
                if product is not None and len(product)>0:
90
                    merchantSubOrder.brand = product[0]["brand"]
94
                    merchantSubOrder.brand = product[0]["brand"]
91
                else:
95
                else:
92
                    merchantSubOrder.brand = 'NA'
96
                    merchantSubOrder.brand = 'NA'
-
 
97
                skuData=Mongo.getItemByMerchantIdentifier(merchantSubOrder.productCode,merchantSubOrder.storeId)
-
 
98
                if(skuData.has_key('category_id')):
-
 
99
                    merchantSubOrder.category_id=skuData['category_id']
93
                
100
                else:
-
 
101
                    merchantSubOrder.category_id=None    
94
                existingMerchantSubOrder = MerchantSubOrders.query.filter(MerchantSubOrders.orderId == orderId).filter(MerchantSubOrders.merchantOrderId == merchantOrderId).filter(MerchantSubOrders.merchantSubOrderId == merchantSubOrder.merchantSubOrderId).first()
102
                existingMerchantSubOrder = MerchantSubOrders.query.filter(MerchantSubOrders.orderId == orderId).filter(MerchantSubOrders.merchantOrderId == merchantOrderId).filter(MerchantSubOrders.merchantSubOrderId == merchantSubOrder.merchantSubOrderId).first()
95
                if existingMerchantSubOrder is None:
103
                if existingMerchantSubOrder is None:
96
                    merchantSubOrderDetail = MerchantSubOrders()
104
                    merchantSubOrderDetail = MerchantSubOrders()
97
                    merchantSubOrderDetail.orderId = merchantSubOrder.orderId
105
                    merchantSubOrderDetail.orderId = merchantSubOrder.orderId
98
                    merchantSubOrderDetail.merchantOrderId = merchantSubOrder.merchantOrderId
106
                    merchantSubOrderDetail.merchantOrderId = merchantSubOrder.merchantOrderId
Line 100... Line 108...
100
                    merchantSubOrderDetail.storeId = merchantSubOrder.storeId
108
                    merchantSubOrderDetail.storeId = merchantSubOrder.storeId
101
                    merchantSubOrderDetail.userId = merchantSubOrder.userId
109
                    merchantSubOrderDetail.userId = merchantSubOrder.userId
102
                    merchantSubOrderDetail.productCode = merchantSubOrder.productCode
110
                    merchantSubOrderDetail.productCode = merchantSubOrder.productCode
103
                    merchantSubOrderDetail.brand = merchantSubOrder.brand
111
                    merchantSubOrderDetail.brand = merchantSubOrder.brand
104
                    merchantSubOrderDetail.productName = merchantSubOrder.productName
112
                    merchantSubOrderDetail.productName = merchantSubOrder.productName
-
 
113
                    merchantSubOrderDetail.categoryId = merchantSubOrder.category_id
105
                    merchantSubOrderDetail.amountPaid = merchantSubOrder.amountPaid
114
                    merchantSubOrderDetail.amountPaid = merchantSubOrder.amountPaid
106
                    merchantSubOrderDetail.quantity = merchantSubOrder.quantity
115
                    merchantSubOrderDetail.quantity = merchantSubOrder.quantity
107
                    merchantSubOrderDetail.unitPrice = merchantSubOrder.unitPrice
116
                    merchantSubOrderDetail.unitPrice = merchantSubOrder.unitPrice
108
                    merchantSubOrderDetail.status = merchantSubOrder.status
117
                    merchantSubOrderDetail.status = merchantSubOrder.status
109
                    merchantSubOrderDetail.createdTime = merchantSubOrder.createdTime
118
                    merchantSubOrderDetail.createdTime = merchantSubOrder.createdTime