Beispiel #1
0
def get_product_info(item_code):
	"""get product price / stock info"""
	if not is_cart_enabled():
		return {}

	qty = 0
	cart_quotation = _get_cart_quotation()
	template_item_code = frappe.db.get_value("Item", item_code, "variant_of")
	stock_status = get_qty_in_stock(item_code, template_item_code)
	in_stock = stock_status.in_stock
	stock_qty = stock_status.stock_qty
	price = get_price(item_code, template_item_code, cart_quotation.selling_price_list)

	if price:
		price["formatted_price"] = fmt_money(price["price_list_rate"], currency=price["currency"])

		price["currency"] = not cint(frappe.db.get_default("hide_currency_symbol")) \
			and (frappe.db.get_value("Currency", price.currency, "symbol") or price.currency) \
			or ""

		if frappe.session.user != "Guest":
			item = cart_quotation.get({"item_code": item_code})
			if item:
				qty = item[0].qty

	return {
		"price": price,
		"stock_qty": stock_qty,
		"in_stock": in_stock,
		"uom": frappe.db.get_value("Item", item_code, "stock_uom"),
		"qty": qty,
		"show_stock_qty": show_quantity_in_website()
	}
Beispiel #2
0
def get_product_info(item_code):
    """get product price / stock info"""
    if not is_cart_enabled():
        return {}

    qty = 0
    cart_quotation = _get_cart_quotation()
    template_item_code = frappe.db.get_value("Item", item_code, "variant_of")
    stock_status = get_qty_in_stock(item_code, template_item_code)
    in_stock = stock_status.in_stock
    stock_qty = stock_status.stock_qty
    price = get_price(item_code, template_item_code,
                      cart_quotation.selling_price_list)

    if price:
        price["formatted_price"] = fmt_money(price["price_list_rate"],
                                             currency=price["currency"])

        price["currency"] = not cint(frappe.db.get_default("hide_currency_symbol")) \
         and (frappe.db.get_value("Currency", price.currency, "symbol") or price.currency) \
         or ""

        if frappe.session.user != "Guest":
            item = cart_quotation.get({"item_code": item_code})
            if item:
                qty = item[0].qty

    return {
        "price": price,
        "stock_qty": stock_qty,
        "in_stock": in_stock,
        "uom": frappe.db.get_value("Item", item_code, "stock_uom"),
        "qty": qty,
        "show_stock_qty": show_quantity_in_website()
    }
Beispiel #3
0
def get_product_info_for_website(item_code):
	"""get product price / stock info for website"""
	if not is_cart_enabled():
		return {}

	cart_quotation = _get_cart_quotation()
	cart_settings = get_shopping_cart_settings()

	price = get_price(
		item_code,
		cart_quotation.selling_price_list,
		cart_settings.default_customer_group,
		cart_settings.company
	)

	stock_status = get_qty_in_stock(item_code, "website_warehouse")

	product_info = {
		"price": price,
		"stock_qty": stock_status.stock_qty,
		"in_stock": stock_status.in_stock if stock_status.is_stock_item else 1,
		"qty": 0,
		"uom": frappe.db.get_value("Item", item_code, "stock_uom"),
		"show_stock_qty": show_quantity_in_website() if stock_status.is_stock_item else 0
	}

	if product_info["price"]:
		if frappe.session.user != "Guest":
			item = cart_quotation.get({"item_code": item_code})
			if item:
				product_info["qty"] = item[0].qty

	return product_info
Beispiel #4
0
def get_product_info_for_website(item_code):
	"""get product price / stock info for website"""

	cart_quotation = _get_cart_quotation()
	cart_settings = get_shopping_cart_settings()

	price = get_price(
		item_code,
		cart_quotation.selling_price_list,
		cart_settings.default_customer_group,
		cart_settings.company
	)

	stock_status = get_qty_in_stock(item_code, "website_warehouse")

	product_info = {
		"price": price,
		"stock_qty": stock_status.stock_qty,
		"in_stock": stock_status.in_stock if stock_status.is_stock_item else 1,
		"qty": 0,
		"uom": frappe.db.get_value("Item", item_code, "stock_uom"),
		"show_stock_qty": show_quantity_in_website(),
		"sales_uom": frappe.db.get_value("Item", item_code, "sales_uom")
	}

	if product_info["price"]:
		if frappe.session.user != "Guest":
			item = cart_quotation.get({"item_code": item_code})
			if item:
				product_info["qty"] = item[0].qty

	return {
		"product_info": product_info,
		"cart_settings": cart_settings
	}
