From cdba02180291d31dce62b32f4e3463f112e1a831 Mon Sep 17 00:00:00 2001 From: Manas Solanki Date: Wed, 21 Jun 2017 16:52:49 +0530 Subject: [PATCH 1/3] patch for removing the address field from company and creating address doc, fixes #9011 --- erpnext/patches.txt | 1 + ...dress_doc_from_address_field_in_company.py | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 80d64e8ae55..d83363852cc 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -406,6 +406,7 @@ erpnext.patches.v8_0.change_in_words_varchar_length erpnext.patches.v8_0.update_stock_qty_value_in_bom_item erpnext.patches.v8_0.create_domain_docs #16-05-2017 erpnext.patches.v8_0.update_sales_cost_in_project +erpnext.patches.v8_0.create_address_doc_from_address_field_in_company #10-05-2017 erpnext.patches.v8_0.save_system_settings erpnext.patches.v8_1.delete_deprecated_reports erpnext.patches.v8_1.setup_gst_india #2017-06-27 diff --git a/erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py b/erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py new file mode 100644 index 00000000000..6e248555f3d --- /dev/null +++ b/erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py @@ -0,0 +1,33 @@ +# Copyright (c) 2017, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + # new field address_html is created in place of address field for the company's address + # patch for moving the address details in the address doc + company_list = [] + if frappe.db.sql("SHOW COLUMNS FROM `tabCompany` LIKE 'address'"): + company_list = frappe.db.sql('''select name, address from `tabCompany` where address is not null''', as_dict=1) + + for company in company_list: + add_list = company.address.split(" ") + if ',' in company.address: + add_list = company.address.rpartition(',') + elif ' ' in company.address: + add_list = company.address.rpartition(' ') + else: + add_list = [company.address, None, company.address] + + doc = frappe.get_doc({ + "doctype":"Address", + "address_line1": add_list[0], + "city": add_list[2], + "is_your_company_address":1, + "links": [{ + "link_doctype": "Company", + "link_name": company.name + }] + }) + doc.save() From 1a0536bff4cccff502b9d68a058f2c6767eb96ca Mon Sep 17 00:00:00 2001 From: Manas Solanki Date: Tue, 11 Jul 2017 11:10:14 +0530 Subject: [PATCH 2/3] changes as per review --- .../create_address_doc_from_address_field_in_company.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py b/erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py index 6e248555f3d..822d9f027b2 100644 --- a/erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py +++ b/erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py @@ -5,10 +5,10 @@ from __future__ import unicode_literals import frappe def execute(): - # new field address_html is created in place of address field for the company's address - # patch for moving the address details in the address doc + # new field address_html is created in place of address field for the company's address in PR #8754 (without patch) + # so here is the patch for moving the address details in the address doc company_list = [] - if frappe.db.sql("SHOW COLUMNS FROM `tabCompany` LIKE 'address'"): + if 'address' in frappe.db.get_table_columns('Company'): company_list = frappe.db.sql('''select name, address from `tabCompany` where address is not null''', as_dict=1) for company in company_list: @@ -24,7 +24,6 @@ def execute(): "doctype":"Address", "address_line1": add_list[0], "city": add_list[2], - "is_your_company_address":1, "links": [{ "link_doctype": "Company", "link_name": company.name From 3a200bbc447ee05c650bbd592a331b2817c9a498 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 11 Jul 2017 11:34:27 +0530 Subject: [PATCH 3/3] Update create_address_doc_from_address_field_in_company.py --- .../v8_0/create_address_doc_from_address_field_in_company.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py b/erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py index 822d9f027b2..cf1bc5af057 100644 --- a/erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py +++ b/erpnext/patches/v8_0/create_address_doc_from_address_field_in_company.py @@ -9,7 +9,8 @@ def execute(): # so here is the patch for moving the address details in the address doc company_list = [] if 'address' in frappe.db.get_table_columns('Company'): - company_list = frappe.db.sql('''select name, address from `tabCompany` where address is not null''', as_dict=1) + company_list = frappe.db.sql('''select name, address from `tabCompany` + where address is not null and address != ""''', as_dict=1) for company in company_list: add_list = company.address.split(" ")