From e2095c0dd7a8184879ad8a9dd395f3ddb98aaeb3 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 1 Sep 2014 11:36:34 +0530 Subject: [PATCH] Created new doctype Party Account to maintain default party account, it is a child table for Customer, Supplier, Customer Group, Supplier type Default Receivable / Payable Account in company Filter results in all receivable/payable link fields --- .../doctype/party_account/__init__.py | 0 .../doctype/party_account/party_account.json | 75 +++++++++++++++++++ .../doctype/party_account/party_account.py | 9 +++ erpnext/buying/doctype/supplier/supplier.js | 25 +++++-- erpnext/buying/doctype/supplier/supplier.json | 15 +++- erpnext/buying/doctype/supplier/supplier.py | 4 +- erpnext/selling/doctype/customer/customer.js | 25 +++++-- .../selling/doctype/customer/customer.json | 26 +++---- erpnext/selling/doctype/customer/customer.py | 4 +- erpnext/setup/doctype/company/company.js | 16 +++- erpnext/setup/doctype/company/company.json | 24 +++--- erpnext/setup/doctype/company/company.py | 12 +-- .../doctype/customer_group/customer_group.js | 11 +++ .../customer_group/customer_group.json | 15 +++- .../doctype/supplier_type/supplier_type.js | 13 +++- .../doctype/supplier_type/supplier_type.json | 15 +++- 16 files changed, 234 insertions(+), 55 deletions(-) create mode 100644 erpnext/accounts/doctype/party_account/__init__.py create mode 100644 erpnext/accounts/doctype/party_account/party_account.json create mode 100644 erpnext/accounts/doctype/party_account/party_account.py diff --git a/erpnext/accounts/doctype/party_account/__init__.py b/erpnext/accounts/doctype/party_account/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/accounts/doctype/party_account/party_account.json b/erpnext/accounts/doctype/party_account/party_account.json new file mode 100644 index 0000000000..14e9250ce8 --- /dev/null +++ b/erpnext/accounts/doctype/party_account/party_account.json @@ -0,0 +1,75 @@ +{ + "allow_copy": 0, + "allow_import": 0, + "allow_rename": 0, + "creation": "2014-08-29 16:02:39.740505", + "custom": 0, + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "fields": [ + { + "allow_on_submit": 0, + "fieldname": "company", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 1, + "label": "Company", + "no_copy": 0, + "options": "Company", + "permlevel": 0, + "print_hide": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0 + }, + { + "fieldname": "col_break1", + "fieldtype": "Column Break", + "label": "col_break1", + "permlevel": 0, + "width": "50%" + }, + { + "allow_on_submit": 0, + "fieldname": "account", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 1, + "label": "Account", + "no_copy": 0, + "options": "Account", + "permlevel": 0, + "print_hide": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0 + } + ], + "hide_heading": 0, + "hide_toolbar": 0, + "in_create": 0, + "in_dialog": 0, + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "modified": "2014-08-29 16:08:49.388820", + "modified_by": "Administrator", + "module": "Accounts", + "name": "Party Account", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "read_only": 0, + "read_only_onload": 0, + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/party_account/party_account.py b/erpnext/accounts/doctype/party_account/party_account.py new file mode 100644 index 0000000000..e5672d42fe --- /dev/null +++ b/erpnext/accounts/doctype/party_account/party_account.py @@ -0,0 +1,9 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class PartyAccount(Document): + pass diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js index 5339067516..39584100a6 100644 --- a/erpnext/buying/doctype/supplier/supplier.js +++ b/erpnext/buying/doctype/supplier/supplier.js @@ -43,12 +43,14 @@ cur_frm.cscript.make_dashboard = function(doc) { }, callback: function(r) { if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) { - cur_frm.dashboard.set_headline( - __("Total Billing This Year: ") + "" - + format_currency(r.message.total_billing, erpnext.get_currency(cur_frm.doc.company)) - + ' / ' + __("Unpaid") + ": " - + format_currency(r.message.total_unpaid, erpnext.get_currency(cur_frm.doc.company)) - + ''); + if(r.message["company_currency"].length == 1) { + cur_frm.dashboard.set_headline( + __("Total Billing This Year: ") + "" + + format_currency(r.message.total_billing, company_currency[0]) + + ' / ' + __("Unpaid") + ": " + + format_currency(r.message.total_unpaid, company_currency[0]) + + ''); + } } cur_frm.dashboard.set_badge_count(r.message); } @@ -99,3 +101,14 @@ cur_frm.fields_dict['default_price_list'].get_query = function(doc, cdt, cdn) { filters:{'buying': 1} } } + +cur_frm.fields_dict['party_accounts'].grid.get_field('account').get_query = function(doc, cdt, cdn) { + var d = locals[cdt][cdn]; + return { + filters: { + 'account_type': 'Payable', + 'company': d.company, + 'group_or_ledger': 'Ledger' + } + } +} diff --git a/erpnext/buying/doctype/supplier/supplier.json b/erpnext/buying/doctype/supplier/supplier.json index 2c2fbff555..1fa295e2b5 100644 --- a/erpnext/buying/doctype/supplier/supplier.json +++ b/erpnext/buying/doctype/supplier/supplier.json @@ -83,6 +83,19 @@ "permlevel": 0, "read_only": 1 }, + { + "fieldname": "default_payable_accounts", + "fieldtype": "Section Break", + "label": "Default Payable Accounts", + "permlevel": 0 + }, + { + "fieldname": "party_accounts", + "fieldtype": "Table", + "label": "Party Accounts", + "options": "Party Account", + "permlevel": 0 + }, { "fieldname": "more_info", "fieldtype": "Section Break", @@ -170,7 +183,7 @@ ], "icon": "icon-user", "idx": 1, - "modified": "2014-09-12 12:26:37.606976", + "modified": "2014-09-10 17:53:09.286715", "modified_by": "Administrator", "module": "Buying", "name": "Supplier", diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index 02983bd37b..afd1f14eb9 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -35,9 +35,6 @@ class Supplier(TransactionBase): self.update_address() self.update_contact() - def get_company_abbr(self): - return frappe.db.sql("select abbr from tabCompany where name=%s", self.company)[0][0] - def validate(self): #validation for Naming Series mandatory field... if frappe.defaults.get_global_default('supp_master_name') == 'Naming Series': @@ -96,5 +93,6 @@ def get_dashboard_info(supplier): out["total_billing"] = billing[0][0] out["total_unpaid"] = billing[0][1] + out["company_currency"] = frappe.db.sql_list("select distinct default_currency from tabCompany") return out diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index 9829ed249c..1f5d1f431f 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -62,12 +62,14 @@ cur_frm.cscript.setup_dashboard = function(doc) { }, callback: function(r) { if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) { - cur_frm.dashboard.set_headline( - __("Total Billing This Year: ") + "" - + format_currency(r.message.total_billing, erpnext.get_currency(cur_frm.doc.company)) - + ' / ' + __("Unpaid") + ": " - + format_currency(r.message.total_unpaid, erpnext.get_currency(cur_frm.doc.company)) - + ''); + if(r.message["company_currency"].length == 1) { + cur_frm.dashboard.set_headline( + __("Total Billing This Year: ") + "" + + format_currency(r.message.total_billing, company_currency[0]) + + ' / ' + __("Unpaid") + ": " + + format_currency(r.message.total_unpaid, company_currency[0]) + + ''); + } } cur_frm.dashboard.set_badge_count(r.message); } @@ -129,3 +131,14 @@ cur_frm.fields_dict['default_price_list'].get_query = function(doc, cdt, cdn) { filters:{'selling': 1} } } + +cur_frm.fields_dict['party_accounts'].grid.get_field('account').get_query = function(doc, cdt, cdn) { + var d = locals[cdt][cdn]; + return { + filters: { + 'account_type': 'Receivable', + 'company': d.company, + 'group_or_ledger': 'Ledger' + } + } +} diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json index bb481faa75..557334ad36 100644 --- a/erpnext/selling/doctype/customer/customer.json +++ b/erpnext/selling/doctype/customer/customer.json @@ -129,6 +129,19 @@ "permlevel": 0, "read_only": 1 }, + { + "fieldname": "default_receivable_accounts", + "fieldtype": "Section Break", + "label": "Default Receivable Accounts", + "permlevel": 0 + }, + { + "fieldname": "party_accounts", + "fieldtype": "Table", + "label": "Party Accounts", + "options": "Party Account", + "permlevel": 0 + }, { "fieldname": "more_info", "fieldtype": "Section Break", @@ -143,19 +156,6 @@ "permlevel": 0, "width": "50%" }, - { - "description": "To create an Account Head under a different company, select the company and save customer.", - "fieldname": "company", - "fieldtype": "Link", - "in_filter": 1, - "label": "Company", - "oldfieldname": "company", - "oldfieldtype": "Link", - "options": "Company", - "permlevel": 0, - "reqd": 1, - "search_index": 1 - }, { "description": "Your Customer's TAX registration numbers (if applicable) or any general information", "fieldname": "customer_details", diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 4d0642c0c5..dc5ae7d563 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -22,9 +22,6 @@ class Customer(TransactionBase): else: self.name = make_autoname(self.naming_series+'.#####') - def get_company_abbr(self): - return frappe.db.get_value('Company', self.company, 'abbr') - def validate_values(self): if frappe.defaults.get_global_default('cust_master_name') == 'Naming Series' and not self.naming_series: frappe.throw(_("Series is mandatory"), frappe.MandatoryError) @@ -130,6 +127,7 @@ def get_dashboard_info(customer): out["total_billing"] = billing[0][0] out["total_unpaid"] = billing[0][1] + out["company_currency"] = frappe.db.sql_list("select distinct default_currency from tabCompany") return out diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js index 2e5898e5ea..090c30841a 100644 --- a/erpnext/setup/doctype/company/company.js +++ b/erpnext/setup/doctype/company/company.js @@ -87,16 +87,26 @@ cur_frm.fields_dict.default_bank_account.get_query = function(doc) { cur_frm.fields_dict.default_cash_account.get_query = cur_frm.fields_dict.default_bank_account.get_query; -cur_frm.fields_dict.receivables_group.get_query = function(doc) { +cur_frm.fields_dict.default_receivable_account.get_query = function(doc) { return{ filters:{ 'company': doc.name, - 'group_or_ledger': "Group" + 'group_or_ledger': "Ledger", + "account_type": "Receivable" + } + } +} + +cur_frm.fields_dict.default_payable_account.get_query = function(doc) { + return{ + filters:{ + 'company': doc.name, + 'group_or_ledger': "Ledger", + "account_type": "Payable" } } } -cur_frm.fields_dict.payables_group.get_query = cur_frm.fields_dict.receivables_group.get_query; cur_frm.fields_dict.default_expense_account.get_query = function(doc) { diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index 70ca8443b4..3439f0a9b1 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -60,6 +60,13 @@ "permlevel": 0, "reqd": 0 }, + { + "fieldname": "charts_section", + "fieldtype": "Section Break", + "hidden": 0, + "label": "Chart of Accounts", + "permlevel": 0 + }, { "fieldname": "country", "fieldtype": "Link", @@ -69,13 +76,6 @@ "permlevel": 0, "reqd": 1 }, - { - "fieldname": "charts_section", - "fieldtype": "Section Break", - "hidden": 0, - "label": "Chart of Accounts", - "permlevel": 0 - }, { "fieldname": "chart_of_accounts", "fieldtype": "Select", @@ -118,10 +118,10 @@ }, { "depends_on": "eval:!doc.__islocal", - "fieldname": "receivables_group", + "fieldname": "default_receivable_account", "fieldtype": "Link", "ignore_user_permissions": 1, - "label": "Receivables Group", + "label": "Default Receivable Account", "no_copy": 1, "oldfieldname": "receivables_group", "oldfieldtype": "Link", @@ -131,10 +131,10 @@ }, { "depends_on": "eval:!doc.__islocal", - "fieldname": "payables_group", + "fieldname": "default_payable_account", "fieldtype": "Link", "ignore_user_permissions": 1, - "label": "Payables Group", + "label": "Default Payable Account", "no_copy": 1, "oldfieldname": "payables_group", "oldfieldtype": "Link", @@ -356,7 +356,7 @@ ], "icon": "icon-building", "idx": 1, - "modified": "2014-08-25 17:11:09.320856", + "modified": "2014-08-29 15:50:18.539228", "modified_by": "Administrator", "module": "Setup", "name": "Company", diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index c3149dfae5..9a60b9cb04 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -39,7 +39,7 @@ class Company(Document): self.validate_default_accounts() def validate_default_accounts(self): - for field in ["default_bank_account", "default_cash_account", "receivables_group", "payables_group", + for field in ["default_bank_account", "default_cash_account", "default_receivable_account", "default_payable_account", "default_expense_account", "default_income_account", "stock_received_but_not_billed", "stock_adjustment_account", "expenses_included_in_valuation"]: if self.get(field): @@ -55,8 +55,7 @@ class Company(Document): self.create_default_warehouses() self.install_country_fixtures() - if not frappe.db.get_value("Cost Center", {"group_or_ledger": "Ledger", - "company": self.name}): + if not frappe.db.get_value("Cost Center", {"group_or_ledger": "Ledger", "company": self.name}): self.create_default_cost_center() self.set_default_accounts() @@ -87,8 +86,11 @@ class Company(Document): create_charts(self.chart_of_accounts, self.name) else: self.create_standard_accounts() - frappe.db.set(self, "receivables_group", _("Accounts Receivable") + " - " + self.abbr) - frappe.db.set(self, "payables_group", _("Accounts Payable") + " - " + self.abbr) + + frappe.db.set(self, "default_receivable_account", frappe.db.get_value("Account", + {"company": self.name, "account_type": "Receivable"})) + frappe.db.set(self, "default_payable_account", frappe.db.get_value("Account", + {"company": self.name, "account_type": "Payable"})) def add_acc(self, lst): account = frappe.get_doc({ diff --git a/erpnext/setup/doctype/customer_group/customer_group.js b/erpnext/setup/doctype/customer_group/customer_group.js index 2e8cd7e6c4..902f4a6288 100644 --- a/erpnext/setup/doctype/customer_group/customer_group.js +++ b/erpnext/setup/doctype/customer_group/customer_group.js @@ -25,3 +25,14 @@ cur_frm.fields_dict['parent_customer_group'].get_query = function(doc,cdt,cdn) { } } } + +cur_frm.fields_dict['party_accounts'].grid.get_field('account').get_query = function(doc, cdt, cdn) { + var d = locals[cdt][cdn]; + return { + filters: { + 'account_type': 'Receivable', + 'company': d.company, + 'group_or_ledger': 'Ledger' + } + } +} diff --git a/erpnext/setup/doctype/customer_group/customer_group.json b/erpnext/setup/doctype/customer_group/customer_group.json index 7490158261..5e1ccab72a 100644 --- a/erpnext/setup/doctype/customer_group/customer_group.json +++ b/erpnext/setup/doctype/customer_group/customer_group.json @@ -108,12 +108,25 @@ "permlevel": 0, "print_hide": 1, "report_hide": 1 + }, + { + "fieldname": "default_receivable_account", + "fieldtype": "Section Break", + "label": "Default Receivable Account", + "permlevel": 0 + }, + { + "fieldname": "party_accounts", + "fieldtype": "Table", + "label": "Party Accounts", + "options": "Party Account", + "permlevel": 0 } ], "icon": "icon-sitemap", "idx": 1, "in_create": 1, - "modified": "2014-08-27 17:41:35.154380", + "modified": "2014-08-29 16:37:35.877256", "modified_by": "Administrator", "module": "Setup", "name": "Customer Group", diff --git a/erpnext/setup/doctype/supplier_type/supplier_type.js b/erpnext/setup/doctype/supplier_type/supplier_type.js index 0949b6a033..f54edca92c 100644 --- a/erpnext/setup/doctype/supplier_type/supplier_type.js +++ b/erpnext/setup/doctype/supplier_type/supplier_type.js @@ -3,4 +3,15 @@ cur_frm.cscript.refresh = function(doc) { cur_frm.set_intro(doc.__islocal ? "" : __("There is nothing to edit.")) -} \ No newline at end of file +} + +cur_frm.fields_dict['party_accounts'].grid.get_field('account').get_query = function(doc, cdt, cdn) { + var d = locals[cdt][cdn]; + return { + filters: { + 'account_type': 'Payable', + 'company': d.company, + 'group_or_ledger': 'Ledger' + } + } +} diff --git a/erpnext/setup/doctype/supplier_type/supplier_type.json b/erpnext/setup/doctype/supplier_type/supplier_type.json index e44e9a80a5..51ffb2a24f 100644 --- a/erpnext/setup/doctype/supplier_type/supplier_type.json +++ b/erpnext/setup/doctype/supplier_type/supplier_type.json @@ -22,11 +22,24 @@ "fieldtype": "Int", "label": "Credit Days", "permlevel": 1 + }, + { + "fieldname": "default_payable_account", + "fieldtype": "Section Break", + "label": "Default Payable Account", + "permlevel": 0 + }, + { + "fieldname": "party_accounts", + "fieldtype": "Table", + "label": "Party Accounts", + "options": "Party Account", + "permlevel": 0 } ], "icon": "icon-flag", "idx": 1, - "modified": "2014-08-27 17:43:31.479133", + "modified": "2014-08-29 16:38:22.219286", "modified_by": "Administrator", "module": "Setup", "name": "Supplier Type",