By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

can help me with this Update inventory funciton, where is wrong?

P: 88
hi

currently i am doing this car booking website. i would like to only update our inventory one day before customer's start booking time, thus before that, i am still able to rent to other customers. E.g. if she book two month before, i can still rent this car to others within this 2 month, but one day before i need to deduct this car inventory as the next day i have to give this car to that customer.
the following is my car inventory update function. but it seems did not work in my way, as i loop through my Booking1 table to get all the start_datetime and update my inventory only if it is one day before this start_datetime. my start_datetime is in the format of "2007-12-21 17:05:05", i have changed it into seconds by using Bktime=time.mktime(time.strptime(invtime,"%Y-%m-%d %H:%M:%S")). but it seems not work. can anyone help me with this. can update my car inventory only one day before the start_datetime. thanks for any kind help:)

Expand|Select|Wrap|Line Numbers
  1. def inventory(request):
  2.  
  3.     allObj=[]
  4.     for i in Booking1.objects.all():
  5.         #print i.booking_time
  6.         invtime=i.start_datetime
  7.         #t=str(invtime).split('.')[0]
  8.         Bktime=time.mktime(time.strptime(invtime,"%Y-%m-%d %H:%M:%S"))
  9.         #now=datetime.datetime.now()
  10.         one_day=60*60*24
  11.         #diff=comp_dates(t,str(now).split('.')[0])
  12.         #print diff
  13.         onebefore=Bktime-one_day------>>>Error,where is wrong?date type?
  14.         if str(onebefore):
  15.             for a in CarModel.objects.all():    
  16.                 qtyInStock=a.car_inventory
  17.                 orderQuantity = 1
  18.                 qtyLeft = int(qtyInStock) - int(orderQuantity)
  19.                 a.car_inventory=qtyLeft
  20.                 a.save()
  21.                 allObj=CarModel.objects.all()
  22.                 print allObj
  23.                 print "LLLLLLLLLLLLLLLLLL"
  24.                 return render_to_response("inventoryupdate.html", {'allObj':allObj})    
  25.         if not str(onebefore):
  26.             all=CarModel.objects.all()
  27.             return render_to_response("inventory.html",{'all':all})
  28.  
Dec 22 '07 #1
Share this Question
Share on Google+
12 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
hi

currently i am doing this car booking website. i would like to only update our inventory one day before customer's start booking time, thus before that, i am still able to rent to other customers. E.g. if she book two month before, i can still rent this car to others within this 2 month, but one day before i need to deduct this car inventory as the next day i have to give this car to that customer.
the following is my car inventory update function. but it seems did not work in my way, as i loop through my Booking1 table to get all the start_datetime and update my inventory only if it is one day before this start_datetime. my start_datetime is in the format of "2007-12-21 17:05:05", i have changed it into seconds by using Bktime=time.mktime(time.strptime(invtime,"%Y-%m-%d %H:%M:%S")). but it seems not work. can anyone help me with this. can update my car inventory only one day before the start_datetime. thanks for any kind help:)

Expand|Select|Wrap|Line Numbers
  1. def inventory(request):
  2.  
  3.     allObj=[]
  4.     for i in Booking1.objects.all():
  5.         #print i.booking_time
  6.         invtime=i.start_datetime
  7.         #t=str(invtime).split('.')[0]
  8.         Bktime=time.mktime(time.strptime(invtime,"%Y-%m-%d %H:%M:%S"))
  9.         #now=datetime.datetime.now()
  10.         one_day=60*60*24
  11.         #diff=comp_dates(t,str(now).split('.')[0])
  12.         #print diff
  13.         onebefore=Bktime-one_day------>>>Error,where is wrong?date type?
  14.         if str(onebefore):
  15.             for a in CarModel.objects.all():    
  16.                 qtyInStock=a.car_inventory
  17.                 orderQuantity = 1
  18.                 qtyLeft = int(qtyInStock) - int(orderQuantity)
  19.                 a.car_inventory=qtyLeft
  20.                 a.save()
  21.                 allObj=CarModel.objects.all()
  22.                 print allObj
  23.                 print "LLLLLLLLLLLLLLLLLL"
  24.                 return render_to_response("inventoryupdate.html", {'allObj':allObj})    
  25.         if not str(onebefore):
  26.             all=CarModel.objects.all()
  27.             return render_to_response("inventory.html",{'all':all})
  28.  
