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
This commit is contained in:
Nabin Hait 2014-09-01 11:36:34 +05:30
parent 3225102eb9
commit e2095c0dd7
16 changed files with 234 additions and 55 deletions

View File

@ -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"
}

View File

@ -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

View File

@ -43,12 +43,14 @@ cur_frm.cscript.make_dashboard = function(doc) {
}, },
callback: function(r) { callback: function(r) {
if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) { if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) {
cur_frm.dashboard.set_headline( if(r.message["company_currency"].length == 1) {
__("Total Billing This Year: ") + "<b>" cur_frm.dashboard.set_headline(
+ format_currency(r.message.total_billing, erpnext.get_currency(cur_frm.doc.company)) __("Total Billing This Year: ") + "<b>"
+ '</b> / <span class="text-muted">' + __("Unpaid") + ": <b>" + format_currency(r.message.total_billing, company_currency[0])
+ format_currency(r.message.total_unpaid, erpnext.get_currency(cur_frm.doc.company)) + '</b> / <span class="text-muted">' + __("Unpaid") + ": <b>"
+ '</b></span>'); + format_currency(r.message.total_unpaid, company_currency[0])
+ '</b></span>');
}
} }
cur_frm.dashboard.set_badge_count(r.message); 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} 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'
}
}
}

View File

@ -83,6 +83,19 @@
"permlevel": 0, "permlevel": 0,
"read_only": 1 "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", "fieldname": "more_info",
"fieldtype": "Section Break", "fieldtype": "Section Break",
@ -170,7 +183,7 @@
], ],
"icon": "icon-user", "icon": "icon-user",
"idx": 1, "idx": 1,
"modified": "2014-09-12 12:26:37.606976", "modified": "2014-09-10 17:53:09.286715",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Buying", "module": "Buying",
"name": "Supplier", "name": "Supplier",

View File

@ -35,9 +35,6 @@ class Supplier(TransactionBase):
self.update_address() self.update_address()
self.update_contact() 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): def validate(self):
#validation for Naming Series mandatory field... #validation for Naming Series mandatory field...
if frappe.defaults.get_global_default('supp_master_name') == 'Naming Series': 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_billing"] = billing[0][0]
out["total_unpaid"] = billing[0][1] out["total_unpaid"] = billing[0][1]
out["company_currency"] = frappe.db.sql_list("select distinct default_currency from tabCompany")
return out return out

View File

@ -62,12 +62,14 @@ cur_frm.cscript.setup_dashboard = function(doc) {
}, },
callback: function(r) { callback: function(r) {
if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) { if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) {
cur_frm.dashboard.set_headline( if(r.message["company_currency"].length == 1) {
__("Total Billing This Year: ") + "<b>" cur_frm.dashboard.set_headline(
+ format_currency(r.message.total_billing, erpnext.get_currency(cur_frm.doc.company)) __("Total Billing This Year: ") + "<b>"
+ '</b> / <span class="text-muted">' + __("Unpaid") + ": <b>" + format_currency(r.message.total_billing, company_currency[0])
+ format_currency(r.message.total_unpaid, erpnext.get_currency(cur_frm.doc.company)) + '</b> / <span class="text-muted">' + __("Unpaid") + ": <b>"
+ '</b></span>'); + format_currency(r.message.total_unpaid, company_currency[0])
+ '</b></span>');
}
} }
cur_frm.dashboard.set_badge_count(r.message); 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} 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'
}
}
}

View File

@ -129,6 +129,19 @@
"permlevel": 0, "permlevel": 0,
"read_only": 1 "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", "fieldname": "more_info",
"fieldtype": "Section Break", "fieldtype": "Section Break",
@ -143,19 +156,6 @@
"permlevel": 0, "permlevel": 0,
"width": "50%" "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", "description": "Your Customer's TAX registration numbers (if applicable) or any general information",
"fieldname": "customer_details", "fieldname": "customer_details",

View File

@ -22,9 +22,6 @@ class Customer(TransactionBase):
else: else:
self.name = make_autoname(self.naming_series+'.#####') 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): def validate_values(self):
if frappe.defaults.get_global_default('cust_master_name') == 'Naming Series' and not self.naming_series: if frappe.defaults.get_global_default('cust_master_name') == 'Naming Series' and not self.naming_series:
frappe.throw(_("Series is mandatory"), frappe.MandatoryError) frappe.throw(_("Series is mandatory"), frappe.MandatoryError)
@ -130,6 +127,7 @@ def get_dashboard_info(customer):
out["total_billing"] = billing[0][0] out["total_billing"] = billing[0][0]
out["total_unpaid"] = billing[0][1] out["total_unpaid"] = billing[0][1]
out["company_currency"] = frappe.db.sql_list("select distinct default_currency from tabCompany")
return out return out

View File

