Example #1
0
    def deleteitem(self, id):
        if session["user"] != "admin":
            return id

        item = self.item_q.filter_by(rep=id).first()
        Session.delete(item)
        Session.commit()
        return id
Example #2
0
    def deleteallitems(self):
        if session["user"] != "admin":
            return

        for item in self.item_q.all():
            Session.delete(item)
        Session.commit()
        c.pagetitle = "DOB/DOA Tracker"
        c.itemcount = 0
        return redirect("/")
Example #3
0
 def rtsform(self, id):
     import datetime
     c.item = self.item_q.filter_by(rep=id).first()
     repstring = "REP{0:0=7}".format(c.item.rep)
     c.printrep = repstring[0:6] + " " + repstring[6:10]
     c.pagetitle = "RTS form for # %s" % c.item.rep
     now = datetime.datetime.now()
     if not c.item.rtsdate:
         c.item.rtsdate = "%s/%s/%s" % (now.day, now.month, now.year)
     Session.commit()
     return render("/rtsform.mako")
Example #4
0
    def addtodb(self):
        if session["user"] != "admin":
            return

        import datetime

        if request.params['value']:
            f = float(request.params['value'])
        else:
            f = 0.0

        r = round(f, 2)
        newvalue = int(r*100)

        newitem = Item(rep=int(request.params['rep']),
                       customer=request.params['customer'].upper()[:30],
                       value=newvalue,
                       costcentre=request.params['costcentre'].upper()[:20],
                       ordernum=request.params['ordernum'].upper()[:20],
                       make=request.params['make'].upper()[:30],
                       model=request.params['model'].upper()[:50],
                       part=request.params['part'].upper()[:30],
                       serial=request.params['serial'].upper()[:30],
                       asset=request.params['asset'].upper()[:30],
                       warranty=request.params['warranty'].upper()[:30],
                       issue=request.params['issue'].upper()[:300],
                       state=request.params['state'].upper()[:300],
                       location=request.params['location'].upper()[:300],
                       comment=request.params['comment'].upper()[:300])
        if request.params.get('fujitsuowned') == 'yes':
            newitem.fujitsuowned = True
        else:
            newitem.fujitsuowned = False

        newitem.initials = "AF";
        now = datetime.datetime.now()
        newitem.datein = "%s%s%s" % (now.year, now.month, now.day)
        Session.add(newitem)
        Session.commit()

        fields = ("rep", "datein", "kind", "initials", "customer", "value",
                  "costcentre", "ordernum", "make", "model", "part", "serial",
                  "asset", "warranty", "location", "issue", "state", "solution",
                  "grn", "sap", "rtsdate", "folio", "comment")

        return dict((field, getattr(newitem, field)) for field in fields)
Example #5
0
    def applyitemedit(self, id):
        if session["user"] != "admin":
            return

        item = self.item_q.filter_by(rep=id).first()

        f = float(request.params["value"])
        r = round(f, 2)
        item.value = int(r * 100)

        fields30 = ("customer", "make", "part", "serial", "asset", "warranty")
        fields20 = ("costcentre", "ordernum", "rtsdate")
        fields300 = ("issue", "state", "solution", "location", "comment")

        allfields = (
            fields30
            + fields20
            + fields300
            + ("rep", "initials", "value", "model", "grn", "sap", "folio", "fujitsuowned")
        )

        for field in fields30:
            setattr(item, field, request.params[field].upper()[:30])

        for field in fields20:
            setattr(item, field, request.params[field].upper()[:20])

        for field in fields300:
            setattr(item, field, request.params[field].upper()[:300])

        item.model = request.params["model"].upper()[:50]
        item.grn = request.params["grn"].upper()[:8]
        item.sap = request.params["sap"].upper()[:8]
        item.folio = int(request.params["folio"])

        if request.params.get("fujitsuowned") == "yes":
            item.fujitsuowned = True
        else:
            item.fujitsuowned = False

        Session.commit()

        result = dict((field, getattr(item, field)) for field in allfields)

        # Return info to JS handler, so it can update the index table
        return result
