Subversion Repositories SmartDukaan

Rev

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

Rev 21594 Rev 21844
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 collections
-
 
10
import MySQLdb
-
 
11
import base64
-
 
12
from datetime import date, timedelta
9
from datetime import date, timedelta
13
import datetime
-
 
14
from decimal import Decimal
10
from decimal import Decimal
15
from elixir import *
11
from elixir import *
16
import httplib
-
 
17
import logging
12
from expiringdict import ExpiringDict
18
from math import ceil
13
from math import ceil
19
import math
-
 
20
import os
-
 
21
from random import randrange
14
from random import randrange
22
import re
-
 
23
from reportlab.lib import colors
15
from reportlab.lib import colors
24
from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY
16
from reportlab.lib.enums import TA_CENTER, TA_JUSTIFY
25
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
17
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
26
from reportlab.lib.units import inch, mm
18
from reportlab.lib.units import inch, mm
27
from reportlab.pdfgen.canvas import Canvas
19
from reportlab.pdfgen.canvas import Canvas
28
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, \
20
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, \
29
    BaseDocTemplate, Frame, PageTemplate, Table, TableStyle
21
    BaseDocTemplate, Frame, PageTemplate, Table, TableStyle
30
from reportlab.rl_config import defaultPageSize
22
from reportlab.rl_config import defaultPageSize
31
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
-
 
32
from sqlalchemy.sql import func
-
 
33
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, \
-
 
34
    between
-
 
35
from string import Template
-
 
36
import sys
-
 
37
from textwrap import dedent
-
 
38
import time
-
 
39
import traceback
-
 
40
import urllib
-
 
41
from xml.dom.minidom import parseString
-
 
42
 
-
 
43
from shop2020.clients.AlertClient import AlertClient
23
from shop2020.clients.AlertClient import AlertClient
44
from shop2020.clients.CRMClient import CRMClient
24
from shop2020.clients.CRMClient import CRMClient
45
from shop2020.clients.CatalogClient import CatalogClient
25
from shop2020.clients.CatalogClient import CatalogClient
46
from shop2020.clients.HelperClient import HelperClient
26
from shop2020.clients.HelperClient import HelperClient
47
from shop2020.clients.InventoryClient import InventoryClient
27
from shop2020.clients.InventoryClient import InventoryClient
Line 65... Line 45...
65
    AmazonOrder, StoreOrderDetail, EdcBank, StoreOrderCollection, \
45
    AmazonOrder, StoreOrderDetail, EdcBank, StoreOrderCollection, \
66
    HotspotServiceMatrix, SnapdealOrder, FlipkartOrder, DataInsuranceDetailForOrder, \
46
    HotspotServiceMatrix, SnapdealOrder, FlipkartOrder, DataInsuranceDetailForOrder, \
67
    AmazonFbaOrderReturns, FlipkartAdvantageOrder, InvoiceCounterGenerator, \
47
    AmazonFbaOrderReturns, FlipkartAdvantageOrder, InvoiceCounterGenerator, \
68
    TransactionShipmentSequence, HsOrder, Creditor, UserSanction, CreditHistory, \
48
    TransactionShipmentSequence, HsOrder, Creditor, UserSanction, CreditHistory, \
69
    LoanHistory, ShipmentLogisticsCostDetail, ReturnOrderInfo, ReturnTransaction, \
49
    LoanHistory, ShipmentLogisticsCostDetail, ReturnOrderInfo, ReturnTransaction, \
70
    ReturnPickupRequest, SellerWarehouse, Seller, Organisation,\
50
    ReturnPickupRequest, SellerWarehouse, Seller, Organisation, \
71
    WarehouseAddressMapping, WarehouseAddressMaster, PMSA, PMSA_Agents, AdvancePayments
51
    WarehouseAddressMapping, WarehouseAddressMaster, PMSA, PMSA_Agents, \
-
 
52
    AdvancePayments
72
from shop2020.model.v1.order.impl.model.BaseOrder import BaseOrder
53
from shop2020.model.v1.order.impl.model.BaseOrder import BaseOrder
73
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
54
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
74
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import \
55
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import \
75
    MobileRechargeOrder
