Пример #1
0
def serializeSubCart(subcartEntry, parameters={}):
    subcart = {}
    subcart["subcartID"] = subcartEntry.id
    subcart["cartID"] = subcartEntry.cart_id

    subcart["pieces"] = subcartEntry.pieces
    subcart["product_count"] = subcartEntry.product_count
    subcart["retail_price"] = subcartEntry.retail_price
    subcart["calculated_price"] = subcartEntry.calculated_price
    subcart["shipping_charge"] = subcartEntry.shipping_charge
    subcart["final_price"] = subcartEntry.final_price

    subcart["created_at"] = subcartEntry.created_at
    subcart["updated_at"] = subcartEntry.updated_at

    subcart["remarks"] = subcartEntry.remarks

    if "seller_details" in parameters and parameters["seller_details"] == 1:
        subcart["seller"] = serialize_seller(subcartEntry.seller, parameters)
    else:
        seller = {}
        seller["sellerID"] = subcartEntry.seller.id
        seller["name"] = subcartEntry.seller.name
        subcart["seller"] = seller

    if "cart_item_details" in parameters and parameters[
            "cart_item_details"] == 1:
        cartItems = filterCartItem(parameters)
        cartItems = cartItems.filter(subcart_id=subcartEntry.id)
        subcart["cart_items"] = parseCartItem(cartItems, parameters)

    return subcart
Пример #2
0
def serializeSellerPayment(SellerPaymentEntry, parameters = {}):
	sellerPayment = {}
	sellerPayment["suborderID"] = SellerPaymentEntry.suborder_id
	sellerPayment["suborder_display_number"] = SellerPaymentEntry.suborder.display_number
	sellerPayment["sellerpaymentID"] = SellerPaymentEntry.id	
	sellerPayment["reference_number"] = SellerPaymentEntry.reference_number
	sellerPayment["payment_time"] = SellerPaymentEntry.payment_time
	sellerPayment["details"] = SellerPaymentEntry.details
	sellerPayment["payment_value"] = '{0:.0f}'.format(float(SellerPaymentEntry.payment_value))
	sellerPayment["created_at"] = SellerPaymentEntry.created_at
	sellerPayment["updated_at"] = SellerPaymentEntry.updated_at

	sellerPayment["seller_payment_status"] = {
		"value": SellerPaymentEntry.payment_status,
		"display_value":SellerPaymentStatus[SellerPaymentEntry.payment_status]["display_value"]
	}

	sellerPayment["seller_payment_method"] = {
		"value": SellerPaymentEntry.payment_method,
		"display_value":SellerPaymentMethod[SellerPaymentEntry.payment_method]["display_value"]
	}

	if "seller_details" in parameters and parameters["seller_details"] == 1:
		sellerPayment["seller"] = serialize_seller(SellerPaymentEntry.suborder.seller, parameters)
	else:
		seller = {}
		seller["sellerID"] = SellerPaymentEntry.suborder.seller.id
		seller["name"] = SellerPaymentEntry.suborder.seller.name
		sellerPayment["seller"] = seller

	if "order_item_details" in parameters and parameters["order_item_details"] == 1:
		orderItemQuerySet = filterOrderItem(parameters)
		orderItemQuerySet = orderItemQuerySet.filter(seller_payment_id = SellerPaymentEntry.id)
		sellerPayment["order_items"] = parseOrderItem(orderItemQuerySet, parameters)

	return sellerPayment
