def merge_s_d(dict_line_item, string):
    result_s_d = function_regex.re_find_all_s_d(string)
    print('Found possible SKU and Description:', len(result_s_d))
    for raw_sku, raw_description in result_s_d:
        if function_cleaner.is_description_valid(raw_description):
            cleaned_sku = raw_sku.strip()
            aLineItem = class_general.LineItem()
            aLineItem.merge_s_d(raw_sku, raw_description)
            dict_line_item[cleaned_sku] = aLineItem
    return dict_line_item
Ejemplo n.º 2
0
def parse_single_json_string(string):
    list_line_item = []

    regex_sku = function_regex.re_parse_sku(string)
    regex_description = function_regex.re_parse_description(string)
    regex_line_total_and_tax_code = function_regex.re_parse_line_total_and_tax_type(
        string)
    regex_container_deposit = function_regex.re_parse_container_deposit(string)
    regex_quantity_unit_price = function_regex.re_parse_quantity_unit_price(
        string)

    print('\t {:<30} found: {:<2}: {}'.format('SKU', len(regex_sku),
                                              regex_sku))
    print('\t {:<30} found: {:<2}: {}'.format('Description',
                                              len(regex_description),
                                              regex_description))
    print('\t {:<30} found: {:<2}: {}'.format(
        'Line Total & Tax Code', len(regex_line_total_and_tax_code),
        regex_line_total_and_tax_code))
    print('\t {:<30} found: {:<2}: {}'.format('Container Deposit',
                                              len(regex_container_deposit),
                                              regex_container_deposit))
    print('\t {:<30} found: {:<2}: {}'.format('Quantity & Unit Price',
                                              len(regex_quantity_unit_price),
                                              regex_quantity_unit_price))

    for sku, description, line_total_and_tax_code, container_deposit, (unit, price) in \
            zip(regex_sku, regex_description, regex_line_total_and_tax_code, regex_container_deposit, regex_quantity_unit_price):

        line_item = class_general.LineItem()

        line_item.sku = sku
        line_item.description = description

        line_item.line_total = line_total_and_tax_code[0]
        line_item.tax_code = line_total_and_tax_code[1]

        line_item.container_deposit = container_deposit

        line_item.quantity = unit if unit is not None else None
        line_item.unit_price = price if price is not None else None

        list_line_item.append(line_item)

    # testing/debug
    # for i in list_line_item:
    #     print(i.get_dict())

    # compile to recepit
    aReceipt = class_general.Receipt(bill_from=class_general.BillFrom(),
                                     bill_to=class_general.BillTo(),
                                     bill=class_general.Bill(),
                                     line_items=list_line_item)
    return aReceipt
def merge_s_d_cd(dict_line_item, string):
    result_s_d_cd = function_regex.re_find_all_s_d_cd(string)
    print('Found possible Container Deposit:', len(result_s_d_cd))

    for raw_sku, raw_description, container_deposit in result_s_d_cd:
        if function_cleaner.is_description_valid(raw_description):
            cleaned_sku = raw_sku.strip()

            if cleaned_sku in dict_line_item:
                dict_line_item[cleaned_sku].merge_s_d_cd(
                    raw_sku, raw_description, container_deposit)
            else:
                aLineItem = class_general.LineItem()
                aLineItem.merge_s_d_cd(raw_sku, raw_description,
                                       container_deposit)
                dict_line_item[cleaned_sku] = aLineItem
    return dict_line_item
def merge_s_d_lt_tc(dict_line_item, string):
    result_s_d_lt_tc = function_regex.re_find_all_s_d_lt_tc(string)
    print('Found possible Line Total and Tax Code:', len(result_s_d_lt_tc))

    for raw_sku, raw_description, line_total, tax_code in result_s_d_lt_tc:
        if function_cleaner.is_description_valid(raw_description):
            cleaned_sku = raw_sku.strip()

            if cleaned_sku in dict_line_item:
                dict_line_item[cleaned_sku].merge_s_d_lt_tc(
                    raw_sku, raw_description, line_total, tax_code)
            else:
                aLineItem = class_general.LineItem()
                aLineItem.merge_s_d_lt_tc(raw_sku, raw_description, line_total,
                                          tax_code)
                dict_line_item[cleaned_sku] = aLineItem
    return dict_line_item
def merge_s_d_q_up(dict_line_item, string):
    result_s_d_q_up = function_regex.re_find_all_s_d_q_up(string)
    print('Found possible Quantity and Unit Price:', len(result_s_d_q_up))

    for raw_sku, raw_description, raw_quantity_and_unit_price in result_s_d_q_up:
        if function_cleaner.is_description_valid(raw_description):
            cleaned_sku = raw_sku.strip()
            quantity, unit_price = function_cleaner.clean_quantity_and_unit_price(
                raw_quantity_and_unit_price)

            if cleaned_sku in dict_line_item:
                dict_line_item[cleaned_sku].merge_s_d_q_up(
                    raw_sku, raw_description, quantity, unit_price)
            else:
                aLineItem = class_general.LineItem()
                aLineItem.merge_s_d_q_up(raw_sku, raw_description, quantity,
                                         unit_price)
                dict_line_item[cleaned_sku] = aLineItem
    return dict_line_item