56
    MobileRechargeOrder
76
from shop2020.model.v1.order.impl.model.RechargeDenomination import \
57
from shop2020.model.v1.order.impl.model.RechargeDenomination import \
Line 86... Line 67...
86
from shop2020.model.v1.order.impl.model.UserWalletHistory import \
67
from shop2020.model.v1.order.impl.model.UserWalletHistory import \
87
    UserWalletHistory
68
    UserWalletHistory
88
from shop2020.model.v1.user.impl.Converters import to_t_address
69
from shop2020.model.v1.user.impl.Converters import to_t_address
89
from shop2020.thriftpy.alert.ttypes import MonitoredEntity, EntityType
70
from shop2020.thriftpy.alert.ttypes import MonitoredEntity, EntityType
90
from shop2020.thriftpy.crm.ttypes import *
71
from shop2020.thriftpy.crm.ttypes import *
91
from shop2020.thriftpy.payments.ttypes import PaymentStatus
-
 
92
from shop2020.thriftpy.logistics.ttypes import DeliveryType, PickUpType
72
from shop2020.thriftpy.logistics.ttypes import DeliveryType, PickUpType
93
from shop2020.thriftpy.model.v1.catalog.ttypes import ItemType, ItemCondition
73
from shop2020.thriftpy.model.v1.catalog.ttypes import ItemType, ItemCondition
94
from shop2020.thriftpy.model.v1.inventory.ttypes import BillingType, \
74
from shop2020.thriftpy.model.v1.inventory.ttypes import BillingType, \
95
    InventoryServiceException, WarehouseType, InventoryType, VatType, ItemInventory
75
    InventoryServiceException, WarehouseType, InventoryType, VatType, ItemInventory, \
-
 
76
    WarehouseLocation
96
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
77
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
97
    TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
78
    TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
98
    HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType, RechargeOrderStatus, \
79
    HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType, RechargeOrderStatus, \
99
    RechargeType, RechargeStatistics, DeviceNumberInfo, EmiChargeType, PayMethod, \
80
    RechargeType, RechargeStatistics, DeviceNumberInfo, EmiChargeType, PayMethod, \
100
    OrderSource, StorePaymentStatus, ProductCondition, TaxType, \
81
    OrderSource, StorePaymentStatus, ProductCondition, TaxType, \
Line 104... Line 85...
104
    ReturnTransactionStatus, ReturnAction, ReturnTxnResolutionStatus, \
85
    ReturnTransactionStatus, ReturnAction, ReturnTxnResolutionStatus, \
105
    ReplacementShippingType, ReturnTxnPickupStatus, ReceivedReturnType, \
86
    ReplacementShippingType, ReturnTxnPickupStatus, ReceivedReturnType, \
106
    ReturnPickupType, RefundType, SellerInfo, BuyerInfo, WalletReferenceType
87
    ReturnPickupType, RefundType, SellerInfo, BuyerInfo, WalletReferenceType
107
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType, CouponCategory, \
88
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType, CouponCategory, \
108
    User, Sex
89
    User, Sex
109
from shop2020.thriftpy.payments.ttypes import PaymentException
90
from shop2020.thriftpy.payments.ttypes import PaymentException, PaymentStatus
110
from shop2020.thriftpy.utils.ttypes import UserSmsInfo, SmsType
91
from shop2020.thriftpy.utils.ttypes import UserSmsInfo, SmsType
111
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
92
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
112
    WarehouseServiceException
93
    WarehouseServiceException
113
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part, \
94
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part, \
114
    mail_html
95
    mail_html
115
from shop2020.utils.Utils import to_py_date, to_java_date, \
96
from shop2020.utils.Utils import to_py_date, to_java_date, \
116
    getSyncOperatorsForRecharge, generate_random_code
97
    getSyncOperatorsForRecharge, generate_random_code
117
from suds.client import Client
-
 
118
from sqlalchemy.orm import aliased
98
from sqlalchemy.orm import aliased
-
 
