Beispiel #1
0
 def finalize_step_2(self, **kwargs):
     try:
         if 'transaction_key' not in self.session:
             return {'valid': False, 'is_error': False, 'payload': 'Unable to find the current transaction!'}
         else:
             trans = Transaction2.get(Key(encoded=self.session['transaction_key']))    
         customer_total = str_to_money(urllib.unquote_plus(self.request.get('customer_total')))
         grand_total = 0
         for i in trans.items:
             j = LineItem2.get(Key(encoded=i))
             grand_total += j.total()
         if customer_total < grand_total:
             return {'valid': False, 'is_error': False, 'payload':"The amount received from the customer is not enough to pay the outstanding balance."}
         else:
             trans.finalized = True
             trans.put()
             del self.session['transaction_key']
             return {'valid': True, 'is_error': False}
     except:
         return {'valid': False, 'is_error': True, 'payload':traceback.format_exc()}
Beispiel #2
0
 def donate(self, **kwargs):
     try:
         amt = str_to_money(self.request.get('amt', False))
     except:
         return dict(valid=False, payload=traceback.format_exc())
     trans = Transaction2()
     trans.owner = self.users.get_current_user()
     trans.put()
     item = LineItem2()
     item.category = "DONATION"
     item.category_code = "+++"
     item.quantity = 1
     item.price = amt
     item.color = "DONATION"
     item.color_code = "+++"
     item.discount = 0
     item.put()
     trans.items.append(str(item.key()))
     trans.finalized = True
     trans.put()
     return dict(valid=True)
Beispiel #3
0
 def add_item(self, **kwargs):
     try:
         if 'transaction_key' not in self.session:
             trans = Transaction2()
             trans.owner = self.users.get_current_user()
             trans.put()
             self.session['transaction_key'] = str(trans.key())
         else:
             trans = Transaction2.get(Key(encoded=self.session['transaction_key']))    
         t = self.request.get('data')
         if t.startswith('$'):
             #misc processing
             l = t.split()
             price, color_inp = l[0], l[1]
             #if '.' in price:
             #    z = price.split('.')
             #    dollars, cents = z[0], z[1]
             #    price = int(dollars) + int(cents)*100
             price = str_to_money(price[1:])
             item = LineItem2()
             item.category = "MISC"
             item.category_code = "$$$"
             item.price = price
             item.quantity = 1
             color = ColorCode.all().filter('code =', color_inp).get()
             if color == None:
                 raise "Bad color"
             item.color = color.color
             item.color_code = color.code
             item.discount = color.discount
             item.put()
             trans.items.append(str(item.key()))
             if len(trans.items) % 2 == 0:
                 class_val = 'even'
             else:
                 class_val = 'odd'
             html = """<tr class="%(class)s" id="%(key)s"><td>%(item_id)s</td><td>%(description)s</td><td>$%(price)s</td><td>%(quantity)s</td><td>%(discount)s%%</td><td>$%(total)s</td><td><a class="delete_button" onclick="void_item('%(key)s')">void</a></td></tr>""" % {'key': str(item.key()), 'item_id': str(item.category_code), 'description': str(item.category), 'price': money_to_str(price), 'quantity': str(1), 'discount':str(item.get_discount()), 'total': item.total_str(), "class":class_val}
         elif t.startswith(':'):
             #gift certificate processing
             price = str_to_money(t[1:])
             item = LineItem2()
             item.category = 'Gift Card Use'
             item.category_code = ":::"
             item.price = -price
             item.quantity = 1
             item.color = 'Special'
             item.color_code = ':::'
             item.discount = 0
             item.put()
             trans.items.append(str(item.key()))
             if len(trans.items) % 2 == 0:
                 class_val = 'even'
             else:
                 class_val = 'odd'
             html = """<tr class="%(class)s" id="%(key)s"><td>%(item_id)s</td><td>%(description)s</td><td>$%(price)s</td><td>%(quantity)s</td><td>%(discount)s%%</td><td>$%(total)s</td><td><a class="delete_button" onclick="void_item('%(key)s')">void</a></td></tr>""" % {'key': str(item.key()), 'item_id': str(item.category_code), 'description': str(item.category), 'price': money_to_str(price), 'quantity': str(1), 'discount':str(item.get_discount()), 'total': item.total_str(), "class":class_val}
         else:
             item = LineItem2()
             l = t.split()
             if len(l) == 2:
                 quantity, cat_code, color = 1, l[0], l[1]
             else:
                 quantity, cat_code, color = l[0], l[1], l[2]
             item.quantity = int(quantity)
             if color.startswith('%'):
                 #custom precentage handler
                 item.discount = int(color[1:])
                 item.color = 'CUSTOM'
                 item.color_code = '%%%'
             else:                
                 color = ColorCode.all().filter('code =', color).filter('display =', True).fetch(1)[0]
             category = ItemCategory.all().filter('code =', cat_code).filter('display =', True).fetch(1)[0]
             item.set_color(color)
             item.set_category(category)
             item.put()
             trans.items.append(str(item.key()))
             if len(trans.items) % 2 == 0:
                 class_val = 'even'
             else:
                 class_val = 'odd'
             total = item.total()
             html = """<tr class="%(class)s" id="%(key)s"><td>%(item_id)s</td><td>%(description)s</td><td>%(price)s</td><td>%(quantity)s</td><td>%(discount)s%%</td><td>$%(total)#.2f</td><td><a class="delete_button" onclick="void_item('%(key)s')">void</a></td></tr>""" % {'key': str(item.key()), 'item_id': str(cat_code), 'description': str(category.description), 'price': money_to_str(category.price), 'quantity': str(quantity), 'discount':str(item.get_discount()), 'total': total, "class":class_val}
         trans.put()
         return {'valid':True, 'html':html, 'total_row':str(trans.total_str()), 'sess':repr(self.session)}
     except:
         return {'valid':False, 'payload':traceback.format_exc()}