Пример #3
0
def serialize_product(productsItem, parameters = {}):

	product = {}

	product["productID"] = productsItem.id
	product["name"] = productsItem.name
	product["price_per_unit"] = productsItem.price_per_unit
	product["unit"] = productsItem.unit
	product["tax"] = productsItem.tax
	product["min_price_per_unit"] = productsItem.min_price_per_unit
	product["lot_size"] = productsItem.lot_size
	product["price_per_lot"] = productsItem.price_per_lot
	product["verification"] = productsItem.verification
	product["show_online"] = productsItem.show_online
	product["created_at"] = productsItem.created_at
	product["updated_at"] = productsItem.updated_at
	product["slug"] = productsItem.slug
	product["display_name"] = productsItem.display_name
	product["is_catalog"] = productsItem.is_catalog
	product["delete_status"] = productsItem.delete_status
	product["product_score"] = productsItem.product_score
	product["absolute_path"] = productsItem.get_absolute_url()
	product["margin"] = '{0:.1f}'.format((float(productsItem.price_per_unit) - float(productsItem.min_price_per_unit))/float(productsItem.price_per_unit)*100)
	product["url"] = productsItem.category.slug + "-" + str(productsItem.category.id) + "/" + productsItem.slug+ "-" + str(productsItem.id)

	if "seller_details" in parameters and parameters["seller_details"] == 1:
		product["seller"] = serialize_seller(productsItem.seller, parameters)
	else:
		seller = {}
		seller["sellerID"] =productsItem.seller.id
		seller["name"] =productsItem.seller.name
		product["seller"] = seller

	if "category_details" in parameters and parameters["category_details"] == 1 and not "category_product_details" in parameters:
		product["category"] = serialize_categories(productsItem.category, parameters)
	else:
		category = {}
		category["categoryID"] = productsItem.category.id
		category["name"] = productsItem.category.name
		product["category"] = category
	
	if "product_details_details" in parameters and parameters["product_details_details"] == 1 and hasattr(productsItem, 'productdetails'):
		product["details"] = serialize_product_details(productsItem, parameters)
	else:
		product_details = {}
		product_details["seller_catalog_number"] = productsItem.productdetails.seller_catalog_number
		product_details["fabric_gsm"] = productsItem.productdetails.fabric_gsm
		product_details["colours"] = productsItem.productdetails.colours
		product_details["sizes"] = productsItem.productdetails.sizes
		product["details"] = product_details

	if "product_lot_details" in parameters and parameters["product_lot_details"] == 1:
		product["product_lot"] = serialize_product_lots(productsItem, parameters)

	if "product_image_details" in parameters and parameters["product_image_details"] == 1:
		image = {}

		image_numbers = productsItem.get_image_numbers_arr()
	
		image["absolute_path"] = productsItem.get_image_url()

		image["image_numbers"] = image_numbers
		image["image_count"] = len(image_numbers)
		image["image_path"] = productsItem.image_path
		image["image_name"] = productsItem.image_name

		product["image"] = image

	if "isBuyer" in parameters and parameters["isBuyer"] == 1:
		
		response = {}
		buyerProductResponsePtr = filterBuyerProductResponse(parameters)
		buyerProductResponsePtr = buyerProductResponsePtr.filter(product_id = productsItem.id)
		if len(buyerProductResponsePtr) == 0:
			response["response_code"] = 0
		else:
			buyerProductResponsePtr = buyerProductResponsePtr[0]
			response["response_code"] = buyerProductResponsePtr.response_code 

		product["response"] = response

		"""
		cartitem = {}
		cartItemPtr =filterCartItem(parameters)
		cartItemPtr = cartItemPtr.filter(product_id = productsItem.id, status=0)
		if len(cartItemPtr) == 0:
			cartitem["lots"] = 0
		else:
			cartItemPtr = cartItemPtr[0]
			cartitem["lots"] = cartItemPtr.lots

		product["cartitem"] = cartitem
		"""

	if ("isBuyerStore" in parameters and parameters["isBuyerStore"] == 1) or ("isBuyer" in parameters and parameters["isBuyer"] == 1):

		buyerstore = {}

		buyerstore["buyer_store_price"] = None
		buyerstore["buyer_store_margin"] = None

		buyerProductResponsePtr = filterBuyerProductResponse(parameters)
		buyerProductResponsePtr = buyerProductResponsePtr.filter(product_id = productsItem.id)
		flag = 0
		if not len(buyerProductResponsePtr) == 0:
			buyerProductResponsePtr = buyerProductResponsePtr[0]
			if buyerProductResponsePtr.store_margin != None and buyerProductResponsePtr.store_margin != 0:
				margin_factor =  buyerProductResponsePtr.store_margin/100 + 1
				buyerstore["buyer_store_price"] = productsItem.min_price_per_unit*margin_factor
				buyerstore["buyer_store_margin"] = buyerProductResponsePtr.store_margin
				flag = 1

		if flag == 0:
			buyerPtr = Buyer.objects.filter(id=parameters["buyersArr"][0])
			if len(buyerPtr) > 0:
				buyerPtr = buyerPtr[0]
				if buyerPtr.store_global_margin != None and buyerPtr.store_global_margin != 0:
					margin_factor = buyerPtr.store_global_margin/100 + 1
					buyerstore["buyer_store_price"] = productsItem.min_price_per_unit*margin_factor
					buyerstore["buyer_store_margin"] = buyerPtr.store_global_margin

		product["buyerstore"] = buyerstore

		orderitem = {}
		orderItemPtr = OrderItem.objects.filter(product_id = productsItem.id, current_status=11, suborder__order__buyer_id=parameters["buyersArr"][0])
		if len(orderItemPtr) == 0:
			orderitem["pieces"] = 0
		else:
			orderItemPtr = orderItemPtr[0]
			orderitem["pieces"] = orderItemPtr.pieces

		product["orderitem"] = orderitem


	return product