99
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
-
 
100
from sqlalchemy.sql import func
-
 
101
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, \
-
 
102
    between
-
 
103
from string import Template
-
 
104
from suds.client import Client
-
 
105
from textwrap import dedent
-
 
106
from xml.dom.minidom import parseString
-
 
107
import MySQLdb
-
 
108
import base64
-
 
109
import collections
-
 
110
import datetime
-
 
111
import httplib
-
 
112
import logging
-
 
113
import math
-
 
114
import os
-
 
115
import re
-
 
116
import sys
-
 
117
import time
-
 
118
import traceback
-
 
119
import urllib
-
 
120
 
119
 
121
 
120
 
122
 
121
#Start:- 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
122
#End:- 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
123
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
125
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
Line 194... Line 196...
194
stateIdMap = {}
196
stateIdMap = {}
195
 
197
 
196
gvGatewayId = 9
198
gvGatewayId = 9
197
walletGatewayId = 8
199
walletGatewayId = 8
198
 
200
 
-
 
201
HOURS=3600
-
 
202
CACHE_THREE_HOURS = ExpiringDict(max_len=10, max_age_seconds=3*HOURS)
-
 
203
 
-
 
204
 
-
 
205
    
199
def fetchStateMaster():
206
def fetchStateMaster():
200
    global stateIdMap
-
 
201
    if stateIdMap:
-
 
202
        return stateIdMap
207
    if not CACHE_THREE_HOURS.get("statemaster"):
203
    else:
-
 
204
        try:
208
        try:
205
            glob_inventory_client = InventoryClient().get_client()
209
            inventory_client = InventoryClient().get_client()
206
            stateIdMap = glob_inventory_client.getStateMaster()
210
            CACHE_THREE_HOURS["statemaster"] = inventory_client.getStateMaster()
207
            return stateIdMap
211
            
208
        except:
212
        except:
209
            print "Could not fetch"
213
            print "Could not fetch"
-
 
214
    return CACHE_THREE_HOURS.get("statemaster")
210
            
215
            
211
def fetchCreditorTicketSizeMap():
216
def fetchCreditorTicketSizeMap():
212
    global creditorTicketSizeMap
217
    global creditorTicketSizeMap
213
    allCreditors = Creditor.query.all()
218
    allCreditors = Creditor.query.all()
214
    for creditor in allCreditors:
219
    for creditor in allCreditors:
Line 352... Line 357...
352
        for line_item in t_order.lineitems:
357
        for line_item in t_order.lineitems:
353
            litem = LineItem()
358
            litem = LineItem()
354
            litem.item_id = line_item.item_id
359
            litem.item_id = line_item.item_id
355
            litem.productGroup = line_item.productGroup
360
            litem.productGroup = line_item.productGroup
356
            litem.brand = line_item.brand
361
            litem.brand = line_item.brand
-
 
362
            litem.hsnCode = line_item.hsnCode
357
            if line_item.model_number:
363
            if line_item.model_number:
358
                litem.model_number = line_item.model_number
364
                litem.model_number = line_item.model_number
359
            if line_item.model_name:    
365
            if line_item.model_name:    
360
                litem.model_name = line_item.model_name
366
                litem.model_name = line_item.model_name
361
            if line_item.color:
367
            if line_item.color:
Line 2152... Line 2158...
2152
    if parentOrder.cod and parentOrder.status!=12:
2158
    if parentOrder.cod and parentOrder.status!=12:
2153
        return False
2159
        return False
2154
    else:
2160
    else:
2155
        return True
2161
        return True
2156
 
2162
 
-
 
2163
 
2157
def __getOrderTaxType(order):
2164
def __getOrderTaxType(order, state='Delhi'):
-
 
2165
    
-
 
2166
    return TaxType.SGST if state == order.customer_state else TaxType.IGST
2158
    delhiPincodePrefix = "11";
2167
#    delhiPincodePrefix = "11";
2159
    maharashtraPincodePrefix = ["40", "41", "42", "43", "44"];