Beispiel #5
0
    def test_get_cart_customer(self):
        self.login_as_customer()

        # test if quotation with customer is fetched
        quotation = _get_cart_quotation()
        self.assertEqual(quotation.quotation_to, "Customer")
        self.assertEqual(quotation.party_name, "_Test Customer")
        self.assertEqual(quotation.contact_email, frappe.session.user)

        return quotation
	def test_get_cart_customer(self):
		self.login_as_customer()

		# test if quotation with customer is fetched
		quotation = _get_cart_quotation()
		self.assertEqual(quotation.quotation_to, "Customer")
		self.assertEqual(quotation.party_name, "_Test Customer")
		self.assertEqual(quotation.contact_email, frappe.session.user)

		return quotation
Beispiel #7
0
    def test_get_cart_new_user(self):
        self.login_as_new_user()

        # test if lead is created and quotation with new lead is fetched
        quotation = _get_cart_quotation()
        self.assertEqual(quotation.quotation_to, "Customer")
        self.assertEqual(quotation.contact_person,
                         frappe.db.get_value("Contact", dict(email_id="*****@*****.**")))
        self.assertEqual(quotation.contact_email, frappe.session.user)

        return quotation
	def test_get_cart_new_user(self):
		self.login_as_new_user()

		# test if lead is created and quotation with new lead is fetched
		quotation = _get_cart_quotation()
		self.assertEqual(quotation.quotation_to, "Customer")
		self.assertEqual(quotation.contact_person,
			frappe.db.get_value("Contact", dict(email_id="*****@*****.**")))
		self.assertEqual(quotation.contact_email, frappe.session.user)

		return quotation
Beispiel #9
0
	def test_get_cart_new_user(self):
		self.login_as_new_user()

		# test if lead is created and quotation with new lead is fetched
		quotation = _get_cart_quotation()
		self.assertEquals(quotation.quotation_to, "Customer")
		self.assertEquals(frappe.db.get_value("Contact", {"customer": quotation.customer}, "email_id"),
			"*****@*****.**")
		self.assertEquals(quotation.lead, None)
		self.assertEquals(quotation.contact_email, frappe.session.user)

		return quotation
Beispiel #10
0
	def test_get_cart_new_user(self):
		self.login_as_new_user()

		# test if lead is created and quotation with new lead is fetched
		quotation = _get_cart_quotation()
		self.assertEquals(quotation.quotation_to, "Customer")
		self.assertEquals(frappe.db.get_value("Contact", {"customer": quotation.customer}, "email_id"),
			"*****@*****.**")
		self.assertEquals(quotation.lead, None)
		self.assertEquals(quotation.contact_email, frappe.session.user)

		return quotation
Beispiel #11
0
def get_product_info_for_website(item_code, skip_quotation_creation=False):
    """get product price / stock info for website"""

    cart_settings = get_shopping_cart_settings()
    if not cart_settings.enabled:
        return frappe._dict()

    cart_quotation = frappe._dict()
    if not skip_quotation_creation:
        cart_quotation = _get_cart_quotation()
    selling_price_list = cart_quotation.get(
        "selling_price_list") if cart_quotation else _set_price_list(
            cart_settings, None)

    price = get_price(
        item_code,
        #cart_quotation.selling_price_list,
        selling_price_list,
        cart_settings.default_customer_group,
        cart_settings.company)

    stock_status = get_qty_in_stock(item_code, "website_warehouse")

    product_info = {
        "price":
        price,
        "stock_qty":
        stock_status.stock_qty,
        "in_stock":
        stock_status.in_stock if stock_status.is_stock_item else
        get_non_stock_item_status(item_code, "website_warehouse"),
        "qty":
        0,
        "uom":
        frappe.db.get_value("Item", item_code, "stock_uom"),
        "show_stock_qty":
        show_quantity_in_website(),
        "sales_uom":
        frappe.db.get_value("Item", item_code, "sales_uom")
    }

    if product_info["price"]:
        if frappe.session.user != "Guest":
            #		item = cart_quotation.get({"item_code": item_code})
            item = cart_quotation.get({"item_code": item_code
                                       }) if cart_quotation else None
            if item:
                product_info["qty"] = item[0].qty

    return frappe._dict({
        "product_info": product_info,
        "cart_settings": cart_settings
    })
