From 37982a6a1fc29a8e2516ebabf4a803abd57bb4b0 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 14 Jun 2013 13:29:20 +0530 Subject: [PATCH] [contact/address] fixed auto setting closes #475 (erpnext) --- .../purchase_invoice/purchase_invoice.js | 11 ---- .../doctype/purchase_order/purchase_order.js | 11 ---- buying/doctype/supplier/supplier.js | 20 ------- .../supplier_quotation/supplier_quotation.js | 10 ---- controllers/js/contact_address_common.js | 27 +++++++++ docs/docs.user.setup.accounting.md | 55 ++----------------- docs/docs.user.setup.cost_centers.md | 54 ++++++++++++++++++ docs/docs.user.setup.md | 1 + selling/doctype/customer/customer.js | 23 -------- .../installation_note/installation_note.js | 10 ---- selling/doctype/opportunity/opportunity.js | 10 ---- selling/doctype/sales_common/sales_common.js | 10 ---- .../purchase_receipt/purchase_receipt.js | 12 ---- .../doctype/customer_issue/customer_issue.js | 10 ---- .../maintenance_schedule.js | 10 ---- .../maintenance_visit/maintenance_visit.js | 10 ---- utilities/doctype/address/address.js | 8 +-- utilities/doctype/contact/contact.js | 10 +--- 18 files changed, 91 insertions(+), 211 deletions(-) create mode 100644 controllers/js/contact_address_common.js create mode 100644 docs/docs.user.setup.cost_centers.md diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.js b/accounts/doctype/purchase_invoice/purchase_invoice.js index c6a787e50a..fa58d9fda7 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -71,17 +71,6 @@ cur_frm.cscript.supplier_address = cur_frm.cscript.contact_person = function(doc if(doc.supplier) get_server_fields('get_supplier_address', JSON.stringify({supplier: doc.supplier, address: doc.supplier_address, contact: doc.contact_person}),'', doc, dt, dn, 1); } -cur_frm.fields_dict.supplier_address.on_new = function(dn) { - locals['Address'][dn].supplier = locals[cur_frm.doctype][cur_frm.docname].supplier; - locals['Address'][dn].supplier_name = locals[cur_frm.doctype][cur_frm.docname].supplier_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].supplier = locals[cur_frm.doctype][cur_frm.docname].supplier; - locals['Contact'][dn].supplier_name = locals[cur_frm.doctype][cur_frm.docname].supplier_name; -} - - cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){ cl = getchildren('Purchase Invoice Item', doc.name, cur_frm.cscript.fname, doc.doctype); diff --git a/buying/doctype/purchase_order/purchase_order.js b/buying/doctype/purchase_order/purchase_order.js index 64aa9136a4..442925131a 100644 --- a/buying/doctype/purchase_order/purchase_order.js +++ b/buying/doctype/purchase_order/purchase_order.js @@ -56,17 +56,6 @@ cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; } - -cur_frm.fields_dict.supplier_address.on_new = function(dn) { - locals['Address'][dn].supplier = locals[cur_frm.doctype][cur_frm.docname].supplier; - locals['Address'][dn].supplier_name = locals[cur_frm.doctype][cur_frm.docname].supplier_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].supplier = locals[cur_frm.doctype][cur_frm.docname].supplier; - locals['Contact'][dn].supplier_name = locals[cur_frm.doctype][cur_frm.docname].supplier_name; -} - cur_frm.fields_dict['po_details'].grid.get_field('project_name').get_query = function(doc, cdt, cdn) { return 'SELECT `tabProject`.name FROM `tabProject` \ WHERE `tabProject`.status not in ("Completed", "Cancelled") \ diff --git a/buying/doctype/supplier/supplier.js b/buying/doctype/supplier/supplier.js index 202be71dfe..d364655610 100644 --- a/buying/doctype/supplier/supplier.js +++ b/buying/doctype/supplier/supplier.js @@ -49,19 +49,6 @@ cur_frm.cscript.make_address = function() { parent: cur_frm.fields_dict['address_html'].wrapper, page_length: 5, new_doctype: "Address", - custom_new_doc: function(doctype) { - var address = wn.model.make_new_doc_and_get_name('Address'); - address = locals['Address'][address]; - address.supplier = cur_frm.doc.name; - address.supplier_name = cur_frm.doc.supplier_name; - address.address_title = cur_frm.doc.supplier_name; - - if(!(cur_frm.address_list.data && cur_frm.address_list.data.length)) { - address.address_type = "Office"; - } - - wn.set_route("Form", "Address", address.name); - }, get_query: function() { return "select name, address_type, address_line1, address_line2, city, state, country, pincode, fax, email_id, phone, is_primary_address, is_shipping_address from tabAddress where supplier='"+cur_frm.docname+"' and docstatus != 2 order by is_primary_address desc" }, @@ -80,13 +67,6 @@ cur_frm.cscript.make_contact = function() { parent: cur_frm.fields_dict['contact_html'].wrapper, page_length: 5, new_doctype: "Contact", - custom_new_doc: function(doctype) { - var contact = wn.model.make_new_doc_and_get_name('Contact'); - contact = locals['Contact'][contact]; - contact.supplier = cur_frm.doc.name; - contact.supplier_name = cur_frm.doc.supplier_name; - wn.set_route("Form", "Contact", contact.name); - }, get_query: function() { return "select name, first_name, last_name, email_id, phone, mobile_no, department, designation, is_primary_contact from tabContact where supplier='"+cur_frm.docname+"' and docstatus != 2 order by is_primary_contact desc" }, diff --git a/buying/doctype/supplier_quotation/supplier_quotation.js b/buying/doctype/supplier_quotation/supplier_quotation.js index 20a20ac5a5..0ed85ff2f9 100644 --- a/buying/doctype/supplier_quotation/supplier_quotation.js +++ b/buying/doctype/supplier_quotation/supplier_quotation.js @@ -87,13 +87,3 @@ cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { department, designation FROM tabContact WHERE supplier = \"" + doc.supplier +"\" AND docstatus != 2 AND name LIKE \"%s\" ORDER BY name ASC LIMIT 50"; } - -cur_frm.fields_dict.supplier_address.on_new = function(dn) { - locals['Address'][dn].supplier = locals[cur_frm.doctype][cur_frm.docname].supplier; - locals['Address'][dn].supplier_name = locals[cur_frm.doctype][cur_frm.docname].supplier_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].supplier = locals[cur_frm.doctype][cur_frm.docname].supplier; - locals['Contact'][dn].supplier_name = locals[cur_frm.doctype][cur_frm.docname].supplier_name; -} \ No newline at end of file diff --git a/controllers/js/contact_address_common.js b/controllers/js/contact_address_common.js new file mode 100644 index 0000000000..ca9e084f5c --- /dev/null +++ b/controllers/js/contact_address_common.js @@ -0,0 +1,27 @@ +cur_frm.cscript.onload = function(doc, cdt, cdn) { + cur_frm.add_fetch('customer', 'customer_name', 'customer_name'); + cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name'); + + cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; + cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query; + + if(doc.__islocal) { + var last_route = wn.route_history.slice(-2, -1)[0]; + if(last_route && last_route[0]==="Form") { + if(["Customer", "Quotation", "Sales Order", "Sales Invoice", "Delivery Note", + "Installation Note", "Opportunity", "Customer Issue", "Maintenance Visit", + "Maintenance Schedule"] + .indexOf(last_route[1])!==-1) { + var refdoc = wn.model.get_doc(last_route[1], last_route[2]); + cur_frm.set_value("customer", refdoc.customer || refdoc.name); + cur_frm.set_value("customer_name", refdoc.customer_name); + } + if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"] + .indexOf(last_route[1])!==-1) { + var customer = wn.model.get_doc(last_route[1], last_route[2]); + cur_frm.set_value("supplier", refdoc.supplier || refdoc.name); + cur_frm.set_value("supplier_name", refdoc.supplier_name); + } + } + } +} diff --git a/docs/docs.user.setup.accounting.md b/docs/docs.user.setup.accounting.md index 152530ecc9..b40b2218f6 100644 --- a/docs/docs.user.setup.accounting.md +++ b/docs/docs.user.setup.accounting.md @@ -32,6 +32,8 @@ For each company, Chart of Accounts signifies the way to classify the accounting Let us understand the main groups of the Chart of Accounts. +![Chart of Accounts: Root Accounts](img/chart-of-accounts.png) + ### Balance Sheet Accounts The Balance Sheet has Application of Funds (Assets) and Sources of Funds (Liabilities) that signify the net-worth of your company at any given time. When you begin or end a financial period, all the Assets are equal to the Liabilities. @@ -60,6 +62,8 @@ Accounting Transactions can only be made against Ledger Accounts (not Groups) > Note: An Account “Ledger” is also sometimes called as Account “Head”. +![Chart of Accounts: Groups and Ledger](img/chart-of-accounts-1.png) + ### Other Account Types In ERPNext, you can also specify more information when you create a new Account, this is there to help you select that particular account in a scenario like Bank Account or a Tax Account and has no affect on the Chart itself. @@ -70,6 +74,8 @@ You can also tag if an account represents a Customer, Supplier or Employee in "M To create new Accounts, explore your Chart of Accounts and click on an Account group under which you want to create the new Account. On the right side, you will see a options to “Edit” or “Add” a new Account. +![Chart of Accounts: New Account](img/chart-of-accounts-2.png) + Option to create will only appear if you click on a Group (folder) type Account. ERPNext creates a standard structure for you when the Company is created but it is up to you to modify or add or remove accounts. @@ -80,52 +86,3 @@ Typically, you might want to create Accounts for - Taxes (VAT, Sales Tax etc based on your country) under Current Liabilities. - Types of Sales (for example, Product Sales, Service Sales etc.) under Income. - Types of Assets (building, machinery, furniture etc.) under Fixed Assets. - ---- - -## Chart of Cost Centers - -Your Chart of Accounts is mainly for reporting your information for governmental purposes and less for how you business actually performs. Though you can tweak it a bit to resemble your business. - -Most businesses have multiple activities like different product lines, market segments, areas of business that share some common overheads but should ideally have their own structure to report whether they are profitable or not. For this purpose, there is an alternate structure, called the Chart of Cost Centers. - -You can create a tree of Cost Centers to represent your business better. Each Income / Expense entry is also tagged against a Cost Center. - -For example, if you have two types of sales: - -- Walk-in Sales -- Online Sales - -You may not have shipping expenses for your walk-in customers, and no shop-rent for your online customers. If you want to get the profitability of each of these separately, you create the two as Cost Centers and you can mark all sales as either "Walk-in" or "Online" and also all your purchases in the same way. - -So when you do your analysis you can get a better idea which side of your business is doing better. Since ERPNext has option to add multiple Companies, you can create Cost Centers for each Company and manage it separately. - -To setup your Chart of Cost Centers go to: - -> Accounts > Chart of Cost Centers - -Cost centers help you in one more activity, budgeting. - -### Budgeting - -ERPNext will help you set and manage budgets on your Cost Centers. This is useful when, for example, you are doing online sales and you have a budget for search ads and you want ERPNext to stop or warn you from over spending based on that budget. - -Budgets are also great for planning purposes. When you are making your plans for the next financial year, you would typically target a revenue and based on that you would set your expenses. Setting a budget will ensure that your expenses do not get out of hand at any point based on your plans. - -You can define it in the Cost Center. If you have seasonal sales you can also define a budget distribution that the budget will follow. - -#### Budget Actions - -ERPNext allows you to either: - -- Stop. -- Warn or, -- Ignore - -if you exceed budgets. - -These can be defined from the Company record. - -Even if you choose to “ignore” budget overruns, you will get a wealth of information from the “Budget vs Actual” variance report. - -> Note: When you set a budget, it has to be set per Account under the Cost Center. For example if you have a Cost Center “Online Sales”, you can restrict “Advertising Budget” by creating a row with that Account and defining the amount. \ No newline at end of file diff --git a/docs/docs.user.setup.cost_centers.md b/docs/docs.user.setup.cost_centers.md new file mode 100644 index 0000000000..14498eddeb --- /dev/null +++ b/docs/docs.user.setup.cost_centers.md @@ -0,0 +1,54 @@ +--- +{ + "_label": "Cost Centers and Budgeting", + "_links": [ + "docs.user.accounts" + ] +} +--- +## Chart of Cost Centers + +Your Chart of Accounts is mainly for reporting your information for governmental purposes and less for how you business actually performs. Though you can tweak it a bit to resemble your business. + +Most businesses have multiple activities like different product lines, market segments, areas of business that share some common overheads but should ideally have their own structure to report whether they are profitable or not. For this purpose, there is an alternate structure, called the Chart of Cost Centers. + +You can create a tree of Cost Centers to represent your business better. Each Income / Expense entry is also tagged against a Cost Center. + +For example, if you have two types of sales: + +- Walk-in Sales +- Online Sales + +You may not have shipping expenses for your walk-in customers, and no shop-rent for your online customers. If you want to get the profitability of each of these separately, you create the two as Cost Centers and you can mark all sales as either "Walk-in" or "Online" and also all your purchases in the same way. + +So when you do your analysis you can get a better idea which side of your business is doing better. Since ERPNext has option to add multiple Companies, you can create Cost Centers for each Company and manage it separately. + +To setup your Chart of Cost Centers go to: + +> Accounts > Chart of Cost Centers + +Cost centers help you in one more activity, budgeting. + +### Budgeting + +ERPNext will help you set and manage budgets on your Cost Centers. This is useful when, for example, you are doing online sales and you have a budget for search ads and you want ERPNext to stop or warn you from over spending based on that budget. + +Budgets are also great for planning purposes. When you are making your plans for the next financial year, you would typically target a revenue and based on that you would set your expenses. Setting a budget will ensure that your expenses do not get out of hand at any point based on your plans. + +You can define it in the Cost Center. If you have seasonal sales you can also define a budget distribution that the budget will follow. + +#### Budget Actions + +ERPNext allows you to either: + +- Stop. +- Warn or, +- Ignore + +if you exceed budgets. + +These can be defined from the Company record. + +Even if you choose to “ignore” budget overruns, you will get a wealth of information from the “Budget vs Actual” variance report. + +> Note: When you set a budget, it has to be set per Account under the Cost Center. For example if you have a Cost Center “Online Sales”, you can restrict “Advertising Budget” by creating a row with that Account and defining the amount. \ No newline at end of file diff --git a/docs/docs.user.setup.md b/docs/docs.user.setup.md index ecada5386e..a33e34f43a 100644 --- a/docs/docs.user.setup.md +++ b/docs/docs.user.setup.md @@ -6,6 +6,7 @@ "docs.user.setup.strategy", "docs.user.setup.first", "docs.user.setup.accounting", + "docs.user.setup.cost_centers", "docs.user.setup.item", "docs.user.setup.customer", "docs.user.setup.supplier", diff --git a/selling/doctype/customer/customer.js b/selling/doctype/customer/customer.js index 40a7846430..35a6f59a03 100644 --- a/selling/doctype/customer/customer.js +++ b/selling/doctype/customer/customer.js @@ -59,19 +59,6 @@ cur_frm.cscript.make_address = function() { parent: cur_frm.fields_dict['address_html'].wrapper, page_length: 5, new_doctype: "Address", - custom_new_doc: function(doctype) { - var address = wn.model.make_new_doc_and_get_name('Address'); - address = locals['Address'][address]; - address.customer = cur_frm.doc.name; - address.customer_name = cur_frm.doc.customer_name; - address.address_title = cur_frm.doc.customer_name; - - if(!(cur_frm.address_list.data && cur_frm.address_list.data.length)) { - address.address_type = "Office"; - } - - wn.set_route("Form", "Address", address.name); - }, get_query: function() { return "select name, address_type, address_line1, address_line2, city, state, country, pincode, fax, email_id, phone, is_primary_address, is_shipping_address from tabAddress where customer='"+cur_frm.docname+"' and docstatus != 2 order by is_primary_address desc" }, @@ -89,16 +76,6 @@ cur_frm.cscript.make_contact = function() { cur_frm.contact_list = new wn.ui.Listing({ parent: cur_frm.fields_dict['contact_html'].wrapper, page_length: 5, - custom_new_doc: function(doctype) { - var contact = wn.model.make_new_doc_and_get_name('Contact'); - contact = locals['Contact'][contact]; - contact.customer = cur_frm.doc.name; - contact.customer_name = cur_frm.doc.customer_name; - if(cur_frm.doc.customer_type == 'Individual') { - contact.first_name = cur_frm.doc.customer_name; - } - wn.set_route("Form", "Contact", contact.name); - }, new_doctype: "Contact", get_query: function() { return "select name, first_name, last_name, email_id, phone, mobile_no, department, designation, is_primary_contact from tabContact where customer='"+cur_frm.docname+"' and docstatus != 2 order by is_primary_contact desc" diff --git a/selling/doctype/installation_note/installation_note.js b/selling/doctype/installation_note/installation_note.js index 64c6e98a23..b0e005eb0b 100644 --- a/selling/doctype/installation_note/installation_note.js +++ b/selling/doctype/installation_note/installation_note.js @@ -65,16 +65,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1); } -cur_frm.fields_dict.customer_address.on_new = function(dn) { - locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; } diff --git a/selling/doctype/opportunity/opportunity.js b/selling/doctype/opportunity/opportunity.js index dc322ebf58..3a56d4dbcb 100644 --- a/selling/doctype/opportunity/opportunity.js +++ b/selling/doctype/opportunity/opportunity.js @@ -122,16 +122,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1); } -cur_frm.fields_dict.customer_address.on_new = function(dn) { - locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { return 'SELECT name, address_line1, city FROM tabAddress \ WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND \ diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js index ef23bab59a..0a7bef7e2f 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -548,16 +548,6 @@ cur_frm.fields_dict[cur_frm.cscript.fname].grid.get_field('batch_no').get_query } } -cur_frm.fields_dict.customer_address.on_new = function(dn) { - locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { return 'SELECT name, address_line1, city FROM tabAddress \ WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND \ diff --git a/stock/doctype/purchase_receipt/purchase_receipt.js b/stock/doctype/purchase_receipt/purchase_receipt.js index f405a5501e..0f656c4507 100644 --- a/stock/doctype/purchase_receipt/purchase_receipt.js +++ b/stock/doctype/purchase_receipt/purchase_receipt.js @@ -94,18 +94,6 @@ cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) { return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE supplier = "'+ doc.supplier +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; } - -cur_frm.fields_dict.supplier_address.on_new = function(dn) { - locals['Address'][dn].supplier = locals[cur_frm.doctype][cur_frm.docname].supplier; - locals['Address'][dn].supplier_name = locals[cur_frm.doctype][cur_frm.docname].supplier_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].supplier = locals[cur_frm.doctype][cur_frm.docname].supplier; - locals['Contact'][dn].supplier_name = locals[cur_frm.doctype][cur_frm.docname].supplier_name; -} - - // Get Purchase Order Button // ----------------- cur_frm.cscript.pull_purchase_order_details = function(doc, dt, dn) { diff --git a/support/doctype/customer_issue/customer_issue.js b/support/doctype/customer_issue/customer_issue.js index 523b240172..0f3007ea10 100644 --- a/support/doctype/customer_issue/customer_issue.js +++ b/support/doctype/customer_issue/customer_issue.js @@ -46,16 +46,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1); } -cur_frm.fields_dict.customer_address.on_new = function(dn) { - locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer + '" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.js b/support/doctype/maintenance_schedule/maintenance_schedule.js index a931327d35..30fbecf832 100644 --- a/support/doctype/maintenance_schedule/maintenance_schedule.js +++ b/support/doctype/maintenance_schedule/maintenance_schedule.js @@ -39,16 +39,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1); } -cur_frm.fields_dict.customer_address.on_new = function(dn) { - locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; } diff --git a/support/doctype/maintenance_visit/maintenance_visit.js b/support/doctype/maintenance_visit/maintenance_visit.js index a53c0903c0..3514a3a710 100644 --- a/support/doctype/maintenance_visit/maintenance_visit.js +++ b/support/doctype/maintenance_visit/maintenance_visit.js @@ -45,16 +45,6 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1); } -cur_frm.fields_dict.customer_address.on_new = function(dn) { - locals['Address'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Address'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - -cur_frm.fields_dict.contact_person.on_new = function(dn) { - locals['Contact'][dn].customer = locals[cur_frm.doctype][cur_frm.docname].customer; - locals['Contact'][dn].customer_name = locals[cur_frm.doctype][cur_frm.docname].customer_name; -} - cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) { return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50'; } diff --git a/utilities/doctype/address/address.js b/utilities/doctype/address/address.js index a11dd05b6d..f17f8236ca 100644 --- a/utilities/doctype/address/address.js +++ b/utilities/doctype/address/address.js @@ -14,10 +14,4 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -cur_frm.cscript.onload = function(doc, cdt, cdn) { - cur_frm.add_fetch('customer', 'customer_name', 'customer_name'); - cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name'); - - cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; - cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query; -} \ No newline at end of file +wn.require('app/controllers/js/contact_address_common.js'); \ No newline at end of file diff --git a/utilities/doctype/contact/contact.js b/utilities/doctype/contact/contact.js index 5f15327009..1dfa45409c 100644 --- a/utilities/doctype/contact/contact.js +++ b/utilities/doctype/contact/contact.js @@ -14,13 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -cur_frm.cscript.onload = function(doc, cdt, cdn) { - cur_frm.add_fetch('customer', 'customer_name', 'customer_name'); - cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name'); - - cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; - cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query; -} +wn.require('app/controllers/js/contact_address_common.js'); cur_frm.cscript.refresh = function(doc) { cur_frm.communication_view = new wn.views.CommunicationList({ @@ -28,7 +22,7 @@ cur_frm.cscript.refresh = function(doc) { parent: cur_frm.fields_dict.communication_html.wrapper, doc: doc, recipients: doc.email_id - }) + }); } cur_frm.cscript.hide_dialog = function() {