def submit_lc_cancellation(data):
    cust_address = data['customer_address'].replace("\r\n", ", ").strip()
    application = {
        'update_registration': {
            'type': 'Cancellation'
        },
        'applicant': {
            'key_number': data['key_number'],
            'name': data['customer_name'],
            'address': cust_address,
            'address_type': data['address_type'],
            'reference': data['customer_ref']
        },
        'registration_no': session['regn_no'],
        'document_id': session['document_id'],
        'registration': {
            'date': session['reg_date']
        },
        'fee_details': {
            'type': data['payment'],
            'fee_factor': 1,
            'delivery': session['application_dict']['delivery_method']
        }
    }
    if "class_of_charge" in session:
        application["class_of_charge"] = session["class_of_charge"]
    # if plan attached selected then pass the part_cans_text into that field
    if 'cancellation_type' in session:
        application['update_registration'] = {
            'type': session['cancellation_type']
        }
        if 'plan_attached' in session:
            if session['plan_attached'] == 'true':
                application['update_registration']['plan_attached'] = session[
                    'part_cans_text']
        elif 'part_cans_text' in session:
            application['update_registration']['part_cancelled'] = session[
                'part_cans_text']
    url = app.config['CASEWORK_API_URL'] + '/applications/' + session[
        'worklist_id'] + '?action=cancel'
    headers = get_headers({'Content-Type': 'application/json'})
    response = requests.put(url, data=json.dumps(application), headers=headers)
    if response.status_code == 200:
        logging.info(format_message("Cancellation submitted to CASEWORK_API"))
        data = response.json()
        if 'cancellations' in data:
            reg_list = []
            for item in data['cancellations']:
                reg_list.append(item['number'])
            session['confirmation'] = {'reg_no': reg_list}
        else:
            session['confirmation'] = {'reg_no': []}

    return response
def register_correction():

    logging.info(session['original_regns']['applicant'])

    applicant = {
        'name': session['original_regns']['applicant']['name'],
        'address': session['original_regns']['applicant']['address'],
        'key_number': session['original_regns']['applicant']['key_number'],
        'reference': session['original_regns']['applicant']['reference'],
        'address_type': session['original_regns']['applicant']['address_type'],
    }

    registration = {
        'parties': session['parties'],
        'class_of_charge': session['original_regns']['class_of_charge'],
        'applicant': applicant,
        'update_registration': {
            'type': 'Correction'
        }
    }

    application = {
        'registration': registration,
        'orig_regn': session['details_entered'],
        'update_registration': {
            'type': 'Correction'
        }
    }

    if request.form['generate_K22'] == 'yes':
        application['k22'] = True
    else:
        application['k22'] = False

    url = app.config[
        'CASEWORK_API_URL'] + '/applications/0' + '?action=correction'

    headers = get_headers({'Content-Type': 'application/json'})
    headers['X-Transaction-ID'] = session['transaction_id']
    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
def submit_lc_rectification(form):
    rect_details = (session['rectification_details'])
    if 'instrument' in rect_details['update_registration']:
        orig_date = rect_details['update_registration']['instrument']['original']
        orig_date = datetime.strptime(orig_date, "%d/%m/%Y").strftime("%Y-%m-%d")
        cur_date = rect_details['update_registration']['instrument']['current']
        cur_date = datetime.strptime(cur_date, "%d/%m/%Y").strftime("%Y-%m-%d")
        rect_details['update_registration']['instrument']['original'] = orig_date
        rect_details['update_registration']['instrument']['current'] = cur_date
    cust_address = form['customer_address'].replace("\r\n", ", ").strip()
    application = {'update_registration': {'type': 'Rectification'},
                   'applicant': {
                       'key_number': form['key_number'],
                       'name': form['customer_name'],
                       'address': cust_address,
                       'address_type': form['address_type'],
                       'reference': form['customer_ref']},
                   'parties': [get_party_name(rect_details)],
                   'particulars': {'counties': rect_details['county'], 'district': rect_details['district'],
                                   'description': rect_details['short_description']},
                   'class_of_charge': convert_class_of_charge(rect_details['class']),
                   'regn_no': session['regn_no'],
                   'registration': {'date': session['reg_date']},
                   'document_id': session['document_id'],
                   'additional_information': rect_details['additional_info'],
                   'fee_details': {'type': form['payment'],
                                   'fee_factor': 1,
                                   'delivery': session['application_dict']['delivery_method']}
                   }
    if "update_registration" in rect_details:
        application["update_registration"] = rect_details["update_registration"]
    url = app.config['CASEWORK_API_URL'] + '/applications/' + session['worklist_id'] + '?action=rectify'
    headers = get_headers({'Content-Type': 'application/json'})
    response = http_put(url, data=json.dumps(application), headers=headers)
    if response.status_code == 200:
        logging.info(format_message("Rectification submitted to CASEWORK_API"))
        data = response.json()

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

    return Response(status=200)