The way you have calculated onebefore, it will always evaluate to True. I think you should calculate the difference between the date the car has been rented and the present date, and if the difference is greater than one day, keep the car in inventory, otherwise remove it.
Dec 22 '07 #2

P: 88
The way you have calculated onebefore, it will always evaluate to True. I think you should calculate the difference between the date the car has been rented and the present date, and if the difference is greater than one day, keep the car in inventory, otherwise remove it.
hi, thanks for it, i have done according to this logic and i feel it is correct. but it got small error. my code is in the following:

Expand|Select|Wrap|Line Numbers
  1. def inventory(request):
  2.  
  3.     allObj=[]
  4.     for i in Booking1.objects.all():
  5.         #print i.booking_time
  6.         invtime=i.start_datetime
  7.         now=datetime.datetime.now()
  8.         one_day=60*60*24
  9.         diff=comp_dates(invtime,str(now).split('.')[0])
  10.         print diff
  11.         print"LLLLLLLLLLLLLLLLLPPPPPPPPPPPPPPPPPJ"
  12.         if diff < one_day:
  13.             for a in CarModel.objects.all():    
  14.                 qtyInStock=a.car_inventory
  15.                 orderQuantity = 1
  16.                 qtyLeft = int(qtyInStock) - int(orderQuantity)
  17.                 a.car_inventory=qtyLeft
  18.                 a.save()
  19.                 allObj=CarModel.objects.all()
  20.                 print allObj
  21.                 print "LLLLLLLLLLLLLLLLLL"
  22.                 return render_to_response("inventoryupdate.html", {'allObj':allObj})    
  23.         if not diff < one_day:
  24.                 all=CarModel.objects.all()
  25.                 return render_to_response("inventory.html",{'all':all})
  26.  
my error is:

Request Method: GET
Request URL: http://localhost:8000/inventoryupdate/
Exception Type: TypeError
Exception Value: expected string or buffer
Exception Location: C:\Python25\lib\_strptime.py in strptime, line 328
Python Executable: C:\Python25\python.exe

i think there is some TypeError, but i am not sure where? can help me with this, thanks in advance. i believe it is just a small step to success..haha
Dec 23 '07 #3

P: 88
The way you have calculated onebefore, it will always evaluate to True. I think you should calculate the difference between the date the car has been rented and the present date, and if the difference is greater than one day, keep the car in inventory, otherwise remove it.
hi, thanks for it, i have done according to this logic and i feel it is correct. but it got small error. my code is in the following:

Expand|Select|Wrap|Line Numbers
  1. def inventory(request):
  2.  
  3.     allObj=[]
  4.     for i in Booking1.objects.all():
  5.         #print i.booking_time
  6.         invtime=i.start_datetime
  7.         now=datetime.datetime.now()
  8.         one_day=60*60*24
  9.         diff=comp_dates(invtime,str(now).split('.')[0])
  10.         print diff
  11.         print"LLLLLLLLLLLLLLLLLPPPPPPPPPPPPPPPPPJ"
  12.         if diff < one_day:
  13.             for a in CarModel.objects.all():    
  14.                 qtyInStock=a.car_inventory
  15.                 orderQuantity = 1
  16.                 qtyLeft = int(qtyInStock) - int(orderQuantity)
  17.                 a.car_inventory=qtyLeft
  18.                 a.save()
  19.                 allObj=CarModel.objects.all()
  20.                 print allObj
  21.                 print "LLLLLLLLLLLLLLLLLL"
  22.                 return render_to_response("inventoryupdate.html", {'allObj':allObj})    
  23.         if not diff < one_day:
  24.                 all=CarModel.objects.all()
  25.                 return render_to_response("inventory.html",{'all':all})
  26.  
my error is:

Request Method: GET
Request URL: http://localhost:8000/inventoryupdate/
Exception Type: TypeError
Exception Value: expected string or buffer
Exception Location: C:\Python25\lib\_strptime.py in strptime, line 328
Python Executable: C:\Python25\python.exe

i think there is some TypeError, but i am not sure where? can help me with this, thanks in advance. i believe it is just a small step to success..haha
Dec 23 '07 #4

P: 88
The way you have calculated onebefore, it will always evaluate to True. I think you should calculate the difference between the date the car has been rented and the present date, and if the difference is greater than one day, keep the car in inventory, otherwise remove it.
hi, thanks for it, i have done according to this logic and i feel it is correct. but it got small error. my code is in the following:

