示例#1
0
 def test_regimen_crud(self):
     data = {
         "animalname": "Testio",
         "estimatedage": "1",
         "animaltype": "1",
         "entryreason": "1",
         "species": "1"
     }
     post = utils.PostedData(data, "en")
     aid, code = animal.insert_animal_from_form(base.get_dbo(), post,
                                                "test")
     data = {
         "startdate": base.today_display(),
         "treatmentname": "Test",
         "dosage": "Test",
         "timingrule": "1",
         "timingrulenofrequencies": "1",
         "timingrulefrequency": "1",
         "totalnumberoftreatments": "1",
         "treatmentrule": "1",
         "singlemulti": "1"
     }
     post = utils.PostedData(data, "en")
     mid = medical.insert_regimen_from_form(base.get_dbo(), "test", post)
     medical.update_regimen_from_form(base.get_dbo(), "test", post)
     medical.delete_regimen(base.get_dbo(), "test", mid)
     animal.delete_animal(base.get_dbo(), "test", aid)
示例#2
0
 def setUp(self):
     data = {
         "datelost": base.today_display(),
         "datereported": base.today_display(),
         "owner": "1",
         "species": "1", 
         "sex": "1",
         "breed": "1",
         "colour": "1",
         "markings": "Test",
         "arealost": "Test",
         "areapostcode": "Test"
     }
     post = utils.PostedData(data, "en")
     self.laid = lostfound.insert_lostanimal_from_form(base.get_dbo(), post, "test")
     data = {
         "datefound": base.today_display(),
         "datereported": base.today_display(),
         "owner": "1",
         "species": "1", 
         "sex": "1",
         "breed": "1",
         "colour": "1",
         "markings": "Test",
         "areafound": "Test",
         "areapostcode": "Test"
     }
     post = utils.PostedData(data, "en")
     self.faid = lostfound.insert_foundanimal_from_form(base.get_dbo(), post, "test")
示例#3
0
 def test_transport_crud(self):
     data = {
         "animalname": "Testio",
         "estimatedage": "1",
         "animaltype": "1",
         "entryreason": "1",
         "species": "1"
     }
     post = utils.PostedData(data, "en")
     aid, code = animal.insert_animal_from_form(base.get_dbo(), post,
                                                "test")
     data = {
         "animal": "1",
         "driver": "1",
         "pickup": "1",
         "dropoff": "1",
         "pickupdate": base.today_display(),
         "dropoffdate": base.today_display(),
         "status": "1"
     }
     post = utils.PostedData(data, "en")
     tid = movement.insert_transport_from_form(base.get_dbo(), "test", post)
     post.data["transportid"] = str(tid)
     movement.update_transport_from_form(base.get_dbo(), "test", post)
     movement.delete_transport(base.get_dbo(), "test", tid)
     animal.delete_animal(base.get_dbo(), "test", aid)
示例#4
0
文件: movement.py 项目: tgage/asm3
def insert_retailer_from_form(dbo, username, post):
    """
    Inserts a retailer from the workflow move to retailer screen.
    Returns the new movement id
    """
    # Validate that we have a movement date before doing anthing
    l = dbo.locale
    if None is post.date("retailerdate"):
        raise utils.ASMValidationError(i18n._("Retailer movements must have a valid movement date.", l))

    # Is this animal already at a foster? If so, return that foster first
    fm = get_animal_movements(dbo, post.integer("animal"))
    for m in fm:
        if m.MOVEMENTTYPE == FOSTER and m.RETURNDATE is None:
            return_movement(dbo, m.ID, post.integer("animal"), post.date("retailerdate"))
    # Create the retailer movement
    move_dict = {
        "person"                : post["person"],
        "animal"                : post["animal"],
        "movementdate"          : post["retailerdate"],
        "adoptionno"            : post["movementnumber"],
        "type"                  : str(RETAILER),
        "donation"              : post["amount"],
        "returncategory"        : configuration.default_return_reason(dbo)
    }
    movementid = insert_movement_from_form(dbo, username, utils.PostedData(move_dict, l))
    return movementid