Exemplo n.º 4
0
def register_correction():

    logging.info(session["original_regns"]["applicant"])

    applicant = {
        "name": session["original_regns"]["applicant"]["name"],
        "address": session["original_regns"]["applicant"]["address"],
        "key_number": session["original_regns"]["applicant"]["key_number"],
        "reference": session["original_regns"]["applicant"]["reference"],
        "address_type": session["original_regns"]["applicant"]["address_type"],
    }

    registration = {
        "parties": session["parties"],
        "class_of_charge": session["original_regns"]["class_of_charge"],
        "applicant": applicant,
        "update_registration": {"type": "Correction"},
    }

    application = {
        "registration": registration,
        "orig_regn": session["details_entered"],
        "update_registration": {"type": "Correction"},
    }

    if request.form["generate_K22"] == "yes":
        application["k22"] = True
    else:
        application["k22"] = False

    url = app.config["CASEWORK_API_URL"] + "/applications/0" + "?action=correction"

    headers = get_headers({"Content-Type": "application/json"})
    headers["X-Transaction-ID"] = session["transaction_id"]
    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
Exemplo n.º 5
0
def submit_lc_registration(cust_fee_data):
    application = session['application_dict']
    application['class_of_charge'] = convert_application_type(session['application_type'])
    application['application_ref'] = cust_fee_data['application_reference']
    application['key_number'] = cust_fee_data['key_number']
    application['customer_name'] = cust_fee_data['customer_name']
    application['customer_address'] = cust_fee_data['customer_address']
    application['address_type'] = cust_fee_data['address_type']
    today = datetime.now().strftime('%Y-%m-%d')
    application['date'] = today
    application['residence_withheld'] = False
    #application['date_of_birth'] = "1980-01-01"  # DONE?: what are we doing about the DOB??
    application['document_id'] = session['document_id']
    application['fee_details'] = {'type': cust_fee_data['payment'],
                                  'fee_factor': 1,
                                  'delivery': session['application_dict']['delivery_method']}

    if session['application_dict']['form'] == 'K6':
        application['priority_notice_ind'] = True
        result_string = 'priority_notices'
    else:
        result_string = 'new_registrations'

    session['register_details']['estate_owner']['estate_owner_ind'] = session['register_details']['estate_owner_ind']
    #     convert_estate_owner_ind(session['register_details']['estate_owner_ind'])
    application['lc_register_details'] = session['register_details']

    url = app.config['CASEWORK_API_URL'] + '/applications/' + session['worklist_id'] + '?action=complete'
    headers = get_headers({'Content-Type': 'application/json'})
    response = http_put(url, data=json.dumps(application), headers=headers)
    if response.status_code == 200:
        logging.info(format_message("Registration submitted to CASEWORK_API"))
        data = response.json()
        reg_list = []

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

    return response
def submit_lc_cancellation(data):
    cust_address = data['customer_address'].replace("\r\n", ", ").strip()
    application = {'update_registration': {'type': 'Cancellation'},
                   'applicant': {
                       'key_number': data['key_number'],
                       'name': data['customer_name'],
                       'address': cust_address,
                       'address_type': data['address_type'],
                       'reference': data['customer_ref']},
                   'registration_no': session['regn_no'],
                   'document_id': session['document_id'],
                   'registration': {'date': session['reg_date']},
                   'fee_details': {'type': data['payment'],
                                   'fee_factor': 1,
                                   'delivery': session['application_dict']['delivery_method']}}
    if "class_of_charge" in session:
        application["class_of_charge"] = session["class_of_charge"]
    # if plan attached selected then pass the part_cans_text into that field
    if 'cancellation_type' in session:
        application['update_registration'] = {'type': session['cancellation_type']}
        if 'plan_attached' in session:
            if session['plan_attached'] == 'true':
                application['update_registration']['plan_attached'] = session['part_cans_text']
        elif 'part_cans_text' in session:
            application['update_registration']['part_cancelled'] = session['part_cans_text']
    url = app.config['CASEWORK_API_URL'] + '/applications/' + session['worklist_id'] + '?action=cancel'
    headers = get_headers({'Content-Type': 'application/json'})
    response = requests.put(url, data=json.dumps(application), headers=headers)
    if response.status_code == 200:
        logging.info(format_message("Cancellation submitted to CASEWORK_API"))
        data = response.json()
        if 'cancellations' in data:
            reg_list = []
            for item in data['cancellations']:
                reg_list.append(item['number'])
            session['confirmation'] = {'reg_no': reg_list}
        else:
            session['confirmation'] = {'reg_no': []}

    return response
