예제 #1
0
def orders(request, **kwargs):
    message = ''
    
    if request.method == 'POST':
        barcode = request.POST.get('barcode')
        if barcode:
            try:
                inventory = Inventory.objects.get(barcode=barcode, status=InventoryStatus.InStock, buy_only=True)
                order_item = BuyOrderItem.objects.filter(status=BuyOrderItemStatus.Pending, 
                                                         source_dc=inventory.dropship,
                                                         is_new=inventory.is_new,
                                                         item=inventory.item).order_by('order__create_date')
                if order_item.count():
                    order_item = order_item[0]
                    slip_item = PackSlip.prepare_order_item(order_item)
                    slip_item.order_item.inventory = inventory
                    slip_item.order_item.status = BuyOrderItemStatus.Prepared 
                    slip_item.order_item.date_prepared = datetime.now()
                    slip_item.order_item.save()
                    inventory.status = InventoryStatus.Pending
                    inventory.save()
                    message = 'Barcode "<strong>%s</strong>" was successfully added to the Prepared List.' % barcode
                else:
                    message = 'Barcode "<strong>%s</strong>" does not match any item in Picked List.' % barcode
            except Inventory.DoesNotExist, e: #@UnusedVariable
                message = 'Barcode "<strong>%s</strong>" does not exist or it does not in stock.' % barcode
예제 #2
0
    def import_buy_orders(self, user_id):
        ocursor = self.mconn.cursor()
        icursor = self.mconn.cursor()
        ocursor.execute("select * from shop_orders where ref_user=%s order by id", [user_id,])
        order_field_names = map(lambda x: x[0], ocursor.description)
        for ro in ocursor.fetchall():
            o = dict(zip(order_field_names, ro))
            
            data = {}
            update_dict(data, self.fix_name({
                'first_name': o['first_name'],
                'last_name': o['last_name'],
            }))
            update_dict(data, self.fix_address({
                'address1': o['address'], 
                'address2': o['address2'], 
                'city': o['city'], 
                'state': self.STATES[o['ref_state']], 
                #'country': 'USA', 
                'zip_code': o['postal_code'], 
            }), 'shipping')
            update_dict(data, self.fix_name({
                'first_name': o['billing_first_name'],
                'last_name': o['billing_last_name'],
            }), 'billing')
            update_dict(data, self.fix_address({
                'address1': o['billing_address'], 
                'address2': o['billing_address2'], 
                'city': o['billing_city'], 
                'state': self.STATES[o['billing_ref_state']], 
                #'country': 'USA', 
                'zip_code': o['billing_postal_code'], 
            }), 'billing')
            
            status = self.BUY_STATUS_MAP[o['ref_order_status']]
            if status == 6: #shipped
                if o['ref_shipping_status'] == 4: # cancelled
                    status = 4 # Canceled 
            
            bo = BuyOrder(
                id = o['id'], 
                user_id = user_id,
                status = status,
                create_date = o['order_date'],

                tax = decimal.Decimal('%.02f' % o['tax_fee']),
                total = decimal.Decimal('%.02f' % o['total']),
                
                **data
            )
            bo.save()
            
            icursor = self.mconn.cursor()
            icursor.execute("select i.price, i.count, r.upc, r.id from shop_order_items i left join items r on i.ref_item=r.id where i.ref_order=%s order by i.id", o['id'])
            for i_price, i_count, i_upc, r_id in icursor.fetchall():
                item = self.get_item(i_upc)
                if not item: 
                    self.missing_items.add(r_id)
                    continue
                status = BuyOrderItemStatus.Shipped if bo.status == BuyOrderStatus.Shipped else BuyOrderItemStatus.Canceled  
                for _qty in xrange(i_count): 
                    boi = BuyOrderItem(
                        order = bo,
                        status = status,
                        item = item,
                        price = decimal.Decimal(str(i_price))
                        )
                    boi.save()
                    
            if bo.status == BuyOrderStatus.Shipped:
                
                icursor = self.mconn.cursor()
                image_filename, tracking_code = None, None
                icursor.execute("SELECT image_filename, tracking_code FROM endicia_labels e where ref_shop_order = %s", o['id'])
                for image_filename, tracking_code in icursor.fetchall():
                    break
                                
                if image_filename:
                    image_filename = 'media/labels/old/endicia/' + image_filename 
                                
                pack_slip = PackSlip(
                    order = bo,
                    created = bo.create_date,
                    mail_label = image_filename,
                    tracking_number = tracking_code,
                    date_shipped = bo.create_date,
                )
                pack_slip.save()
                for order_item in bo.items.all():
                    PackSlipItem(
                        slip = pack_slip,
                        order_item = order_item,
                        added = bo.create_date,
                    ).save()