Beispiel #12
0
def change_in_shipping(shipp):
	with_items=True
	quotation = _get_cart_quotation()
	if shipp == '0':
		quotation.shipping_rule = None
	else:
		quotation.shipping_rule = shipp
	empty_card = False
	"""qty = flt(qty)
	if qty == 0:
		quotation_items = quotation.get("items", {"item_code": ["!=", item_code]})
		if quotation_items:
			quotation.set("items", quotation_items)
		else:
			empty_card = True

	else:
		quotation_items = quotation.get("items", {"item_code": item_code})
		if not quotation_items:
			quotation.append("items", {
				"doctype": "Quotation Item",
				"item_code": item_code,
				"qty": qty
			})
		else:
			quotation_items[0].qty = qty"""

	apply_cart_settings(quotation=quotation)

	quotation.flags.ignore_permissions = True
	if not empty_card:
		quotation.save()
	else:
		quotation.delete()
		quotation = None

	set_cart_count(quotation)

	context = get_cart_quotation(quotation)

	if cint(with_items):
		return {
			"items": frappe.render_template("templates/includes/cart/cart_items.html",
				context),
			"taxes": frappe.render_template("templates/includes/order/order_taxes.html",
				context),
		}
	else:
		return {
			'name': quotation.name,
			'shopping_cart_menu': get_shopping_cart_menu(context)
		}
Beispiel #13
0
def get_booked_slots(quotation=None, uom=None):
    if not quotation and not frappe.session.user == "Guest":
        quotation = _get_cart_quotation().get("name")

    if not quotation:
        return []

    filters = dict(parenttype="Quotation", parent=quotation)
    if uom:
        filters["uom"] = uom

    return frappe.get_all("Quotation Item",
                          filters=filters,
                          fields=["item_booking as name"])
Beispiel #14
0
def update_calendar_items_cart(item_code, qty, with_items=False):
    from erpnext.shopping_cart.cart import _get_cart_quotation, apply_cart_settings, \
     set_cart_count, get_cart_quotation, get_shopping_cart_menu
    quotation = _get_cart_quotation()

    empty_card = False
    qty = flt(qty)
    if qty == 0:
        quotation_items = quotation.get("items",
                                        {"item_code": ["!=", item_code]})
        if quotation_items:
            quotation.set("items", quotation_items)
        else:
            empty_card = True

    else:
        quotation.append("items", {
            "doctype": "Quotation Item",
            "item_code": item_code,
            "qty": qty
        })

    apply_cart_settings(quotation=quotation)

    quotation.flags.ignore_permissions = True
    quotation.payment_schedule = []
    if not empty_card:
        quotation.save()
    else:
        quotation.delete()
        quotation = None

    set_cart_count(quotation)

    context = get_cart_quotation(quotation)

    if cint(with_items):
        return {
            "items":
            frappe.render_template("templates/includes/cart/cart_items.html",
                                   context),
            "taxes":
            frappe.render_template("templates/includes/order/order_taxes.html",
                                   context),
        }
    else:
        return {
            'name': quotation.name,
            'shopping_cart_menu': get_shopping_cart_menu(context)
        }
Beispiel #15
0
def get_product_info_for_website1(item_code):
    # custom implementation
    print(item_code,'--------------------------------------')
    print("""
    
    
    =
    overriden get_product_info_for_website
    =


    """)

    # original
    cart_settings = get_shopping_cart_settings()
    if not cart_settings.enabled:
        return frappe._dict()

    cart_quotation = _get_cart_quotation()

    price = get_price(
        item_code,
        cart_quotation.selling_price_list,
        cart_settings.default_customer_group,
        cart_settings.company
    )

    stock_status = get_qty_in_stock(item_code, "website_warehouse")
    product_info = {
        "price": price,
        "stock_qty": stock_status.stock_qty,
        "in_stock": stock_status.in_stock if stock_status.is_stock_item else 1,
        "qty": 0,
        "uom": "ll",
        "show_stock_qty": show_quantity_in_website(),
        "sales_uom": frappe.db.get_value("Item", item_code, "sales_uom"),
        "white_list":"ashish"
    }

    if product_info["price"]:
        if frappe.session.user != "Guest":
            item = cart_quotation.get({"item_code": item_code})
            if item:
                product_info["qty"] = 99999999999

    return frappe._dict({
        "product_info": product_info,
        "cart_settings": cart_settings
    })