2168
#    maharashtraPincodePrefix = ["40", "41", "42", "43", "44"];
2160
    karnatakaPincodePrefix = ["56", "57", "58", "59"];
2169
#    karnatakaPincodePrefix = ["56", "57", "58", "59"];
2161
    telenganaPincodes = ["500001","500002","500003","500004","500005","500006","500007","500008","500009","500010","500011","500012","500013","500014","500015","500016","500017","500018","500019","500020","500021","500022","500023","500024","500025","500026","500027","500028","500029","500030","500031","500032","500033","500034","500035","500036","500037","500038","500039","500040","500041","500042","500043","500044","500045","500046","500047","500048","500049","500050","500051","500052","500053","500054","500055","500056","500057","500058","500059","500060","500061","500062","500063","500064","500065","500066","500067","500068","500069","500070","500071","500072","500073","500074","500075","500076","500077","500078","500079","500080","500081","500082","500083","500084","500085","500086","500087","500088","500089","500090","500091","500092","500093","500094","500095","500096","500097","500098","500178","500409","501218","501301","501401","501510","501511","501512","502307","502319","517501","517502","517503","517505","517507","520001","520002","520003","520004","520005","520006","520007","520008","520009","520010","520011","520012","520013","520014","520015","521108","521225","522001","522002","522003","522004","522005","522006","522007","522019","522509","530001","530002","530003","530004","530005","530007","530008","530009","530010","530010","530011","530012","530013","530014","530015","530016","530017","530018","530020","530021","530022","530023","530024","530026","530027","530028","530029","530032","530035","530040","530041","530043","530044","530045","530046","531001","533101","533103","533104","533105"]
2170
#    telenganaPincodes = ["500001","500002","500003","500004","500005","500006","500007","500008","500009","500010","500011","500012","500013","500014","500015","500016","500017","500018","500019","500020","500021","500022","500023","500024","500025","500026","500027","500028","500029","500030","500031","500032","500033","500034","500035","500036","500037","500038","500039","500040","500041","500042","500043","500044","500045","500046","500047","500048","500049","500050","500051","500052","500053","500054","500055","500056","500057","500058","500059","500060","500061","500062","500063","500064","500065","500066","500067","500068","500069","500070","500071","500072","500073","500074","500075","500076","500077","500078","500079","500080","500081","500082","500083","500084","500085","500086","500087","500088","500089","500090","500091","500092","500093","500094","500095","500096","500097","500098","500178","500409","501218","501301","501401","501510","501511","501512","502307","502319","517501","517502","517503","517505","517507","520001","520002","520003","520004","520005","520006","520007","520008","520009","520010","520011","520012","520013","520014","520015","521108","521225","522001","522002","522003","522004","522005","522006","522007","522019","522509","530001","530002","530003","530004","530005","530007","530008","530009","530010","530010","530011","530012","530013","530014","530015","530016","530017","530018","530020","530021","530022","530023","530024","530026","530027","530028","530029","530032","530035","530040","530041","530043","530044","530045","530046","531001","533101","533103","533104","533105"]
2162
    haryanaPincodes = ["133001","134003","123307","133205","125047","122005","131104","132111","121001","132038","134002","124411","132039","124505","124021","124521","132122","121105","133301","125021","132154","133005","123308","124105","125048","122101","124507","125028","131021","123413","124142","124110","125054"
2171
#    haryanaPincodes = ["133001","134003","123307","133205","125047","122005","131104","132111","121001","132038","134002","124411","132039","124505","124021","124521","132122","121105","133301","125021","132154","133005","123308","124105","125048","122101","124507","125028","131021","123413","124142","124110","125054"
2163
                       ,"134007","124416","121004","132040","126145","125061","125026","125078","133201","124101","124304","125045","134118","126010","126011","125042","123025","123501","125032","123034","132108","124201","124409","124401","124503","131022","125053","124415","122102","135106","126008","124310","132140","133101","135102","123026","125022","133021","135101","124302","134107","125027","123306","125101","135103","124504","132034","171208","124542","122002","126153","125036","125025","124109","124424","132020","123412","125106","122106","132112","133202","124107","125058","124202","124202","124528","125102","121007","121001","121002","121005","121006","124408","123506","125050","132042","122104","122001","131101","123505","132114","124301","125103","132035","125001","123504","124423","125033","124404","121107","121103","132115","125004","125011","125002","121106","134109","132041","122016","132129","132107","124103","126102","135003","135002","126001","131023","124535","124314","134201","132130","123310","131024","125030","126101","132036","132001","132118","132025","124412","125085","125029","132027","124113","143512","125201","133105","126117","126133","133302","124530","123027","132021","133102","125057","123502","125038","124305","124114","124402","135105","135021","123103","123101","124144","123102","131028","132022","132119","132132","124514","124108","132037","124111","132113","124203","125052","123021","125104","125056","124506","125105","123309","124510","124106","124112","125005","125088","123029","124022","134205","133203","125041","124306","131027","133103","123001","122108","124145","131103","125037","125039","134012","123023","123028","123414","134203","126116","132106","132145","124104","124513","124531","132117","132024","122107","125077","131029","132103","126007","123035","132043","124417","121102","132104","132105","134011","123503","125003","176050","132128","132128","124205","126113","134102","134101","132131","132026","121104","131102","124001","132133","134204","132044","151301","126110","125076","131030","125051","123401","125067","124429","125043","124403","125055","131001","133204","126112","133104","124146","132023","132046","132101","124501","124303","123020","133206","123024","125044","132033","125046","132135","176206","134202","126114","125060","125049","124407","124430","122103","125075","132153","132116","122105","132136","121101","125031","126119","125040","126115","132124","133207","126009","125083","132137","124406"]
