Hi

I've been pulling my hair out over this program. It is uses a Class for creating objects to be used in an ordering tracking system. I'm having problems calling the objects and implementing them.

I'm trying to follow a structure along these lines

When an order is created payment is unconfirmed
orders must be paid before any other processing
unpaid orders can't be shipped
orders cannot be completed unless they are shipped
orders cannot be cancelled after they are shipped

The timestamp parameter is supposed to be called at the end of each method to increment a counter by 1 so that steps in the order cannot be skipped once the counter hits a certain value. But I can't even get a step in the process to work. I hope this makes sense

class Order(object):

    

    def __init__(self, tracker, timestamp):
        '''This is the constructor we give it 2 arguments'''
        self.tracker = tracker
        self.time = time

        print ('New order created').format(self.tracker)
        

        self.__timestamp()
 

    def pay(self,payment):
        '''This is a method that belong to Order class'''
        self.payment = payment
        self.payment_timer = timer

        print('Enter payment: ')

        self.__timestamp()


 
    def ship(self,timestamp):
        self.timestamp = timestamp

        self.__timestamp()
        
 
    def complete(self, timestamp):
        self.timestamp = timestamp

        self.__timestamp()
        
 
    def cancel(self, timestamp):
        self.timestamp = timestamp

        self.__timestamp()
           
 
    def __str__(self):
        '''Return a pleasant representation'''
        return "tracking_number %s payment %.2f payment_timer %s" % (self.tracker, self.payment,self.payment_timer)    
 
    def __timestamp(self, time):
        self.time += 1
        
        
        time = time.localtime(time.time())
        return "%02d.%02d.%02d.%02d.%02d" % (lt[0], lt[1], lt[2], lt[3], lt[4])
 
def main():
        
    orderNumber = input("Order tracking number 5 digits: ")
    newOrder = Order(orderNumber)



    choice = None
    while choice != '0':
        print \
              '''Order Tracking System
        0 - Quit
        1 - New Order
        2 - Pay Order
        3 - Ship order
        4 - Complete Order
        5 - Cancel Order
        6 - Display Order
        '''
        choice = input('Enter decision: ')


        if choice == "0":
            print("Good-bye.") 


            
              
        elif choice == 2:
                Order.pay()

        elif choice == 3:
                Order.ship()

        elif choice == 4:
                Order.complete()

        elif choice == 5:
                Order.cancel()

        elif choice == 6:
                Order.__str__()

        else:
                    print "Invalid selection", choice, "isn't valid."

                    
                
if __name__ == "__main__":
    main()

I keep getting an argument error on the first part of main, requires atleast 3 arguments and only 2 given...This confuses me because it considers 'self' in the error

Anyone have any ideas?

Recommended Answers

All 2 Replies

Your constructor (__init__) is defined as such

def __init__(self, tracker, timestamp):

So when you create an instance of the class, it should be

newOrder = Order(orderNumber, timestamp)

Alternately, change your __init__() as

def __init__(self, tracker):

I was able to get the orders created from the __init__ thanks!

I want to know if I'm implementing the timestamp counter correctly?

I'm removing 'time' from timestamp because i found that simplified things, but now I'm not sure how it will be printed. Is it wise to use a private method for something like a counter?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.