Пример #4
0
def serializeSubOrder(subOrderEntry, parameters={}):
    subOrder = {}
    subOrder["orderID"] = subOrderEntry.order_id
    subOrder["suborderID"] = subOrderEntry.id
    subOrder["product_count"] = subOrderEntry.product_count
    subOrder["pieces"] = subOrderEntry.pieces
    subOrder["retail_price"] = '{0:.0f}'.format(
        float(subOrderEntry.retail_price))
    subOrder["calculated_price"] = '{0:.0f}'.format(
        float(subOrderEntry.calculated_price))
    subOrder["edited_price"] = '{0:.0f}'.format(
        float(subOrderEntry.edited_price))
    subOrder["cod_charge"] = '{0:.0f}'.format(float(subOrderEntry.cod_charge))
    subOrder["shipping_charge"] = '{0:.0f}'.format(
        float(subOrderEntry.shipping_charge))
    subOrder["final_price"] = '{0:.0f}'.format(float(
        subOrderEntry.final_price))
    subOrder["display_number"] = subOrderEntry.display_number
    subOrder["created_at"] = subOrderEntry.created_at
    subOrder["updated_at"] = subOrderEntry.updated_at
    subOrder["merchant_notified_time"] = subOrderEntry.merchant_notified_time
    subOrder["completed_time"] = subOrderEntry.completed_time
    subOrder["closed_time"] = subOrderEntry.closed_time

    subOrder["sub_order_status"] = {
        "value":
        subOrderEntry.suborder_status,
        "display_value":
        SubOrderStatus[subOrderEntry.suborder_status]["display_value"]
    }

    subOrder["sub_order_payment_status"] = {
        "value":
        subOrderEntry.suborder_payment_status,
        "display_value":
        SubOrderPaymentStatus[subOrderEntry.suborder_payment_status]
        ["display_value"]
    }

    subOrder["seller_address"] = serialize_seller_address(
        subOrderEntry.seller_address_history)

    if "seller_details" in parameters and parameters["seller_details"] == 1:
        subOrder["seller"] = serialize_seller(subOrderEntry.seller, parameters)
    else:
        seller = {}
        seller["sellerID"] = subOrderEntry.seller.id
        seller["name"] = subOrderEntry.seller.name
        subOrder["seller"] = seller

    if "buyer_details" in parameters and parameters["buyer_details"] == 1:
        subOrder["buyer"] = serialize_buyer(subOrderEntry.order.buyer,
                                            parameters)
    else:
        buyer = {}
        buyer["buyerID"] = subOrderEntry.order.buyer.id
        buyer["name"] = subOrderEntry.order.buyer.name
        subOrder["buyer"] = buyer

    if "seller_payment_details" in parameters and parameters[
            "seller_payment_details"] == 1:
        sellerPaymentQuerySet = filterSellerPayment(parameters)
        sellerPaymentQuerySet = sellerPaymentQuerySet.filter(
            suborder_id=subOrderEntry.id)
        subOrder["seller_payments"] = parseSellerPayments(
            sellerPaymentQuerySet, parameters)

    if "order_shipment_details" in parameters and parameters[
            "order_shipment_details"] == 1:
        orderShipmentQuerySet = filterOrderShipment(parameters)
        orderShipmentQuerySet = orderShipmentQuerySet.filter(
            suborder_id=subOrderEntry.id)
        subOrder["order_shipments"] = parseOrderShipments(
            orderShipmentQuerySet, parameters)

    if "order_item_details" in parameters and parameters[
            "order_item_details"] == 1:
        orderItemQuerySet = filterOrderItem(parameters)
        orderItemQuerySet = orderItemQuerySet.filter(
            suborder_id=subOrderEntry.id)
        subOrder["order_items"] = parseOrderItem(orderItemQuerySet, parameters)

    return subOrder