示例#5
0
文件: movement.py 项目: tgage/asm3
def insert_reserve_from_form(dbo, username, post):
    """
    Inserts a movement from the workflow reserve an animal screen.
    Returns the new movement id
    """
    # Validate that we have a date before doing anthing
    l = dbo.locale
    if None is post.date("reservationdate"):
        raise utils.ASMValidationError(i18n._("Reservations must have a valid reservation date.", l))

    # Do the movement itself first
    move_dict = {
        "person"                : post["person"],
        "animal"                : post["animal"],
        "reservationdate"       : post["reservationdate"],
        "reservationstatus"     : post["reservationstatus"],
        "adoptionno"            : post["movementnumber"],
        "movementdate"          : "",
        "type"                  : str(NO_MOVEMENT),
        "donation"              : post["amount"],
        "returncategory"        : configuration.default_return_reason(dbo)
    }
    movementid = insert_movement_from_form(dbo, username, utils.PostedData(move_dict, l))
    # Create any payments
    financial.insert_donations_from_form(dbo, username, post, post["reservationdate"], False, post["person"], post["animal"], movementid) 
    return movementid
示例#6
0
 def test_stock_take_from_mobile_form(self):
     data = {
         "sl%d" % self.nid: "5",
         "usagetype": "1"
     }
     post = utils.PostedData(data, "en")
     stock.stock_take_from_mobile_form(base.get_dbo(), "test", post)
示例#7
0
def create_animalcontrol(dbo, username, collationid):
    """
    Creates a animal control/incident record from the incoming form data with 
    collationid.
    Also, attaches the form to the incident as media.
    """
    l = dbo.locale
    fields = get_onlineformincoming_detail(dbo, collationid)
    d = {}
    d["incidentdate"] = i18n.python2display(l, i18n.now(dbo.timezone))
    d["incidenttime"] = i18n.format_time_now(dbo.timezone)
    d["calldate"] = d["incidentdate"]
    d["calltime"] = d["incidenttime"]
    d["incidenttype"] = 1
    for f in fields:
        if f["FIELDNAME"] == "callnotes": d["callnotes"] = f["VALUE"]
        if f["FIELDNAME"] == "dispatchaddress": d["dispatchaddress"] = f["VALUE"]
        if f["FIELDNAME"] == "dispatchcity": d["dispatchtown"] = f["VALUE"]
        if f["FIELDNAME"] == "dispatchstate": d["dispatchcounty"] = f["VALUE"]
        if f["FIELDNAME"] == "dispatchzipcode": d["dispatchpostcode"] = f["VALUE"]
    # Have we got enough info to create the animal control record? We need notes and dispatchaddress
    if not d.has_key("callnotes") or not d.has_key("dispatchaddress"):
        raise utils.ASMValidationError(i18n._("There is not enough information in the form to create an incident record (need call notes and dispatch address).", l))
    # We need the person/caller record before we create the incident
    collationid, personid, personname = create_person(dbo, username, collationid)
    d["caller"] = personid
    # Create the incident 
    incidentid = animalcontrol.insert_animalcontrol_from_form(dbo, utils.PostedData(d, dbo.locale), username)
    # Attach the form to the incident
    formname = get_onlineformincoming_name(dbo, collationid)
    formhtml = get_onlineformincoming_html(dbo, collationid)
    media.create_document_media(dbo, username, media.ANIMALCONTROL, incidentid, formname, formhtml )
    return (collationid, incidentid, utils.padleft(incidentid, 6) + " - " + personname)
def insert_transfer_from_form(dbo, username, post):
    """
    Inserts a movement from the workflow transfer an animal screen.
    Returns the new movement id
    """
    # Validate that we have a movement date before doing anthing
    l = dbo.locale
    if None == post.date("transferdate"):
        raise utils.ASMValidationError(
            i18n._("Transfers must have a valid transfer date.", l))

    # Is this animal already on foster? If so, return that foster first
    fm = get_animal_movements(dbo, post.integer("animal"))
    for m in fm:
        if m["MOVEMENTTYPE"] == FOSTER and m["RETURNDATE"] is None:
            return_movement(dbo, m["ID"], post.integer("animal"),
                            post.date("transferdate"))
    # Create the transfer movement
    move_dict = {
        "person": post["person"],
        "animal": post["animal"],
        "adoptionno": post["movementnumber"],
        "movementdate": post["transferdate"],
        "type": str(TRANSFER),
        "donation": post["amount"],
        "returncategory": configuration.default_return_reason(dbo)
    }
    movementid = insert_movement_from_form(dbo, username,
                                           utils.PostedData(move_dict, l))
    return movementid