def submit_lc_rectification(form):
    rect_details = (session['rectification_details'])
    if 'instrument' in rect_details['update_registration']:
        orig_date = rect_details['update_registration']['instrument'][
            'original']
        orig_date = datetime.strptime(orig_date,
                                      "%d/%m/%Y").strftime("%Y-%m-%d")
        cur_date = rect_details['update_registration']['instrument']['current']
        cur_date = datetime.strptime(cur_date, "%d/%m/%Y").strftime("%Y-%m-%d")
        rect_details['update_registration']['instrument'][
            'original'] = orig_date
        rect_details['update_registration']['instrument']['current'] = cur_date
    cust_address = form['customer_address'].replace("\r\n", ", ").strip()
    application = {
        'update_registration': {
            'type': 'Rectification'
        },
        'applicant': {
            'key_number': form['key_number'],
            'name': form['customer_name'],
            'address': cust_address,
            'address_type': form['address_type'],
            'reference': form['customer_ref']
        },
        'parties': [get_party_name(rect_details)],
        'particulars': {
            'counties': rect_details['county'],
            'district': rect_details['district'],
            'description': rect_details['short_description']
        },
        'class_of_charge': convert_class_of_charge(rect_details['class']),
        'regn_no': session['regn_no'],
        'registration': {
            'date': session['reg_date']
        },
        'document_id': session['document_id'],
        'additional_information': rect_details['additional_info'],
        'fee_details': {
            'type': form['payment'],
            'fee_factor': 1,
            'delivery': session['application_dict']['delivery_method']
        }
    }
    if "update_registration" in rect_details:
        application["update_registration"] = rect_details[
            "update_registration"]
    url = app.config['CASEWORK_API_URL'] + '/applications/' + session[
        'worklist_id'] + '?action=rectify'
    headers = get_headers({'Content-Type': 'application/json'})
    response = http_put(url, data=json.dumps(application), headers=headers)
    if response.status_code == 200:
        logging.info(format_message("Rectification submitted to CASEWORK_API"))
        data = response.json()

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

    return Response(status=200)
