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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kang jia
    New Member
    • Jun 2007
    • 88

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

    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:)

    [code=python]
    def inventory(reque st):

    allObj=[]
    for i in Booking1.object s.all():
    #print i.booking_time
    invtime=i.start _datetime
    #t=str(invtime) .split('.')[0]
    Bktime=time.mkt ime(time.strpti me(invtime,"%Y-%m-%d %H:%M:%S"))
    #now=datetime.d atetime.now()
    one_day=60*60*2 4
    #diff=comp_date s(t,str(now).sp lit('.')[0])
    #print diff
    onebefore=Bktim e-one_day------>>>Error,wher e is wrong?date type?
    if str(onebefore):
    for a in CarModel.object s.all():
    qtyInStock=a.ca r_inventory
    orderQuantity = 1
    qtyLeft = int(qtyInStock) - int(orderQuanti ty)
    a.car_inventory =qtyLeft
    a.save()
    allObj=CarModel .objects.all()
    print allObj
    print "LLLLLLLLLLLLLL LLLL"
    return render_to_respo nse("inventoryu pdate.html", {'allObj':allOb j})
    if not str(onebefore):
    all=CarModel.ob jects.all()
    return render_to_respo nse("inventory. html",{'all':al l})
    [/code]
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by kang jia
    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:)

    [code=python]
    def inventory(reque st):

    allObj=[]
    for i in Booking1.object s.all():
    #print i.booking_time
    invtime=i.start _datetime
    #t=str(invtime) .split('.')[0]
    Bktime=time.mkt ime(time.strpti me(invtime,"%Y-%m-%d %H:%M:%S"))
    #now=datetime.d atetime.now()
    one_day=60*60*2 4
    #diff=comp_date s(t,str(now).sp lit('.')[0])
    #print diff
    onebefore=Bktim e-one_day------>>>Error,wher e is wrong?date type?
    if str(onebefore):
    for a in CarModel.object s.all():
    qtyInStock=a.ca r_inventory
    orderQuantity = 1
    qtyLeft = int(qtyInStock) - int(orderQuanti ty)
    a.car_inventory =qtyLeft
    a.save()
    allObj=CarModel .objects.all()
    print allObj
    print "LLLLLLLLLLLLLL LLLL"
    return render_to_respo nse("inventoryu pdate.html", {'allObj':allOb j})
    if not str(onebefore):
    all=CarModel.ob jects.all()
    return render_to_respo nse("inventory. html",{'all':al l})
    [/code]
    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.

    Comment

    • kang jia
      New Member
      • Jun 2007
      • 88

      #3
      Originally posted by bvdet
      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:

      [code=python]
      def inventory(reque st):

      allObj=[]
      for i in Booking1.object s.all():
      #print i.booking_time
      invtime=i.start _datetime
      now=datetime.da tetime.now()
      one_day=60*60*2 4
      diff=comp_dates (invtime,str(no w).split('.')[0])
      print diff
      print"LLLLLLLLL LLLLLLLLPPPPPPP PPPPPPPPPPJ"
      if diff < one_day:
      for a in CarModel.object s.all():
      qtyInStock=a.ca r_inventory
      orderQuantity = 1
      qtyLeft = int(qtyInStock) - int(orderQuanti ty)
      a.car_inventory =qtyLeft
      a.save()
      allObj=CarModel .objects.all()
      print allObj
      print "LLLLLLLLLLLLLL LLLL"
      return render_to_respo nse("inventoryu pdate.html", {'allObj':allOb j})
      if not diff < one_day:
      all=CarModel.ob jects.all()
      return render_to_respo nse("inventory. html",{'all':al l})
      [/code]

      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

      Comment

      • kang jia
        New Member
        • Jun 2007
        • 88

        #4
        Originally posted by bvdet
        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:

        [code=python]
        def inventory(reque st):

        allObj=[]
        for i in Booking1.object s.all():
        #print i.booking_time
        invtime=i.start _datetime
        now=datetime.da tetime.now()
        one_day=60*60*2 4
        diff=comp_dates (invtime,str(no w).split('.')[0])
        print diff
        print"LLLLLLLLL LLLLLLLLPPPPPPP PPPPPPPPPPJ"
        if diff < one_day:
        for a in CarModel.object s.all():
        qtyInStock=a.ca r_inventory
        orderQuantity = 1
        qtyLeft = int(qtyInStock) - int(orderQuanti ty)
        a.car_inventory =qtyLeft
        a.save()
        allObj=CarModel .objects.all()
        print allObj
        print "LLLLLLLLLLLLLL LLLL"
        return render_to_respo nse("inventoryu pdate.html", {'allObj':allOb j})
        if not diff < one_day:
        all=CarModel.ob jects.all()
        return render_to_respo nse("inventory. html",{'all':al l})
        [/code]

        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

        Comment

        • kang jia
          New Member
          • Jun 2007
          • 88

          #5
          Originally posted by bvdet
          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:

          [code=python]
          def inventory(reque st):

          allObj=[]
          for i in Booking1.object s.all():
          #print i.booking_time
          invtime=i.start _datetime
          now=datetime.da tetime.now()
          one_day=60*60*2 4
          diff=comp_dates (invtime,str(no w).split('.')[0])
          print diff
          print"LLLLLLLLL LLLLLLLLPPPPPPP PPPPPPPPPPJ"
          if diff < one_day:
          for a in CarModel.object s.all():
          qtyInStock=a.ca r_inventory
          orderQuantity = 1
          qtyLeft = int(qtyInStock) - int(orderQuanti ty)
          a.car_inventory =qtyLeft
          a.save()
          allObj=CarModel .objects.all()
          print allObj
          print "LLLLLLLLLLLLLL LLLL"
          return render_to_respo nse("inventoryu pdate.html", {'allObj':allOb j})
          if not diff < one_day:
          all=CarModel.ob jects.all()
          return render_to_respo nse("inventory. html",{'all':al l})
          [/code]

          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

          Comment

          • bvdet
            Recognized Expert Specialist
            • Oct 2006
            • 2851

            #6
            Check the type of object returned by:[code=Python]invtime=i.start _datetime[/code]

            Comment

            • kang jia
              New Member
              • Jun 2007
              • 88

              #7
              Originally posted by bvdet
              Check the type of object returned by:[code=Python]invtime=i.start _datetime[/code]
              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.....

              [code=python]
              def inventory(reque st):

              allObj=[]
              for i in Booking1.object s.all():
              #print i.booking_time
              invtime=i.start _datetime
              #start_datetime = datetime.dateti me(*strptime(in vtime,"%Y-%m-%dT%H:%M:%S")[0:6])
              print invtime
              print type(invtime)
              print"KKKKKKKKK KKKKKKK"
              now=datetime.da tetime.now()
              one_day=60*60*2 4
              diff=comp_dates (str(invtime),s tr(now).split(' .')[0])
              print diff
              print"LLLLLLLLL LLLLLLLLPPPPPPP PPPPPPPPPPJ"

              if diff < one_day:
              for a in CarModel.object s.all():
              qtyInStock=a.ca r_inventory
              orderQuantity = 1
              qtyLeft = int(qtyInStock) - int(orderQuanti ty)
              a.car_inventory =qtyLeft
              a.save()
              allObj=CarModel .objects.all()
              print allObj
              print "LLLLLLLLLLLLLL LLLL"
              return render_to_respo nse("inventoryu pdate.html", {'allObj':allOb j})
              if not diff < one_day:
              all=CarModel.ob jects.all()
              return render_to_respo nse("inventory. html",{'all':al l})

              [/code]

              thanks so much for your kind help.

              Comment

              • bvdet
                Recognized Expert Specialist
                • Oct 2006
                • 2851

                #8
                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.[code=Python]
                if diff < one_day and Booking1.object .deducted_from_ inventory == False:[/code]

                Comment

                • kang jia
                  New Member
                  • Jun 2007
                  • 88

                  #9
                  Originally posted by bvdet
                  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.[code=Python]
                  if diff < one_day and Booking1.object .deducted_from_ inventory == False:[/code]
                  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. :)

                  Comment

                  • kang jia
                    New Member
                    • Jun 2007
                    • 88

                    #10
                    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.

                    [code=python]
                    def inventory(reque st):

                    allObj=[]
                    for i in Booking1.object s.all():
                    invtime=i.start _datetime
                    #print invtime
                    #print type(invtime)
                    now=datetime.da tetime.now()
                    one_day=60*60*2 4
                    diff=comp_dates (str(invtime),s tr(now).split(' .')[0])
                    print diff
                    print"LLLLLLLLL LLLLLLLLPPPPPPP PPPPPPPPPPJ"

                    #if diff < one_day and CarModel.object s.filter(invent ory_deduct=0):
                    for a in CarModel.object s.all():
                    if a.inventory_ded uct==0 and diff<one_day:
                    qtyInStock=a.ca r_inventory
                    orderQuantity = 1
                    qtyLeft = int(qtyInStock) - int(orderQuanti ty)
                    a.car_inventory =qtyLeft
                    a.inventory_ded uct=1
                    a.save()

                    allObj=CarModel .objects.all()
                    print allObj
                    print "LLLLLLLLLLLLLL LLLL"
                    return render_to_respo nse("inventoryu pdate.html", {'allObj':allOb j})
                    if a.inventory_ded uct==1 and diff < one_day:
                    all=CarModel.ob jects.all()
                    return render_to_respo nse("inventory. html",{'all':al l})
                    if diff > one_day:
                    all=CarModel.ob jects.all()
                    return render_to_respo nse("inventory. html",{'all':al l})

                    [/code]

                    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?

                    Comment

                    • kang jia
                      New Member
                      • Jun 2007
                      • 88

                      #11
                      Originally posted by kang jia
                      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.

                      [code=python]
                      def inventory(reque st):

                      allObj=[]
                      for i in Booking1.object s.all():
                      invtime=i.start _datetime
                      #print invtime
                      #print type(invtime)
                      now=datetime.da tetime.now()
                      one_day=60*60*2 4
                      diff=comp_dates (str(invtime),s tr(now).split(' .')[0])
                      print diff
                      print"LLLLLLLLL LLLLLLLLPPPPPPP PPPPPPPPPPJ"

                      #if diff < one_day and CarModel.object s.filter(invent ory_deduct=0):
                      for a in CarModel.object s.all():
                      if a.inventory_ded uct==0 and diff<one_day:
                      qtyInStock=a.ca r_inventory
                      orderQuantity = 1
                      qtyLeft = int(qtyInStock) - int(orderQuanti ty)
                      a.car_inventory =qtyLeft
                      a.inventory_ded uct=1
                      a.save()

                      allObj=CarModel .objects.all()
                      print allObj
                      print "LLLLLLLLLLLLLL LLLL"
                      return render_to_respo nse("inventoryu pdate.html", {'allObj':allOb j})
                      if a.inventory_ded uct==1 and diff < one_day:
                      all=CarModel.ob jects.all()
                      return render_to_respo nse("inventory. html",{'all':al l})
                      if diff > one_day:
                      all=CarModel.ob jects.all()
                      return render_to_respo nse("inventory. html",{'all':al l})

                      [/code]

                      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?
                      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.

                      Comment

                      • bvdet
                        Recognized Expert Specialist
                        • Oct 2006
                        • 2851

                        #12
                        Originally posted by kang jia
                        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.

                        [code=python]
                        def inventory(reque st):

                        allObj=[]
                        for i in Booking1.object s.all():
                        invtime=i.start _datetime
                        #print invtime
                        #print type(invtime)
                        now=datetime.da tetime.now()
                        one_day=60*60*2 4
                        diff=comp_dates (str(invtime),s tr(now).split(' .')[0])
                        print diff
                        print"LLLLLLLLL LLLLLLLLPPPPPPP PPPPPPPPPPJ"

                        #if diff < one_day and CarModel.object s.filter(invent ory_deduct=0):
                        for a in CarModel.object s.all():
                        if a.inventory_ded uct==0 and diff<one_day:
                        qtyInStock=a.ca r_inventory
                        orderQuantity = 1
                        qtyLeft = int(qtyInStock) - int(orderQuanti ty)
                        a.car_inventory =qtyLeft
                        a.inventory_ded uct=1
                        a.save()

                        allObj=CarModel .objects.all()
                        print allObj
                        print "LLLLLLLLLLLLLL LLLL"
                        return render_to_respo nse("inventoryu pdate.html", {'allObj':allOb j})
                        if a.inventory_ded uct==1 and diff < one_day:
                        all=CarModel.ob jects.all()
                        return render_to_respo nse("inventory. html",{'all':al l})
                        if diff > one_day:
                        all=CarModel.ob jects.all()
                        return render_to_respo nse("inventory. html",{'all':al l})

                        [/code]

                        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?
                        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.

                        Comment

                        • kang jia
                          New Member
                          • Jun 2007
                          • 88

                          #13
                          Originally posted by bvdet
                          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_deduc t 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_deduc t 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_deduc t in Booking1 table? i would like to hear from you and clear my doubts about this part. haha, thanks so much :)

                          Comment

                          Working...