Example #6
0
    def upload(self):
        """
        Really nasty CSV importer that does minimal error checking and
        expects everything to be laid out in a particular manner.
        """
        import csv
        csvfile = request.POST['csvfile']
        csvreader = csv.reader(csvfile.file, delimiter="\t", quotechar='"')

        rowsadded = 0
        repsadded = []
        c.duplicatereps = []
        c.unknowncustomers = []

        for row in csvreader:
            rep = row[3][3:][:7]
            if rep == '':
                rep = rowsadded

            # Skip over duplicate REP numbers
            if rep not in repsadded:
                newitem = Item(rep=int(rep),
                               kind=row[0].decode('utf-8', 'ignore')[:3],
                               initials=row[1].decode('utf-8', 'ignore')[:3],
                               customer=row[4].decode('utf-8', 'ignore')[:30],
                               costcentre=row[6].decode('utf-8', 'ignore')[:20],
                               ordernum=row[7].decode('utf-8', 'ignore')[:20],
                               make=row[8].decode('utf-8', 'ignore')[:30],
                               model=row[9].decode('utf-8', 'ignore')[:50],
                               part=row[10].decode('utf-8', 'ignore')[:30],
                               serial=row[11].decode('utf-8', 'ignore')[:30],
                               asset=row[12].decode('utf-8', 'ignore')[:30],
                               issue=row[14].decode('utf-8', 'ignore')[:300],
                               state=row[15].decode('utf-8', 'ignore')[:300],
                               location=row[16].decode('utf-8', 'ignore')[:300],
                               solution=row[17].decode('utf-8', 'ignore')[:300],
                               sap=row[18].decode('utf-8', 'ignore')[:8],
                               grn=row[19].decode('utf-8', 'ignore')[:8])

                # Sometimes Excel doesn't include the last column (or the CSV
                # reader doesn't read it properly).
                if len(row) >= 21:
                    # Sometimes the Folio column has non-numbers in it
                    try:
                        newitem.folio = int(row[21])
                    except ValueError:
                        newitem.folio = 0

                # Ditto for Value column, particularly items added long ago
                # by a certain "JH".
                try:
                    f = float(row[5])
                except ValueError:
                    f = 0.0

                # Store values as integers
                r = round(f, 2)
                newitem.value = int(r*100)

                newitem.datein = parsedate(row[2].decode('utf-8', 'ignore')[:20])
                newitem.warranty = parsedate(row[13].decode('utf-8', 'ignore')[:20])
                newitem.rtsdate = parsedate(row[20].decode('utf-8', 'ignore')[:20])

                # Return
                custs = ["TESCO", "HSBC", "SPECSAVERS", "HBOS", "RBSG"]
                def detectcust(cust):
                    for acust in custs:
                        if cust[:len(acust)] == acust:
                            return acust
                    if cust != "UNKNOWN":
                        c.unknowncustomers.append({"rep": newitem.rep,
                                                   "customer": cust})
                    return "UNKNOWN"

                newcust = detectcust(newitem.customer)

                # If there's a "/" in the customer name, assume it's owned
                # by Fujitsu if the character after the "/" is an "F"
                slash = newitem.customer.find("/")
                if slash != -1:
                    if newitem.customer[slash + 1] == "F":
                        newitem.fujitsuowned = True
                    else:
                        newitem.fujitsuowned = False

                newitem.customer = newcust

                Session.add(newitem)
                rowsadded = rowsadded + 1
                repsadded += [rep]
            else:
                c.duplicatereps += [rep]
                print "[dobtrack] Ignoring duplicate rep of %s" % rep

        Session.commit()
        print "[dobtrack] Unrecognised 'customer' entries:"
        print c.unknowncustomers

        c.rowsadded = rowsadded
        c.pagetitle = "CSV file uploaded successfully"
        return render('/upload.mako')
Example #7
0
 def fixdate(self):
     items = self.item_q.all()
     for i, item in enumerate(items):
         items[i].rtsdate = parsedate(item.rtsdate)
     Session.commit()
     return redirect("/")
Example #8
0
    def addtodb(self):
        if session["user"] != "admin":
            return

        import datetime

        if request.params["value"]:
            f = float(request.params["value"])
        else:
            f = 0.0

        r = round(f, 2)
        newvalue = int(r * 100)

        newitem = Item(
            rep=int(request.params["rep"]),
            customer=request.params["customer"].upper()[:30],
            value=newvalue,
            costcentre=request.params["costcentre"].upper()[:20],
            ordernum=request.params["ordernum"].upper()[:20],
            make=request.params["make"].upper()[:30],
            model=request.params["model"].upper()[:50],
            part=request.params["part"].upper()[:30],
            serial=request.params["serial"].upper()[:30],
            asset=request.params["asset"].upper()[:30],
            warranty=request.params["warranty"].upper()[:30],
            issue=request.params["issue"].upper()[:300],
            state=request.params["state"].upper()[:300],
            location=request.params["location"].upper()[:300],
            comment=request.params["comment"].upper()[:300],
        )
        if request.params.get("fujitsuowned") == "yes":
            newitem.fujitsuowned = True
        else:
            newitem.fujitsuowned = False

        newitem.initials = "AF"
        now = datetime.datetime.now()
        newitem.datein = "%s/%s/%s" % (now.day, now.month, now.year)
        Session.add(newitem)
        Session.commit()

        fields = (
            "rep",
            "datein",
            "kind",
            "initials",
            "customer",
            "value",
            "costcentre",
            "ordernum",
            "make",
            "model",
            "part",
            "serial",
            "asset",
            "warranty",
            "location",
            "issue",
            "state",
            "solution",
            "grn",
            "sap",
            "rtsdate",
            "folio",
            "comment",
        )

        return dict((field, getattr(newitem, field)) for field in fields)