Beispiel #1
0
def login(email, password):
	result = dict(
		success=False,
		msg="Internal Unhandled Error"
	)

	log("Are we still using this method?\n{0}".format(get_trace()))

	try:

		quotation = cart.get_cart_quotation()["doc"]

		user_doc = check_password(email, password)
		frappe.local.login_manager.login_as(email)
		frappe.set_user(email)
		user = frappe.get_doc("User", email)

		# move quotation to logged in user
		transfer_quotation_to_user(quotation, user)

		result["success"] = True
		result["msg"] = ""
		result["user"] = {
			"full_name": user.full_name,
			"name": user.name
		}
	except frappe.AuthenticationError as ex:
		result["success"] = False
		result["msg"] = str(ex)

	return result
Beispiel #2
0
def get_booked_items():
    from erpnext.shopping_cart.cart import get_cart_quotation
    doc = get_cart_quotation()

    items = {}
    for item in doc["doc"].items:
        items.update({item.item_code: item.stock_qty})

    return items
Beispiel #3
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 #4
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 #5
0
def get_context(context):
    # if frappe.session.user == 'Guest':
    #     frappe.local.flags.redirect_location = '/'
    #     raise frappe.Redirect

    context.session = frappe.session
    context.user = frappe.session.user
    context.csrf_token = frappe.sessions.get_csrf_token()
    context.item_group = frappe.get_all("Item Group",
                                        filters={
                                            "show_in_website": 1,
                                            "is_group": 0
                                        },
                                        fields=["name"])
    # context.item = frappe.get_all("Item",filters={"show_in_website":1},fields=["name","image","item_group"])
    context.item_result = get_items()
    context.update(get_cart_quotation())

    return context
Beispiel #6
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)
    }
def get_context(context):
    # if frappe.session.user == 'Guest':
    #     frappe.local.flags.redirect_location = '/'
    #     raise frappe.Redirect

    context.session = frappe.session
    context.user = frappe.session.user
    context.csrf_token = frappe.sessions.get_csrf_token()
    context.item_group = frappe.get_all('Item Group', filters={"show_in_website":1,"is_group":0}, fields=["name","weightage","route"], order_by='weightage desc')
    context.warehouse = frappe.get_all("Warehouse",filters={"show_in_website":1,"is_group":0},fields = ["name","warehouse_name"])
    context.cust_def_warehouse = check_warehouse()
    context.default_warehouse = frappe.db.get_value("Organic Cart Settings",None,"default_warehouse")
    
    # context.item = frappe.get_all("Item",filters={"show_in_website":1},fields=["name","image","item_group"])
    context.item_result = get_items()
    context.update(get_cart_quotation())
    context.no_cache = 1
    

    return context
Beispiel #8
0
def get_context(context):
    try:
        boot = frappe.sessions.get()
    except Exception as e:
        boot = frappe._dict(status='failed', error=str(e))
        frappe.log_error(frappe.get_traceback(),
                         "Error while building session boot object")

    # Disable document creation from frontend for quick forms, etc...
    boot.user.can_create = []

    boot_json = frappe.as_json(boot)
    # remove script tags from boot
    boot_json = re.sub(r"\<script\>[^<]*\</script\>", "", boot_json)

    context.update({"boot": boot if context.get("for_mobile") else boot_json})

    context.update(get_cart_quotation())

    if not hasattr(context, "doc"):
        context["doc"] = {"items": []}
