66 lines
2.0 KiB
Python
Raw Normal View History

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2014-10-21 16:16:30 +05:30
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
2015-02-23 22:14:12 +05:30
from frappe import _
2014-10-21 16:16:30 +05:30
import frappe.defaults
2015-02-23 22:14:12 +05:30
from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import is_cart_enabled
2014-10-21 16:16:30 +05:30
def show_cart_count():
if (is_cart_enabled() and
2014-10-21 16:16:30 +05:30
frappe.db.get_value("User", frappe.session.user, "user_type") == "Website User"):
return True
return False
def set_cart_count(login_manager):
2016-03-03 14:00:35 +05:30
role, parties = check_customer_or_supplier()
if role == 'Supplier': return
2014-10-21 16:16:30 +05:30
if show_cart_count():
2015-02-23 22:14:12 +05:30
from erpnext.shopping_cart.cart import set_cart_count
2014-10-21 16:16:30 +05:30
set_cart_count()
def clear_cart_count(login_manager):
if show_cart_count():
frappe.local.cookie_manager.delete_cookie("cart_count")
2015-02-24 17:50:44 +05:30
def update_website_context(context):
2015-02-23 22:14:12 +05:30
cart_enabled = is_cart_enabled()
2014-10-21 16:16:30 +05:30
context["shopping_cart_enabled"] = cart_enabled
2015-02-23 22:14:12 +05:30
def update_my_account_context(context):
2016-03-03 14:00:35 +05:30
check_user_role, parties = check_customer_or_supplier()
if check_user_role == 'Supplier':
get_supplier_context(context)
else:
get_customer_context(context)
def get_supplier_context(context):
context["my_account_list"].extend([
{"label": _("Request for Quotations"), "url": "rfq"},
])
def get_customer_context(context):
2015-02-23 22:14:12 +05:30
context["my_account_list"].extend([
{"label": _("Projects"), "url": "project"},
2015-02-23 22:14:12 +05:30
{"label": _("Orders"), "url": "orders"},
{"label": _("Invoices"), "url": "invoices"},
{"label": _("Shipments"), "url": "shipments"},
2015-06-01 17:15:42 +05:30
{"label": _("Issues"), "url": "issues"},
{"label": _("Addresses"), "url": "addresses"}
2015-02-23 22:14:12 +05:30
])
2016-03-03 14:00:35 +05:30
def check_customer_or_supplier():
if frappe.session.user:
contacts = frappe.get_all("Contact", fields=["customer", "supplier", "email_id"],
filters={"email_id": frappe.session.user})
customer = [d.customer for d in contacts if d.customer] or None
supplier = [d.supplier for d in contacts if d.supplier] or None
if customer: return 'Customer', customer
if supplier : return 'Supplier', supplier
return 'Customer', None