Subversion Repositories SmartDukaan

Rev

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

Rev 5331 Rev 5499
Line 1... Line 1...
1
'''
1
'''
2
Created on 06-Sept-2011
2
Created on 27-June-2012
3
 
-
 
4
@author: Varun Gupta
3
@author: Varun Gupta
5
 
4
 
6
Max Uses: 2000
5
Max Uses: 200
7
 
6
 
8
A user can use the coupon only 2 times.
7
A user can use the coupon only 1 times.
9
 
8
 
10
Spice Blueberry Mini QT-58    Rs.150 off
9
Samsung Galaxy Ace S5830i    Rs.401 off
11
Nokia (All models, other than C2-03 & C2-06, from Rs.3000 to Rs.5000)  Rs.200 off
10
Samsung Galaxy Ace Duos S6802    Rs.401 off
-
 
11
HTC One V T320e    Rs.512 off
12
Nokia (All models, other than Lumia 710, above Rs.5000)    Rs.500 off
12
HTC Desire C A320e    Rs.762 off
13
'''
13
'''
14
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
14
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
15
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
15
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
16
from shop2020.clients.CatalogClient import CatalogClient
16
from shop2020.clients.CatalogClient import CatalogClient
17
from shop2020.thriftpy.model.v1.user.ttypes import Discount
17
from shop2020.thriftpy.model.v1.user.ttypes import Discount
Line 22... Line 22...
22
    user = user_client.getUserByCartId(cart.id)
22
    user = user_client.getUserByCartId(cart.id)
23
    
23
    
24
    #Allow only first 2000 users to use the coupon
24
    #Allow only first 2000 users to use the coupon
25
    count_coupon_usage = get_coupon_usage_count(coupon_code)
25
    count_coupon_usage = get_coupon_usage_count(coupon_code)
26
    
26
    
27
    if count_coupon_usage >= 2000:
27
    if count_coupon_usage >= 200:
28
        raise PromotionException(112, 'This promotion is over.')
28
        raise PromotionException(112, 'This promotion is over.')
29
    
29
    
30
    #Allow a user to use the coupon only 5 times max.
30
    #Allow a user to use the coupon only 5 times max.
31
    count_users_usage = get_coupon_usage_count_by_user(coupon_code, user.id)
31
    count_users_usage = get_coupon_usage_count_by_user(coupon_code, user.id)
32
    
32
    
33
    if count_users_usage > 1:
33
    if count_users_usage > 0:
34
        raise PromotionException(111, 'This promotion is over.')
34
        raise PromotionException(111, 'This promotion is over.')
35
    
35
    
36
    discounts = []
36
    discounts = []
37
    
37
    
38
    if cart.lines:
38
    if cart.lines:
Line 44... Line 44...
44
        for line in cart.lines:
44
        for line in cart.lines:
45
            
45
            
46
            line.discountedPrice = line.actualPrice
46
            line.discountedPrice = line.actualPrice
47
            discount_value = 0
47
            discount_value = 0
48
            
48
            
49
            if line.itemId in (159, 160, 161) and not has_qualified_model:  #Spice QT-58
49
            if line.itemId in (6829, 7243, 7298):  #Samsung Galaxy Ace Duos S6802 & Galaxy Ace S5830i
-
 
50
                
-
 
51
                has_qualified_model = True
-
 
52
                
-
 
53
                if line.actualPrice:
-
 
54
                    line.discountedPrice = round(line.actualPrice - 401)
-
 
55
                    discount_value = 401
-
 
56
            
-
 
57
            elif line.itemId == 4645:  #HTC One V T320e
50
                
58
                
51
                has_qualified_model = True
59
                has_qualified_model = True
52
                
60
                
53
                if line.actualPrice:
61
                if line.actualPrice:
54
                    line.discountedPrice = round(line.actualPrice - 150)
62
                    line.discountedPrice = round(line.actualPrice - 512)
55
                    discount_value = 150
63
                    discount_value = 512
56
            
64
            
57
            # Excluded: Nokia C2-03, C2-06, Lumia 710 and Price above Rs.1,999
65
            elif line.itemId in (6747, 7127):  #HTC Desire C A320e
58
            elif line.itemId not in (1590, 2014, 2063, 2035, 2036, 2565, 2602, 2210, 2478) and line.actualPrice > 2999 and not has_qualified_model:
-
 
59
                
66
                
60
                catalog_client = CatalogClient().get_client()
-
 
61
                item = catalog_client.getItem(line.itemId)
67
                has_qualified_model = True
62
                
68
                
63
                if item.brand.lower() == 'nokia':
69
                if line.actualPrice:
64
                    has_qualified_model = True
-
 
65
                    
-
 
66
                    discount_value = 200 if line.actualPrice < 5001 else 500
70
                    line.discountedPrice = round(line.actualPrice - 762)
67
                    line.discountedPrice = line.actualPrice - discount_value
71
                    discount_value = 762
68
            
72
            
69
            total_selling_price += line.actualPrice * line.quantity
73
            total_selling_price += line.actualPrice * line.quantity
70
            total_discounted_price += line.discountedPrice + (line.actualPrice * (line.quantity - 1))
74
            total_discounted_price += line.discountedPrice * line.quantity
71
            
75
            
72
            if discount_value > 0:
76
            if discount_value > 0:
73
                discount = Discount()
77
                discount = Discount()
74
                discount.cart_id = cart.id
78
                discount.cart_id = cart.id
75
                discount.item_id = line.itemId
79
                discount.item_id = line.itemId
76
                discount.discount = discount_value
80
                discount.discount = discount_value
77
                discount.quantity = 1
81
                discount.quantity = line.quantity
78
                
82
                
79
                discounts.append(discount)
83
                discounts.append(discount)
80
        
84
        
81
        if has_qualified_model is False:
85
        if has_qualified_model is False:
82
            raise PromotionException(115, 'This coupon is applicable only for selective handsets.')
86
            raise PromotionException(115, 'This coupon is applicable only for selective handsets.')