Пример #5
0
def serializeOrderShipment(orderShipmentEntry, parameters={}):
    orderShipment = {}
    orderShipment["suborderID"] = orderShipmentEntry.suborder_id
    orderShipment[
        "suborder_display_number"] = orderShipmentEntry.suborder.display_number
    orderShipment["ordershipmentID"] = orderShipmentEntry.id
    orderShipment["pickup_address"] = serialize_seller_address(
        orderShipmentEntry.pickup_address)
    orderShipment["drop_address"] = serialize_buyer_address(
        orderShipmentEntry.drop_address)
    orderShipment["invoice_number"] = orderShipmentEntry.invoice_number
    orderShipment["invoice_date"] = orderShipmentEntry.invoice_date
    orderShipment[
        "logistics_partner"] = orderShipmentEntry.logistics_partner_name
    orderShipment["waybill_number"] = orderShipmentEntry.waybill_number
    orderShipment["packaged_weight"] = orderShipmentEntry.packaged_weight
    orderShipment["packaged_length"] = orderShipmentEntry.packaged_length
    orderShipment["packaged_breadth"] = orderShipmentEntry.packaged_breadth
    orderShipment["packaged_height"] = orderShipmentEntry.packaged_height
    orderShipment["cod_charge"] = '{0:.0f}'.format(
        float(orderShipmentEntry.cod_charge))
    orderShipment["shipping_charge"] = '{0:.0f}'.format(
        float(orderShipmentEntry.shipping_charge))
    orderShipment["pieces"] = orderShipmentEntry.pieces
    orderShipment["product_count"] = orderShipmentEntry.product_count
    orderShipment["remarks"] = orderShipmentEntry.remarks
    orderShipment[
        "tpl_manifested_time"] = orderShipmentEntry.tpl_manifested_time
    orderShipment[
        "tpl_in_transit_time"] = orderShipmentEntry.tpl_in_transit_time
    orderShipment[
        "tpl_stuck_in_transit_time"] = orderShipmentEntry.tpl_stuck_in_transit_time
    orderShipment["delivered_time"] = orderShipmentEntry.delivered_time
    orderShipment[
        "rto_in_transit_time"] = orderShipmentEntry.rto_in_transit_time
    orderShipment["rto_delivered_time"] = orderShipmentEntry.rto_delivered_time
    orderShipment[
        "sent_for_pickup_time"] = orderShipmentEntry.sent_for_pickup_time
    orderShipment["lost_time"] = orderShipmentEntry.lost_time
    orderShipment["tracking_url"] = orderShipmentEntry.tracking_url
    orderShipment["rto_remarks"] = orderShipmentEntry.rto_remarks
    orderShipment["created_at"] = orderShipmentEntry.created_at
    orderShipment["updated_at"] = orderShipmentEntry.updated_at
    orderShipment["manifest_link"] = orderShipmentEntry.manifest_link
    orderShipment["label_link"] = orderShipmentEntry.label_link
    orderShipment["soft_data_csv_link"] = orderShipmentEntry.soft_data_csv_link
    orderShipment[
        "vendor_pickup_csv_link"] = orderShipmentEntry.vendor_pickup_csv_link
    orderShipment["final_price"] = '{0:.0f}'.format(
        float(orderShipmentEntry.final_price))
    orderShipment["amount_to_collect"] = '{0:.0f}'.format(
        float(orderShipmentEntry.final_price) +
        float(orderShipmentEntry.cod_charge) +
        float(orderShipmentEntry.shipping_charge))

    if "buyer_details" in parameters and parameters["buyer_details"] == 1:
        orderShipment["buyer"] = serialize_buyer(
            orderShipmentEntry.suborder.order.buyer, parameters)
    else:
        buyer = {}
        buyer["buyerID"] = orderShipmentEntry.suborder.order.buyer.id
        buyer["name"] = orderShipmentEntry.suborder.order.buyer.name
        orderShipment["buyer"] = buyer

    if "seller_details" in parameters and parameters["seller_details"] == 1:
        orderShipment["seller"] = serialize_seller(
            orderShipmentEntry.suborder.seller, parameters)
    else:
        seller = {}
        seller["sellerID"] = orderShipmentEntry.suborder.seller.id
        seller["name"] = orderShipmentEntry.suborder.seller.name
        orderShipment["seller"] = seller

    if "order_item_details" in parameters and parameters[
            "order_item_details"] == 1:
        orderItemQuerySet = filterOrderItem(parameters)
        orderItemQuerySet = orderItemQuerySet.filter(
            order_shipment_id=orderShipmentEntry.id)
        orderShipment["order_items"] = parseOrderItem(orderItemQuerySet,
                                                      parameters)

    orderShipment["order_shipment_status"] = {
        "value":
        orderShipmentEntry.current_status,
        "display_value":
        OrderShipmentStatus[orderShipmentEntry.current_status]["display_value"]
    }

    try:
        orderShipment["order_shipment_status"]["display_time"] = getattr(
            orderShipmentEntry, OrderShipmentStatus[
                orderShipmentEntry.current_status]["display_time"])
        orderShipment["order_shipment_status"][
            "display_time_name"] = OrderShipmentStatus[
                orderShipmentEntry.current_status]["display_time"]
    except Exception, e:
        pass