2172
#                       ,"134007","124416","121004","132040","126145","125061","125026","125078","133201","124101","124304","125045","134118","126010","126011","125042","123025","123501","125032","123034","132108","124201","124409","124401","124503","131022","125053","124415","122102","135106","126008","124310","132140","133101","135102","123026","125022","133021","135101","124302","134107","125027","123306","125101","135103","124504","132034","171208","124542","122002","126153","125036","125025","124109","124424","132020","123412","125106","122106","132112","133202","124107","125058","124202","124202","124528","125102","121007","121001","121002","121005","121006","124408","123506","125050","132042","122104","122001","131101","123505","132114","124301","125103","132035","125001","123504","124423","125033","124404","121107","121103","132115","125004","125011","125002","121106","134109","132041","122016","132129","132107","124103","126102","135003","135002","126001","131023","124535","124314","134201","132130","123310","131024","125030","126101","132036","132001","132118","132025","124412","125085","125029","132027","124113","143512","125201","133105","126117","126133","133302","124530","123027","132021","133102","125057","123502","125038","124305","124114","124402","135105","135021","123103","123101","124144","123102","131028","132022","132119","132132","124514","124108","132037","124111","132113","124203","125052","123021","125104","125056","124506","125105","123309","124510","124106","124112","125005","125088","123029","124022","134205","133203","125041","124306","131027","133103","123001","122108","124145","131103","125037","125039","134012","123023","123028","123414","134203","126116","132106","132145","124104","124513","124531","132117","132024","122107","125077","131029","132103","126007","123035","132043","124417","121102","132104","132105","134011","123503","125003","176050","132128","132128","124205","126113","134102","134101","132131","132026","121104","131102","124001","132133","134204","132044","151301","126110","125076","131030","125051","123401","125067","124429","125043","124403","125055","131001","133204","126112","133104","124146","132023","132046","132101","124501","124303","123020","133206","123024","125044","132033","125046","132135","176206","134202","126114","125060","125049","124407","124430","122103","125075","132153","132116","122105","132136","121101","125031","126119","125040","126115","132124","133207","126009","125083","132137","124406"]
2164
    
2173
#    
2165
    
2174
#    #Simplify either its IGST or SGST
2166
    if order.warehouse_id == 7 or order.warehouse_id == 9: 
2175
#    if state == WarehouseLocation.Delhi: 
2167
        if order.customer_pincode.startswith(delhiPincodePrefix):
