Subversion Repositories SmartDukaan

Rev

Rev 22120 | Rev 22393 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
22059 amit.gupta 1
'''
2
Created on Apr 12, 2016
3
 
4
@author: amit
5
'''
6
from datetime import datetime
7
from elixir import *
8
from random import randint
9
from shop2020.clients.CatalogClient import CatalogClient
10
from shop2020.clients.InventoryClient import InventoryClient
11
from shop2020.clients.PurchaseClient import PurchaseClient
12
from shop2020.clients.TransactionClient import TransactionClient
13
from shop2020.clients.UserClient import UserClient
14
from shop2020.model.v1.catalog.impl import DataService
15
from shop2020.model.v1.catalog.impl.DataService import CentralGstMaster, \
22119 amit.gupta 16
    StateGstMaster, Category, CategoryHsnCodes
22059 amit.gupta 17
from shop2020.thriftpy.model.v1.order.ttypes import TransactionStatus
18
from sqlalchemy import desc, asc
19
from sqlalchemy.orm import aliased
20
from sqlalchemy.sql.expression import or_, distinct, func, and_, exists
21
from sqlalchemy.sql.functions import now
22
 
23
 
22119 amit.gupta 24
def getCategories():
25
 
26
    categories = session.query(Category).all()
27
    rootCategory = 10000
28
    l1 = []
29
    for category in categories:
30
        if category.parent_category_id == rootCategory:
31
            l1.append(category.id)
32
 
33
    leaves = []
34
    for category in categories:
35
        if category.parent_category_id in l1:
36
            leaves.append(category)
22059 amit.gupta 37
 
22119 amit.gupta 38
    for leaf in leaves:
39
        print "({}, '{}')".format(leaf.id, leaf.label) 
40
 
41
def getChildCategories(rootCategory, categories):
42
    childCategories = []
43
 
44
 
22059 amit.gupta 45
def addHsnCodes():
22119 amit.gupta 46
    gstTuple = [
47
                (10027, 'Power Bank', '85076000', 28),
22123 amit.gupta 48
                (10030, 'USB Cables', '85444220', 28),
49
                (10024, 'Ear Buds', '85183000', 18),
22119 amit.gupta 50
                (12101, 'Fitness Band', '90318000', 18)
51
            ]
22059 amit.gupta 52
 
22119 amit.gupta 53
 
54
 
55
    for (categoryId, description, hsnCode, rate)  in gstTuple:
22123 amit.gupta 56
        categoryHsnCode = session.query(CategoryHsnCodes).filter(CategoryHsnCodes.hsnCode==hsnCode).filter(CategoryHsnCodes.categoryId==categoryId).first()
22119 amit.gupta 57
        if categoryHsnCode:
22123 amit.gupta 58
            if categoryHsnCode.description !=description:
59
                categoryHsnCode.description = description
22119 amit.gupta 60
        else:
61
            categoryHsnCode = CategoryHsnCodes()
62
            categoryHsnCode.hsnCode = hsnCode
63
            categoryHsnCode.categoryId = categoryId
64
            categoryHsnCode.description = description
65
 
22059 amit.gupta 66
        cgs = session.query(CentralGstMaster).filter(CentralGstMaster.hsnCode==hsnCode).filter(CentralGstMaster.gstPercent==rate).first()
67
        if cgs is None:
68
            cgs = CentralGstMaster()
69
            cgs.hsnCode = hsnCode
70
            cgs.gstPercent = rate
71
            cgs.startDate = datetime.now()
72
        for i in range(37):
73
            sgst = rate/2
74
            cgst = rate/2
75
            sgs = session.query(StateGstMaster).filter(StateGstMaster.hsnCode==hsnCode).filter(StateGstMaster.sgstPercent==sgst).filter(StateGstMaster.cgstPercent==cgst).filter(StateGstMaster.stateId==i).first()
76
            if sgs is None:
77
                sgs = StateGstMaster()
78
                sgs.sgstPercent = sgst
79
                sgs.cgstPercent = cgst
80
                sgs.hsnCode = hsnCode
81
                sgs.stateId = i
82
                sgs.startDate = datetime.now()
83
 
84
    session.commit()
85
    session.close()
86
#c = CatalogClient().get_client()
87
#print c.getGstRatesByState(0)
88
#print c.getInterStateGstRates()
89
#print c.getHsnCodesByCategory(10006)
90
#
91
#ic = InventoryClient().get_client()
92
#print ic.getStateMaster()
93
#
94
#
95
#pc = PurchaseClient().get_client()
96
#print pc.getPurchaseOrder(22141)
97
 
98
 
99
#uc = UserClient().get_client()
100
#print uc.getCounterByUserId(120398953)
101
 
102
def main():
103
    pass
22120 amit.gupta 104
    DataService.initialize('catalog', 'localhost', False)
22119 amit.gupta 105
    addHsnCodes()
106
    #getCategories()
22059 amit.gupta 107
 
108
#tc = TransactionClient().get_client()
109
#tc.changeTransactionStatus(699979, TransactionStatus.COD_IN_PROCESS, "COD in Process", 0, 0, 1)
110
#tc.verifyOrderForTransaction(699983)
111
#tc.acceptOrder(748108)
112
#tc.addBillingDetailsForGrouppedOrders([748108], 'AMIT2', {748108:'1'}, {748108:['443423432431', '443423432432']}, {}, 'dl-ad-adonis', 1, 0, False, 'BulkInvoice')
113
                                        #order_ids, invoice_number, itemNumbersMap, serialNumbersMap, {}, 'mp-mmx-admin', 1, 0, False, 'Individual'