Пример #6
0
    def create_label(self):
        subOrderPtr = self.suborder
        buyerPtr = subOrderPtr.order.buyer
        sellerPtr = subOrderPtr.seller
        sellerAddressPtr = subOrderPtr.seller_address_history
        buyerAddressPtr = subOrderPtr.order.buyer_address_history

        outputLink = "media/generateddocs/shipmentlabel/{}/{}/".format(
            sellerPtr.id, subOrderPtr.display_number)
        outputDirectory = settings.STATIC_ROOT + outputLink
        outputFileName = "WholdusLabel-{}-{}.pdf".format(
            self.id, subOrderPtr.display_number)

        barcodeObj = barcode.codex.Code39(code=self.waybill_number,
                                          add_checksum=False)
        barcodeFileName = "barcode-{}-{}".format(self.id,
                                                 subOrderPtr.display_number)
        barcodeOptions = {"module_width": 0.36, "font_size": 12}
        if not os.path.exists(outputDirectory):
            os.makedirs(outputDirectory)
        barcodeFullPath = barcodeObj.save(outputDirectory + barcodeFileName,
                                          barcodeOptions)

        self.label_link = outputLink + outputFileName
        self.save()

        manifest_dict = {}

        from orders.serializers.subOrder import serializeSubOrder
        manifest_dict["sub_order"] = serializeSubOrder(subOrderPtr)

        manifest_dict["buyer"] = serialize_buyer(buyerPtr)
        manifest_dict["buyer_address"] = serialize_buyer_address(
            buyerAddressPtr)

        manifest_dict["seller"] = serialize_seller(
            sellerPtr, {"seller_details_details": 1})
        manifest_dict["seller_address"] = serialize_seller_address(
            sellerAddressPtr)

        from orders.serializers.orderShipment import serializeOrderShipment
        manifest_dict["shipment"] = serializeOrderShipment(self)

        manifest_dict["barcode_full_path"] = barcodeFullPath

        manifest_dict["pageDataArr"] = []
        manifest_dict["pageDataArr"].append(
            {"page_copy_label": "Original Customer's Copy"})
        manifest_dict["pageDataArr"].append(
            {"page_copy_label": "Duplicate Copy"})
        manifest_dict["pageDataArr"].append(
            {"page_copy_label": "Triplicate Copy"})
        manifest_dict["total_pages"] = len(manifest_dict["pageDataArr"])

        pincodeServiceabilityPtr = PincodeServiceability.objects.filter(
            logistics_partner_id=self.logistics_partner_id,
            pincode=buyerAddressPtr.pincode_id)

        if len(pincodeServiceabilityPtr) > 0:
            pincodeServiceabilityPtr = pincodeServiceabilityPtr[0]
            manifest_dict["buyer_ou_code"] = pincodeServiceabilityPtr.ou_code

        pincodeServiceabilityPtr = PincodeServiceability.objects.filter(
            logistics_partner_id=self.logistics_partner_id,
            pincode=sellerAddressPtr.pincode_id)

        if len(pincodeServiceabilityPtr) > 0:
            pincodeServiceabilityPtr = pincodeServiceabilityPtr[0]
            manifest_dict["seller_ou_code"] = pincodeServiceabilityPtr.ou_code

        template_file = "shipment/shipment_label.html"

        generate_pdf(template_file,
                     manifest_dict,
                     outputDirectory,
                     outputFileName,
                     landscape=True)