2176
#        if order.customer_pincode.startswith(delhiPincodePrefix):
2168
            return 0
2177
#            return TaxType.SGST
2169
        else:
2178
#        else:
2170
            return 1
2179
#            return TaxType.IGST
-
 
2180
#    #Maharashta
2171
    if order.warehouse_id == 12 or order.warehouse_id == 13:
2181
#    if state == WarehouseLocation.Mumbai:
2172
        for mahaPincodePrefix in maharashtraPincodePrefix:
2182
#        for mahaPincodePrefix in maharashtraPincodePrefix:
2173
            if order.customer_pincode.startswith(mahaPincodePrefix):
2183
#            if order.customer_pincode.startswith(mahaPincodePrefix):
2174
                return 0
2184
#                return TaxType.SGST
2175
        return 1
2185
#        return TaxType.IGST
2176
    if order.warehouse_id == 1765 or order.warehouse_id == 1768:
2186
#    if state == WarehouseLocation.Karnataka:
2177
        for knkPincodePrefix in karnatakaPincodePrefix:
2187
#        for knkPincodePrefix in karnatakaPincodePrefix:
2178
            if order.customer_pincode.startswith(knkPincodePrefix):
2188
#            if order.customer_pincode.startswith(knkPincodePrefix):
2179
                return 0
2189
#                return TaxType.SGST
2180
        return 1
2190
#        return 1
2181
    if order.warehouse_id == 3298:
2191
#    if state == WarehouseLocation.Telangana:
2182
        if order.customer_pincode in telenganaPincodes:
2192
#        if order.customer_pincode in telenganaPincodes:
2183
            return 0
2193
#            return TaxType.SGST
2184
        return 1
2194
#        return TaxType.IGST
2185
    if order.warehouse_id == 7441:
2195
#    if state == WarehouseLocation.Haryana:
2186
        if order.customer_pincode in haryanaPincodes:
2196
#        if order.customer_pincode in haryanaPincodes:
2187
            return 0
2197
#            return TaxType.SGST
2188
        return 1
2198
#        return TaxType.IGST
2189
    return 0
2199
#    return TaxType.SGST
2190
    #raise TransactionServiceException(110, "No Vat/CST logic defined for warehouse " + str(order.warehouse_id)) 
-
 
2191
 
2200
 
2192
def add_billing_details(orderId, invoice_number, serialNumbers, itemNumbers, freebieWarehouseId, billedBy, jacketNumber, billingType, fulfilmentWarehouseId, authorize):
2201
def add_billing_details(orderId, invoice_number, serialNumbers, itemNumbers, freebieWarehouseId, billedBy, jacketNumber, billingType, fulfilmentWarehouseId, authorize):
2193
    if billedBy is None or billedBy.strip() == "":
2202
    if billedBy is None or billedBy.strip() == "":
2194
        raise TransactionServiceException(110, "Invalid Biller")
2203
        raise TransactionServiceException(110, "Invalid Biller")
2195
    
2204
    
Line 8958... Line 8967...
8958
    except:
8967
    except:
8959
        raise TransactionServiceException(302, "Unable to connect to Warehouse System")
8968
        raise TransactionServiceException(302, "Unable to connect to Warehouse System")
8960
    inventory_client = InventoryClient().get_client()
8969
    inventory_client = InventoryClient().get_client()
8961
    warehouse_client = WarehouseClient().get_client()
8970
    warehouse_client = WarehouseClient().get_client()
8962
    catalog_client = CatalogClient().get_client()
8971
    catalog_client = CatalogClient().get_client()
8963
    whStateId = None
-
 
8964
    lineItemSize = 0
8972
    lineItemSize = 0
8965
    individualInvoice = True
8973
    individualInvoice = True
8966
    
-
 
-
 
8974
    warehouse = inventory_client.getWarehouse(ordersList[0].warehouse_id)
-
 
8975
    whState = fetchStateMaster().get(warehouse.stateId)
8967
    
8976
     
-
 
8977
    newTaxType = __getOrderTaxType(ordersList[0], whState.name)    
