Esempio n. 1
0
def create_backorder(order_id):
    # check that it has not been requested already
    unfulfilled_items = fulfill_api.unfulfilled(str(order_id), {})['unfulfilled_items']
    inv_items = dict((i['label'], i['id']) for i in products_api.inventoryitem({}))
    order = sales_api.sale(order_id, {})
    
    if unfulfilled_items is None:
        return 'FULFILL_ALREADY_REQUESTED'
    else:
        # now create a fulfillment request
        today = get_today()

        fulfill_info = {}
        fulfill_info['request_date'] = today
        fulfill_info['order_id'] = str(order_id)
        fulfill_info['status'] = 'back-ordered'
        fulfill_obj = Fulfillment(**fulfill_info)
        fulfill_obj.save()

        for label, quantity in unfulfilled_items.iteritems():
            inv_id = inv_items[label]
            fline_info = {}
            fline_info['inventory_item_id'] = inv_id
            fline_info['quantity'] = quantity
            fline_info['fulfillment_id'] = fulfill_obj.id
            fline_obj = FulfillLine(**fline_info)
            fline_obj.save()

    return 'FULFILL_BACKORDERED'
Esempio n. 2
0
def create_fulfill_request(warehouse, order_id):
    warehouse_labels = [w['label'] for w in inventory_api.warehouse({})]
    unfulfilled_items = fulfill_api.unfulfilled(str(order_id), {})['unfulfilled_items']
    inv_items = dict((i['label'], i['id']) for i in products_api.inventoryitem({}))
    order = sales_api.sale(order_id, {})

    if unfulfilled_items is None:
        return 'FULFILL_ALREADY_REQUESTED'
    elif warehouse not in warehouse_labels:
        return 'WAREHOUSE_NOT_RECOGNISED'
    else:
        # now create a fulfillment request
        today = get_today()
        warehouse = Warehouse.objects.get(label=warehouse)

        fulfill_info = {}
        fulfill_info['request_date'] = today
        fulfill_info['warehouse_id'] = warehouse.id
        fulfill_info['order_id'] = str(order_id)
        fulfill_info['status'] = 'requested'
        fulfill_obj = Fulfillment(**fulfill_info)
        fulfill_obj.save()

        for label, quantity in unfulfilled_items.iteritems():
            inv_id = inv_items[label]
            fline_info = {}
            fline_info['inventory_item_id'] = inv_id
            fline_info['quantity'] = quantity
            fline_info['fulfillment_id'] = fulfill_obj.id
            fline_obj = FulfillLine(**fline_info)
            fline_obj.save()

        return 'FULFILL_REQUESTED'
Esempio n. 3
0
def MICH_pick_list(request, data, label='MICH_batch'):

    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="%s.csv"' % label
    writer = csv.writer(response)

    sku_names = dict((i['label'], i['description']) for i in products_api.inventoryitem({}))
    flf_data = [{'skus': d['fulfill_lines'], 'ship': flatdict.FlatDict(d)} for d in data]

    for f in flf_data:
        f['ship']['id'] = 'FLF%s' % f['ship']['id']
    
    headers = OrderedDict([('SAVOR ID', 'id'),
                            ('Channel', 'order:channel'),
                            ('Name', 'order:shipping_name'),
                            ('Shipping Company', 'order:shipping_company'),
                            ('Customer Reference', 'order:external_routing_id'),
                            ('Shipping Address1', 'order:shipping_address1'),
                            ('Shipping Address2', 'order:shipping_address2'),
                            ('Shipping City', 'order:shipping_city'),
                            ('Shipping Zip', 'order:shipping_zip'),
                            ('Shipping Province', 'order:shipping_province'),
                            ('Shipping Country', 'order:shipping_country'),
                            ('Shipping Phone', 'order:shipping_phone'),
                            ('Email', 'order:notification_email'),
                            ('Shipping Type', 'ship_type:description'),
                            ('Bill To', 'bill_to'),
                            ('Gift Message', 'order:gift_message'),
                            ('Use PDF?', 'use_pdf'),
                            ('Pack Type', 'packing_type'),
                            ('Ship From Company', 'ship_from:company'),
                            ('Ship From Address1', 'ship_from:address1'),
                            ('Ship From Address2', 'ship_from:address2'),
                            ('Ship From City', 'ship_from:city'),
                            ('Ship From ZIP', 'ship_from:postal_code')
                           ])

    header_row = headers.keys()
    header_row += [u'Item', u'Item Name', u'Quantity']
    writer.writerow(header_row)

    for flf in flf_data:
        row = [flf['ship'].get(headers[col], '') for col in headers]
        label = flf['skus'][0]['inventory_item']
        row += [label, sku_names[label], flf['skus'][0]['quantity']]
        writer.writerow(row)

        # if more than 1 sku..
        for i in range(1, len(flf['skus'])):
            line = [''] * len(headers)
            label = flf['skus'][i]['inventory_item']
            line += [label, sku_names[label], flf['skus'][i]['quantity']]
            writer.writerow(line)

        writer.writerow([unicode('=' * 20).encode('utf-8')] * (len(header_row)))

    return response