114
 
22119 amit.gupta 115
#tc = TransactionClient().get_client()
116
#print tc.getLatestUserWalletHistory(483649, 0, 20)
117
 
118
 
119
#tupleList = [
120
#(10006, 'Mobile Phone')
121
#(10008, 'Codless Phones')
122
#(10010, 'Tablets')
123
#(10012, 'Bluetooth Headset')
124
#(10013, 'Memory Card')
125
#(10014, 'Battery')
126
#(10015, 'Headset')
127
#(10016, 'Charger')
128
#(10017, 'Pen Drive')
129
#(10018, 'Carrying Case')
130
#(10019, 'Car Charger')
131
#(10020, 'Screen Guard')
132
#(10021, 'Face Plate')
133
#(10022, 'Decal')
134
#(10023, 'Data Cable')
135
#(10024, 'Ear Buds')
136
#(10025, 'Cleaning Kit')
137
#(10026, 'Speaker')
138
#(10027, 'Power Bank')
139
#(10028, 'AUX Cable')
140
#(10029, 'Vehiclle Mounts')
141
#(10030, 'Cables')
142
#(10032, 'LED Lights')
143
#(10050, 'Laptops')
144
#(10071, 'RAM')
145
#(10072, 'Cooling Stands')
146
#(10073, 'External Hard Disks')
147
#(10074, 'USB Hubs')
148
#(10075, 'Solid State Drives')
149
#(10076, 'Wi-Fi Routers')
150
#(10077, 'Laptop Batteries')
151
#(10078, 'Antivirus')
152
#(10079, 'Office Packs')
153
#(10080, 'Keyboards')
154
#(10081, 'Mouse')
155
#(10082, 'Headphones')
156
#(10083, 'Data Card')
157
#(10084, 'Mouse pads')
158
#(10085, 'Laptop bags')
159
#(10086, 'Laptop Chargers')
160
#(10087, 'Printer cartridges')
161
#(10088, 'TV Tuner')
162
#(10089, 'USB Light')
163
#(10090, 'Card Reader')
164
#(10091, 'USB Devices')
165
#(11002, 'Compact Cameras')
166
#(11003, 'DSLR Cameras')
167
#(12002, 'Portable Music Players')
168
#(12101, 'Smart Watches')
169
#(12102, 'Corded Phones')
170
#(12103, 'Screen Magnifier')
171
#(12104, 'Mobile Holder')
172
#(12105, 'Selfie Stick')
173
#(13101, 'Projectors')
174
#(14101, 'Scanners')
175
#(14201, 'DVD Player')
176
#(14202, 'LED TV')
177
#(14203, 'LCD TV')
178
#(14204, 'Home Theater')
179
#(14205, 'Karaoke')
180
#(14206, 'Radio')
181
#(14207, 'Lens')
182
#(14208, 'Boom Box')
183
#(14301, 'Watch Strap')
184
#(14401, 'Gaming Consoles')
185
#(14501, 'Power Sockets')
186
#(14601, 'Remote')
187
#(15001, 'Trimmers')
188
#(15002, 'Shavers')
189
#(15003, 'Hair Dryers')
190
#(15004, 'Hair Stylers')
191
#(15005, 'Epilators')
192
#(15006, 'Hair Straightners')
193
#(15007, 'Hair  Curlers')
194
#(15008, 'Grooming Kits')
195
#(15009, 'Clippers')
196
#(15101, 'Microwave Ovens and OTG')
197
#(15102, 'Juicer, Mixer, Grinder')
198
#(15103, 'Food Processors')
199
#(15104, 'Choppers and Blenders')
200
#(15105, 'Cookers and Steamers')
201
#(15106, 'Induction Cooktops')
202
#(15107, 'Toasters and Sandwich Makers')
203
#(15108, 'Grills and Tandoors')
204
#(15109, 'Coffee Maker and Kettles')
205
#(15110, 'Air Fryers')
206
#(15111, 'Chimney and Hoods')
207
#(15112, 'Gas Stoves and Hobs')
208
#(15113, 'Roti Maker and Snack Maker')
209
#(15301, 'Irons')
210
#(15302, 'Vacuum Cleaners')
211
#(15303, 'Lighting')
212
#(15304, 'Air Purifiers')
213
#(15305, 'Water Purifiers')
214
#(15306, 'Dish Washers')
215
#(16001, 'Power and Hand Tool Kits')
216
#(16002, 'Drills')
217
#(16003, 'Power Planes')
218
#(16004, 'Sanders and Polishers')
219
#(16005, 'Soldering Irons')
220
#(16006, 'Nailers and Staplers')
221
#(16007, 'Blowers')
222
#(16101, 'Hammers')
223
#(16102, 'Axes')
224
#(16103, 'Clamps')
225
#(16104, 'Crimpers')
226
#(16105, 'Chisels and Sets')
227
#(16106, 'Socket Sets')
228
#(16107, 'Cutters and Snips')
229
#(16108, 'Power and Hand Tool Kits')
230
#(16109, 'Wrenches and Sets')
231
#(16110, 'Pliers')
232
#(16111, 'Locks')
233
#(16112, 'Screwdrivers and Allen Keys')
234
#(16113, 'Handsaws and Sets')
235
#(16201, 'Calipers')
236
#(16202, 'Level Measuring Instruments')
237
#]
238
 
239
 
22059 amit.gupta 240
 
241
 
242
if __name__ == "__main__":
22119 amit.gupta 243
    main()
244
 
245
 
246
 
247