Exemplo n.º 8
0
def process_search_criteria(data, search_type):
    logging.debug("process search data")
    counties = []
    parameters = {
        "counties": counties,
        "search_type": "banks" if search_type == "search_bank" else "full",
        "search_items": [],
    }
    counter = 1

    while True:

        name_type = "nameType_{}".format(counter)
        if name_type not in data:
            break

        name_extracted = False

        if data[name_type] == "privateIndividual" and data["surname_{}".format(counter)] != "":

            forename = "forename_{}".format(counter)
            surname = "surname_{}".format(counter)
            search_item = {
                "name_type": "Private Individual",
                "name": {"forenames": data[forename], "surname": data[surname]},
            }
            name_extracted = True

        elif data[name_type] == "limitedCompany" and data["company_{}".format(counter)] != "":

            company = "company_{}".format(counter)
            search_item = {"name_type": "Limited Company", "name": {"company_name": data[company]}}
            name_extracted = True

        elif (
            data[name_type] == "countyCouncil"
            and data["loc_auth_{}".format(counter)] != ""
            and data["loc_auth_area_{}".format(counter)] != ""
        ):

            loc_auth = "loc_auth_{}".format(counter)
            loc_auth_area = "loc_auth_area_{}".format(counter)
            search_item = {
                "name_type": "County Council",
                "name": {"local_authority_name": data[loc_auth], "local_authority_area": data[loc_auth_area]},
            }
            name_extracted = True

        elif (
            data[name_type] == "ruralCouncil"
            and data["loc_auth_{}".format(counter)] != ""
            and data["loc_auth_area_{}".format(counter)] != ""
        ):

            loc_auth = "loc_auth_{}".format(counter)
            loc_auth_area = "loc_auth_area_{}".format(counter)
            search_item = {
                "name_type": "Rural Council",
                "name": {"local_authority_name": data[loc_auth], "local_authority_area": data[loc_auth_area]},
            }
            name_extracted = True

        elif (
            data[name_type] == "parishCouncil"
            and data["loc_auth_{}".format(counter)] != ""
            and data["loc_auth_area_{}".format(counter)] != ""
        ):

            loc_auth = "loc_auth_{}".format(counter)
            loc_auth_area = "loc_auth_area_{}".format(counter)
            search_item = {
                "name_type": "Parish Council",
                "name": {"local_authority_name": data[loc_auth], "local_authority_area": data[loc_auth_area]},
            }
            name_extracted = True

        elif (
            data[name_type] == "otherCouncil"
            and data["loc_auth_{}".format(counter)] != ""
            and data["loc_auth_area_{}".format(counter)] != ""
        ):

            loc_auth = "loc_auth_{}".format(counter)
            loc_auth_area = "loc_auth_area_{}".format(counter)
            search_item = {
                "name_type": "Other Council",
                "name": {"local_authority_name": data[loc_auth], "local_authority_area": data[loc_auth_area]},
            }
            name_extracted = True

        elif data[name_type] == "codedName" and data["other_name_{}".format(counter)] != "":
            other_name = "other_name_{}".format(counter)
            search_item = {"name_type": "Coded Name", "name": {"other_name": data[other_name]}}
            name_extracted = True

        elif (
            data[name_type] == "complexName"
            and data["complex_name_{}".format(counter)] != ""
            and data["complex_number_{}".format(counter)] != ""
        ):

            complex_name = "complex_name_{}".format(counter)
            complex_number = "complex_number_{}".format(counter)
            search_item = {
                "name_type": "Complex Name",
                "name": {
                    "complex_name": data[complex_name],
                    "complex_number": int(data[complex_number]),
                    "complex_variations": [],
                },
            }
            url = app.config["CASEWORK_API_URL"] + "/complex_names/search"
            headers = get_headers({"Content-Type": "application/json"})
            comp_name = {"name": data[complex_name], "number": int(data[complex_number])}
            response = http_post(url, data=json.dumps(comp_name), headers=headers)
            logging.info(format_message("POST {} -- {}".format(url, response)))
            result = response.json()

            for item in result:
                search_item["name"]["complex_variations"].append({"name": item["name"], "number": int(item["number"])})
            name_extracted = True

        elif data[name_type] == "developmentCorporation" and data["other_name_{}".format(counter)] != "":
            # name_type is other
            other_name = "other_name_{}".format(counter)
            search_item = {"name_type": "Development Corporation", "name": {"other_name": data[other_name]}}
            name_extracted = True

        elif data[name_type] == "other" and data["other_name_{}".format(counter)] != "":
            # name_type is other
            other_name = "other_name_{}".format(counter)
            search_item = {"name_type": "Other", "name": {"other_name": data[other_name]}}
            name_extracted = True

        if search_type == "search_full" and name_extracted:
            logging.debug("Getting year stuff")
            search_item["year_to"] = int(data["year_to_{}".format(counter)])
            search_item["year_from"] = int(data["year_from_{}".format(counter)])

        if name_extracted:
            parameters["search_items"].append(search_item)

        counter += 1

    result = {}
    if search_type == "search_full":
        if "all_counties" in data and data["all_counties"] == "yes":
            result["county"] = ["ALL"]
        else:
            add_counties(result, data)
    else:
        result["county"] = []

    parameters["counties"] = result["county"]
    session["application_dict"]["search_criteria"] = parameters
    return
