Beispiel #1
0
 def handle(self, sale_string):
     seller = self.msg.connection.contact
     sale_result = self.verify_sale(sale_string, seller)
     if sale_result[0] == 0: #sale failed
         self.respond("ERROR: " + ', '.join(sale_result[1]) + ". Sale format: sale serial# firstname lastname mobile# price regioncode description" )
     else:
         sale_data = sale_result[1]
         product_code = sale_result[2]
     
     #verify that seller has the item to be sold in stock
     current_stock = Stock.get_existing(sale_data['seller'].alias, product_code)
     if current_stock is None or current_stock.stock_amount <= 0:
         self.respond("ERROR: No %s in stock." % product_code)
         return True
     
     #verify that the serial # is not a duplicate
     exists = Sale.by_serial(sale_data['serial'])
     if exists:
         self.respond("ERROR: %s is already registered." % sale_data['serial'])
         return True
       
     #now create and save the new sale record
     s = Sale(**sale_data)
     s.save()
     
     #subtract the sale from the retailer's stock
     current_stock.stock_amount -= 1
     current_stock.save()
     
     payment_response = "Cash sale."
     self.respond("%s registered to %s %s by %s." % (s.serial, s.fname, s.lname, s.seller.alias, ) + " " + payment_response)        
Beispiel #2
0
    def handle(self, sn):
        serial = sn.upper()
        to_cancel = Sale.by_serial(serial)
        if to_cancel is None:
            self.respond("ERROR: No sale record found for %s" % serial)
            return True
        #verify that the person requesting the cancellation is the seller
        if to_cancel.seller != self.msg.connection.contact:
            self.respond("ERROR: You are not allowed to cancel this sale")
            return True
        #save values for later, then delete
        seller = to_cancel.seller
        owner_name = "%s %s" % (to_cancel.fname, to_cancel.lname)
        purchase_price = to_cancel.purchase_price
        to_cancel.delete()
        
        #now increase the seller's stock by one to reflect the canceled sale
        #this assumes the stock exists, and the seller only has one stock for a given product type
        stk = Stock.objects.filter(seller=seller, product__code=serial[0:2])[0]
        stk.stock_amount += 1
        stk.save()
        seller.cached_revenue -= (purchase_price * 1000)
        seller.save()

        #confirm the cancellation
        response = self.get_current_stock(seller)
        self.respond("Sale %s to %s canceled. Stock for %s: %s" % (serial, owner_name, seller.alias, response))
Beispiel #3
0
 def handle(self, serial):
     s = Sale.by_serial(serial)
     if s:
         locale.setlocale( locale.LC_ALL, '')
         self.respond("%s: %s Tsh paid on %s. Owner: %s %s (%s) %s, %s" % (s.serial, locale.format('%d', s.purchase_price*1000, True), s.purchase_date.strftime("%d-%m-%y"), s.fname, s.lname, s.pri_phone, s.get_region_display(), s.description))
     else:
         self.respond("Serial number %s not recognized" % serial)
Beispiel #4
0
 def handle(self, serial):
     s = Sale.by_serial(serial)
     if s:
         locale.setlocale(locale.LC_ALL, '')
         self.respond(
             "%s: %s Tsh paid on %s. Owner: %s %s (%s) %s, %s" %
             (s.serial, locale.format('%d', s.purchase_price * 1000, True),
              s.purchase_date.strftime("%d-%m-%y"), s.fname, s.lname,
              s.pri_phone, s.get_region_display(), s.description))
     else:
         self.respond("Serial number %s not recognized" % serial)
Beispiel #5
0
    def handle(self, sale_string):
        seller = self.msg.connection.contact
        sale_result = self.verify_sale(sale_string, seller)
        if sale_result[0] == 0:  #sale failed
            self.respond(
                "ERROR: " + ', '.join(sale_result[1]) +
                ". Sale format: sale serial# firstname lastname mobile# price regioncode description"
            )
        else:
            sale_data = sale_result[1]
            product_code = sale_result[2]

        #verify that seller has the item to be sold in stock
        current_stock = Stock.get_existing(sale_data['seller'].alias,
                                           product_code)
        if current_stock is None or current_stock.stock_amount <= 0:
            self.respond("ERROR: No %s in stock." % product_code)
            return True

        #verify that the serial # is not a duplicate
        exists = Sale.by_serial(sale_data['serial'])
        if exists:
            self.respond("ERROR: %s is already registered." %
                         sale_data['serial'])
            return True

        #now create and save the new sale record
        s = Sale(**sale_data)
        s.save()

        #subtract the sale from the retailer's stock
        current_stock.stock_amount -= 1
        current_stock.save()

        payment_response = "Cash sale."
        self.respond("%s registered to %s %s by %s." % (
            s.serial,
            s.fname,
            s.lname,
            s.seller.alias,
        ) + " " + payment_response)