Beispiel #9
0
def checkout(form):
	log("Are we still using this method?\n{0}".format(get_trace()))

	result = {
		"success": False,
		"msg": "Not Implemented",
		"errors": {}
	}

	try:
		form = json.loads(form)
	except:
		result["msg"] = "Invalid data"
		return result

	billing = form.get("billing", {})
	shipping = form.get("shipping", {})
	session_user = frappe.get_user()
	customer = None
	user = frappe.get_doc("User", session_user.name)
	form["user"] = {
		"email": user.email
	}
	result['form'] = form	# set form back to browser to update any ids as neccessary


	gateway = None

	try:
		quotation = cart.get_cart_quotation()
		quote = quotation["doc"]
		gateway = embed.get_gateway_module(billing.get("gateway", None))
		customer = frappe.get_doc("Customer", quote.customer)
	except:
		result["success"] = False
		result["msg"] = "Internal Error"
		result["exception"] = traceback.format_exc()

	try:
		if gateway:

			bill_address = None
			bill_address_insert = False
			ship_address = None
			ship_address_insert = False

			# lets extract billing address if one was entered
			if not billing['fields'].get('bill_address_id', False):
				bill_address = {
					k: billing['fields'].get(k, None) \
					for k in ["bill_%s" % j for j in ADDRESS_FIELDS]
				}
				bill_address = _create_customer_address(bill_address, customer, 'bill_')
				bill_address.flags.ignore_permissions = True
				bill_address_insert = True
			else:
				bill_address = frappe.get_doc('Address', billing['fields']['bill_address_id'])

			if not shipping['fields'].get('ship_address_id', False):
				ship_address = {
					k: shipping['fields'].get(k, None) \
					for k in ["ship_%s" % j for j in ADDRESS_FIELDS]
				}
				ship_address = _create_customer_address(ship_address, customer, 'ship_')
				ship_address.flags.ignore_permissions = True
				ship_address_insert = True
			else:
				ship_address = frappe.get_doc('Address', shipping['fields']['ship_address_id'])

			# setup transaction
			transaction = create_transaction(quote.grand_total, quote.currency)
			transaction.email = user.email

			stored_payment = None
			if form.get("stored_payment", False):
				stored_payment = None # update with new doctype

			try:
				success, msg = gateway.process(transaction, form, stored_payment, bill_address, ship_address)
				if success:
					result["success"] = True

					# on success insert new addresses
					if bill_address_insert:
						bill_address.insert()
						billing['fields']['bill_address_id'] = bill_address.name

					if ship_address_insert:
						# regenerate title since erpnext uses
						# title to generate id(name) in case
						# billing address uses same title
						ship_address.address_title = get_doctype_next_series('Address', "%s-%s" % (shipping['fields']['ship_address_title'], 'Shipping'))

						ship_address.insert()
						shipping['fields']['ship_address_id'] = ship_address.name
					# apply addresses to quotation
					quote.shipping_address_name = ship_address.name
					quote.shipping_address = get_address_display(ship_address.as_dict())
					quote.customer_address = bill_address.name
					quote.address_display = get_address_display(bill_address.as_dict())
					quote.flags.ignore_permissions = True
					quote.save()

					# now we'll submit quotation, create sales order,
					# create payment request and fullfill it
					so_name = cart.place_order() # submit quotation and create so
					result["so_name"] = so_name

					# lets now create a payment request and fullfill it immediately
					preq = payment_request.make_payment_request(dt="Sales Order", dn=so_name, submit_doc=1, return_doc=1)

					if preq:
						gdoc = gateway.get_gateway()
						adoc = gateway.get_bank_account()
						gadoc = gateway.get_account()

						preq.payment_gateway = gdoc.name
						preq.payment_account = adoc.name
						preq.payment_gateway_account = gadoc.name

						preq.flags.ignore_validate_update_after_submit = 1
						preq.flags.ignore_permissions = True
						preq.save()

						payment_entry = preq.run_method("set_as_paid")

						transaction.log(json.dumps(sanitize_checkout_form(form), indent=4))
						transaction.reference_doctype = "Payment Request"
						transaction.reference_docname = preq.name
						transaction.gateway = gdoc.name
						transaction.save()

						# find invoice
						inv_item = frappe.get_list("Sales Invoice Item", fields=["parent"], filters={"sales_order": so_name})[0]
						result["inv_name"] = inv_item.get("parent")

						frappe.session['awc_success_inv_name'] = inv_item.get("parent")
						frappe.session['awc_success_so_name'] = so_name
						frappe.session['awc_success_email'] = user.email


				else:
					result["success"] = False
					result["msg"] = msg
			except:
				transaction.log(json.dumps(sanitize_checkout_form(form), indent=4))
				transaction.status = "Failed"
				transaction.log(traceback.format_exc() + "\n---\n")
				transaction.save()

				result["success"] = False
				result["msg"] = 'Internal Error'
				result["exception"] = traceback.format_exc()
				raise
	except:
		result["success"] = False
		if not result.get('msg'):
			result['msg'] = 'Internal Error'

		if not result.get('exception'):
			result['exception'] = traceback.format_exc()

	return result
Beispiel #10
0
def register(email, password, password_check, first_name, last_name):
	log("Are we still using this method?\n{0}".format(get_trace()))

	result = dict(
		success=False,
		msg="Unhandled Error"
	)

	guest_user = frappe.get_user()
	user = frappe.get_doc("User", guest_user.name)

	quotation = cart.get_cart_quotation()["doc"]

	if user:
		if user.email[-12:] == "@guest.local":
			user.email = email
			user.first_name = first_name
			user.last_name = last_name
			user.new_password = password
			user.flags.ignore_permissions = True
			user.save()

			old_name = user.name

			frappe.rename_doc("User", old_name, email, ignore_permissions=True)
			user.name = email
			user.owner = user.name
			user.save()

			frappe.local.login_manager.login_as(email)
	                frappe.set_user(email)

			customer = None
			contact = frappe.get_doc("Contact", {
				"user": email
			})

			if contact:
				contact.first_name = first_name
				contact.last_name = last_name
				contact.email_id = email
				contact.flags.ignore_permissions = True
				contact.save()

				frappe.rename_doc("Contact", contact.name, email, ignore_permissions=True)
				contact.name = email

				customer = frappe.get_doc("Customer", contact.customer)

				if customer and customer.name.startswith("Guest"):
					customer.full_name = "%s %s" % (first_name, last_name)

					customer.flags.ignore_permissions = True
					customer.save()

					customer_next = get_doctype_next_series("Customer", customer.full_name)
					frappe.rename_doc("Customer", customer.name, customer_next, ignore_permissions=True)
					customer.name = customer_next

			# move quotation to logged in user
			transfer_quotation_to_user(quotation, user, customer=customer, contact=contact)

			result["success"] = True
			result["msg"] = ""
			result["user"] = {
				"full_name": user.full_name,
				"name": user.name
			}

		else:
			result["msg"] = "User is not a guest: %s" % user.email
	else:
		result["msg"] = "Internal Error, could not fetch user: %s" % guest_user.name

	return result
Beispiel #11
0
def get_context(context):
    context.update(get_cart_quotation())
Beispiel #12
0
def get_context(context):
	context.update(get_cart_quotation())
Beispiel #13
0
def get_context(context):
    context.update(get_cart_quotation())
    context.msg = 'hello'