From 35b665cb2639f6aa1666985a12b016e5215b605f Mon Sep 17 00:00:00 2001 From: Vishal Dhayagude Date: Mon, 5 Mar 2018 11:10:01 +0530 Subject: [PATCH] [new] Create multiple warehouse address and fetch address to stock entry (#13109) * [new] Create multiple warehouse address and fetch address to stock entry * [fix] Deleted unwanted field and added patch to link warehouse details to Address * [fix] Codacy fixed * [fix] Modified patch for warehouse address * [fix] Modified patch for warehouse address * [fix] Patch updated and removed contact details from stock entry * [fix] Patch Updated --- erpnext/patches.txt | 1 + .../v10_0/update_warehouse_address_details.py | 37 +++++ .../stock/doctype/stock_entry/stock_entry.js | 8 ++ .../doctype/stock_entry/stock_entry.json | 126 +++++++++++++++++- erpnext/stock/doctype/warehouse/warehouse.js | 9 ++ .../stock/doctype/warehouse/warehouse.json | 121 ++++++++++++++++- erpnext/stock/doctype/warehouse/warehouse.py | 5 +- 7 files changed, 302 insertions(+), 5 deletions(-) create mode 100644 erpnext/patches/v10_0/update_warehouse_address_details.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 705d2198aa..a963b53f11 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -492,3 +492,4 @@ erpnext.patches.v10_0.added_extra_gst_custom_field_in_gstr2 #2018-02-13 erpnext.patches.v10_0.set_b2c_limit erpnext.patches.v10_0.set_auto_created_serial_no_in_stock_entry erpnext.patches.v10_0.update_territory_and_customer_group +erpnext.patches.v10_0.update_warehouse_address_details \ No newline at end of file diff --git a/erpnext/patches/v10_0/update_warehouse_address_details.py b/erpnext/patches/v10_0/update_warehouse_address_details.py new file mode 100644 index 0000000000..b982b9a662 --- /dev/null +++ b/erpnext/patches/v10_0/update_warehouse_address_details.py @@ -0,0 +1,37 @@ +# Copyright (c) 2017, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + warehouse = frappe.db.sql("""select name, email_id, phone_no, mobile_no, address_line_1, + address_line_2, city, state, pin from `tabWarehouse` where ifnull(address_line_1, '') != '' + or ifnull(mobile_no, '') != '' + or ifnull(email_id, '') != '' """, as_dict=1) + + for d in warehouse: + try: + address = frappe.new_doc('Address') + address.name = d.name + address.address_title = d.name + address.address_line1 = d.address_line_1 + address.city = d.city + address.state = d.state + address.pincode = d.pin + address.db_insert() + address.append('links',{'link_doctype':'Warehouse','link_name':d.name}) + address.links[0].db_insert() + if d.name and (d.email_id or d.mobile_no or d.phone_no): + contact = frappe.new_doc('Contact') + contact.name = d.name + contact.first_name = d.name + contact.mobile_no = d.mobile_no + contact.email_id = d.email_id + contact.phone = d.phone_no + contact.db_insert() + contact.append('links',{'link_doctype':'Warehouse','link_name':d.name}) + contact.links[0].db_insert() + except frappe.DuplicateEntryError: + pass + \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 9093946d31..d4be6b4755 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -278,6 +278,14 @@ frappe.ui.form.on('Stock Entry', { frm.set_value("total_additional_costs", flt(total_additional_costs, precision("total_additional_costs"))); }, + + source_warehouse_address: function(frm) { + erpnext.utils.get_address_display(frm, 'source_warehouse_address', 'source_address_display', false); + }, + + target_warehouse_address: function(frm) { + erpnext.utils.get_address_display(frm, 'target_warehouse_address', 'target_address_display', false); + }, }) frappe.ui.form.on('Stock Entry Detail', { diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.json b/erpnext/stock/doctype/stock_entry/stock_entry.json index f68690cf8f..f6709baf19 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.json +++ b/erpnext/stock/doctype/stock_entry/stock_entry.json @@ -737,6 +737,68 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "depends_on": "from_warehouse", + "fieldname": "source_warehouse_address", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Source Warehouse Address", + "length": 0, + "no_copy": 0, + "options": "Address", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "source_address_display", + "fieldtype": "Small Text", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Source Warehouse Address", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 1, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_bulk_edit": 0, "allow_on_submit": 0, @@ -797,6 +859,68 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "depends_on": "to_warehouse", + "fieldname": "target_warehouse_address", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Target Warehouse Name", + "length": 0, + "no_copy": 0, + "options": "Address", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "target_address_display", + "fieldtype": "Small Text", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Target Warehouse Address", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 1, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_bulk_edit": 0, "allow_on_submit": 0, @@ -1739,7 +1863,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2017-06-13 14:28:47.818067", + "modified": "2018-03-01 12:27:12.884611", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry", diff --git a/erpnext/stock/doctype/warehouse/warehouse.js b/erpnext/stock/doctype/warehouse/warehouse.js index 5c23a9729a..1bfa416bdf 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.js +++ b/erpnext/stock/doctype/warehouse/warehouse.js @@ -5,6 +5,15 @@ frappe.ui.form.on("Warehouse", { refresh: function(frm) { frm.toggle_display('warehouse_name', frm.doc.__islocal); + frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal); + + + if(!frm.doc.__islocal) { + frappe.contacts.render_address_and_contact(frm); + + } else { + frappe.contacts.clear_address_and_contact(frm); + } frm.add_custom_button(__("Stock Balance"), function() { frappe.set_route("query-report", "Stock Balance", {"warehouse": frm.doc.name}); diff --git a/erpnext/stock/doctype/warehouse/warehouse.json b/erpnext/stock/doctype/warehouse/warehouse.json index b6307a4633..82d0d0c4fb 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.json +++ b/erpnext/stock/doctype/warehouse/warehouse.json @@ -226,6 +226,125 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "address_and_contact", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Address and Contact", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "address_html", + "fieldtype": "HTML", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Address HTML", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "column_break_10", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "contact_html", + "fieldtype": "HTML", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Contact HTML", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_bulk_edit": 0, "allow_on_submit": 0, @@ -699,7 +818,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-01-23 16:45:45.546649", + "modified": "2018-02-28 09:15:33.463838", "modified_by": "Administrator", "module": "Stock", "name": "Warehouse", diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index 5186408721..0eee6baddd 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -7,6 +7,7 @@ from frappe.utils import cint, validate_email_add from frappe import throw, _ from frappe.utils.nestedset import NestedSet from erpnext.stock import get_warehouse_account +from frappe.contacts.address_and_contact import load_address_and_contact class Warehouse(NestedSet): nsm_parent_field = 'parent_warehouse' @@ -25,10 +26,8 @@ class Warehouse(NestedSet): if account: self.set_onload('account', account) + load_address_and_contact(self) - def validate(self): - if self.email_id: - validate_email_add(self.email_id, True) def on_update(self): self.update_nsm_model()