From 224c2ddaf4b9a9ff4406e1d4d8764a5c09bf08a0 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Thu, 8 Aug 2019 23:34:34 +0530 Subject: [PATCH 01/17] feat: render multiple addresses --- erpnext/public/js/templates/contact_list.html | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/erpnext/public/js/templates/contact_list.html b/erpnext/public/js/templates/contact_list.html index 893b4e0ec2..c4bc04ff38 100644 --- a/erpnext/public/js/templates/contact_list.html +++ b/erpnext/public/js/templates/contact_list.html @@ -14,19 +14,30 @@ style="margin-top:-3px; margin-right: -5px;"> {%= __("Edit") %}

- {% if (contact_list[i].phone || contact_list[i].mobile_no || - contact_list[i].email_id) { %} + {% if (contact_list[i].phones || contact_list[i].email_ids) { %}

- {% if(contact_list[i].phone) { %} - {%= __("Phone") %}: {%= contact_list[i].phone %}
- {% } %} - {% if(contact_list[i].mobile_no) { %} - {%= __("Mobile No.") %}: {%= contact_list[i].mobile_no %}
- {% } %} - {% if(contact_list[i].email_id) { %} - {%= __("Email Address") %}: {%= contact_list[i].email_id %} - {% } %} + {% if(contact_list[i].phone) { %} + {%= __("Phone ") %}: {%= contact_list[i].phone %}
+ {% endif %} + {% if(contact_list[i].phones) { %} + {% for(var j=0, k=contact_list[i].phones.length; j + {% } %} + {% endif %}

+

+ {% if(contact_list[i].email_id) { %} + {%= __("Email ") %}: {%= contact_list[i].email_id %}
+ {% endif %} + {% if(contact_list[i].email_ids) { %} + {% for(var j=0, k=contact_list[i].email_ids.length; j + {% } %} + {% endif %} +

+ {% endif %} + {% if (contact_list[i].address) { %} + {%= __("Address ") %}: {%= contact_list[i].address %}
{% endif %} {% } %} From f94d1832977516e726a9f71994c5b917ea521308 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Thu, 8 Aug 2019 23:50:03 +0530 Subject: [PATCH 02/17] feat: move to newer contacts structure --- erpnext/crm/doctype/opportunity/test_opportunity.py | 7 ++++--- erpnext/hub_node/legacy.py | 5 +++-- erpnext/selling/doctype/customer/customer.py | 7 ++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index 1a9f66ad9a..8927d93027 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -45,15 +45,16 @@ class TestOpportunity(unittest.TestCase): # create new customer and create new contact against 'new.opportunity@example.com' customer = make_customer(opp_doc.party_name).insert(ignore_permissions=True) - frappe.get_doc({ + d = frappe.get_doc({ "doctype": "Contact", - "email_id": new_lead_email_id, "first_name": "_Test Opportunity Customer", "links": [{ "link_doctype": "Customer", "link_name": customer.name }] - }).insert(ignore_permissions=True) + }) + d.add_email(new_lead_email_id) + d.insert(ignore_permissions=True) opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) self.assertTrue(opp_doc.party_name) diff --git a/erpnext/hub_node/legacy.py b/erpnext/hub_node/legacy.py index 95ada76a6a..85eb1b2bb0 100644 --- a/erpnext/hub_node/legacy.py +++ b/erpnext/hub_node/legacy.py @@ -68,12 +68,13 @@ def make_contact(supplier): contact = frappe.get_doc({ 'doctype': 'Contact', 'first_name': supplier.supplier_name, - 'email_id': supplier.supplier_email, 'is_primary_contact': 1, 'links': [ {'link_doctype': 'Supplier', 'link_name': supplier.supplier_name} ] - }).insert() + }) + contact.add_email(supplier.supplier_email) + contact.insert() else: contact = frappe.get_doc('Contact', contact_name) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index c946c47c59..d0b4ba0e65 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -337,14 +337,15 @@ def make_contact(args, is_primary_contact=1): contact = frappe.get_doc({ 'doctype': 'Contact', 'first_name': args.get('name'), - 'mobile_no': args.get('mobile_no'), - 'email_id': args.get('email_id'), 'is_primary_contact': is_primary_contact, 'links': [{ 'link_doctype': args.get('doctype'), 'link_name': args.get('name') }] - }).insert() + }) + contact.add_email(args.get('email_id')) + contact.add_phone(args.get('mobile_no')) + contact.insert() return contact From 86f3310ac1492fbd6aba27666dae852f28dc9dba Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Fri, 9 Aug 2019 11:05:04 +0530 Subject: [PATCH 03/17] fix: iterate over valid variable --- erpnext/public/js/templates/contact_list.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/public/js/templates/contact_list.html b/erpnext/public/js/templates/contact_list.html index c4bc04ff38..a90580f652 100644 --- a/erpnext/public/js/templates/contact_list.html +++ b/erpnext/public/js/templates/contact_list.html @@ -19,9 +19,9 @@ {% if(contact_list[i].phone) { %} {%= __("Phone ") %}: {%= contact_list[i].phone %}
{% endif %} - {% if(contact_list[i].phones) { %} - {% for(var j=0, k=contact_list[i].phones.length; j + {% if(contact_list[i].phone_nos) { %} + {% for(var j=0, k=contact_list[i].phone_nos.length; j {% } %} {% endif %}

From 12fbecf48bc781df144d5e1311f613578131565b Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Fri, 9 Aug 2019 17:50:03 +0530 Subject: [PATCH 04/17] fix: use primary label instead of bold letters --- erpnext/public/js/templates/contact_list.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/templates/contact_list.html b/erpnext/public/js/templates/contact_list.html index a90580f652..0a339aa539 100644 --- a/erpnext/public/js/templates/contact_list.html +++ b/erpnext/public/js/templates/contact_list.html @@ -17,7 +17,7 @@ {% if (contact_list[i].phones || contact_list[i].email_ids) { %}

{% if(contact_list[i].phone) { %} - {%= __("Phone ") %}: {%= contact_list[i].phone %}
+ {%= __("Phone ") %}: {%= contact_list[i].phone %} ({%= __("Primary") %})
{% endif %} {% if(contact_list[i].phone_nos) { %} {% for(var j=0, k=contact_list[i].phone_nos.length; j

{% if(contact_list[i].email_id) { %} - {%= __("Email ") %}: {%= contact_list[i].email_id %}
+ {%= __("Email ") %}: {%= contact_list[i].email_id %} ({%= __("Primary") %})
{% endif %} {% if(contact_list[i].email_ids) { %} {% for(var j=0, k=contact_list[i].email_ids.length; j Date: Tue, 20 Aug 2019 22:20:02 +0530 Subject: [PATCH 05/17] fix: call popup get contact name from number --- erpnext/crm/doctype/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/erpnext/crm/doctype/utils.py b/erpnext/crm/doctype/utils.py index 9cfab15995..2257ee5cce 100644 --- a/erpnext/crm/doctype/utils.py +++ b/erpnext/crm/doctype/utils.py @@ -1,6 +1,7 @@ import frappe from frappe import _ import json +from frappe.contacts.doctype.contact.contact import get_contact_with_phone_number @frappe.whitelist() def get_document_with_phone_number(number): @@ -11,10 +12,10 @@ def get_document_with_phone_number(number): 'phone': ['like', '%{}'.format(number)], 'mobile_no': ['like', '%{}'.format(number)] } - contacts = frappe.get_all('Contact', or_filters=number_filter, limit=1) + contact = get_contact_with_phone_number(number) - if contacts: - return frappe.get_doc('Contact', contacts[0].name) + if contact: + return frappe.get_doc('Contact', contact) leads = frappe.get_all('Lead', or_filters=number_filter, limit=1) From c6e02e2a74995f9eeb8dc96ff501223e22bf5f15 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Wed, 21 Aug 2019 13:36:41 +0530 Subject: [PATCH 06/17] fix: make contact structure call popup compatible --- erpnext/communication/doctype/call_log/call_log.py | 6 +++++- erpnext/crm/doctype/utils.py | 1 - .../doctype/exotel_settings/exotel_settings.py | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/erpnext/communication/doctype/call_log/call_log.py b/erpnext/communication/doctype/call_log/call_log.py index c9fdfbe447..88965def45 100644 --- a/erpnext/communication/doctype/call_log/call_log.py +++ b/erpnext/communication/doctype/call_log/call_log.py @@ -70,9 +70,13 @@ def set_caller_information(doc, state): numbers = [doc.get('phone'), doc.get('mobile_no')] for_doc = doc.doctype.lower() + # Contact now has all the nos saved in child table + if doc.doctype == 'Contact': + numbers = [nos.phone for nos in doc.phone_nos] + for number in numbers: if not number: continue - print(number) + filters = frappe._dict({ 'from': ['like', '%{}'.format(number.lstrip('0'))], for_doc: '' diff --git a/erpnext/crm/doctype/utils.py b/erpnext/crm/doctype/utils.py index 756b0a2fc8..55532761c2 100644 --- a/erpnext/crm/doctype/utils.py +++ b/erpnext/crm/doctype/utils.py @@ -1,7 +1,6 @@ import frappe from frappe import _ import json -from frappe.contacts.doctype.contact.contact import get_contact_with_phone_number @frappe.whitelist() def get_last_interaction(contact=None, lead=None): diff --git a/erpnext/erpnext_integrations/doctype/exotel_settings/exotel_settings.py b/erpnext/erpnext_integrations/doctype/exotel_settings/exotel_settings.py index 77de84ce5c..6a846efad7 100644 --- a/erpnext/erpnext_integrations/doctype/exotel_settings/exotel_settings.py +++ b/erpnext/erpnext_integrations/doctype/exotel_settings/exotel_settings.py @@ -3,7 +3,6 @@ # For license information, please see license.txt from __future__ import unicode_literals -# import frappe from frappe.model.document import Document import requests import frappe From 81f20891c14432f3c6a4c413d7d13d289e6b8914 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Wed, 21 Aug 2019 16:09:35 +0530 Subject: [PATCH 07/17] fix: query --- erpnext/communication/doctype/call_log/call_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/communication/doctype/call_log/call_log.py b/erpnext/communication/doctype/call_log/call_log.py index 88965def45..29342042ff 100644 --- a/erpnext/communication/doctype/call_log/call_log.py +++ b/erpnext/communication/doctype/call_log/call_log.py @@ -54,7 +54,7 @@ def get_employees_with_number(number): if employee_emails: return employee_emails employees = frappe.get_all('Employee', filters={ - 'cell_number': ['like', '%{}'.format(number.lstrip('0'))], + 'cell_number': ['like', '{}'.format(number.lstrip('0'))], 'user_id': ['!=', ''] }, fields=['user_id']) From 7243e774c27477ffeb30c0c155af7332697eb3df Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Mon, 26 Aug 2019 12:49:20 +0530 Subject: [PATCH 08/17] fix: add city, state and country --- erpnext/public/js/templates/contact_list.html | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/public/js/templates/contact_list.html b/erpnext/public/js/templates/contact_list.html index 0a339aa539..0df19bb996 100644 --- a/erpnext/public/js/templates/contact_list.html +++ b/erpnext/public/js/templates/contact_list.html @@ -37,7 +37,17 @@

{% endif %} {% if (contact_list[i].address) { %} - {%= __("Address ") %}: {%= contact_list[i].address %}
+ {%= __("Address ") %}: {%= contact_list[i].address %} + {% if (contact_list[i].city) { %} + , {%= contact_list[i].city %} + {% endif %} + {% if (contact_list[i].state) { %} + , {%= contact_list[i].state %} + {% endif %} + {% if (contact_list[i].country) { %} + , {%= contact_list[i].country %} + {% endif %} +
{% endif %} {% } %} From 9057239c3c92228ba0b957e47b73cc9e01de7891 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Mon, 26 Aug 2019 22:40:54 +0530 Subject: [PATCH 09/17] fix: display address --- erpnext/public/js/templates/contact_list.html | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/erpnext/public/js/templates/contact_list.html b/erpnext/public/js/templates/contact_list.html index 0df19bb996..0a339aa539 100644 --- a/erpnext/public/js/templates/contact_list.html +++ b/erpnext/public/js/templates/contact_list.html @@ -37,17 +37,7 @@

{% endif %} {% if (contact_list[i].address) { %} - {%= __("Address ") %}: {%= contact_list[i].address %} - {% if (contact_list[i].city) { %} - , {%= contact_list[i].city %} - {% endif %} - {% if (contact_list[i].state) { %} - , {%= contact_list[i].state %} - {% endif %} - {% if (contact_list[i].country) { %} - , {%= contact_list[i].country %} - {% endif %} -
+ {%= __("Address ") %}: {%= contact_list[i].address %}
{% endif %} {% } %} From a5b78f3c0d3e8230b410f78eb2d576fcb4159434 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Wed, 28 Aug 2019 00:04:05 +0530 Subject: [PATCH 10/17] fix: get address in single line --- erpnext/public/js/templates/contact_list.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/public/js/templates/contact_list.html b/erpnext/public/js/templates/contact_list.html index 0a339aa539..8dd220f72d 100644 --- a/erpnext/public/js/templates/contact_list.html +++ b/erpnext/public/js/templates/contact_list.html @@ -36,9 +36,11 @@ {% endif %}

{% endif %} +

{% if (contact_list[i].address) { %} {%= __("Address ") %}: {%= contact_list[i].address %}
{% endif %} +

{% } %} {% if(!contact_list.length) { %} From fd85b1689d38a746387044597ce9fbf2f0571a90 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Mon, 2 Sep 2019 12:10:15 +0530 Subject: [PATCH 11/17] fix: review fixes --- erpnext/communication/doctype/call_log/call_log.py | 2 +- erpnext/crm/doctype/opportunity/test_opportunity.py | 6 +++--- erpnext/public/js/templates/contact_list.html | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/erpnext/communication/doctype/call_log/call_log.py b/erpnext/communication/doctype/call_log/call_log.py index 411f56c5ec..35c31a0bf8 100644 --- a/erpnext/communication/doctype/call_log/call_log.py +++ b/erpnext/communication/doctype/call_log/call_log.py @@ -75,7 +75,7 @@ def set_caller_information(doc, state): # Contact now has all the nos saved in child table if doc.doctype == 'Contact': - numbers = [nos.phone for nos in doc.phone_nos] + numbers = [d.phone for d in doc.phone_nos] for number in numbers: number = strip_number(number) diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index 8927d93027..8f61edf00e 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -45,7 +45,7 @@ class TestOpportunity(unittest.TestCase): # create new customer and create new contact against 'new.opportunity@example.com' customer = make_customer(opp_doc.party_name).insert(ignore_permissions=True) - d = frappe.get_doc({ + contact = frappe.get_doc({ "doctype": "Contact", "first_name": "_Test Opportunity Customer", "links": [{ @@ -53,8 +53,8 @@ class TestOpportunity(unittest.TestCase): "link_name": customer.name }] }) - d.add_email(new_lead_email_id) - d.insert(ignore_permissions=True) + contact.add_email(new_lead_email_id) + contact.insert(ignore_permissions=True) opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) self.assertTrue(opp_doc.party_name) diff --git a/erpnext/public/js/templates/contact_list.html b/erpnext/public/js/templates/contact_list.html index 8dd220f72d..da7b059fcd 100644 --- a/erpnext/public/js/templates/contact_list.html +++ b/erpnext/public/js/templates/contact_list.html @@ -21,7 +21,7 @@ {% endif %} {% if(contact_list[i].phone_nos) { %} {% for(var j=0, k=contact_list[i].phone_nos.length; j + {%= __("Phone") %}: {%= contact_list[i].phone_nos[j].phone %}
{% } %} {% endif %}

@@ -31,14 +31,14 @@ {% endif %} {% if(contact_list[i].email_ids) { %} {% for(var j=0, k=contact_list[i].email_ids.length; j + {%= __("Email") %}: {%= contact_list[i].email_ids[j].email_id %}
{% } %} {% endif %}

{% endif %}

{% if (contact_list[i].address) { %} - {%= __("Address ") %}: {%= contact_list[i].address %}
+ {%= __("Address") %}: {%= contact_list[i].address %}
{% endif %}

From 26dfd5b3140d827c24a8f5ec061112809a243f21 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Mon, 2 Sep 2019 12:21:41 +0530 Subject: [PATCH 12/17] fix: translation strings --- erpnext/public/js/templates/contact_list.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/templates/contact_list.html b/erpnext/public/js/templates/contact_list.html index da7b059fcd..50fbfd9f12 100644 --- a/erpnext/public/js/templates/contact_list.html +++ b/erpnext/public/js/templates/contact_list.html @@ -17,7 +17,7 @@ {% if (contact_list[i].phones || contact_list[i].email_ids) { %}

{% if(contact_list[i].phone) { %} - {%= __("Phone ") %}: {%= contact_list[i].phone %} ({%= __("Primary") %})
+ {%= __("Phone") %}: {%= contact_list[i].phone %} ({%= __("Primary") %})
{% endif %} {% if(contact_list[i].phone_nos) { %} {% for(var j=0, k=contact_list[i].phone_nos.length; j

{% if(contact_list[i].email_id) { %} - {%= __("Email ") %}: {%= contact_list[i].email_id %} ({%= __("Primary") %})
+ {%= __("Email") %}: {%= contact_list[i].email_id %} ({%= __("Primary") %})
{% endif %} {% if(contact_list[i].email_ids) { %} {% for(var j=0, k=contact_list[i].email_ids.length; j Date: Mon, 2 Sep 2019 13:20:27 +0530 Subject: [PATCH 13/17] fix: fix query for contacts --- erpnext/accounts/doctype/sales_invoice/pos.py | 4 ++-- erpnext/selling/doctype/sms_center/sms_center.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index e290b235a9..7e23793700 100755 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -227,8 +227,8 @@ def get_contacts(customers): customers = [frappe._dict({'name': customers})] for data in customers: - contact = frappe.db.sql(""" select email_id, phone, mobile_no from `tabContact` - where is_primary_contact =1 and name in + contact = frappe.db.sql(""" select email_id, phone from `tabContact` + where is_primary_contact=1 and name in (select parent from `tabDynamic Link` where link_doctype = 'Customer' and link_name = %s and parenttype = 'Contact')""", data.name, as_dict=1) if contact: diff --git a/erpnext/selling/doctype/sms_center/sms_center.py b/erpnext/selling/doctype/sms_center/sms_center.py index bb6ba1ffce..289b045e1c 100644 --- a/erpnext/selling/doctype/sms_center/sms_center.py +++ b/erpnext/selling/doctype/sms_center/sms_center.py @@ -31,7 +31,7 @@ class SMSCenter(Document): self.sales_partner.replace("'", "\'") or " and ifnull(dl.link_name, '') != ''" if self.send_to in ['All Contact', 'All Customer Contact', 'All Supplier Contact', 'All Sales Partner Contact']: rec = frappe.db.sql("""select CONCAT(ifnull(c.first_name,''), ' ', ifnull(c.last_name,'')), - c.mobile_no from `tabContact` c, `tabDynamic Link` dl where ifnull(c.mobile_no,'')!='' and + c.phone from `tabContact` c, `tabDynamic Link` dl where ifnull(c.phone,'')!='' and c.docstatus != 2 and dl.parent = c.name%s""" % where_clause) elif self.send_to == 'All Lead (Open)': From 711d1acffd969e18859421e80c1677c6ab3b549f Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Mon, 2 Sep 2019 13:31:10 +0530 Subject: [PATCH 14/17] fix: remove references of mobile_no --- erpnext/accounts/page/pos/pos.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js index b5a02d0e49..0e7301204a 100755 --- a/erpnext/accounts/page/pos/pos.js +++ b/erpnext/accounts/page/pos/pos.js @@ -816,7 +816,6 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ contact = me.contacts[data.name]; if(reg.test(data.name.toLowerCase()) || reg.test(data.customer_name.toLowerCase()) - || (contact && reg.test(contact["mobile_no"])) || (contact && reg.test(contact["phone"])) || (data.customer_group && reg.test(data.customer_group.toLowerCase()))){ return data; @@ -834,7 +833,6 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ if(contact && !c['phone']) { c["phone"] = contact["phone"]; c["email_id"] = contact["email_id"]; - c["mobile_no"] = contact["mobile_no"]; } me.customers_mapper.push({ @@ -844,10 +842,9 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ customer_group: c.customer_group, territory: c.territory, phone: contact ? contact["phone"] : '', - mobile_no: contact ? contact["mobile_no"] : '', email_id: contact ? contact["email_id"] : '', searchtext: ['customer_name', 'customer_group', 'name', 'value', - 'label', 'email_id', 'phone', 'mobile_no'] + 'label', 'email_id', 'phone'] .map(key => c[key]).join(' ') .toLowerCase() }); From 402d82b4c54ad643832f1216384a220fe296766a Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Mon, 2 Sep 2019 14:37:18 +0530 Subject: [PATCH 15/17] fix: Remove delete_doc from tests --- .../accounts/doctype/budget/test_budget.py | 52 +++++++++---------- .../loyalty_program/test_loyalty_program.py | 3 -- .../sales_invoice/test_sales_invoice.py | 1 - .../test_tax_withholding_category.py | 3 -- erpnext/assets/doctype/asset/test_asset.py | 2 - .../expense_claim/test_expense_claim.py | 1 - .../test_stock_reconciliation.py | 4 -- 7 files changed, 25 insertions(+), 41 deletions(-) diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py index b126b1fb0a..33aefd67d1 100644 --- a/erpnext/accounts/doctype/budget/test_budget.py +++ b/erpnext/accounts/doctype/budget/test_budget.py @@ -11,32 +11,32 @@ from erpnext.buying.doctype.purchase_order.test_purchase_order import create_pur from erpnext.accounts.doctype.budget.budget import get_actual_expense, BudgetError from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry -class TestBudget(unittest.TestCase): +class TestBudget(unittest.TestCase): def test_monthly_budget_crossed_ignore(self): set_total_expense_zero("2013-02-28", "Cost Center") budget = make_budget(budget_against="Cost Center") - + jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", posting_date="2013-02-28", submit=True) self.assertTrue(frappe.db.get_value("GL Entry", {"voucher_type": "Journal Entry", "voucher_no": jv.name})) - + budget.cancel() def test_monthly_budget_crossed_stop1(self): set_total_expense_zero("2013-02-28", "Cost Center") budget = make_budget(budget_against="Cost Center") - + frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", posting_date="2013-02-28") self.assertRaises(BudgetError, jv.submit) - + budget.load_from_db() budget.cancel() @@ -46,7 +46,7 @@ class TestBudget(unittest.TestCase): budget = make_budget(budget_against="Cost Center") frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") - + jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", posting_date="2013-03-02") @@ -117,14 +117,14 @@ class TestBudget(unittest.TestCase): set_total_expense_zero("2013-02-28", "Project") budget = make_budget(budget_against="Project") - + frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", project="_Test Project", posting_date="2013-02-28") self.assertRaises(BudgetError, jv.submit) - + budget.load_from_db() budget.cancel() @@ -132,31 +132,31 @@ class TestBudget(unittest.TestCase): set_total_expense_zero("2013-02-28", "Cost Center") budget = make_budget(budget_against="Cost Center") - + jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 150000, "_Test Cost Center - _TC", posting_date="2013-03-28") self.assertRaises(BudgetError, jv.submit) - + budget.cancel() def test_yearly_budget_crossed_stop2(self): set_total_expense_zero("2013-02-28", "Project") budget = make_budget(budget_against="Project") - + jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 150000, "_Test Cost Center - _TC", project="_Test Project", posting_date="2013-03-28") self.assertRaises(BudgetError, jv.submit) - + budget.cancel() def test_monthly_budget_on_cancellation1(self): set_total_expense_zero("2013-02-28", "Cost Center") budget = make_budget(budget_against="Cost Center") - + jv1 = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date="2013-02-28", submit=True) @@ -170,9 +170,9 @@ class TestBudget(unittest.TestCase): {"voucher_type": "Journal Entry", "voucher_no": jv2.name})) frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") - + self.assertRaises(BudgetError, jv1.cancel) - + budget.load_from_db() budget.cancel() @@ -180,7 +180,7 @@ class TestBudget(unittest.TestCase): set_total_expense_zero("2013-02-28", "Project") budget = make_budget(budget_against="Project") - + jv1 = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date="2013-02-28", submit=True, project="_Test Project") @@ -194,16 +194,16 @@ class TestBudget(unittest.TestCase): {"voucher_type": "Journal Entry", "voucher_no": jv2.name})) frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") - + self.assertRaises(BudgetError, jv1.cancel) - + budget.load_from_db() budget.cancel() def test_monthly_budget_against_group_cost_center(self): set_total_expense_zero("2013-02-28", "Cost Center") set_total_expense_zero("2013-02-28", "Cost Center", "_Test Cost Center 2 - _TC") - + budget = make_budget(budget_against="Cost Center", cost_center="_Test Company - _TC") frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") @@ -211,7 +211,7 @@ class TestBudget(unittest.TestCase): "_Test Bank - _TC", 40000, "_Test Cost Center 2 - _TC", posting_date="2013-02-28") self.assertRaises(BudgetError, jv.submit) - + budget.load_from_db() budget.cancel() @@ -239,8 +239,6 @@ class TestBudget(unittest.TestCase): budget.cancel() jv.cancel() - frappe.delete_doc('Journal Entry', jv.name) - frappe.delete_doc('Cost Center', cost_center) def set_total_expense_zero(posting_date, budget_against_field=None, budget_against_CC=None): if budget_against_field == "Project": @@ -256,7 +254,7 @@ def set_total_expense_zero(posting_date, budget_against_field=None, budget_again "budget_against_field": budget_against_field, "budget_against": budget_against })) - + if existing_expense: if budget_against_field == "Cost Center": make_journal_entry("_Test Account Cost for Goods Sold - _TC", @@ -281,13 +279,13 @@ def make_budget(**args): frappe.db.sql("delete from `tabBudget Account` where parent = %(name)s", d) budget = frappe.new_doc("Budget") - + if budget_against == "Project": budget.project = "_Test Project" else: budget.cost_center =cost_center or "_Test Cost Center - _TC" - - + + budget.fiscal_year = "_Test Fiscal Year 2013" budget.monthly_distribution = "_Test Distribution" budget.company = "_Test Company" @@ -299,7 +297,7 @@ def make_budget(**args): "account": "_Test Account Cost for Goods Sold - _TC", "budget_amount": 100000 }) - + if args.applicable_on_material_request: budget.applicable_on_material_request = 1 budget.action_if_annual_budget_exceeded_on_mr = args.action_if_annual_budget_exceeded_on_mr or 'Warn' diff --git a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py index 56a0d2f39c..4a7406e0cb 100644 --- a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py +++ b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py @@ -49,7 +49,6 @@ class TestLoyaltyProgram(unittest.TestCase): # cancel and delete for d in [si_redeem, si_original]: d.cancel() - frappe.delete_doc('Sales Invoice', d.name) def test_loyalty_points_earned_multiple_tier(self): frappe.db.set_value("Customer", "Test Loyalty Customer", "loyalty_program", "Test Multiple Loyalty") @@ -91,7 +90,6 @@ class TestLoyaltyProgram(unittest.TestCase): # cancel and delete for d in [si_redeem, si_original]: d.cancel() - frappe.delete_doc('Sales Invoice', d.name) def test_cancel_sales_invoice(self): ''' cancelling the sales invoice should cancel the earned points''' @@ -143,7 +141,6 @@ class TestLoyaltyProgram(unittest.TestCase): d.cancel() except frappe.TimestampMismatchError: frappe.get_doc('Sales Invoice', d.name).cancel() - frappe.delete_doc('Sales Invoice', d.name) def test_loyalty_points_for_dashboard(self): doc = frappe.get_doc('Customer', 'Test Loyalty Customer') diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index dff55947df..4f253b69f7 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -818,7 +818,6 @@ class TestSalesInvoice(unittest.TestCase): self.assertEqual(expected_gl_entries[i][2], gle.credit) si.cancel() - frappe.delete_doc('Sales Invoice', si.name) gle = frappe.db.sql("""select * from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s""", si.name) diff --git a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py index 638e57ed2b..b1468999fc 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py @@ -48,7 +48,6 @@ class TestTaxWithholdingCategory(unittest.TestCase): #delete invoices to avoid clashing for d in invoices: d.cancel() - frappe.delete_doc("Purchase Invoice", d.name) def test_single_threshold_tds(self): invoices = [] @@ -83,7 +82,6 @@ class TestTaxWithholdingCategory(unittest.TestCase): # delete invoices to avoid clashing for d in invoices: d.cancel() - frappe.delete_doc("Purchase Invoice", d.name) def test_single_threshold_tds_with_previous_vouchers(self): invoices = [] @@ -102,7 +100,6 @@ class TestTaxWithholdingCategory(unittest.TestCase): # delete invoices to avoid clashing for d in invoices: d.cancel() - frappe.delete_doc("Purchase Invoice", d.name) def create_purchase_invoice(**args): # return sales invoice doc object diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 481ee7d9f4..c09b94fa8e 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -456,8 +456,6 @@ class TestAsset(unittest.TestCase): self.assertEqual(gle, expected_gle) si.cancel() - frappe.delete_doc("Sales Invoice", si.name) - self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Partially Depreciated") def test_asset_expected_value_after_useful_life(self): diff --git a/erpnext/hr/doctype/expense_claim/test_expense_claim.py b/erpnext/hr/doctype/expense_claim/test_expense_claim.py index 6618a4f7c5..b559dfd81d 100644 --- a/erpnext/hr/doctype/expense_claim/test_expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/test_expense_claim.py @@ -45,7 +45,6 @@ class TestExpenseClaim(unittest.TestCase): self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_expense_claim"), 700) expense_claim2.cancel() - frappe.delete_doc("Expense Claim", expense_claim2.name) self.assertEqual(frappe.db.get_value("Task", task_name, "total_expense_claim"), 200) self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_expense_claim"), 200) diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index ededc4d8b4..cd05929743 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -152,7 +152,6 @@ class TestStockReconciliation(unittest.TestCase): for d in to_delete_records: stock_doc = frappe.get_doc("Stock Reconciliation", d) stock_doc.cancel() - frappe.delete_doc("Stock Reconciliation", stock_doc.name) for d in serial_nos + serial_nos1: if frappe.db.exists("Serial No", d): @@ -203,9 +202,6 @@ class TestStockReconciliation(unittest.TestCase): stock_doc = frappe.get_doc("Stock Reconciliation", d) stock_doc.cancel() - frappe.delete_doc("Batch", sr.items[0].batch_no) - for d in to_delete_records: - frappe.delete_doc("Stock Reconciliation", d) def insert_existing_sle(): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry From 063144c514ac4e42112935592380bd15466d6d7a Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Mon, 2 Sep 2019 15:53:28 +0530 Subject: [PATCH 16/17] fix: Check in_patch before adding 'All Item Group' --- erpnext/setup/doctype/item_group/item_group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py index 760b20a476..bb357d8bf8 100644 --- a/erpnext/setup/doctype/item_group/item_group.py +++ b/erpnext/setup/doctype/item_group/item_group.py @@ -27,7 +27,7 @@ class ItemGroup(NestedSet, WebsiteGenerator): def validate(self): super(ItemGroup, self).validate() - if not self.parent_item_group: + if not self.parent_item_group and not frappe.flags.in_test: self.parent_item_group = 'All Item Groups' self.make_route() From 8666ecc26f8bdba6346dddab782c44e7198ccfb3 Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Mon, 2 Sep 2019 17:41:12 +0530 Subject: [PATCH 17/17] fix: Purchase receipt test --- .../stock/doctype/purchase_receipt/test_purchase_receipt.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index d124ae4747..ab9311b480 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -329,6 +329,11 @@ class TestPurchaseReceipt(unittest.TestCase): location = frappe.db.get_value('Serial No', serial_nos[0].name, 'location') self.assertEquals(location, "Test Location") + frappe.db.set_value("Asset", asset, "purchase_receipt", "") + frappe.db.set_value("Purchase Receipt Item", pr.items[0].name, "asset", "") + + pr.load_from_db() + pr.cancel() serial_nos = frappe.get_all('Serial No', {'asset': asset}, 'name') or [] self.assertEquals(len(serial_nos), 0)