def validateCountyCouncil(data):
    url = "{}/county_council/{}".format(
        app.config['CASEWORK_API_URL'],
        data['loc_auth_area']
    )
    resp = http_get(url)
    if resp.status_code == 404:
        return False

    # Manchester & London have special rules, but the table based check above will cover those
    if re.match(".*(MANCHESTER|LONDON).*", data['loc_auth'], re.IGNORECASE) is not None:
        return True

    # Not London or Manchester
    word_match = re.match(".*(COUNTY COUNCIL|COUNCIL OF THE COUNTY OF|ADMINISTRATIVE|CYNGOR).*", data['loc_auth'], re.IGNORECASE)
    if word_match is None:
        return False

    return True
def register_bankruptcy(key_number):

    url = app.config['CASEWORK_API_URL'] + '/keyholders/' + key_number
    response = http_get(
        url, headers={'X-Transaction-ID': session['transaction_id']})
    text = json.loads(response.text)
    if response.status_code == 200:
        cust_address = ', '.join(text['address']['address_lines']
                                 ) + ', ' + text['address']['postcode']
        address_type = "RM"
        if ("dx_number" in text) and ("dx_exchange" in text):
            if text["dx_number"]:  # switch to dx address if available
                if text["dx_exchange"]:
                    dx_no = str(text["dx_number"]).upper()
                    if not dx_no.startswith("DX"):
                        dx_no = "DX " + dx_no
                    cust_address = dx_no + ', ' + text["dx_exchange"]
                    address_type = "DX"
        cust_name = text['name']
        applicant = {
            'name': cust_name,
            'address': cust_address.upper(),
            'key_number': key_number,
            'reference': ' ',
            'address_type': address_type
        }
    else:
        return response

    if session['application_type'] == 'bank_amend':
        class_of_charge = session['original_regns']['class_of_charge']
    elif session['application_dict']['form'] == 'PA(B)':
        class_of_charge = 'PAB'
    elif session['application_dict']['form'] == 'WO(B)':
        class_of_charge = 'WOB'
    else:
        class_of_charge = session['application_dict']['form']

    registration = {
        'parties': session['parties'],
        'class_of_charge': class_of_charge,
        'applicant': applicant
    }

    application = {
        'registration': registration,
        'application_data': session['application_dict']['application_data'],
        'form': session['application_dict']['form']
    }

    if session['application_type'] == 'bank_amend':
        # TODO: update registration added twice to get around bad structure for rectifications which needs changing!
        application['update_registration'] = {'type': 'Amendment'}
        application['registration']['update_registration'] = {
            'type': 'Amendment'
        }
        if 'wob_entered' in session:
            application['wob_original'] = session['wob_entered']
        if 'pab_entered' in session:
            application['pab_original'] = session['pab_entered']
        url = app.config['CASEWORK_API_URL'] + '/applications/' + session[
            'worklist_id'] + '?action=amend'
    else:
        url = app.config['CASEWORK_API_URL'] + '/applications/' + session[
            'worklist_id'] + '?action=complete'

    headers = get_headers({'Content-Type': 'application/json'})
    logging.debug("bankruptcy details: " + json.dumps(application))
    response = http_put(url, data=json.dumps(application), headers=headers)
    if response.status_code == 200:
        logging.info(
            format_message("Registration (bank) submitted to CASEWORK_API"))
        data = response.json()
        reg_list = []

        for item in data['new_registrations']:
            reg_list.append(item['number'])
        session['confirmation'] = {'reg_no': reg_list}

    return response
Пример #3
0
def register_bankruptcy(key_number):

    url = app.config["CASEWORK_API_URL"] + "/keyholders/" + key_number
    response = http_get(url, headers={"X-Transaction-ID": session["transaction_id"]})
    text = json.loads(response.text)
    if response.status_code == 200:
        cust_address = ", ".join(text["address"]["address_lines"]) + ", " + text["address"]["postcode"]
        address_type = "RM"
        if ("dx_number" in text) and ("dx_exchange" in text):
            if text["dx_number"]:  # switch to dx address if available
                if text["dx_exchange"]:
                    dx_no = str(text["dx_number"]).upper()
                    if not dx_no.startswith("DX"):
                        dx_no = "DX " + dx_no
                    cust_address = dx_no + ", " + text["dx_exchange"]
                    address_type = "DX"
        cust_name = text["name"]
        applicant = {
            "name": cust_name,
            "address": cust_address.upper(),
            "key_number": key_number,
            "reference": " ",
            "address_type": address_type,
        }
    else:
        return response

    if session["application_type"] == "bank_amend":
        class_of_charge = session["original_regns"]["class_of_charge"]
    elif session["application_dict"]["form"] == "PA(B)":
        class_of_charge = "PAB"
    elif session["application_dict"]["form"] == "WO(B)":
        class_of_charge = "WOB"
    else:
        class_of_charge = session["application_dict"]["form"]

    registration = {"parties": session["parties"], "class_of_charge": class_of_charge, "applicant": applicant}

    application = {
        "registration": registration,
        "application_data": session["application_dict"]["application_data"],
        "form": session["application_dict"]["form"],
    }

    if session["application_type"] == "bank_amend":
        # TODO: update registration added twice to get around bad structure for rectifications which needs changing!
        application["update_registration"] = {"type": "Amendment"}
        application["registration"]["update_registration"] = {"type": "Amendment"}
        if "wob_entered" in session:
            application["wob_original"] = session["wob_entered"]
        if "pab_entered" in session:
            application["pab_original"] = session["pab_entered"]
        url = app.config["CASEWORK_API_URL"] + "/applications/" + session["worklist_id"] + "?action=amend"
    else:
        url = app.config["CASEWORK_API_URL"] + "/applications/" + session["worklist_id"] + "?action=complete"

    headers = get_headers({"Content-Type": "application/json"})
    logging.debug("bankruptcy details: " + json.dumps(application))
    response = http_put(url, data=json.dumps(application), headers=headers)
    if response.status_code == 200:
        logging.info(format_message("Registration (bank) submitted to CASEWORK_API"))
        data = response.json()
        reg_list = []

        for item in data["new_registrations"]:
            reg_list.append(item["number"])
        session["confirmation"] = {"reg_no": reg_list}

    return response