473,545 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

88 New Member
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.mkt ime(time.strpti me(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
12 1842
bvdet
2,851 Recognized Expert Moderator Specialist
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.mkt ime(time.strpti me(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
kang jia
88 New Member
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\pyt hon.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
kang jia
88 New Member
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\pyt hon.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
kang jia
88 New Member
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\pyt hon.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
2,851 Recognized Expert Moderator Specialist
Check the type of object returned by:
Expand|Select|Wrap|Line Numbers
  1. invtime=i.start_datetime
Dec 23 '07 #6
kang jia
88 New Member
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.dateti me. 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
2,851 Recognized Expert Moderator Specialist
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
kang jia
88 New Member
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
kang jia
88 New Member
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_deduc t 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

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

Similar topics

1
2631
by: Melissa | last post by:
Products appear on multiple orders in a batch of orders. I created a totals query with the fields, ProductID and SumOfQuantity. I have a TblProduct table of products with the fields ProductID, Inventory, and other fields not relevant here. My intent was to join the query and the table on the ProductID fields in an update query to update...
6
4824
by: ralph_noble | last post by:
Can someome please advise what the equivalent query would be in Microsoft SQL Server ... I've tried a number of combinations with no success ... Thanks, Ralph Noble (ralph_noble@hotmail.com) ================ UPDATE INVENTORY INNER JOIN SALES ON (INVENTORY.BAR_CODE = SALES.BAR_CODE)
12
2230
by: qt1504 | last post by:
I have two small stores in two different building which is not a LAN network. However, each has an internet access. I am trying to write an inventory program which manage inventory two stores. Can anyone help or guide me how to start? Please advise. Thanks, QT
0
1162
by: Jeff | last post by:
I have a simple database with Table Inventory and Order. In Table Order, I have fields SKU#......QtySold Where Inventory-SKU# related to Order-SKU# (One SKU# to many Order) Now I want to calculate the percentage of QtySold>5 to Total number of Order. And I want to put the result into a field in Inventory. Anyone can help?
2
413
by: SamDev | last post by:
I have a table that lists inventory items with prices and suppler and inventory description. There are times when a supplier will have a % increase of prices for all items so I want to be able to enter the price % increase and have a query update all inventory items for that supplier by the specified % increase. Not sure what is the best...
46
2842
by: arion | last post by:
Hello, I am working on a very complex database and now I am trying to create an update query. The query is showing too few records. I am trying to update data in the table "inventory" with data from "workorder" table. The query is just copying the last workorder. I would like to update all new workorders to the inventory (can be until 100...
5
3366
by: cblank | last post by:
I'm having some trouble with my inventory program. Its due tom and my teacher is not wanting to help. He keeps giving me a soluction that is not related to my code. I have everything working except the Delete and Modify Button. The Search button works but it only searchs the new .dat file or what is set in the array. Not sure what is going on...
6
1382
by: deltamami0999 | last post by:
I just received this e-mail from a colleague of mine that got stuck and she sent it to me and i'm stuck....we're wondering what this is all about.....can anyone help? Inventory Management System The inventory management system is designed to be used primarily by warehouse workers. The system must use a simple command line driven...
3
4464
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional...
0
7475
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7918
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7436
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5981
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
715
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.