示例#9
0
文件: clinic.py 项目: tgage/asm3
def insert_payment_from_appointment(dbo, username, appointmentid, post):
    """
    Creates a payment record from an appointment via the create payment dialog.
    """
    l = dbo.locale
    c = get_appointment(dbo, appointmentid)
    d = {
        "person":
        str(c.OwnerID),
        "animal":
        str(c.AnimalID),
        "type":
        post["paymenttype"],
        "payment":
        post["paymentmethod"],
        "amount":
        str(c.Amount),
        "due":
        post["due"],
        "received":
        post["received"],
        "vat":
        utils.iif(c.IsVAT == 1, "on", ""),
        "vatrate":
        str(c.VATRate),
        "vatamount":
        str(c.VATAmount),
        "comments":
        i18n._("Appointment {0}. {1} on {2} for {3}").format(
            utils.padleft(c.ID, 6), c.OWNERNAME,
            i18n.python2display(l, c.DATETIME), c.ANIMALNAME)
    }
    return financial.insert_donation_from_form(dbo, username,
                                               utils.PostedData(d, l))
示例#10
0
文件: movement.py 项目: tgage/asm3
def insert_reserve_for_animal_name(dbo, username, personid, animalname):
    """
    Creates a reservation for the animal with animalname to personid.
    animalname can either be just the name of a shelter animal, or it
    can be in the form name::code. If a code is present, that will be
    used to locate the animal.
    If the person is banned from adopting animals, an exception is raised.
    """
    l = dbo.locale
    if animalname.find("::") != -1:
        animalcode = animalname.split("::")[1]
        aid = dbo.query_int("SELECT ID FROM animal WHERE ShelterCode = ? ORDER BY ID DESC", [animalcode])
    else:
        aid = dbo.query_int("SELECT ID FROM animal WHERE LOWER(AnimalName) LIKE ? ORDER BY ID DESC", [animalname.lower()])
    if 1 == dbo.query_int("SELECT IsBanned FROM owner WHERE ID=?", [personid]):
        raise utils.ASMValidationError("owner %s is banned from adopting animals - not creating reserve")
    if aid == 0: 
        raise utils.ASMValidationError("could not find an animal for '%s' - not creating reserve" % animalname)
    move_dict = {
        "person"                : str(personid),
        "animal"                : str(aid),
        "reservationdate"       : i18n.python2display(l, dbo.today()),
        "reservationstatus"     : configuration.default_reservation_status(dbo),
        "movementdate"          : "",
        "type"                  : str(NO_MOVEMENT),
        "returncategory"        : configuration.default_return_reason(dbo)
    }
    return insert_movement_from_form(dbo, username, utils.PostedData(move_dict, l))
示例#11
0
文件: lostfound.py 项目: rutaq/asm3
def create_animal_from_found(dbo, username, aid):
    """
    Creates an animal record from a found animal with the id given
    """
    a = dbo.first_row( dbo.query("SELECT * FROM animalfound WHERE ID = %d" % int(aid)) )
    l = dbo.locale
    data = {
        "animalname":           _("Found Animal {0}", l).format(aid),
        "markings":             str(a["DISTFEAT"]),
        "species":              str(a["ANIMALTYPEID"]),
        "comments":             str(a["COMMENTS"]),
        "broughtinby":          str(a["OWNERID"]),
        "originalowner":        str(a["OWNERID"]),
        "animaltype":           configuration.default_type(dbo),
        "breed1":               a["BREEDID"],
        "breed2":               a["BREEDID"],
        "basecolour":           str(a["BASECOLOURID"]),
        "size":                 configuration.default_size(dbo),
        "internallocation":     configuration.default_location(dbo),
        "dateofbirth":          python2display(l, subtract_years(now(dbo.timezone))),
        "estimateddob":         "1",
    }
    # If we're creating shelter codes manually, we need to put something unique
    # in there for now. Use the id
    if configuration.manual_codes(dbo):
        data["sheltercode"] = "FA" + str(aid)
        data["shortcode"] = "FA" + str(aid)
    nextid, code = animal.insert_animal_from_form(dbo, utils.PostedData(data, l), username)
    return nextid