Beispiel #16
0
def get_product_info(item_code):
    """get product price / stock info"""
    if not cint(frappe.db.get_default("shopping_cart_enabled")):
        return {}

    cart_quotation = _get_cart_quotation()

    price_list = cstr(
        unquote(frappe.local.request.cookies.get("selling_price_list")))

    warehouse = frappe.db.get_value("Item", item_code, "website_warehouse")
    if warehouse:
        in_stock = frappe.db.sql(
            """select actual_qty from tabBin where
			item_code=%s and warehouse=%s""", (item_code, warehouse))
        if in_stock:
            in_stock = in_stock[0][0] > 0 and 1 or 0
    else:
        in_stock = -1

    price = price_list and frappe.db.sql(
        """select price_list_rate, currency from
		`tabItem Price` where item_code=%s and price_list=%s""",
        (item_code, price_list),
        as_dict=1) or []

    price = price and price[0] or None
    qty = 0

    if price:
        price["formatted_price"] = fmt_money(price["price_list_rate"],
                                             currency=price["currency"])

        price["currency"] = not cint(frappe.db.get_default("hide_currency_symbol")) \
         and (frappe.db.get_value("Currency", price.currency, "symbol") or price.currency) \
         or ""

        if frappe.session.user != "Guest":
            item = cart_quotation.get({"item_code": item_code})
            if item:
                qty = item[0].qty

    return {
        "price": price,
        "stock": in_stock,
        "uom": frappe.db.get_value("Item", item_code, "stock_uom"),
        "qty": qty
    }
Beispiel #17
0
def book_slot(doctype, resource, start, end, option=None):
    from erpnext.shopping_cart.cart import _get_cart_quotation
    user = frappe.db.get_values("User",
                                frappe.session.user, ["full_name", "name"],
                                as_dict=True)[0]
    resource = json.loads(resource)
    option = option if option else None
    bookings = {"quotation": None, "bookings": []}

    quotation = _get_cart_quotation()
    bookings["quotation"] = quotation.name

    booking = frappe.get_doc({
        "doctype": "Shared Place Booking",
        "booking_type": doctype,
        "booked_resource": resource['id'],
        "booked_by": user.name,
        "starts_on": start,
        "ends_on": end,
        "title": user.full_name,
        "quotation": quotation.name,
        "option": option
    }).insert()

    if 'room' in resource and resource['room'] is not None:

        room_booking = frappe.get_doc({
            "doctype": "Shared Place Booking",
            "booking_type": "Shared Place Room",
            "booked_resource": resource['room'],
            "booked_by": user.name,
            "starts_on": start,
            "ends_on": end,
            "title": user.full_name,
            "quotation": quotation.name,
            "option": option
        }).insert()

        booking.linked_booking = room_booking.name
        booking.save(ignore_permissions=True)

        bookings["bookings"].append(room_booking)

    bookings["bookings"].append(booking)
    frappe.clear_cache()

    return bookings
Beispiel #18
0
def get_item_price(item_code, uom):
    cart_settings = get_shopping_cart_settings()

    if not cart_settings.enabled:
        return frappe._dict()

    cart_quotation = _get_cart_quotation()

    price = get_price(item_code=item_code,
                      price_list=cart_quotation.selling_price_list,
                      customer_group=cart_settings.default_customer_group,
                      company=cart_settings.company,
                      uom=uom)

    return {
        "item_name": frappe.db.get_value("Item", item_code, "item_name"),
        "price": price
    }
Beispiel #19
0
def get_product_info(item_code):
	"""get product price / stock info"""
	if not cint(frappe.db.get_default("shopping_cart_enabled")):
		return {}

	cart_quotation = _get_cart_quotation()

	price_list = cstr(unquote(frappe.local.request.cookies.get("selling_price_list")))

	warehouse = frappe.db.get_value("Item", item_code, "website_warehouse")
	if warehouse:
		in_stock = frappe.db.sql("""select actual_qty from tabBin where
			item_code=%s and warehouse=%s""", (item_code, warehouse))
		if in_stock:
			in_stock = in_stock[0][0] > 0 and 1 or 0
	else:
		in_stock = -1

	price = price_list and frappe.db.sql("""select price_list_rate, currency from
		`tabItem Price` where item_code=%s and price_list=%s""",
		(item_code, price_list), as_dict=1) or []

	price = price and price[0] or None
	qty = 0

	if price:
		price["formatted_price"] = fmt_money(price["price_list_rate"], currency=price["currency"])

		price["currency"] = not cint(frappe.db.get_default("hide_currency_symbol")) \
			and (frappe.db.get_value("Currency", price.currency, "symbol") or price.currency) \
			or ""

		if frappe.session.user != "Guest":
			item = cart_quotation.get({"item_code": item_code})
			if item:
				qty = item[0].qty

	return {
		"price": price,
		"stock": in_stock,
		"uom": frappe.db.get_value("Item", item_code, "stock_uom"),
		"qty": qty
	}
