From 4ad121e1a43f7ac1049118414f1f77300002ffd3 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 16 Jan 2017 12:19:07 +0530 Subject: [PATCH] [minor] fixes for Contact --- erpnext/shopping_cart/cart.py | 20 +++++++++++--------- erpnext/shopping_cart/test_shopping_cart.py | 6 +++--- erpnext/support/doctype/issue/issue.py | 8 ++++---- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index d3db4c97dd..e52ef8105d 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -182,8 +182,7 @@ def _get_cart_quotation(party=None): (party.doctype.lower()): party.name }) - qdoc.contact_person = frappe.db.get_value("Contact", {"email_id": frappe.session.user, - "customer": party.name}) + qdoc.contact_person = frappe.db.get_value("Contact", {"email_id": frappe.session.user}) qdoc.contact_email = frappe.session.user qdoc.flags.ignore_permissions = True @@ -198,8 +197,7 @@ def update_party(fullname, company_name=None, mobile_no=None, phone=None): party.customer_name = company_name or fullname party.customer_type == "Company" if company_name else "Individual" - contact_name = frappe.db.get_value("Contact", {"email_id": frappe.session.user, - "customer": party.name}) + contact_name = frappe.db.get_value("Contact", {"email_id": frappe.session.user}) contact = frappe.get_doc("Contact", contact_name) contact.first_name = fullname contact.last_name = None @@ -291,10 +289,14 @@ def get_party(user=None): if not user: user = frappe.session.user - 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 + contact_name = frappe.db.get_value("Contact", {"email_id": user}) + party = None + + if contact_name: + contact = frappe.get_doc('Contact', contact_name) + if contact.links: + party_doctype = contact.links[0].link_doctype + party = contact.links[0].link_name cart_settings = frappe.get_doc("Shopping Cart Settings") @@ -331,10 +333,10 @@ def get_party(user=None): contact = frappe.new_doc("Contact") contact.update({ - "customer": customer.name, "first_name": fullname, "email_id": user }) + contact.append('links', dict(link_doctype='Customer', link_name=customer.name)) contact.flags.ignore_mandatory = True contact.insert(ignore_permissions=True) diff --git a/erpnext/shopping_cart/test_shopping_cart.py b/erpnext/shopping_cart/test_shopping_cart.py index 528223151c..698d46726c 100644 --- a/erpnext/shopping_cart/test_shopping_cart.py +++ b/erpnext/shopping_cart/test_shopping_cart.py @@ -25,8 +25,8 @@ class TestShoppingCart(unittest.TestCase): # 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"), - "test_cart_user@example.com") + self.assertEquals(frappe.db.get_value("Contact", dict(contact_person="test_cart_user@example.com")), + quotation.contact_name) self.assertEquals(quotation.lead, None) self.assertEquals(quotation.contact_email, frappe.session.user) @@ -101,7 +101,7 @@ class TestShoppingCart(unittest.TestCase): quotation = self.create_quotation() from erpnext.accounts.party import set_taxes - + tax_rule_master = set_taxes(quotation.customer, "Customer", \ quotation.transaction_date, quotation.company, None, None, \ quotation.customer_address, quotation.shipping_address_name, 1) diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py index 36d0876bbd..f2d8bd53e1 100644 --- a/erpnext/support/doctype/issue/issue.py +++ b/erpnext/support/doctype/issue/issue.py @@ -33,11 +33,11 @@ class Issue(Document): if not self.lead: self.lead = frappe.db.get_value("Lead", {"email_id": email_id}) if not self.contact: - values = frappe.db.get_value("Contact", - {"email_id": email_id}, ("name", "customer")) + self.contact = frappe.db.get_value("Contact", {"email_id": email_id}) - if values: - self.contact, self.customer = values + if self.contact: + contact = frappe.get_doc('Contact', self.contact) + self.customer = contact.get_link_for('Customer') if not self.company: self.company = frappe.db.get_value("Lead", self.lead, "company") or \