Expand|Select|Wrap|Line Numbers
  1. def inventory(request):
  2.  
  3.     allObj=[]
  4.     for i in Booking1.objects.all():
  5.         #print i.booking_time
  6.         invtime=i.start_datetime
  7.         now=datetime.datetime.now()
  8.         one_day=60*60*24
  9.         diff=comp_dates(invtime,str(now).split('.')[0])
  10.         print diff
  11.         print"LLLLLLLLLLLLLLLLLPPPPPPPPPPPPPPPPPJ"
  12.         if diff < one_day:
  13.             for a in CarModel.objects.all():    
  14.                 qtyInStock=a.car_inventory
  15.                 orderQuantity = 1
  16.                 qtyLeft = int(qtyInStock) - int(orderQuantity)
  17.                 a.car_inventory=qtyLeft
  18.                 a.save()
  19.                 allObj=CarModel.objects.all()
  20.                 print allObj
  21.                 print "LLLLLLLLLLLLLLLLLL"
  22.                 return render_to_response("inventoryupdate.html", {'allObj':allObj})    
  23.         if not diff < one_day:
  24.                 all=CarModel.objects.all()
  25.                 return render_to_response("inventory.html",{'all':all})
  26.  
my error is:

Request Method: GET
Request URL: http://localhost:8000/inventoryupdate/
Exception Type: TypeError
Exception Value: expected string or buffer
Exception Location: C:\Python25\lib\_strptime.py in strptime, line 328
Python Executable: C:\Python25\python.exe

i think there is some TypeError, but i am not sure where? can help me with this, thanks in advance. i believe it is just a small step to success..haha
Dec 23 '07 #5

bvdet
Expert Mod 2.5K+
P: 2,851
Check the type of object returned by:
Expand|Select|Wrap|Line Numbers
  1. invtime=i.start_datetime
Dec 23 '07 #6

P: 88
Check the type of object returned by:
Expand|Select|Wrap|Line Numbers
  1. invtime=i.start_datetime
i have checked its datatype, it is datetime.datetime. so i use str() to change its data type back to string and thus can compare: my change code is in the following and it works. however, i think there is an logic error, as everytime i click update inventory link, it will deduct inventory one more time. this function is mainly for admin or staff user. if one staff click this link to see the inventory in warehouse, it deduct one already, then within next second, another staff come and click again to view inventory. it deduct one again, which is wrong and inventory is not accurate. how can i solve this issue.....can kindly help me with this.....

Expand|Select|Wrap|Line Numbers
  1. def inventory(request):
  2.  
  3.     allObj=[]
  4.     for i in Booking1.objects.all():
  5.         #print i.booking_time
  6.         invtime=i.start_datetime
  7.         #start_datetime = datetime.datetime(*strptime(invtime,"%Y-%m-%dT%H:%M:%S")[0:6])
  8.         print invtime
  9.         print type(invtime)
  10.         print"KKKKKKKKKKKKKKKK"
  11.         now=datetime.datetime.now()
  12.         one_day=60*60*24
  13.         diff=comp_dates(str(invtime),str(now).split('.')[0])
  14.         print diff
  15.         print"LLLLLLLLLLLLLLLLLPPPPPPPPPPPPPPPPPJ"
  16.  
  17.         if diff < one_day:
  18.             for a in CarModel.objects.all():    
  19.                 qtyInStock=a.car_inventory
  20.                 orderQuantity = 1
  21.                 qtyLeft = int(qtyInStock) - int(orderQuantity)
  22.                 a.car_inventory=qtyLeft
  23.                 a.save()
  24.                 allObj=CarModel.objects.all()
  25.                 print allObj
  26.                 print "LLLLLLLLLLLLLLLLLL"
  27.                 return render_to_response("inventoryupdate.html", {'allObj':allObj})    
  28.         if not diff < one_day:
  29.                 all=CarModel.objects.all()
  30.                 return render_to_response("inventory.html",{'all':all})
  31.  
  32.  
thanks so much for your kind help.
Dec 24 '07 #7

bvdet
Expert Mod 2.5K+
P: 2,851
It seems to me that you need a Booking1.object attribute that can be checked to determine if it has been applied to the existing inventory.
Expand|Select|Wrap|Line Numbers
  1. if diff < one_day and Booking1.object.deducted_from_inventory == False:
Dec 24 '07 #8

P: 88
It seems to me that you need a Booking1.object attribute that can be checked to determine if it has been applied to the existing inventory.
Expand|Select|Wrap|Line Numbers
  1. if diff < one_day and Booking1.object.deducted_from_inventory == False:
i think i need to create one more datebase table and its type should boolean.so when it deducts, i should turn it to true. and when it does not deducts, the default setting should be false. if my understanding is not wrong, i believe this should be the correct way. i will try to do now, thanks so much for giving me this bright idea. i will try now and let you know later. :)
Dec 24 '07 #9

P: 88
i have tried it, in fact car inventory is in CarModel table which is separated from Booking1 table, as i have normalized the database table. Thus i edited the code in the following and i think it works.

Expand|Select|Wrap|Line Numbers
  1. def inventory(request):
  2.  
  3.     allObj=[]
  4.     for i in Booking1.objects.all():
  5.         invtime=i.start_datetime
  6.         #print invtime
  7.         #print type(invtime)
  8.         now=datetime.datetime.now()
  9.         one_day=60*60*24
  10.         diff=comp_dates(str(invtime),str(now).split('.')[0])
  11.         print diff
  12.         print"LLLLLLLLLLLLLLLLLPPPPPPPPPPPPPPPPPJ"
  13.  
  14.         #if diff < one_day and CarModel.objects.filter(inventory_deduct=0):
  15.         for a in CarModel.objects.all():
  16.             if a.inventory_deduct==0 and diff<one_day:
  17.                 qtyInStock=a.car_inventory
  18.                 orderQuantity = 1
  19.                 qtyLeft = int(qtyInStock) - int(orderQuantity)
  20.                 a.car_inventory=qtyLeft
  21.                 a.inventory_deduct=1
  22.                 a.save()
  23.  
  24.                 allObj=CarModel.objects.all()
  25.                 print allObj
  26.                 print "LLLLLLLLLLLLLLLLLL"
  27.                 return render_to_response("inventoryupdate.html", {'allObj':allObj})    
  28.             if a.inventory_deduct==1 and diff < one_day:
  29.                 all=CarModel.objects.all()
  30.                 return render_to_response("inventory.html",{'all':all})
  31.             if diff    > one_day:
  32.                 all=CarModel.objects.all()
  33.                 return render_to_response("inventory.html",{'all':all})
  34.  
  35.  
i have added one field called inventory_deduct and if it is true, it is 1 else it is 0. thus as you can see in my if statement, i have covered three possible situation. this logic is correct, right?? am i lack of any scenario?
Dec 24 '07 #10

P: 88
i have tried it, in fact car inventory is in CarModel table which is separated from Booking1 table, as i have normalized the database table. Thus i edited the code in the following and i think it works.

Expand|Select|Wrap|Line Numbers
  1. def inventory(request):
  2.  
  3.     allObj=[]
  4.     for i in Booking1.objects.all():
  5.         invtime=i.start_datetime
  6.         #print invtime
  7.         #print type(invtime)
  8.         now=datetime.datetime.now()
  9.         one_day=60*60*24
  10.         diff=comp_dates(str(invtime),str(now).split('.')[0])
  11.         print diff
  12.         print"LLLLLLLLLLLLLLLLLPPPPPPPPPPPPPPPPPJ"
  13.  
  14.         #if diff < one_day and CarModel.objects.filter(inventory_deduct=0):
  15.         for a in CarModel.objects.all():
  16.             if a.inventory_deduct==0 and diff<one_day:
  17.                 qtyInStock=a.car_inventory
  18.                 orderQuantity = 1
  19.                 qtyLeft = int(qtyInStock) - int(orderQuantity)
  20.                 a.car_inventory=qtyLeft
  21.                 a.inventory_deduct=1
  22.                 a.save()
  23.  
  24.                 allObj=CarModel.objects.all()
  25.                 print allObj
  26.                 print "LLLLLLLLLLLLLLLLLL"
  27.                 return render_to_response("inventoryupdate.html", {'allObj':allObj})    
  28.             if a.inventory_deduct==1 and diff < one_day:
  29.                 all=CarModel.objects.all()
  30.                 return render_to_response("inventory.html",{'all':all})
  31.             if diff    > one_day:
  32.                 all=CarModel.objects.all()
  33.                 return render_to_response("inventory.html",{'all':all})
  34.  
  35.  