8968
    orderscansMap = {}
8978
    orderscansMap = {}
8969
    orderInventoryItemMap = {}
8979
    orderInventoryItemMap = {}
8970
    orderFulfilmentWarehouseMap = {}
8980
    orderFulfilmentWarehouseMap = {}
8971
    nonSerializedUsedInventoryMap = {}
8981
    nonSerializedUsedInventoryMap = {}
8972
    for order in ordersList:
8982
    for order in ordersList:
8973
        scanList = []
8983
        scanList = []
8974
        inventoryItemList = []
8984
        inventoryItemList = []
8975
        newTaxType = __getOrderTaxType(order)
-
 
8976
        if order.taxType == TaxType.CFORM and newTaxType == TaxType.VAT:
-
 
8977
                raise TransactionServiceException(302, "C-Form billing is not allowed for same state for Order" + str(order.id))
-
 
8978
        else:
-
 
8979
            order.taxType = newTaxType
8985
        order.taxType = newTaxType
8980
        
-
 
8981
        if jacketNumber is None or jacketNumber <= 0:
8986
        if jacketNumber is None or jacketNumber <= 0:
8982
            if order.source == OrderSource.EBAY or order.source == OrderSource.SNAPDEAL or order.source == OrderSource.FLIPKART:
8987
            if order.source == OrderSource.EBAY or order.source == OrderSource.SNAPDEAL or order.source == OrderSource.FLIPKART:
8983
                print "Skipping Jacket Number field for OrderId " + str(orderId)
8988
                print "Skipping Jacket Number field for OrderId " + str(orderId)
8984
            else:
8989
            else:
8985
                raise TransactionServiceException(303, "Invalid jacket number")
8990
                raise TransactionServiceException(303, "Invalid jacket number")
Line 9066... Line 9071...
9066
                warehouse = inventory_client.getWarehouse(order.fulfilmentWarehouseId)
9071
                warehouse = inventory_client.getWarehouse(order.fulfilmentWarehouseId)
9067
                if order.productCondition != ProductCondition.BAD:
9072
                if order.productCondition != ProductCondition.BAD:
9068
                    item_pricing = inventory_client.getItemPricing(item_id, warehouse.vendor.id)
9073
                    item_pricing = inventory_client.getItemPricing(item_id, warehouse.vendor.id)
9069
                    lineitem.transfer_price = item_pricing.transferPrice
9074
                    lineitem.transfer_price = item_pricing.transferPrice
9070
                    lineitem.nlc = item_pricing.nlc
9075
                    lineitem.nlc = item_pricing.nlc
9071
                if order.taxType == TaxType.CFORM:
9076
                #Now onwards vatRates are obsolete, we will be using fields igst, sgst and cgst
9072
                    lineitem.vatRate = 2
9077
                if not catalog_client.isAlive():
9073
                else:
9078
                    catalog_client = CatalogClient().get_client()
9074
                    if not catalog_client.isAlive():
9079
                if order.taxType == TaxType.IGST:
9075
                        catalog_client = CatalogClient().get_client()
9080
                    lineitem.igstRate =  catalog_client.getIgstRate(lineitem.hsnCode)
9076
                    if fetchStateMaster()[warehouse.stateId].vatType==VatType.MRP:
9081
                elif order.taxType == TaxType.SGST:
9077
                        lineitem.vatRate = catalog_client.getVatPercentageForItem(lineitem.item_id, warehouse.stateId, lineitem.mrp)
9082
                    sgstRate = catalog_client.getSgstRates(lineitem.item_id, whStateId)
9078
                    else:
9083
                    
9079
                        lineitem.vatRate = catalog_client.getVatPercentageForItem(lineitem.item_id, warehouse.stateId, lineitem.unit_price)
-
 
9080
                order.vendorId = warehouse.vendor.id
9084
                order.vendorId = warehouse.vendor.id
9081
                whStateId = warehouse.stateId
-
 
9082
            except InventoryServiceException as e:
9085
            except InventoryServiceException as e:
9083
                print sys.exc_info()[0]