示例#12
0
 def test_update_animalcontrol_from_form(self):
     data = {
         "incidentdate":   "01/01/2014",
         "incidenttime":   "00:00:00"
     }
     post = utils.PostedData(data, "en")
     animalcontrol.update_animalcontrol_from_form(base.get_dbo(), post, "test")
示例#13
0
def create_waitinglist(dbo, username, collationid):
    """
    Creates a waitinglist record from the incoming form data with collationid.
    Also, attaches the form to the waiting list as media.
    """
    l = dbo.locale
    fields = get_onlineformincoming_detail(dbo, collationid)
    d = {}
    d["dateputon"] = i18n.python2display(l, i18n.now(dbo.timezone))
    d["urgency"] = "5"
    for f in fields:
        if f["FIELDNAME"] == "species": d["species"] = guess_species(dbo, f["VALUE"])
        if f["FIELDNAME"] == "description": d["description"] = f["VALUE"]
        if f["FIELDNAME"] == "reason": d["reasonforwantingtopart"] = f["VALUE"]
    if not d.has_key("species"): d["species"] = guess_species(dbo, "")
    # Have we got enough info to create the waiting list record? We need a description
    if not d.has_key("description"):
        raise utils.ASMValidationError(i18n._("There is not enough information in the form to create a waiting list record (need a description).", l))
    # We need the person record before we create the waiting list
    collationid, personid, personname = create_person(dbo, username, collationid)
    d["owner"] = personid
    # Create the waiting list
    wlid = waitinglist.insert_waitinglist_from_form(dbo, utils.PostedData(d, dbo.locale), username)
    # Attach the form to the waiting list
    formname = get_onlineformincoming_name(dbo, collationid)
    formhtml = get_onlineformincoming_html(dbo, collationid)
    media.create_document_media(dbo, username, media.WAITINGLIST, wlid, formname, formhtml )
    return (collationid, wlid, utils.padleft(wlid, 6) + " - " + personname)
示例#14
0
 def test_insert_animalcontrol_from_form(self):
     data = {
         "incidentdate":   "01/01/2014",
         "incidenttime":   "00:00:00"
     }
     post = utils.PostedData(data, "en")
     nid = animalcontrol.insert_animalcontrol_from_form(base.get_dbo(), post, "test")
     animalcontrol.delete_animalcontrol(base.get_dbo(), "test", nid)
示例#15
0
 def test_update_traploan_from_form(self):
     data = {
         "person":   "2",
         "type":     "2",
         "loandate": "01/01/2014"
     }
     post = utils.PostedData(data, "en")
     animalcontrol.update_traploan_from_form(base.get_dbo(), "test", post)
示例#16
0
文件: test_clinic.py 项目: tgage/asm3
 def setUp(self):
     data = {
         "animal": "1",
         "person": "1",
         "apptdate": base.today_display(),
         "appttime": "12:00:00",
         "status": "1",
     }
     post = utils.PostedData(data, "en")
     self.anid = clinic.insert_appointment_from_form(base.get_dbo(), "test", post)
     data = {
         "appointmentid": str(self.anid),
         "description": "foo",
         "amount": "50"
     }
     post = utils.PostedData(data, "en")
     self.inid = clinic.insert_invoice_from_form(base.get_dbo(), "test", post)
示例#17
0
文件: test_animal.py 项目: tgage/asm3
 def test_update_diet_from_form(self):
     data = {
         "animalid": self.nid,
         "type": "1",
         "startdate": base.today_display()
     }
     post = utils.PostedData(data, "en")
     animal.update_diet_from_form(base.get_dbo(), "test", post)