i have added one field called inventory_deduct and if it is true, it is 1 else it is 0. thus as you can see in my if statement, i have covered three possible situation. this logic is correct, right?? am i lack of any scenario?
sometimes, i find out that inventory will turn out to be negative....is this really correct to do in this way?? hmm...if inventory becomes negative means the company is lack of this amount of car? i am not sure if this kind of scenario is correct. as from my current coding, it will occurs this negative inventory scenario.i would like to hear from your opinion.
Dec 25 '07 #11

bvdet
Expert Mod 2.5K+
P: 2,851
i have tried it, in fact car inventory is in CarModel table which is separated from Booking1 table, as i have normalized the database table. Thus i edited the code in the following and i think it works.

Expand|Select|Wrap|Line Numbers
  1. def inventory(request):
  2.  
  3.     allObj=[]
  4.     for i in Booking1.objects.all():
  5.         invtime=i.start_datetime
  6.         #print invtime
  7.         #print type(invtime)
  8.         now=datetime.datetime.now()
  9.         one_day=60*60*24
  10.         diff=comp_dates(str(invtime),str(now).split('.')[0])
  11.         print diff
  12.         print"LLLLLLLLLLLLLLLLLPPPPPPPPPPPPPPPPPJ"
  13.  
  14.         #if diff < one_day and CarModel.objects.filter(inventory_deduct=0):
  15.         for a in CarModel.objects.all():
  16.             if a.inventory_deduct==0 and diff<one_day:
  17.                 qtyInStock=a.car_inventory
  18.                 orderQuantity = 1
  19.                 qtyLeft = int(qtyInStock) - int(orderQuantity)
  20.                 a.car_inventory=qtyLeft
  21.                 a.inventory_deduct=1
  22.                 a.save()
  23.  
  24.                 allObj=CarModel.objects.all()
  25.                 print allObj
  26.                 print "LLLLLLLLLLLLLLLLLL"
  27.                 return render_to_response("inventoryupdate.html", {'allObj':allObj})    
  28.             if a.inventory_deduct==1 and diff < one_day:
  29.                 all=CarModel.objects.all()
  30.                 return render_to_response("inventory.html",{'all':all})
  31.             if diff    > one_day:
  32.                 all=CarModel.objects.all()
  33.                 return render_to_response("inventory.html",{'all':all})
  34.  
  35.  
i have added one field called inventory_deduct and if it is true, it is 1 else it is 0. thus as you can see in my if statement, i have covered three possible situation. this logic is correct, right?? am i lack of any scenario?
I think you are going about it the wrong way. You have Inventory (a collection of CarModels) and Booking1 objects. Think about each CarModel in your inventory having a status attribute which would include date information. If the car is in inventory and has not been booked, the date data could be set to False. If the car is in inventory and has been booked for a future date, the date data would be from...to dates. If the car is not in inventory, the date data should be from < now < to.

I don't have much experience with this type of programming, and I am unfamiliar with your objects, so I may be off base. It seems to me that if you set it up this way, you could determine the available inventory on any particular day, either now or in the future.
Dec 26 '07 #12

P: 88
I think you are going about it the wrong way. You have Inventory (a collection of CarModels) and Booking1 objects. Think about each CarModel in your inventory having a status attribute which would include date information. If the car is in inventory and has not been booked, the date data could be set to False. If the car is in inventory and has been booked for a future date, the date data would be from...to dates. If the car is not in inventory, the date data should be from < now < to.

I don't have much experience with this type of programming, and I am unfamiliar with your objects, so I may be off base. It seems to me that if you set it up this way, you could determine the available inventory on any particular day, either now or in the future.
i have 2 tables to complete this function, in my Booking1 table i have car_id, user_id, start_datetime and end_datetime, pickup _location, return_locaiton. and in my CarModel table, i have car_model_code. outlet_id as foreign key, car_model_name, booking_price. inventory_deduct and car_inventory, etc.

i have separate this two tables. only deduct inventory 24 hours before customer's start_datetime of booking car. as before this, i am still able to rent this car to other customers. if this condition is matched, then it inventory_deduct will set to 1, which means it has already deduct car inventory for this booking. hmm...i am not sure is you mean this part is wrong, which means i should include inventory_deduct in Booking1 table? i would like to hear from you and clear my doubts about this part. haha, thanks so much :)
Dec 27 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.