Esempio n. 4
0
def NC2_pick_list(request, data, label='MICH_batch'):

    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="%s.csv"' % label
    writer = csv.writer(response)

    def get_ship_data(d):
        fd = flatdict.FlatDict(d)
        fd['notes'] = NC2_NOTES.get(fd['order:channel'], '')
        if fd['ship_type']['label'] == 'FREIGHT':
            fd['ifs_ship_type'] = 'PICK'
        elif fd['ship_type']['label'] == 'IFS_BEST':
            fd['ifs_ship_type'] = 'BEST'
        else:
            fd['ifs_ship_type'] = 'HOLD'
        return fd

    sku_names = dict((i['label'], i['description']) for i in products_api.inventoryitem({}))
    master_sku_names = dict(('MST%s' % k, '%s Master' % v) for k, v in sku_names.iteritems())
    sku_names.update(master_sku_names)

    flf_data = [{'skus': d['fulfill_lines'], 'ship': get_ship_data(d)} for d in data]

    for f in flf_data:
        f['ship']['id'] = 'FLF%s' % f['ship']['id']

    headers = OrderedDict([('SAVOR ID', 'id'),
                           ('Customer Reference', 'order:external_routing_id'),
                           ('Ship Type', 'ifs_ship_type'),
                           ('Gift Message', 'order:gift_message'),
                           ('Email', 'order:notification_email'),
                           ('Shipping Phone', 'order:shipping_phone'),
                           ('Name', 'order:shipping_name'),
                           ('Shipping Company', 'order:shipping_company'),
                           ('Shipping Address1', 'order:shipping_address1'),
                           ('Shipping Address2', 'order:shipping_address2'),
                           ('Shipping City', 'order:shipping_city'),
                           ('Shipping Province', 'order:shipping_province'),
                           ('Shipping Zip', 'order:shipping_zip'),
                           ('Shipping Country', 'order:shipping_country'),
                           ])

    header_row = headers.keys()
    header_row += [u'Item', u'Item Name', u'Quantity']
    writer.writerow(header_row)

    for flf in flf_data:
        opt_skus = optimize_NC2(flf['skus'])
        for i in range(0, len(opt_skus)):
            line = [flf['ship'].get(headers[col], '') for col in headers]
            label = opt_skus[i]['inventory_item']
            line += [label, sku_names[label], opt_skus[i]['quantity']]
            writer.writerow(line)

    return response
Esempio n. 5
0
def sales_counts(qstring):
    all_skus = product_api.inventoryitem({})
    all_sales = UnitSale.objects.all().prefetch_related(Prefetch("sku__skuunit__inventory_item"))

    sales_counts = dict((k["label"], 0) for k in all_skus)

    for u_sale in all_sales:
        u_sale_counts = u_sale.inventory_items()
        for sku in u_sale_counts:
            sales_counts[sku] += u_sale_counts[sku]

    return sales_counts