Subversion Repositories SmartDukaan

Rev

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

Rev 6730 Rev 6736
Line 16... Line 16...
16
from string import Template
16
from string import Template
17
import datetime
17
import datetime
18
import traceback
18
import traceback
19
import uuid
19
import uuid
20
from shop2020.model.v1.user.impl.Converters import to_t_coupon
20
from shop2020.model.v1.user.impl.Converters import to_t_coupon
-
 
21
from shop2020.model.v1.user.promotionrules import rule_specific_emi_discount_on_specific_items
21
 
22
 
22
 
23
 
23
def initialize(dbname = 'user', db_hostname="localhost"):
24
def initialize(dbname = 'user', db_hostname="localhost"):
24
    Dataservice.initialize(dbname, db_hostname)
25
    Dataservice.initialize(dbname, db_hostname)
25
 
26
 
Line 161... Line 162...
161
            imported_coupon_module = __import__("shop2020.model.v1.user.promotionrules", globals(), locals(), [coupon_module])
162
            imported_coupon_module = __import__("shop2020.model.v1.user.promotionrules", globals(), locals(), [coupon_module])
162
            rule = eval("imported_coupon_module." + coupon_module)
163
            rule = eval("imported_coupon_module." + coupon_module)
163
            
164
            
164
            args = eval(coupon.arguments) if coupon.arguments is not None else {}
165
            args = eval(coupon.arguments) if coupon.arguments is not None else {}
165
            
166
            
-
 
167
            '''
-
 
168
            Processing in case of EMI
-
 
169
            '''
-
 
170
            if coupon.promotion.type == 2:
166
            updated_cart, discounts = rule.execute(cart, coupon_code, args)
171
                updated_cart = rule.execute(cart, coupon_code, args)
-
 
172
                    
167
            
173
            else:
-
 
174
                updated_cart, discounts = rule.execute(cart, coupon_code, args)
-
 
175
                if discounts and len(discounts) > 0:    
168
            if discounts and len(discounts) > 0:    user_client.saveDiscounts(discounts)
176
                    user_client.saveDiscounts(discounts)
169
            
177
                
170
            user_client.applyCouponToCart(cart_id, coupon_code, updated_cart.totalPrice, updated_cart.discountedPrice)
178
            user_client.applyCouponToCart(cart_id, coupon_code, updated_cart.totalPrice, updated_cart.discountedPrice)
171
            
179
            
172
            return updated_cart
180
            return updated_cart
173
        
181
        
174
        except ImportError as e:
182
        except ImportError as e:
Line 177... Line 185...
177
            raise PromotionException(100, 'Internal error occurred.')
185
            raise PromotionException(100, 'Internal error occurred.')
178
    else:
186
    else:
179
        print 'Invalid Coupon Code'
187
        print 'Invalid Coupon Code'
180
        raise PromotionException(101, 'Invalid Coupon Code')
188
        raise PromotionException(101, 'Invalid Coupon Code')
181
 
189
 
-
 
190
def get_emi_discount(cart_id):
-
 
191
    try:
-
 
192
        user_client = UserClient().get_client()
-
 
193
        cart = user_client.getCart(cart_id)
-
 
194
        coupon = Coupon.get_by(coupon_code = cart.couponCode)
-
 
195
        args = eval(coupon.arguments) if coupon.arguments is not None else {}
-
 
196
        if coupon.promotion.type != 2:
-
 
197
            return {}
-
 
198
        else:
-
 
199
            return rule_specific_emi_discount_on_specific_items.getEmiDiscounts(cart, coupon.coupon_code, args)
-
 
200
    
-
 
201
    except ImportError as e:
-
 
202
        traceback.print_stack()
-
 
203
        return {}
-
 
204
 
182
def track_coupon_usage(coupon_code, transaction_id, user_id):
205
def track_coupon_usage(coupon_code, transaction_id, user_id):
183
    promotion_tracker = PromotionTracker()
206
    promotion_tracker = PromotionTracker()
184
    promotion_tracker.coupon_code = coupon_code
207
    promotion_tracker.coupon_code = coupon_code
185
    promotion_tracker.transaction_id = transaction_id
208
    promotion_tracker.transaction_id = transaction_id
186
    promotion_tracker.user_id = user_id
209
    promotion_tracker.user_id = user_id