示例#18
0
文件: test_animal.py 项目: tgage/asm3
 def test_update_litter_from_form(self):
     data = {
         "animal": self.nid,
         "species": "1",
         "startdate": base.today_display(),
         "litterref": "RUBBISH"
     }
     post = utils.PostedData(data, "en")
     animal.update_litter_from_form(base.get_dbo(), "test", post)
示例#19
0
 def test_insert_traploan_from_form(self):
     data = {
         "person":   "1",
         "type":     "1",
         "loandate": "01/01/2014"
     }
     post = utils.PostedData(data, "en")
     tid = animalcontrol.insert_traploan_from_form(base.get_dbo(), "test", post)
     animalcontrol.delete_traploan(base.get_dbo(), "test", tid)
示例#20
0
文件: test_animal.py 项目: tgage/asm3
 def test_insert_cost_from_form(self):
     data = {
         "animalid": self.nid,
         "type": "1",
         "costdate": base.today_display(),
         "cost": "2000"
     }
     post = utils.PostedData(data, "en")
     nid = animal.insert_cost_from_form(base.get_dbo(), "test", post)
     animal.delete_cost(base.get_dbo(), "test", nid)
示例#21
0
 def test_crud(self):
     data = {
         "logdate": base.today_display(),
         "type": "1",
         "entry": "Test entry"
     }
     post = utils.PostedData(data, "en")
     nid = log.insert_log_from_form(base.get_dbo(), "test", 0, 1, post)
     log.update_log_from_form(base.get_dbo(), "test", post)
     log.delete_log(base.get_dbo(), "test", nid)
示例#22
0
 def test_deduct_stocklevel_from_form(self):
     data = {
         "item": str(self.nid),
         "quantity": "1",
         "usagetype": "1",
         "usagedate": base.today_display(),
         "comments": "test"
     }
     post = utils.PostedData(data, "en")
     stock.deduct_stocklevel_from_form(base.get_dbo(), "test", post)
示例#23
0
文件: test_clinic.py 项目: tgage/asm3
 def test_insert_payment_from_appointment(self):
     data = {
         "due":      "01/01/2018",
         "received": "",
         "paymenttype": "1",
         "paymentmethod": "1"
     }
     post = utils.PostedData(data, "en")
     pid = clinic.insert_payment_from_appointment(base.get_dbo(), "test", self.anid, post)
     financial.delete_donation(base.get_dbo(), "test", pid)
示例#24
0
 def setUp(self):
     data = {
         "title": "Mr",
         "forenames": "Test",
         "surname": "Testing",
         "ownertype": "1",
         "address": "123 test street"
     }
     post = utils.PostedData(data, "en")
     self.nid = person.insert_person_from_form(base.get_dbo(), post, "test")
示例#25
0
 def test_investigation_crud(self):
     data = {
         "personid": str(self.nid),
         "date": base.today_display(),
         "notes": "Test"
     }
     post = utils.PostedData(data, "en")
     iid = person.insert_investigation_from_form(base.get_dbo(), "test", post)
     data["investigationid"] = str(iid)
     person.update_investigation_from_form(base.get_dbo(), "test", post)
     person.delete_investigation(base.get_dbo(), "test", iid)
示例#26
0
文件: test_animal.py 项目: tgage/asm3
 def setUp(self):
     data = {
         "animalname": "Testio",
         "estimatedage": "1",
         "animaltype": "1",
         "entryreason": "1",
         "species": "1"
     }
     post = utils.PostedData(data, "en")
     self.nid, self.code = animal.insert_animal_from_form(
         base.get_dbo(), post, "test")
示例#27
0
文件: test_clinic.py 项目: tgage/asm3
 def test_invoice_crud(self):
     data = {
         "appointmentid": self.anid,
         "description": "bar",
         "amount": "1500"
     }
     post = utils.PostedData(data, "en")
     nid = clinic.insert_invoice_from_form(base.get_dbo(), "test", post)
     data["itemid"] = nid
     clinic.update_invoice_from_form(base.get_dbo(), "test", post)
     clinic.delete_invoice(base.get_dbo(), "test", nid)
