From ae270d66485827fc47f924bf4dd337307c537e58 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 4 Apr 2016 18:49:26 +0530 Subject: [PATCH] [Fixes] Supplier can view their addresses, default buying price list issue --- .../controllers/website_list_for_contact.py | 7 ++- erpnext/shopping_cart/cart.py | 50 ++++++++++--------- erpnext/shopping_cart/test_shopping_cart.py | 4 +- erpnext/templates/pages/rfq.html | 2 +- erpnext/templates/pages/rfq.py | 12 ++--- 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/erpnext/controllers/website_list_for_contact.py b/erpnext/controllers/website_list_for_contact.py index e411cdf690..6b514b23d0 100644 --- a/erpnext/controllers/website_list_for_contact.py +++ b/erpnext/controllers/website_list_for_contact.py @@ -31,6 +31,9 @@ def get_transaction_list(doctype, txt=None, filters=None, limit_start=0, limit_p parties_doctype = 'Request for Quotation Supplier' if doctype == 'Request for Quotation' else doctype # find party for this contact customers, suppliers = get_customers_suppliers(parties_doctype, user) + + if not customers and not suppliers: return [] + key, parties = get_party_details(customers, suppliers) if doctype == 'Request for Quotation': @@ -93,7 +96,6 @@ def post_process(doctype, data): return result def get_customers_suppliers(doctype, user): - from erpnext.shopping_cart.cart import get_customer meta = frappe.get_meta(doctype) contacts = frappe.get_all("Contact", fields=["customer", "supplier", "email_id"], filters={"email_id": user}) @@ -101,9 +103,6 @@ def get_customers_suppliers(doctype, user): customers = [c.customer for c in contacts if c.customer] if meta.get_field("customer") else None suppliers = [c.supplier for c in contacts if c.supplier] if meta.get_field("supplier") else None - if not customers and not suppliers: - return [get_customer().name], None - return customers, suppliers def has_website_permission(doc, ptype, user, verbose=False): diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index c353b8d971..2c3257e694 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -24,7 +24,7 @@ def set_cart_count(quotation=None): @frappe.whitelist() def get_cart_quotation(doc=None): - party = get_customer() + party = get_party() if not doc: quotation = _get_cart_quotation(party) @@ -150,7 +150,7 @@ def decorate_quotation_doc(doc): def _get_cart_quotation(party=None): if not party: - party = get_customer() + party = get_party() quotation = frappe.get_all("Quotation", fields=["name"], filters= {party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0}, @@ -182,7 +182,7 @@ def _get_cart_quotation(party=None): return qdoc def update_party(fullname, company_name=None, mobile_no=None, phone=None): - party = get_customer() + party = get_party() party.customer_name = company_name or fullname party.customer_type == "Company" if company_name else "Individual" @@ -211,7 +211,7 @@ def update_party(fullname, company_name=None, mobile_no=None, phone=None): def apply_cart_settings(party=None, quotation=None): if not party: - party = get_customer() + party = get_party() if not quotation: quotation = _get_cart_quotation(party) @@ -276,20 +276,24 @@ def set_taxes(quotation, cart_settings): # # append taxes quotation.append_taxes_from_master() -def get_customer(user=None): +def get_party(user=None): if not user: user = frappe.session.user - customer = frappe.db.get_value("Contact", {"email_id": user}, "customer") + party = frappe.db.get_value("Contact", {"email_id": user}, ["customer", "supplier"], as_dict=1) + if party: + party_doctype = 'Customer' if party.customer else 'Supplier' + party = party.customer or party.supplier + cart_settings = frappe.get_doc("Shopping Cart Settings") - + debtors_account = '' - + if cart_settings.enable_checkout: debtors_account = get_debtors_account(cart_settings) - - if customer: - return frappe.get_doc("Customer", customer) + + if party: + return frappe.get_doc(party_doctype, party) else: customer = frappe.new_doc("Customer") @@ -300,7 +304,7 @@ def get_customer(user=None): "customer_group": get_shopping_cart_settings().default_customer_group, "territory": get_root_of("Territory") }) - + if debtors_account: customer.update({ "accounts": [{ @@ -308,7 +312,7 @@ def get_customer(user=None): "account": debtors_account }] }) - + customer.flags.ignore_mandatory = True customer.insert(ignore_permissions=True) @@ -326,12 +330,12 @@ def get_customer(user=None): def get_debtors_account(cart_settings): payment_gateway_account_currency = \ frappe.get_doc("Payment Gateway Account", cart_settings.payment_gateway_account).currency - + account_name = _("Debtors ({0})".format(payment_gateway_account_currency)) - + debtors_account_name = get_account_name("Receivable", "Asset", is_group=0,\ account_currency=payment_gateway_account_currency, company=cart_settings.company) - + if not debtors_account_name: debtors_account = frappe.get_doc({ "doctype": "Account", @@ -340,18 +344,18 @@ def get_debtors_account(cart_settings): "is_group": 0, "parent_account": get_account_name(root_type="Asset", is_group=1, company=cart_settings.company), "account_name": account_name, - "currency": payment_gateway_account_currency + "currency": payment_gateway_account_currency }).insert(ignore_permissions=True) - + return debtors_account.name - + else: return debtors_account_name - + def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None): if not party: - return + party = get_party() address_docs = frappe.db.sql("""select * from `tabAddress` where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(), @@ -371,7 +375,7 @@ def set_customer_in_address(doc, method=None): if not doc.flags.linked and (frappe.db.get_value("User", frappe.session.user, "user_type") == "Website User"): # creates a customer if one does not exist - get_customer() + get_party() doc.link_address() @frappe.whitelist() @@ -439,4 +443,4 @@ def get_address_territory(address_name): return territory def show_terms(doc): - return doc.tc_name + return doc.tc_name diff --git a/erpnext/shopping_cart/test_shopping_cart.py b/erpnext/shopping_cart/test_shopping_cart.py index 0fe04baa17..a51852a454 100644 --- a/erpnext/shopping_cart/test_shopping_cart.py +++ b/erpnext/shopping_cart/test_shopping_cart.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import unittest import frappe -from erpnext.shopping_cart.cart import _get_cart_quotation, update_cart, get_customer +from erpnext.shopping_cart.cart import _get_cart_quotation, update_cart, get_party class TestShoppingCart(unittest.TestCase): """ @@ -118,7 +118,7 @@ class TestShoppingCart(unittest.TestCase): "doctype": "Quotation", "quotation_to": "Customer", "order_type": "Shopping Cart", - "customer": get_customer(frappe.session.user).name, + "customer": get_party(frappe.session.user).name, "docstatus": 0, "contact_email": frappe.session.user, "selling_price_list": "_Test Price List Rest of the World", diff --git a/erpnext/templates/pages/rfq.html b/erpnext/templates/pages/rfq.html index dfbbbc9d65..e4dc4e6f35 100644 --- a/erpnext/templates/pages/rfq.html +++ b/erpnext/templates/pages/rfq.html @@ -64,7 +64,7 @@
{{ _("Grand Total") }}
- {{doc.currency_symbol}} 0.0 + {{doc.currency_symbol}} 0.0
{% endif %} diff --git a/erpnext/templates/pages/rfq.py b/erpnext/templates/pages/rfq.py index 181cf73c89..4c488d9242 100644 --- a/erpnext/templates/pages/rfq.py +++ b/erpnext/templates/pages/rfq.py @@ -4,16 +4,16 @@ from __future__ import unicode_literals import frappe from frappe import _ -from erpnext.controllers.website_list_for_contact import get_customers_suppliers, \ - get_party_details +from erpnext.controllers.website_list_for_contact import (get_customers_suppliers, + get_party_details) def get_context(context): context.no_cache = 1 context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name) context.parents = frappe.form_dict.parents context.doc.supplier = get_supplier() - update_supplier_details(context) unauthorized_user(context.doc.supplier) + update_supplier_details(context) context["title"] = frappe.form_dict.name def get_supplier(): @@ -31,13 +31,13 @@ def check_supplier_has_docname_access(supplier): return status def unauthorized_user(supplier): - status = check_supplier_has_docname_access(supplier) + status = check_supplier_has_docname_access(supplier) or False if status == False: frappe.throw(_("Not Permitted"), frappe.PermissionError) def update_supplier_details(context): supplier_doc = frappe.get_doc("Supplier", context.doc.supplier) - context.doc.currency = supplier_doc.default_currency + context.doc.currency = supplier_doc.default_currency or frappe.db.get_value("Company", context.doc.company, "default_currency") context.doc.currency_symbol = frappe.db.get_value("Currency", context.doc.currency, "symbol") context.doc.number_format = frappe.db.get_value("Currency", context.doc.currency, "number_format") - context.doc.buying_price_list = supplier_doc.default_price_list \ No newline at end of file + context.doc.buying_price_list = supplier_doc.default_price_list or '' \ No newline at end of file