Beispiel #20
0
def update_calendar_items_cart(item_code, qty, uom_name):
    from erpnext.shopping_cart.cart import _get_cart_quotation, apply_cart_settings, \
     set_cart_count, get_cart_quotation, get_shopping_cart_menu
    quotation = _get_cart_quotation()

    empty_card = False
    qty = flt(qty)
    if qty == 0:
        quotation_items = quotation.get("items",
                                        {"item_code": ["!=", item_code]})
        if quotation_items:
            quotation.set("items", quotation_items)
        else:
            empty_card = True

    else:
        quotation.append(
            "items", {
                "doctype": "Quotation Item",
                "item_code": item_code,
                "qty": qty,
                "uom": get_sp_uom(uom_name)
            })

    apply_cart_settings(quotation=quotation)

    quotation.flags.ignore_permissions = True
    quotation.payment_schedule = []
    if not empty_card:
        quotation.save()
    else:
        quotation.delete()
        quotation = None

    set_cart_count(quotation)

    context = get_cart_quotation(quotation)

    return {
        'name': quotation.name if quotation else None,
        'shopping_cart_menu': get_shopping_cart_menu(context)
    }
Beispiel #21
0
def _get_selected_slots(events, quotation=None):
    linked_items = [
        x for x in events if x.get("status") == "In Cart"
        and x.get("user") == frappe.session.user
    ]
    if not linked_items:
        return []

    if not quotation or quotation == "null":
        quotation = _get_cart_quotation().get("name")

    if quotation:
        quotation_items = [x["item_booking"] for x in frappe.get_all("Quotation Item", \
         filters={"parenttype": "Quotation", "parent": quotation}, fields=["item_booking"]) if x["item_booking"] is not None]

        linked_items = [x for x in linked_items if x.name in quotation_items]

    result = []
    for item in linked_items:
        result.append(get_unavailable_dict(item))

    return result
Beispiel #22
0
 def remove_all_items_from_cart(self):
     quotation = _get_cart_quotation()
     quotation.flags.ignore_permissions = True
     quotation.delete()
Beispiel #23
0
	def remove_all_items_from_cart(self):
		quotation = _get_cart_quotation()
		quotation.flags.ignore_permissions=True
		quotation.delete()
	def remove_all_items_from_cart(self):
		quotation = _get_cart_quotation()
		quotation.set("items", [])
		quotation.save(ignore_permissions=True)
Beispiel #25
0
def remove_linked_bookings(item):
    from erpnext.shopping_cart.cart import _get_cart_quotation, update_cart

    quotation = _get_cart_quotation()

    rooms = [
        x['name']
        for x in frappe.get_all("Shared Place Room", filters={"item": item})
    ]
    resources = [
        x['name'] for x in frappe.get_all("Shared Place Resource",
                                          filters={"item": item})
    ]

    bookings = []
    if rooms:
        bookings.extend(
            frappe.get_all("Shared Place Booking",
                           filters={
                               "booking_type": "Shared Place Room",
                               "booked_resource": ("in", (rooms)),
                               "quotation": quotation.name,
                               "docstatus": 0
                           }))
    if resources:
        bookings.extend(
            frappe.get_all("Shared Place Booking",
                           filters={
                               "booking_type": "Shared Place Resource",
                               "booked_resource": ("in", (resources)),
                               "quotation": quotation.name,
                               "docstatus": 0
                           },
                           fields=["name", "linked_booking"]))

    for booking in bookings:
        if booking.linked_booking:
            room = frappe.db.get_value("Shared Place Booking",
                                       booking.linked_booking,
                                       "booked_resource")
            item = frappe.db.get_value("Shared Place Room", room, "item")
            update_cart(item, 0)

        else:
            links = frappe.get_all("Shared Place Booking",
                                   filters={
                                       "linked_booking": booking.name,
                                       "docstatus": 0,
                                       "name": ["!=", booking.name]
                                   })
            for link in links:
                res = frappe.db.get_value("Shared Place Booking", link.name,
                                          "booked_resource")
                item = frappe.db.get_value("Shared Place Resource", res,
                                           "item")
                update_cart(item, 0)

        frappe.delete_doc("Shared Place Booking",
                          booking.name,
                          ignore_permissions=True)

    return bookings
 def remove_all_items_from_cart(self):
     quotation = _get_cart_quotation()
     quotation.set("items", [])
     quotation.save(ignore_permissions=True)