def process_search_criteria(data, search_type):
    logging.debug('process search data')
    counties = []
    parameters = {
        'counties': counties,
        'search_type': "banks" if search_type == 'search_bank' else 'full',
        'search_items': []
    }
    counter = 1

    while True:

        name_type = 'nameType_{}'.format(counter)
        if name_type not in data:
            break

        name_extracted = False

        if data[name_type] == 'privateIndividual' \
                and data['surname_{}'.format(counter)] != '':

            forename = 'forename_{}'.format(counter)
            surname = 'surname_{}'.format(counter)
            search_item = {
                'name_type': 'Private Individual',
                'name': {
                    'forenames': data[forename],
                    'surname': data[surname]
                }
            }
            name_extracted = True

        elif data[name_type] == 'limitedCompany' \
                and data['company_{}'.format(counter)] != '':

            company = 'company_{}'.format(counter)
            search_item = {
                'name_type': 'Limited Company',
                'name': {
                    'company_name': data[company]
                }
            }
            name_extracted = True

        elif data[name_type] == 'countyCouncil' \
                and data['loc_auth_{}'.format(counter)] != '' \
                and data['loc_auth_area_{}'.format(counter)] != '':

            loc_auth = 'loc_auth_{}'.format(counter)
            loc_auth_area = 'loc_auth_area_{}'.format(counter)
            search_item = {
                'name_type': 'County Council',
                'name': {
                    'local_authority_name': data[loc_auth],
                    'local_authority_area': data[loc_auth_area]
                }
            }
            name_extracted = True

        elif data[name_type] == 'ruralCouncil' \
                and data['loc_auth_{}'.format(counter)] != '' \
                and data['loc_auth_area_{}'.format(counter)] != '':

            loc_auth = 'loc_auth_{}'.format(counter)
            loc_auth_area = 'loc_auth_area_{}'.format(counter)
            search_item = {
                'name_type': 'Rural Council',
                'name': {
                    'local_authority_name': data[loc_auth],
                    'local_authority_area': data[loc_auth_area]
                }
            }
            name_extracted = True

        elif data[name_type] == 'parishCouncil' \
                and data['loc_auth_{}'.format(counter)] != '' \
                and data['loc_auth_area_{}'.format(counter)] != '':

            loc_auth = 'loc_auth_{}'.format(counter)
            loc_auth_area = 'loc_auth_area_{}'.format(counter)
            search_item = {
                'name_type': 'Parish Council',
                'name': {
                    'local_authority_name': data[loc_auth],
                    'local_authority_area': data[loc_auth_area]
                }
            }
            name_extracted = True

        elif data[name_type] == 'otherCouncil' \
                and data['loc_auth_{}'.format(counter)] != '' \
                and data['loc_auth_area_{}'.format(counter)] != '':

            loc_auth = 'loc_auth_{}'.format(counter)
            loc_auth_area = 'loc_auth_area_{}'.format(counter)
            search_item = {
                'name_type': 'Other Council',
                'name': {
                    'local_authority_name': data[loc_auth],
                    'local_authority_area': data[loc_auth_area]
                }
            }
            name_extracted = True

        elif data[name_type] == 'codedName' and data['other_name_{}'.format(
                counter)] != '':
            other_name = 'other_name_{}'.format(counter)
            search_item = {
                'name_type': 'Coded Name',
                'name': {
                    'other_name': data[other_name]
                }
            }
            name_extracted = True

        elif data[name_type] == 'complexName' \
                and data['complex_name_{}'.format(counter)] != '' \
                and data['complex_number_{}'.format(counter)] != '':

            complex_name = 'complex_name_{}'.format(counter)
            complex_number = 'complex_number_{}'.format(counter)
            search_item = {
                'name_type': 'Complex Name',
                'name': {
                    'complex_name': data[complex_name],
                    'complex_number': int(data[complex_number]),
                    'complex_variations': []
                }
            }
            url = app.config['CASEWORK_API_URL'] + '/complex_names/search'
            headers = get_headers({'Content-Type': 'application/json'})
            comp_name = {
                'name': data[complex_name],
                'number': int(data[complex_number])
            }
            response = http_post(url,
                                 data=json.dumps(comp_name),
                                 headers=headers)
            logging.info(format_message('POST {} -- {}'.format(url, response)))
            result = response.json()

            for item in result:
                search_item['name']['complex_variations'].append({
                    'name':
                    item['name'],
                    'number':
                    int(item['number'])
                })
            name_extracted = True

        elif data[name_type] == 'developmentCorporation' and data[
                'other_name_{}'.format(counter)] != '':
            # name_type is other
            other_name = 'other_name_{}'.format(counter)
            search_item = {
                'name_type': 'Development Corporation',
                'name': {
                    'other_name': data[other_name]
                }
            }
            name_extracted = True

        elif data[name_type] == 'other' and data['other_name_{}'.format(
                counter)] != '':
            # name_type is other
            other_name = 'other_name_{}'.format(counter)
            search_item = {
                'name_type': 'Other',
                'name': {
                    'other_name': data[other_name]
                }
            }
            name_extracted = True

        if search_type == 'search_full' and name_extracted:
            logging.debug('Getting year stuff')
            search_item['year_to'] = int(data['year_to_{}'.format(counter)])
            search_item['year_from'] = int(
                data['year_from_{}'.format(counter)])

        if name_extracted:
            parameters['search_items'].append(search_item)

        counter += 1

    result = {}
    if search_type == 'search_full':
        if 'all_counties' in data and data['all_counties'] == 'yes':
            result['county'] = ['ALL']
        else:
            add_counties(result, data)
    else:
        result['county'] = []

    parameters['counties'] = result['county']
    session['application_dict']['search_criteria'] = parameters
    return
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
Exemplo n.º 11
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