示例#28
0
 def setUp(self):
     data = {
         "title": "Test Report",
         "category": "Test",
         "sql": TEST_QUERY,
         "html":
         "$$HEADER HEADER$$ $$BODY <p>$ID</p> BODY$$ $$FOOTER FOOTER$$"
     }
     post = utils.PostedData(data, "en")
     self.nid = reports.insert_report_from_form(base.get_dbo(), "test",
                                                post)
示例#29
0
def create_person(dbo, username, collationid):
    """
    Creates a person record from the incoming form data with collationid.
    Also, attaches the form to the person as media.
    The return value is tuple of collationid, personid, personname
    """
    l = dbo.locale
    fields = get_onlineformincoming_detail(dbo, collationid)
    d = {}
    flags = None
    for f in fields:
        if flags is None: flags = f["FLAGS"]
        if f["FIELDNAME"] == "title": d["title"] = f["VALUE"]
        if f["FIELDNAME"] == "forenames": d["forenames"] = f["VALUE"]
        if f["FIELDNAME"] == "firstname": d["forenames"] = f["VALUE"]
        if f["FIELDNAME"] == "surname": d["surname"] = f["VALUE"]
        if f["FIELDNAME"] == "lastname": d["surname"] = f["VALUE"]
        if f["FIELDNAME"] == "address": d["address"] = f["VALUE"]
        if f["FIELDNAME"] == "town": d["town"] = f["VALUE"]
        if f["FIELDNAME"] == "city": d["town"] = f["VALUE"]
        if f["FIELDNAME"] == "county": d["county"] = f["VALUE"]
        if f["FIELDNAME"] == "state": d["county"] = f["VALUE"]
        if f["FIELDNAME"] == "postcode": d["postcode"] = f["VALUE"]
        if f["FIELDNAME"] == "zipcode": d["postcode"] = f["VALUE"]
        if f["FIELDNAME"] == "hometelephone": d["hometelephone"] = f["VALUE"]
        if f["FIELDNAME"] == "worktelephone": d["worktelephone"] = f["VALUE"]
        if f["FIELDNAME"] == "mobiletelephone": d["mobiletelephone"] = f["VALUE"]
        if f["FIELDNAME"] == "celltelephone": d["mobiletelephone"] = f["VALUE"]
        if f["FIELDNAME"] == "emailaddress": d["emailaddress"] = f["VALUE"]
        if f["FIELDNAME"].startswith("reserveanimalname"): d[f["FIELDNAME"]] = f["VALUE"]
    d["flags"] = flags
    # Have we got enough info to create the person record? We just need a surname
    if not d.has_key("surname"):
        raise utils.ASMValidationError(i18n._("There is not enough information in the form to create a person record (need a surname).", l))
    # Does this person already exist?
    personid = 0
    if d.has_key("surname") and d.has_key("forenames") and d.has_key("address"):
        similar = person.get_person_similar(dbo, d["surname"], d["forenames"], d["address"])
        if len(similar) > 0:
            personid = similar[0]["ID"]
    # Create the person record if we didn't find one
    if personid == 0:
        personid = person.insert_person_from_form(dbo, utils.PostedData(d, dbo.locale), username)
    personname = person.get_person_name_code(dbo, personid)
    # Attach the form to the person
    formname = get_onlineformincoming_name(dbo, collationid)
    formhtml = get_onlineformincoming_html_print(dbo, [collationid,])
    media.create_document_media(dbo, username, media.PERSON, personid, formname, formhtml )
    # Was there a reserveanimalname field? If so, create reservation(s) to the person if possible
    for k, v in d.iteritems():
        if k.startswith("reserveanimalname"):
            movement.insert_reserve_for_animal_name(dbo, username, personid, v)
    return (collationid, personid, personname)
示例#30
0
 def setUp(self):
     data = {
         "dateputon": base.today_display(),
         "description": "Test",
         "species": "1",
         "size": "1",
         "owner": "1",
         "urgency": "5"
     }
     post = utils.PostedData(data, "en")
     self.wlid = waitinglist.insert_waitinglist_from_form(
         base.get_dbo(), post, "test")