Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3249 varun.gupt 1
'''
2
Created on 06-Sept-2011
3
 
4
@author: Varun Gupta
5
'''
6
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
7
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count
8
from shop2020.clients.CatalogClient import CatalogClient
9
from shop2020.thriftpy.model.v1.catalog.ttypes import Item
10
 
11
def execute(cart, coupon_code, args):
12
 
13
    #Allow only first 1000 users to use the coupon
14
    count_coupon_usage = get_coupon_usage_count(coupon_code)
15
 
16
    if count_coupon_usage >= 1000:
17
        raise PromotionException(112, 'This promotion is over.')
18
 
19
    if cart.lines:
20
        total_selling_price = 0
21
        total_discounted_price = 0
22
 
23
        has_qualified_model = False
24
 
25
        for line in cart.lines:
26
            '''
27
            Blackberry    9900    Bold 4    32490    OFF Rs.2000    30490
28
            Samsung    i9100    Galaxy S II    29900    OFF Rs.1000    28900
29
            Spice    QT-58    Blueberry Mini    2849    OFF 20%    2279
30
            Spice    QT-61    Blueberry Exp    3261    OFF 20%    2609
31
            Nokia    All Models    Below Rs.5000 SP    OFF Rs.200/-
32
            Nokia    All Models    Above Rs.5001 SP    OFF Rs.500/-
33
            '''
34
 
35
            line.discountedPrice = line.actualPrice
36
 
37
            if line.itemId in (159, 160, 161, 1557, 1558):  #Spice QT-58/61
38
 
39
                has_qualified_model = True
40
 
41
                if line.actualPrice:
42
                    line.discountedPrice = round(line.actualPrice * 0.8)
43
 
3251 varun.gupt 44
            if line.itemId == 1591:  #Blackberry 9900 Bold 4
3249 varun.gupt 45
 
46
                has_qualified_model = True
47
 
48
                if line.actualPrice:
49
                    line.discountedPrice = line.actualPrice - 2000
50
 
3251 varun.gupt 51
            if line.itemId == 1502:  #Galaxy SII
3249 varun.gupt 52
 
53
                has_qualified_model = True
54
 
55
                if line.actualPrice:
56
                    line.discountedPrice = line.actualPrice - 1000
57
            else:
3254 varun.gupt 58
                print 'Can be Nokia'
3249 varun.gupt 59
                catalog_client = CatalogClient().get_client()
60
                item = catalog_client.getItem(line.itemId)
3254 varun.gupt 61
                print 'Item: %d, Brand: *%s*' % (line.itemId, item.brand.lower())
3249 varun.gupt 62
                if item.brand.lower() == 'nokia':
3254 varun.gupt 63
                    print 'Brand matched'
3249 varun.gupt 64
                    discount_value = 200 if line.actualPrice < 5001 else 500
65
                    line.discountedPrice = line.actualPrice - discount_value
3254 varun.gupt 66
                else:
67
                    print 'Brand not matched'
3249 varun.gupt 68
 
69
            total_selling_price += line.actualPrice * line.quantity
70
            total_discounted_price += line.discountedPrice * line.quantity
71
 
72
        if has_qualified_model is False:
73
            raise PromotionException(115, 'This coupon is applicable only for selected handsets.')
74
 
75
        cart.totalPrice = total_selling_price
76
        cart.discountedPrice = total_discounted_price
77
 
78
    return cart