@ -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.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{ return{
filters:{ filters:{
'company': doc.name, '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) { cur_frm.fields_dict.default_expense_account.get_query = function(doc) {

View File

@ -60,6 +60,13 @@
"permlevel": 0, "permlevel": 0,
"reqd": 0 "reqd": 0
}, },
{
"fieldname": "charts_section",
"fieldtype": "Section Break",
"hidden": 0,
"label": "Chart of Accounts",
"permlevel": 0
},
{ {
"fieldname": "country", "fieldname": "country",
"fieldtype": "Link", "fieldtype": "Link",
@ -69,13 +76,6 @@
"permlevel": 0, "permlevel": 0,
"reqd": 1 "reqd": 1
}, },
{
"fieldname": "charts_section",
"fieldtype": "Section Break",
"hidden": 0,
"label": "Chart of Accounts",
"permlevel": 0
},
{ {
"fieldname": "chart_of_accounts", "fieldname": "chart_of_accounts",
"fieldtype": "Select", "fieldtype": "Select",
@ -118,10 +118,10 @@
}, },
{ {
"depends_on": "eval:!doc.__islocal", "depends_on": "eval:!doc.__islocal",
"fieldname": "receivables_group", "fieldname": "default_receivable_account",
"fieldtype": "Link", "fieldtype": "Link",
"ignore_user_permissions": 1, "ignore_user_permissions": 1,
"label": "Receivables Group", "label": "Default Receivable Account",
"no_copy": 1, "no_copy": 1,
"oldfieldname": "receivables_group", "oldfieldname": "receivables_group",
"oldfieldtype": "Link", "oldfieldtype": "Link",
@ -131,10 +131,10 @@
}, },
{ {
"depends_on": "eval:!doc.__islocal", "depends_on": "eval:!doc.__islocal",
"fieldname": "payables_group", "fieldname": "default_payable_account",
"fieldtype": "Link", "fieldtype": "Link",
"ignore_user_permissions": 1, "ignore_user_permissions": 1,
"label": "Payables Group", "label": "Default Payable Account",
"no_copy": 1, "no_copy": 1,
"oldfieldname": "payables_group", "oldfieldname": "payables_group",
"oldfieldtype": "Link", "oldfieldtype": "Link",
@ -356,7 +356,7 @@
], ],
"icon": "icon-building", "icon": "icon-building",
"idx": 1, "idx": 1,
"modified": "2014-08-25 17:11:09.320856", "modified": "2014-08-29 15:50:18.539228",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Setup", "module": "Setup",
"name": "Company", "name": "Company",

View File

@ -39,7 +39,7 @@ class Company(Document):
self.validate_default_accounts() self.validate_default_accounts()
def validate_default_accounts(self): 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", "default_expense_account", "default_income_account", "stock_received_but_not_billed",
"stock_adjustment_account", "expenses_included_in_valuation"]: "stock_adjustment_account", "expenses_included_in_valuation"]:
if self.get(field): if self.get(field):
@ -55,8 +55,7 @@ class Company(Document):
self.create_default_warehouses() self.create_default_warehouses()
self.install_country_fixtures() self.install_country_fixtures()
if not frappe.db.get_value("Cost Center", {"group_or_ledger": "Ledger", if not frappe.db.get_value("Cost Center", {"group_or_ledger": "Ledger", "company": self.name}):
"company": self.name}):
self.create_default_cost_center() self.create_default_cost_center()
self.set_default_accounts() self.set_default_accounts()
@ -87,8 +86,11 @@ class Company(Document):
create_charts(self.chart_of_accounts, self.name) create_charts(self.chart_of_accounts, self.name)
else: else:
self.create_standard_accounts() 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): def add_acc(self, lst):
account = frappe.get_doc({ account = frappe.get_doc({

View File

@ -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'
}
}
}

View File

@ -108,12 +108,25 @@
"permlevel": 0, "permlevel": 0,
"print_hide": 1, "print_hide": 1,
"report_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", "icon": "icon-sitemap",
"idx": 1, "idx": 1,
"in_create": 1, "in_create": 1,
"modified": "2014-08-27 17:41:35.154380", "modified": "2014-08-29 16:37:35.877256",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Setup", "module": "Setup",
"name": "Customer Group", "name": "Customer Group",

View File

@ -3,4 +3,15 @@
cur_frm.cscript.refresh = function(doc) { cur_frm.cscript.refresh = function(doc) {
cur_frm.set_intro(doc.__islocal ? "" : __("There is nothing to edit.")) cur_frm.set_intro(doc.__islocal ? "" : __("There is nothing to edit."))
} }
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'
}
}
}

View File

@ -22,11 +22,24 @@
"fieldtype": "Int", "fieldtype": "Int",
"label": "Credit Days", "label": "Credit Days",
"permlevel": 1 "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", "icon": "icon-flag",
"idx": 1, "idx": 1,
"modified": "2014-08-27 17:43:31.479133", "modified": "2014-08-29 16:38:22.219286",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Setup", "module": "Setup",
"name": "Supplier Type", "name": "Supplier Type",