Пример #7
0
    def create_manifest(self):

        manifest_dict = {}
        manifest_dict["orderItems"] = []
        manifest_dict["extra_order_items"] = 0
        maxOrderItems = 32

        subOrderPtr = self.suborder
        buyerPtr = subOrderPtr.order.buyer
        sellerPtr = subOrderPtr.seller
        sellerAddressPtr = subOrderPtr.seller_address_history
        buyerAddressPtr = subOrderPtr.order.buyer_address_history

        allOrderItems = OrderItem.objects.filter(order_shipment_id=self.id)

        orderItemCount = len(allOrderItems)

        extraOrderItems = orderItemCount - maxOrderItems

        if extraOrderItems > 0:
            manifest_dict["extra_order_items"] = extraOrderItems
            orderItemCount = maxOrderItems

        for i in range(orderItemCount):

            orderItemPtr = allOrderItems[i]
            manifestOrderItem = {
                "name": orderItemPtr.product.display_name,
                "pieces": orderItemPtr.pieces
            }

            manifest_dict["orderItems"].append(manifestOrderItem)

        from orders.serializers.subOrder import serializeSubOrder
        manifest_dict["sub_order"] = serializeSubOrder(subOrderPtr)

        manifest_dict["buyer"] = serialize_buyer(buyerPtr)
        manifest_dict["buyer_address"] = serialize_buyer_address(
            buyerAddressPtr)

        manifest_dict["seller"] = serialize_seller(
            sellerPtr, {"seller_details_details": 1})
        manifest_dict["seller_address"] = serialize_seller_address(
            sellerAddressPtr)

        from orders.serializers.orderShipment import serializeOrderShipment
        manifest_dict["shipment"] = serializeOrderShipment(self)

        template_file = "shipment/shipment_manifest.html"

        outputLink = "media/generateddocs/shipmentmanifest/{}/{}/".format(
            sellerPtr.id, subOrderPtr.display_number)
        outputDirectory = settings.STATIC_ROOT + outputLink
        outputFileName = "WholdusManifest-{}-{}.pdf".format(
            self.id, subOrderPtr.display_number)

        self.manifest_link = outputLink + outputFileName
        self.save()

        generate_pdf(template_file, manifest_dict, outputDirectory,
                     outputFileName)