From d636c3fb04ae5b1b95c67052bfb5f894e4cbf4f4 Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Wed, 9 Feb 2022 10:52:38 -0500 Subject: [PATCH 1/3] test: many users linked to customer shopping cart --- .../shopping_cart/test_shopping_cart.py | 25 +++++++++++-------- erpnext/tests/utils.py | 14 +++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/erpnext/e_commerce/shopping_cart/test_shopping_cart.py b/erpnext/e_commerce/shopping_cart/test_shopping_cart.py index 8519e68d094..05c874af98c 100644 --- a/erpnext/e_commerce/shopping_cart/test_shopping_cart.py +++ b/erpnext/e_commerce/shopping_cart/test_shopping_cart.py @@ -57,13 +57,19 @@ class TestShoppingCart(unittest.TestCase): return quotation def test_get_cart_customer(self): - self.login_as_customer() + def validate_quotation(): + # 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 - # 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) + self.login_as_customer("test_contact_two_customer@example.com", "_Test Contact 2 For _Test Customer") + validate_quotation() + + self.login_as_customer() + quotation = validate_quotation() return quotation @@ -254,10 +260,9 @@ class TestShoppingCart(unittest.TestCase): self.create_user_if_not_exists("test_cart_user@example.com") frappe.set_user("test_cart_user@example.com") - def login_as_customer(self): - self.create_user_if_not_exists("test_contact_customer@example.com", - "_Test Contact For _Test Customer") - frappe.set_user("test_contact_customer@example.com") + def login_as_customer(self, email="test_contact_customer@example.com", name="_Test Contact For _Test Customer"): + self.create_user_if_not_exists(email, name) + frappe.set_user(email) def clear_existing_quotations(self): quotations = frappe.get_all("Quotation", filters={ diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index 2bd7e9e71d0..40c95eb7a3a 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -66,6 +66,20 @@ def create_test_contact_and_address(): contact.add_phone("+91 0000000000", is_primary_phone=True) contact.insert() + contact_two = frappe.get_doc({ + "doctype": 'Contact', + "first_name": "_Test Contact 2 for _Test Customer", + "links": [ + { + "link_doctype": "Customer", + "link_name": "_Test Customer" + } + ] + }) + contact_two.add_email("test_contact_two_customer@example.com", is_primary=True) + contact_two.add_phone("+92 0000000000", is_primary_phone=True) + contact_two.insert() + @contextmanager def change_settings(doctype, settings_dict): From 34ad5b1abf534f55876fcfac2852df2ea42ecb41 Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Wed, 9 Feb 2022 10:53:24 -0500 Subject: [PATCH 2/3] fix: get cart for logged in user. --- erpnext/e_commerce/shopping_cart/cart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/e_commerce/shopping_cart/cart.py b/erpnext/e_commerce/shopping_cart/cart.py index 458cf69af7e..372aed0b95f 100644 --- a/erpnext/e_commerce/shopping_cart/cart.py +++ b/erpnext/e_commerce/shopping_cart/cart.py @@ -310,7 +310,7 @@ def _get_cart_quotation(party=None): party = get_party() quotation = frappe.get_all("Quotation", fields=["name"], filters= - {"party_name": party.name, "order_type": "Shopping Cart", "docstatus": 0}, + {"party_name": party.name, "contact_email": frappe.session.user, "order_type": "Shopping Cart", "docstatus": 0}, order_by="modified desc", limit_page_length=1) if quotation: From 49bee568a1d5bcfc315f539af734bc55a84a35ef Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Wed, 9 Feb 2022 12:03:05 -0500 Subject: [PATCH 3/3] fix: get cart items for logged in user. --- erpnext/e_commerce/product_data_engine/query.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/e_commerce/product_data_engine/query.py b/erpnext/e_commerce/product_data_engine/query.py index 007bf8b3489..cfc3c7b357c 100644 --- a/erpnext/e_commerce/product_data_engine/query.py +++ b/erpnext/e_commerce/product_data_engine/query.py @@ -264,7 +264,7 @@ class ProductQuery: customer = get_customer(silent=True) if customer: quotation = frappe.get_all("Quotation", fields=["name"], filters= - {"party_name": customer, "order_type": "Shopping Cart", "docstatus": 0}, + {"party_name": customer, "contact_email": frappe.session.user, "order_type": "Shopping Cart", "docstatus": 0}, order_by="modified desc", limit_page_length=1) if quotation: items = frappe.get_all( @@ -298,4 +298,4 @@ class ProductQuery: # slice results manually result[:self.page_length] - return result \ No newline at end of file + return result