9086
                print sys.exc_info()[0]
9084
                print e.message
9087
                print e.message
9085
                if warehouseDbConnection.open:
9088
                if warehouseDbConnection.open:
9086
                    warehouseDbConnection.close()
9089
                    warehouseDbConnection.close()
Line 11244... Line 11247...
11244
    seller = Seller.get_by(id=sellerId)
11247
    seller = Seller.get_by(id=sellerId)
11245
    if seller is None:
11248
    if seller is None:
11246
        return None
11249
        return None
11247
    else:
11250
    else:
11248
        sellerInfo.tin = seller.tin
11251
        sellerInfo.tin = seller.tin
-
 
11252
        sellerInfo.gstin = seller.gstin
11249
        sellerInfo.stateId = seller.state_id 
11253
        sellerInfo.stateId = seller.state_id 
11250
        org = Organisation.get_by(id=seller.organisation_id)
11254
        org = Organisation.get_by(id=seller.organisation_id)
11251
        if org is None:
11255
        if org is None:
11252
            return None
11256
            return None
11253
        else:
11257
        else:
Line 11313... Line 11317...
11313
        buyerInfo = BuyerInfo()
11317
        buyerInfo = BuyerInfo()
11314
        buyerInfo.cinNumber = sellerInfo.cinNumber
11318
        buyerInfo.cinNumber = sellerInfo.cinNumber
11315
        buyerInfo.organisationName = sellerInfo.organisationName
11319
        buyerInfo.organisationName = sellerInfo.organisationName
11316
        buyerInfo.regId = sellerInfo.regId
11320
        buyerInfo.regId = sellerInfo.regId
11317
        buyerInfo.tin = sellerInfo.tin
11321
        buyerInfo.tin = sellerInfo.tin
-
 
11322
        buyerInfo.gstin = sellerInfo.gstin 
11318
        buyerInfo.registeredAddress = sellerInfo.registeredAddress
11323
        buyerInfo.registeredAddress = sellerInfo.registeredAddress
11319
        buyerInfo.buyerId = buyerId
11324
        buyerInfo.buyerId = buyerId
11320
        buyerInfo.stateId = sellerInfo.stateId 
11325
        buyerInfo.stateId = sellerInfo.stateId 
11321
        addressMapping = session.query(WarehouseAddressMaster).join((WarehouseAddressMapping,WarehouseAddressMapping.address_id==WarehouseAddressMaster.id)).filter(WarehouseAddressMapping.warehouse_id==warehouse_id).first()
11326
        addressMapping = session.query(WarehouseAddressMaster).join((WarehouseAddressMapping,WarehouseAddressMapping.address_id==WarehouseAddressMaster.id)).filter(WarehouseAddressMapping.warehouse_id==warehouse_id).first()
11322
        if addressMapping is not None:
11327
        if addressMapping is not None:
Line 11617... Line 11622...
11617
            #Self Pickup
11622
            #Self Pickup
11618
            order.logistics_provider_id = 4 
11623
            order.logistics_provider_id = 4 
11619
            #__refund_shipping(list(transaction.orders), False)
11624
            #__refund_shipping(list(transaction.orders), False)
11620
            #order.shippi    
11625
            #order.shippi    
11621
        session.commit()
11626
        session.commit()
11622
        session.close()    
11627
        session.close()
11623
if __name__ == '__main__':
11628
if __name__ == '__main__':
11624
    DataService.initialize()
11629
    DataService.initialize()
11625
    #transaction_ids=[1030084,1030087,1030090,1030093,1030096,1030099,1030102,1030105,1030108,1030111,1030114,1030117,1030120,1030123,1030144,1030147,1030153]
11630
    #transaction_ids=[1030084,1030087,1030090,1030093,1030096,1030099,1030102,1030105,1030108,1030111,1030114,1030117,1030120,1030123,1030144,1030147,1030153]
11626
    transaction_ids=[]
11631
    transaction_ids=[]
11627
    mark_order_for_selfpickup_temp(transaction_ids)
11632
    mark_order_for_selfpickup_temp(transaction_ids)