Deleted master_type, master_name, credit_days, credit_limit fields from account
Warehouse account is linked via Warehouse field now, instead of master_name field
patch to copy warehouse value from master_name to warehouse
party_type and party field added in GL Entry and Journal Voucher Detail
diff --git a/erpnext/accounts/doctype/account/account.js b/erpnext/accounts/doctype/account/account.js
index aee2d3c..38d9af6 100644
--- a/erpnext/accounts/doctype/account/account.js
+++ b/erpnext/accounts/doctype/account/account.js
@@ -12,8 +12,7 @@
cur_frm.toggle_display('account_name', doc.__islocal);
// hide fields if group
- cur_frm.toggle_display(['account_type', 'master_type', 'master_name',
- 'credit_days', 'credit_limit', 'tax_rate'], doc.group_or_ledger=='Ledger')
+ cur_frm.toggle_display(['account_type', 'tax_rate'], doc.group_or_ledger=='Ledger')
// disable fields
cur_frm.toggle_enable(['account_name', 'group_or_ledger', 'company'], false);
@@ -29,10 +28,7 @@
} else {
// credit days and type if customer or supplier
cur_frm.set_intro(null);
- cur_frm.toggle_display(['credit_days', 'credit_limit'], in_list(['Customer', 'Supplier'],
- doc.master_type));
- cur_frm.cscript.master_type(doc, cdt, cdn);
cur_frm.cscript.account_type(doc, cdt, cdn);
// show / hide convert buttons
@@ -40,22 +36,13 @@
}
}
-cur_frm.cscript.master_type = function(doc, cdt, cdn) {
- cur_frm.toggle_display(['credit_days', 'credit_limit'], in_list(['Customer', 'Supplier'],
- doc.master_type));
-
- cur_frm.toggle_display('master_name', doc.account_type=='Warehouse' ||
- in_list(['Customer', 'Supplier'], doc.master_type));
-}
-
cur_frm.add_fetch('parent_account', 'report_type', 'report_type');
cur_frm.add_fetch('parent_account', 'root_type', 'root_type');
cur_frm.cscript.account_type = function(doc, cdt, cdn) {
if(doc.group_or_ledger=='Ledger') {
cur_frm.toggle_display(['tax_rate'], doc.account_type == 'Tax');
- cur_frm.toggle_display('master_name', doc.account_type=='Warehouse' ||
- in_list(['Customer', 'Supplier'], doc.master_type));
+ cur_frm.toggle_display('warehouse', doc.account_type=='Warehouse');
}
}
@@ -98,20 +85,6 @@
});
}
-cur_frm.fields_dict['master_name'].get_query = function(doc) {
- if (doc.master_type || doc.account_type=="Warehouse") {
- var dt = doc.master_type || "Warehouse";
- return {
- doctype: dt,
- query: "erpnext.accounts.doctype.account.account.get_master_name",
- filters: {
- "master_type": dt,
- "company": doc.company
- }
- }
- }
-}
-
cur_frm.fields_dict['parent_account'].get_query = function(doc) {
return {
filters: {
diff --git a/erpnext/accounts/doctype/account/account.json b/erpnext/accounts/doctype/account/account.json
index f909ef6..62dde15 100644
--- a/erpnext/accounts/doctype/account/account.json
+++ b/erpnext/accounts/doctype/account/account.json
@@ -1,332 +1,299 @@
{
- "allow_copy": 1,
- "allow_import": 1,
- "allow_rename": 1,
- "creation": "2013-01-30 12:49:46",
- "description": "Heads (or groups) against which Accounting Entries are made and balances are maintained.",
- "docstatus": 0,
- "doctype": "DocType",
- "document_type": "Master",
+ "allow_copy": 1,
+ "allow_import": 1,
+ "allow_rename": 1,
+ "creation": "2013-01-30 12:49:46",
+ "description": "Heads (or groups) against which Accounting Entries are made and balances are maintained.",
+ "docstatus": 0,
+ "doctype": "DocType",
+ "document_type": "Master",
"fields": [
{
- "fieldname": "properties",
- "fieldtype": "Section Break",
- "in_list_view": 0,
- "label": "Account Details",
- "oldfieldtype": "Section Break",
+ "fieldname": "properties",
+ "fieldtype": "Section Break",
+ "in_list_view": 0,
+ "label": "Account Details",
+ "oldfieldtype": "Section Break",
"permlevel": 0
- },
+ },
{
- "fieldname": "column_break0",
- "fieldtype": "Column Break",
- "in_list_view": 0,
- "permlevel": 0,
+ "fieldname": "column_break0",
+ "fieldtype": "Column Break",
+ "in_list_view": 0,
+ "permlevel": 0,
"width": "50%"
- },
+ },
{
- "fieldname": "account_name",
- "fieldtype": "Data",
- "in_filter": 1,
- "in_list_view": 1,
- "label": "Account Name",
- "no_copy": 1,
- "oldfieldname": "account_name",
- "oldfieldtype": "Data",
- "permlevel": 0,
- "read_only": 1,
- "reqd": 1,
+ "fieldname": "account_name",
+ "fieldtype": "Data",
+ "in_filter": 1,
+ "in_list_view": 1,
+ "label": "Account Name",
+ "no_copy": 1,
+ "oldfieldname": "account_name",
+ "oldfieldtype": "Data",
+ "permlevel": 0,
+ "read_only": 1,
+ "reqd": 1,
"search_index": 1
- },
+ },
{
- "default": "Ledger",
- "fieldname": "group_or_ledger",
- "fieldtype": "Select",
- "in_filter": 1,
- "in_list_view": 1,
- "label": "Group or Ledger",
- "oldfieldname": "group_or_ledger",
- "oldfieldtype": "Select",
- "options": "\nLedger\nGroup",
- "permlevel": 0,
- "read_only": 1,
- "reqd": 1,
+ "default": "Ledger",
+ "fieldname": "group_or_ledger",
+ "fieldtype": "Select",
+ "in_filter": 1,
+ "in_list_view": 1,
+ "label": "Group or Ledger",
+ "oldfieldname": "group_or_ledger",
+ "oldfieldtype": "Select",
+ "options": "\nLedger\nGroup",
+ "permlevel": 0,
+ "read_only": 1,
+ "reqd": 1,
"search_index": 1
- },
+ },
{
- "fieldname": "company",
- "fieldtype": "Link",
- "in_filter": 1,
- "label": "Company",
- "oldfieldname": "company",
- "oldfieldtype": "Link",
- "options": "Company",
- "permlevel": 0,
- "read_only": 1,
- "reqd": 1,
+ "fieldname": "company",
+ "fieldtype": "Link",
+ "in_filter": 1,
+ "label": "Company",
+ "oldfieldname": "company",
+ "oldfieldtype": "Link",
+ "options": "Company",
+ "permlevel": 0,
+ "read_only": 1,
+ "reqd": 1,
"search_index": 1
- },
+ },
{
- "fieldname": "column_break1",
- "fieldtype": "Column Break",
- "permlevel": 0,
+ "fieldname": "column_break1",
+ "fieldtype": "Column Break",
+ "permlevel": 0,
"width": "50%"
- },
+ },
{
- "fieldname": "parent_account",
- "fieldtype": "Link",
- "ignore_user_permissions": 1,
- "label": "Parent Account",
- "oldfieldname": "parent_account",
- "oldfieldtype": "Link",
- "options": "Account",
- "permlevel": 0,
- "reqd": 1,
+ "fieldname": "parent_account",
+ "fieldtype": "Link",
+ "ignore_user_permissions": 1,
+ "label": "Parent Account",
+ "oldfieldname": "parent_account",
+ "oldfieldtype": "Link",
+ "options": "Account",
+ "permlevel": 0,
+ "reqd": 1,
"search_index": 1
- },
+ },
{
- "description": "Setting Account Type helps in selecting this Account in transactions.",
- "fieldname": "account_type",
- "fieldtype": "Select",
- "in_filter": 1,
- "label": "Account Type",
- "oldfieldname": "account_type",
- "oldfieldtype": "Select",
- "options": "\nBank\nCash\nTax\nChargeable\nWarehouse\nReceivable\nPayable\nEquity\nFixed Asset\nCost of Goods Sold\nExpense Account\nIncome Account\nStock Received But Not Billed\nExpenses Included In Valuation\nStock Adjustment\nStock",
- "permlevel": 0,
+ "description": "Setting Account Type helps in selecting this Account in transactions.",
+ "fieldname": "account_type",
+ "fieldtype": "Select",
+ "in_filter": 1,
+ "label": "Account Type",
+ "oldfieldname": "account_type",
+ "oldfieldtype": "Select",
+ "options": "\nBank\nCash\nTax\nChargeable\nWarehouse\nReceivable\nPayable\nEquity\nFixed Asset\nCost of Goods Sold\nExpense Account\nIncome Account\nStock Received But Not Billed\nExpenses Included In Valuation\nStock Adjustment\nStock",
+ "permlevel": 0,
"search_index": 0
- },
+ },
{
- "description": "Rate at which this tax is applied",
- "fieldname": "tax_rate",
- "fieldtype": "Float",
- "hidden": 0,
- "label": "Rate",
- "oldfieldname": "tax_rate",
- "oldfieldtype": "Currency",
- "permlevel": 0,
+ "description": "Rate at which this tax is applied",
+ "fieldname": "tax_rate",
+ "fieldtype": "Float",
+ "hidden": 0,
+ "label": "Rate",
+ "oldfieldname": "tax_rate",
+ "oldfieldtype": "Currency",
+ "permlevel": 0,
"reqd": 0
- },
+ },
{
- "description": "If the account is frozen, entries are allowed to restricted users.",
- "fieldname": "freeze_account",
- "fieldtype": "Select",
- "label": "Frozen",
- "oldfieldname": "freeze_account",
- "oldfieldtype": "Select",
- "options": "No\nYes",
+ "description": "If the account is frozen, entries are allowed to restricted users.",
+ "fieldname": "freeze_account",
+ "fieldtype": "Select",
+ "label": "Frozen",
+ "oldfieldname": "freeze_account",
+ "oldfieldtype": "Select",
+ "options": "No\nYes",
"permlevel": 0
- },
+ },
{
- "fieldname": "credit_days",
- "fieldtype": "Int",
- "hidden": 1,
- "label": "Credit Days",
- "oldfieldname": "credit_days",
- "oldfieldtype": "Int",
- "permlevel": 0,
- "print_hide": 1
- },
- {
- "fieldname": "credit_limit",
- "fieldtype": "Currency",
- "hidden": 1,
- "label": "Credit Limit",
- "oldfieldname": "credit_limit",
- "oldfieldtype": "Currency",
- "options": "Company:company:default_currency",
- "permlevel": 0,
- "print_hide": 1
- },
- {
- "description": "If this Account represents a Customer, Supplier or Employee, set it here.",
- "fieldname": "master_type",
- "fieldtype": "Select",
- "label": "Master Type",
- "oldfieldname": "master_type",
- "oldfieldtype": "Select",
- "options": "\nSupplier\nCustomer\nEmployee",
+ "fieldname": "warehouse",
+ "fieldtype": "Link",
+ "label": "Warehouse",
+ "options": "Warehouse",
"permlevel": 0
- },
+ },
{
- "fieldname": "master_name",
- "fieldtype": "Link",
- "label": "Master Name",
- "oldfieldname": "master_name",
- "oldfieldtype": "Link",
- "options": "[Select]",
+ "fieldname": "balance_must_be",
+ "fieldtype": "Select",
+ "label": "Balance must be",
+ "options": "\nDebit\nCredit",
"permlevel": 0
- },
+ },
{
- "fieldname": "balance_must_be",
- "fieldtype": "Select",
- "label": "Balance must be",
- "options": "\nDebit\nCredit",
- "permlevel": 0
- },
- {
- "fieldname": "root_type",
- "fieldtype": "Select",
- "label": "Root Type",
- "options": "\nAsset\nLiability\nIncome\nExpense\nEquity",
- "permlevel": 0,
+ "fieldname": "root_type",
+ "fieldtype": "Select",
+ "label": "Root Type",
+ "options": "\nAsset\nLiability\nIncome\nExpense\nEquity",
+ "permlevel": 0,
"read_only": 1
- },
+ },
{
- "fieldname": "report_type",
- "fieldtype": "Select",
- "label": "Report Type",
- "options": "\nBalance Sheet\nProfit and Loss",
- "permlevel": 0,
+ "fieldname": "report_type",
+ "fieldtype": "Select",
+ "label": "Report Type",
+ "options": "\nBalance Sheet\nProfit and Loss",
+ "permlevel": 0,
"read_only": 1
- },
+ },
{
- "fieldname": "lft",
- "fieldtype": "Int",
- "hidden": 1,
- "label": "Lft",
- "permlevel": 0,
- "print_hide": 1,
+ "fieldname": "lft",
+ "fieldtype": "Int",
+ "hidden": 1,
+ "label": "Lft",
+ "permlevel": 0,
+ "print_hide": 1,
"read_only": 1
- },
+ },
{
- "fieldname": "rgt",
- "fieldtype": "Int",
- "hidden": 1,
- "label": "Rgt",
- "permlevel": 0,
- "print_hide": 1,
+ "fieldname": "rgt",
+ "fieldtype": "Int",
+ "hidden": 1,
+ "label": "Rgt",
+ "permlevel": 0,
+ "print_hide": 1,
"read_only": 1
- },
+ },
{
- "fieldname": "old_parent",
- "fieldtype": "Data",
- "hidden": 1,
- "label": "Old Parent",
- "permlevel": 0,
- "print_hide": 1,
+ "fieldname": "old_parent",
+ "fieldtype": "Data",
+ "hidden": 1,
+ "label": "Old Parent",
+ "permlevel": 0,
+ "print_hide": 1,
"read_only": 1
}
- ],
- "icon": "icon-money",
- "idx": 1,
- "in_create": 1,
- "modified": "2014-06-19 18:27:58.109303",
- "modified_by": "Administrator",
- "module": "Accounts",
- "name": "Account",
- "owner": "Administrator",
+ ],
+ "icon": "icon-money",
+ "idx": 1,
+ "in_create": 1,
+ "modified": "2014-08-26 18:18:30.173409",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Account",
+ "owner": "Administrator",
"permissions": [
{
- "amend": 0,
- "apply_user_permissions": 1,
- "create": 1,
- "delete": 1,
- "email": 1,
- "export": 1,
- "import": 1,
- "permlevel": 0,
- "print": 1,
- "read": 1,
- "report": 1,
- "role": "Accounts User",
- "submit": 0,
+ "amend": 0,
+ "apply_user_permissions": 1,
+ "create": 1,
+ "delete": 1,
+ "email": 1,
+ "export": 1,
+ "import": 1,
+ "permlevel": 0,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "Accounts User",
+ "submit": 0,
"write": 1
- },
+ },
{
- "amend": 0,
- "apply_user_permissions": 1,
- "create": 0,
- "delete": 0,
- "email": 1,
- "permlevel": 0,
- "print": 1,
- "read": 1,
- "report": 1,
- "role": "Auditor",
- "submit": 0,
+ "amend": 0,
+ "apply_user_permissions": 1,
+ "create": 0,
+ "delete": 0,
+ "email": 1,
+ "permlevel": 0,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "Auditor",
+ "submit": 0,
"write": 0
- },
+ },
{
- "amend": 0,
- "apply_user_permissions": 1,
- "create": 0,
- "delete": 0,
- "email": 1,
- "permlevel": 0,
- "print": 1,
- "read": 1,
- "report": 1,
- "role": "Sales User",
- "submit": 0,
+ "amend": 0,
+ "apply_user_permissions": 1,
+ "create": 0,
+ "delete": 0,
+ "email": 1,
+ "permlevel": 0,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "Sales User",
+ "submit": 0,
"write": 0
- },
+ },
{
- "amend": 0,
- "apply_user_permissions": 1,
- "create": 0,
- "delete": 0,
- "email": 1,
- "permlevel": 0,
- "print": 1,
- "read": 1,
- "report": 1,
- "role": "Purchase User",
- "submit": 0,
+ "amend": 0,
+ "apply_user_permissions": 1,
+ "create": 0,
+ "delete": 0,
+ "email": 1,
+ "permlevel": 0,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "Purchase User",
+ "submit": 0,
"write": 0
- },
+ },
{
- "amend": 0,
- "cancel": 0,
- "create": 0,
- "delete": 0,
- "permlevel": 2,
- "read": 1,
- "report": 1,
- "role": "Auditor",
- "submit": 0,
+ "amend": 0,
+ "cancel": 0,
+ "create": 0,
+ "delete": 0,
+ "permlevel": 2,
+ "read": 1,
+ "report": 1,
+ "role": "Auditor",
+ "submit": 0,
"write": 0
- },
+ },
{
- "amend": 0,
- "apply_user_permissions": 0,
- "create": 1,
- "delete": 1,
- "email": 1,
- "export": 1,
- "import": 1,
- "permlevel": 0,
- "print": 1,
- "read": 1,
- "report": 1,
- "role": "Accounts Manager",
- "set_user_permissions": 1,
- "submit": 0,
+ "amend": 0,
+ "apply_user_permissions": 0,
+ "create": 1,
+ "delete": 1,
+ "email": 1,
+ "export": 1,
+ "import": 1,
+ "permlevel": 0,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "Accounts Manager",
+ "set_user_permissions": 1,
+ "submit": 0,
"write": 1
- },
+ },
{
- "amend": 0,
- "cancel": 0,
- "create": 0,
- "delete": 0,
- "permlevel": 2,
- "read": 1,
- "report": 1,
- "role": "Accounts Manager",
- "submit": 0,
+ "amend": 0,
+ "cancel": 0,
+ "create": 0,
+ "delete": 0,
+ "permlevel": 2,
+ "read": 1,
+ "report": 1,
+ "role": "Accounts Manager",
+ "submit": 0,
"write": 1
- },
+ },
{
- "amend": 0,
- "cancel": 0,
- "create": 0,
- "delete": 0,
- "permlevel": 2,
- "read": 1,
- "report": 1,
- "role": "Accounts User",
- "submit": 0,
+ "amend": 0,
+ "cancel": 0,
+ "create": 0,
+ "delete": 0,
+ "permlevel": 2,
+ "read": 1,
+ "report": 1,
+ "role": "Accounts User",
+ "submit": 0,
"write": 0
}
- ],
+ ],
"search_fields": "group_or_ledger"
-}
+}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index 7195db8..1e03568 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -20,11 +20,7 @@
self.name = self.account_name.strip() + ' - ' + \
frappe.db.get_value("Company", self.company, "abbr")
- def get_address(self):
- return {'address': frappe.db.get_value(self.master_type, self.master_name, "address")}
-
def validate(self):
- self.validate_master_name()
self.validate_parent()
self.validate_root_details()
self.validate_mandatory()
@@ -32,13 +28,6 @@
self.validate_frozen_accounts_modifier()
self.validate_balance_must_be_debit_or_credit()
- def validate_master_name(self):
- if self.master_type in ('Customer', 'Supplier') or self.account_type == "Warehouse":
- if not self.master_name:
- msgprint(_("Please enter Master Name once the account is created."))
- elif not frappe.db.exists(self.master_type or self.account_type, self.master_name):
- throw(_("Invalid Master Name"))
-
def validate_parent(self):
"""Fetch Parent Details and validate parent account"""
if self.parent_account:
@@ -123,18 +112,19 @@
return
if self.account_type == "Warehouse":
- old_warehouse = cstr(frappe.db.get_value("Account", self.name, "master_name"))
- if old_warehouse != cstr(self.master_name):
+ if not self.warehouse:
+ throw(_("Warehouse is mandatory if account type is Warehouse"))
+
+ old_warehouse = cstr(frappe.db.get_value("Account", self.name, "warehouse"))
+ if old_warehouse != cstr(self.warehouse):
if old_warehouse:
self.validate_warehouse(old_warehouse)
- if self.master_name:
- self.validate_warehouse(self.master_name)
- else:
- throw(_("Master Name is mandatory if account type is Warehouse"))
+ if self.warehouse:
+ self.validate_warehouse(self.warehouse)
def validate_warehouse(self, warehouse):
if frappe.db.get_value("Stock Ledger Entry", {"warehouse": warehouse}):
- throw(_("Stock entries exist against warehouse {0} cannot re-assign or modify 'Master Name'").format(warehouse))
+ throw(_("Stock entries exist against warehouse {0}, hence you cannot re-assign or modify Warehouse").format(warehouse))
def update_nsm_model(self):
"""update lft, rgt indices for nested set model"""
@@ -226,14 +216,6 @@
from frappe.utils.nestedset import rebuild_tree
rebuild_tree("Account", "parent_account")
-def get_master_name(doctype, txt, searchfield, start, page_len, filters):
- conditions = (" and company='%s'"% filters["company"].replace("'", "\'")) if doctype == "Warehouse" else ""
-
- return frappe.db.sql("""select name from `tab%s` where %s like %s %s
- order by name limit %s, %s""" %
- (filters["master_type"], searchfield, "%s", conditions, "%s", "%s"),
- ("%%%s%%" % txt, start, page_len), as_list=1)
-
def get_parent_account(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql("""select name from tabAccount
where group_or_ledger = 'Group' and docstatus != 2 and company = %s
diff --git a/erpnext/accounts/doctype/account/test_records.json b/erpnext/accounts/doctype/account/test_records.json
new file mode 100644
index 0000000..d15f7ad
--- /dev/null
+++ b/erpnext/accounts/doctype/account/test_records.json
@@ -0,0 +1,6 @@
+[
+ {
+ "doctype": "Account",
+ "name": "_Test Account 1"
+ }
+]
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.json b/erpnext/accounts/doctype/gl_entry/gl_entry.json
index 07578e2..673eb47 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.json
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.json
@@ -48,6 +48,20 @@
"search_index": 1
},
{
+ "fieldname": "party_type",
+ "fieldtype": "Select",
+ "label": "Party Type",
+ "options": "\nCustomer\nSupplier",
+ "permlevel": 0
+ },
+ {
+ "fieldname": "party",
+ "fieldtype": "Link",
+ "label": "Party",
+ "options": "[Select]",
+ "permlevel": 0
+ },
+ {
"fieldname": "cost_center",
"fieldtype": "Link",
"in_filter": 1,
@@ -189,7 +203,7 @@
"icon": "icon-list",
"idx": 1,
"in_create": 1,
- "modified": "2014-06-23 08:07:30.678730",
+ "modified": "2014-08-26 17:56:49.147121",
"modified_by": "Administrator",
"module": "Accounts",
"name": "GL Entry",
diff --git a/erpnext/accounts/doctype/gl_entry/test_gl_entry.py b/erpnext/accounts/doctype/gl_entry/test_gl_entry.py
new file mode 100644
index 0000000..aeb6e90
--- /dev/null
+++ b/erpnext/accounts/doctype/gl_entry/test_gl_entry.py
@@ -0,0 +1,10 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and Contributors
+# See license.txt
+
+import frappe
+import unittest
+
+test_records = frappe.get_test_records('GL Entry')
+
+class TestGLEntry(unittest.TestCase):
+ pass
diff --git a/erpnext/accounts/doctype/gl_entry/test_records.json b/erpnext/accounts/doctype/gl_entry/test_records.json
new file mode 100644
index 0000000..55f0057
--- /dev/null
+++ b/erpnext/accounts/doctype/gl_entry/test_records.json
@@ -0,0 +1,6 @@
+[
+ {
+ "doctype": "GL Entry",
+ "name": "_Test GL Entry 1"
+ }
+]
diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.js b/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
index 9174873..4a96480 100644
--- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
+++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
@@ -41,6 +41,18 @@
});
});
+ me.frm.set_query("party", "entries", function(doc, cdt, cdn) {
+ var jvd = frappe.get_doc(cdt, cdn);
+ if(!jvd.party_type) {
+ frappe.throw(__("Please enter Party Type first"));
+ } else {
+ return {
+ doctype: jvd.party_type
+ }
+ }
+ });
+
+
$.each([["against_voucher", "Purchase Invoice", "credit_to"],
["against_invoice", "Sales Invoice", "debit_to"]], function(i, opts) {
me.frm.set_query(opts[0], "entries", function(doc, cdt, cdn) {
diff --git a/erpnext/accounts/doctype/journal_voucher_detail/journal_voucher_detail.json b/erpnext/accounts/doctype/journal_voucher_detail/journal_voucher_detail.json
index 2f15b0b..063e063 100644
--- a/erpnext/accounts/doctype/journal_voucher_detail/journal_voucher_detail.json
+++ b/erpnext/accounts/doctype/journal_voucher_detail/journal_voucher_detail.json
@@ -1,183 +1,197 @@
{
- "autoname": "JVD.######",
- "creation": "2013-02-22 01:27:39",
- "docstatus": 0,
- "doctype": "DocType",
+ "autoname": "JVD.######",
+ "creation": "2013-02-22 01:27:39",
+ "docstatus": 0,
+ "doctype": "DocType",
"fields": [
{
- "fieldname": "account",
- "fieldtype": "Link",
- "in_filter": 1,
- "in_list_view": 1,
- "label": "Account",
- "oldfieldname": "account",
- "oldfieldtype": "Link",
- "options": "Account",
- "permlevel": 0,
- "print_width": "250px",
- "reqd": 1,
- "search_index": 1,
+ "fieldname": "account",
+ "fieldtype": "Link",
+ "in_filter": 1,
+ "in_list_view": 1,
+ "label": "Account",
+ "oldfieldname": "account",
+ "oldfieldtype": "Link",
+ "options": "Account",
+ "permlevel": 0,
+ "print_width": "250px",
+ "reqd": 1,
+ "search_index": 1,
"width": "250px"
- },
+ },
{
- "default": ":Company",
- "description": "If Income or Expense",
- "fieldname": "cost_center",
- "fieldtype": "Link",
- "in_filter": 1,
- "in_list_view": 1,
- "label": "Cost Center",
- "oldfieldname": "cost_center",
- "oldfieldtype": "Link",
- "options": "Cost Center",
- "permlevel": 0,
- "print_hide": 1,
- "print_width": "180px",
- "search_index": 0,
+ "default": ":Company",
+ "description": "If Income or Expense",
+ "fieldname": "cost_center",
+ "fieldtype": "Link",
+ "in_filter": 1,
+ "in_list_view": 1,
+ "label": "Cost Center",
+ "oldfieldname": "cost_center",
+ "oldfieldtype": "Link",
+ "options": "Cost Center",
+ "permlevel": 0,
+ "print_hide": 1,
+ "print_width": "180px",
+ "search_index": 0,
"width": "180px"
- },
+ },
{
- "fieldname": "col_break1",
- "fieldtype": "Column Break",
+ "fieldname": "col_break1",
+ "fieldtype": "Column Break",
"permlevel": 0
- },
+ },
{
- "fieldname": "balance",
- "fieldtype": "Currency",
- "in_list_view": 1,
- "label": "Account Balance",
- "no_copy": 1,
- "oldfieldname": "balance",
- "oldfieldtype": "Data",
- "options": "Company:company:default_currency",
- "permlevel": 0,
- "print_hide": 1,
+ "fieldname": "party_type",
+ "fieldtype": "Select",
+ "label": "Party Type",
+ "options": "\nCustomer\nSupplier",
+ "permlevel": 0
+ },
+ {
+ "fieldname": "party",
+ "fieldtype": "Link",
+ "label": "Party",
+ "options": "[Select]",
+ "permlevel": 0
+ },
+ {
+ "fieldname": "balance",
+ "fieldtype": "Currency",
+ "in_list_view": 1,
+ "label": "Account Balance",
+ "no_copy": 1,
+ "oldfieldname": "balance",
+ "oldfieldtype": "Data",
+ "options": "Company:company:default_currency",
+ "permlevel": 0,
+ "print_hide": 1,
"read_only": 1
- },
+ },
{
- "fieldname": "sec_break1",
- "fieldtype": "Section Break",
+ "fieldname": "sec_break1",
+ "fieldtype": "Section Break",
"permlevel": 0
- },
+ },
{
- "fieldname": "debit",
- "fieldtype": "Currency",
- "in_list_view": 1,
- "label": "Debit",
- "oldfieldname": "debit",
- "oldfieldtype": "Currency",
- "options": "Company:company:default_currency",
+ "fieldname": "debit",
+ "fieldtype": "Currency",
+ "in_list_view": 1,
+ "label": "Debit",
+ "oldfieldname": "debit",
+ "oldfieldtype": "Currency",
+ "options": "Company:company:default_currency",
"permlevel": 0
- },
+ },
{
- "fieldname": "col_break2",
- "fieldtype": "Column Break",
+ "fieldname": "col_break2",
+ "fieldtype": "Column Break",
"permlevel": 0
- },
+ },
{
- "fieldname": "credit",
- "fieldtype": "Currency",
- "in_list_view": 1,
- "label": "Credit",
- "oldfieldname": "credit",
- "oldfieldtype": "Currency",
- "options": "Company:company:default_currency",
+ "fieldname": "credit",
+ "fieldtype": "Currency",
+ "in_list_view": 1,
+ "label": "Credit",
+ "oldfieldname": "credit",
+ "oldfieldtype": "Currency",
+ "options": "Company:company:default_currency",
"permlevel": 0
- },
+ },
{
- "fieldname": "reference",
- "fieldtype": "Section Break",
- "label": "Reference",
+ "fieldname": "reference",
+ "fieldtype": "Section Break",
+ "label": "Reference",
"permlevel": 0
- },
+ },
{
- "fieldname": "against_invoice",
- "fieldtype": "Link",
- "in_filter": 1,
- "label": "Against Sales Invoice",
- "no_copy": 1,
- "oldfieldname": "against_invoice",
- "oldfieldtype": "Link",
- "options": "Sales Invoice",
- "permlevel": 0,
- "print_hide": 0,
+ "fieldname": "against_invoice",
+ "fieldtype": "Link",
+ "in_filter": 1,
+ "label": "Against Sales Invoice",
+ "no_copy": 1,
+ "oldfieldname": "against_invoice",
+ "oldfieldtype": "Link",
+ "options": "Sales Invoice",
+ "permlevel": 0,
+ "print_hide": 0,
"search_index": 1
- },
+ },
{
- "fieldname": "against_voucher",
- "fieldtype": "Link",
- "in_filter": 1,
- "in_list_view": 1,
- "label": "Against Purchase Invoice",
- "no_copy": 1,
- "oldfieldname": "against_voucher",
- "oldfieldtype": "Link",
- "options": "Purchase Invoice",
- "permlevel": 0,
- "print_hide": 0,
+ "fieldname": "against_voucher",
+ "fieldtype": "Link",
+ "in_filter": 1,
+ "in_list_view": 1,
+ "label": "Against Purchase Invoice",
+ "no_copy": 1,
+ "oldfieldname": "against_voucher",
+ "oldfieldtype": "Link",
+ "options": "Purchase Invoice",
+ "permlevel": 0,
+ "print_hide": 0,
"search_index": 1
- },
+ },
{
- "fieldname": "against_jv",
- "fieldtype": "Link",
- "in_filter": 1,
- "label": "Against Journal Voucher",
- "no_copy": 1,
- "oldfieldname": "against_jv",
- "oldfieldtype": "Link",
- "options": "Journal Voucher",
- "permlevel": 0,
- "print_hide": 0,
+ "fieldname": "against_jv",
+ "fieldtype": "Link",
+ "in_filter": 1,
+ "label": "Against Journal Voucher",
+ "no_copy": 1,
+ "oldfieldname": "against_jv",
+ "oldfieldtype": "Link",
+ "options": "Journal Voucher",
+ "permlevel": 0,
+ "print_hide": 0,
"search_index": 1
- },
+ },
{
- "fieldname": "col_break3",
- "fieldtype": "Column Break",
+ "fieldname": "col_break3",
+ "fieldtype": "Column Break",
"permlevel": 0
- },
+ },
{
- "fieldname": "against_sales_order",
- "fieldtype": "Link",
- "label": "Against Sales Order",
- "options": "Sales Order",
+ "fieldname": "against_sales_order",
+ "fieldtype": "Link",
+ "label": "Against Sales Order",
+ "options": "Sales Order",
"permlevel": 0
- },
+ },
{
- "fieldname": "against_purchase_order",
- "fieldtype": "Link",
- "label": "Against Purchase Order",
- "options": "Purchase Order",
+ "fieldname": "against_purchase_order",
+ "fieldtype": "Link",
+ "label": "Against Purchase Order",
+ "options": "Purchase Order",
"permlevel": 0
- },
+ },
{
- "fieldname": "is_advance",
- "fieldtype": "Select",
- "label": "Is Advance",
- "no_copy": 1,
- "oldfieldname": "is_advance",
- "oldfieldtype": "Select",
- "options": "No\nYes",
- "permlevel": 0,
+ "fieldname": "is_advance",
+ "fieldtype": "Select",
+ "label": "Is Advance",
+ "no_copy": 1,
+ "oldfieldname": "is_advance",
+ "oldfieldtype": "Select",
+ "options": "No\nYes",
+ "permlevel": 0,
"print_hide": 1
- },
+ },
{
- "fieldname": "against_account",
- "fieldtype": "Text",
- "hidden": 1,
- "label": "Against Account",
- "no_copy": 1,
- "oldfieldname": "against_account",
- "oldfieldtype": "Text",
- "permlevel": 0,
+ "fieldname": "against_account",
+ "fieldtype": "Text",
+ "hidden": 1,
+ "label": "Against Account",
+ "no_copy": 1,
+ "oldfieldname": "against_account",
+ "oldfieldtype": "Text",
+ "permlevel": 0,
"print_hide": 1
}
- ],
- "idx": 1,
- "istable": 1,
- "modified": "2014-08-20 12:19:55.049973",
- "modified_by": "Administrator",
- "module": "Accounts",
- "name": "Journal Voucher Detail",
- "owner": "Administrator",
+ ],
+ "idx": 1,
+ "istable": 1,
+ "modified": "2014-08-26 17:56:34.294770",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Journal Voucher Detail",
+ "owner": "Administrator",
"permissions": []
-}
\ No newline at end of file
+}
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 8231650..fa8dbe9 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -457,7 +457,7 @@
order by account asc, debit asc""", si.name, as_dict=1)
self.assertTrue(gl_entries)
- stock_in_hand = frappe.db.get_value("Account", {"master_name": "_Test Warehouse - _TC"})
+ stock_in_hand = frappe.db.get_value("Account", {"warehouse": "_Test Warehouse - _TC"})
expected_gl_entries = sorted([
[si.debit_to, 630.0, 0.0],
diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py
index 2114768..cb58abe 100644
--- a/erpnext/accounts/general_ledger.py
+++ b/erpnext/accounts/general_ledger.py
@@ -93,7 +93,7 @@
def validate_account_for_auto_accounting_for_stock(gl_map):
if gl_map[0].voucher_type=="Journal Voucher":
aii_accounts = [d[0] for d in frappe.db.sql("""select name from tabAccount
- where account_type = 'Warehouse' and ifnull(master_name, '')!=''""")]
+ where account_type = 'Warehouse' and ifnull(warehouse, '')!=''""")]
for entry in gl_map:
if entry.account in aii_accounts:
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index de7032e..bac1379 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -136,9 +136,6 @@
acc_head = frappe.db.get_value("Account", {"master_name":party,
"master_type": party_type, "company": company})
- if not acc_head:
- create_party_account(party, party_type, company)
-
return acc_head
def get_due_date(posting_date, party, party_type, account, company):
@@ -157,29 +154,3 @@
return due_date
-def create_party_account(party, party_type, company):
- if not company:
- frappe.throw(_("Company is required"))
-
- company_details = frappe.db.get_value("Company", company,
- ["abbr", "receivables_group", "payables_group"], as_dict=True)
- if not frappe.db.exists("Account", (party.strip() + " - " + company_details.abbr)):
- parent_account = company_details.receivables_group \
- if party_type=="Customer" else company_details.payables_group
- if not parent_account:
- frappe.throw(_("Please enter Account Receivable/Payable group in company master"))
-
- # create
- account = frappe.get_doc({
- "doctype": "Account",
- 'account_name': party,
- 'parent_account': parent_account,
- 'group_or_ledger':'Ledger',
- 'company': company,
- 'master_type': party_type,
- 'master_name': party,
- "freeze_account": "No",
- "report_type": "Balance Sheet"
- }).insert(ignore_permissions=True)
-
- frappe.msgprint(_("Account Created: {0}").format(account.name))
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index d28e8d7..64c62af 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -244,8 +244,8 @@
difference = {}
- account_warehouse = dict(frappe.db.sql("""select name, master_name from tabAccount
- where account_type = 'Warehouse' and ifnull(master_name, '') != ''
+ account_warehouse = dict(frappe.db.sql("""select name, warehouse from tabAccount
+ where account_type = 'Warehouse' and ifnull(warehouse, '') != ''
and name in (%s)""" % ', '.join(['%s']*len(account_list)), account_list))
for account, warehouse in account_warehouse.items():
@@ -322,39 +322,6 @@
and fiscal_year='%(fiscal_year)s' and company='%(company)s' %(condition)s
""" % (args))[0][0]
-def rename_account_for(dt, olddn, newdn, merge, company=None):
- if not company:
- companies = [d[0] for d in frappe.db.sql("select name from tabCompany")]
- else:
- companies = [company]
-
- for company in companies:
- old_account = get_account_for(dt, olddn, company)
- if old_account:
- new_account = None
- if not merge:
- if old_account == add_abbr_if_missing(olddn, company):
- new_account = frappe.rename_doc("Account", old_account, newdn)
- else:
- existing_new_account = get_account_for(dt, newdn, company)
- new_account = frappe.rename_doc("Account", old_account,
- existing_new_account or newdn, merge=True if existing_new_account else False)
-
- frappe.db.set_value("Account", new_account or old_account, "master_name", newdn)
-
-def add_abbr_if_missing(dn, company):
- from erpnext.setup.doctype.company.company import get_name_with_abbr
- return get_name_with_abbr(dn, company)
-
-def get_account_for(account_for_doctype, account_for, company):
- if account_for_doctype in ["Customer", "Supplier"]:
- account_for_field = "master_type"
- elif account_for_doctype == "Warehouse":
- account_for_field = "account_type"
-
- return frappe.db.get_value("Account", {account_for_field: account_for_doctype,
- "master_name": account_for, "company": company})
-
def get_currency_precision(currency=None):
if not currency:
currency = frappe.db.get_value("Company",
diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py
index baf8ce5..1f3ad2b 100644
--- a/erpnext/buying/doctype/supplier/supplier.py
+++ b/erpnext/buying/doctype/supplier/supplier.py
@@ -4,11 +4,8 @@
from __future__ import unicode_literals
import frappe
import frappe.defaults
-
-from frappe.utils import cint
from frappe import msgprint, _
from frappe.model.naming import make_autoname
-from erpnext.accounts.party import create_party_account
from erpnext.utilities.transaction_base import TransactionBase
@@ -19,8 +16,6 @@
def autoname(self):
supp_master_name = frappe.defaults.get_global_default('supp_master_name')
if supp_master_name == 'Supplier Name':
- if frappe.db.exists("Customer", self.supplier_name):
- frappe.msgprint(_("A Customer exists with same name"), raise_exception=1)
self.name = self.supplier_name
else:
self.name = make_autoname(self.naming_series + '.#####')
@@ -33,10 +28,6 @@
frappe.db.sql("""update `tabContact` set supplier_name=%s, modified=NOW()
where supplier=%s""", (self.supplier_name, self.name))
- def update_credit_days_limit(self):
- frappe.db.sql("""update tabAccount set credit_days = %s where name = %s""",
- (cint(self.credit_days), self.name + " - " + self.get_company_abbr()))
-
def on_update(self):
if not self.naming_series:
self.naming_series = ''
@@ -44,12 +35,6 @@
self.update_address()
self.update_contact()
- # create account head
- create_party_account(self.name, "Supplier", self.company)
-
- # update credit days and limit in account
- self.update_credit_days_limit()
-
def get_company_abbr(self):
return frappe.db.sql("select abbr from tabCompany where name=%s", self.company)[0][0]
@@ -88,10 +73,6 @@
self.delete_supplier_contact()
self.delete_supplier_account()
- def before_rename(self, olddn, newdn, merge=False):
- from erpnext.accounts.utils import rename_account_for
- rename_account_for("Supplier", olddn, newdn, merge)
-
def after_rename(self, olddn, newdn, merge=False):
set_field = ''
if frappe.defaults.get_global_default('supp_master_name') == 'Supplier Name':
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 5755253..06a3aa0 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -282,6 +282,6 @@
return gl_entries
def get_warehouse_account():
- warehouse_account = dict(frappe.db.sql("""select master_name, name from tabAccount
- where account_type = 'Warehouse' and ifnull(master_name, '') != ''"""))
+ warehouse_account = dict(frappe.db.sql("""select warehouse, name from tabAccount
+ where account_type = 'Warehouse' and ifnull(warehouse, '') != ''"""))
return warehouse_account
diff --git a/erpnext/patches/v4_2/party_model.py b/erpnext/patches/v4_2/party_model.py
new file mode 100644
index 0000000..91a1a26
--- /dev/null
+++ b/erpnext/patches/v4_2/party_model.py
@@ -0,0 +1,10 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+ frappe.reload_doc("accounts", "doctype", "account")
+ frappe.db.sql("""update tabAccount set warehouse=master_name
+ where ifnull(account_type, '') = 'Warehouse' and ifnull(master_name, '') != ''""")
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index a43b44d..76d78cf 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -4,12 +4,11 @@
from __future__ import unicode_literals
import frappe
from frappe.model.naming import make_autoname
-from frappe import msgprint, _
+from frappe import _
import frappe.defaults
from erpnext.utilities.transaction_base import TransactionBase
-from erpnext.accounts.party import create_party_account
class Customer(TransactionBase):
def get_feed(self):
@@ -18,8 +17,6 @@
def autoname(self):
cust_master_name = frappe.defaults.get_global_default('cust_master_name')
if cust_master_name == 'Customer Name':
- if frappe.db.exists("Supplier", self.customer_name):
- msgprint(_("A Supplier exists with same name"), raise_exception=1)
self.name = self.customer_name
else:
self.name = make_autoname(self.naming_series+'.#####')
@@ -46,11 +43,6 @@
frappe.db.sql("""update `tabContact` set customer_name=%s, modified=NOW()
where customer=%s""", (self.customer_name, self.name))
- def update_credit_days_limit(self):
- frappe.db.sql("""update tabAccount set credit_days = %s, credit_limit = %s
- where master_type='Customer' and master_name = %s""",
- (self.credit_days or 0, self.credit_limit or 0, self.name))
-
def create_lead_address_contact(self):
if self.lead_name:
if not frappe.db.get_value("Address", {"lead": self.lead_name, "customer": self.name}):
@@ -78,13 +70,6 @@
self.update_lead_status()
self.update_address()
self.update_contact()
-
- # create account head
- create_party_account(self.name, "Customer", self.company)
-
- # update credit days and limit in account
- self.update_credit_days_limit()
- #create address and contact from lead
self.create_lead_address_contact()
def validate_name_with_customer_group(self):
@@ -121,10 +106,6 @@
if self.lead_name:
frappe.db.sql("update `tabLead` set status='Interested' where name=%s",self.lead_name)
- def before_rename(self, olddn, newdn, merge=False):
- from erpnext.accounts.utils import rename_account_for
- rename_account_for("Customer", olddn, newdn, merge)
-
def after_rename(self, olddn, newdn, merge=False):
set_field = ''
if frappe.defaults.get_global_default('cust_master_name') == 'Customer Name':
diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
index 6e82ae9..d9ade7a 100644
--- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
@@ -73,7 +73,7 @@
dn.get("delivery_note_details")[0].cost_center = "Main - _TC"
stock_in_hand_account = frappe.db.get_value("Account",
- {"master_name": dn.get("delivery_note_details")[0].warehouse})
+ {"warehouse": dn.get("delivery_note_details")[0].warehouse})
from erpnext.accounts.utils import get_balance_on
prev_bal = get_balance_on(stock_in_hand_account, dn.posting_date)
@@ -128,7 +128,7 @@
dn.get("delivery_note_details")[0].qty = 1
stock_in_hand_account = frappe.db.get_value("Account",
- {"master_name": dn.get("delivery_note_details")[0].warehouse})
+ {"warehouse": dn.get("delivery_note_details")[0].warehouse})
from erpnext.accounts.utils import get_balance_on
prev_bal = get_balance_on(stock_in_hand_account, dn.posting_date)
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
index 51c85ce..9de05fb 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -64,9 +64,9 @@
self.assertTrue(gl_entries)
stock_in_hand_account = frappe.db.get_value("Account",
- {"master_name": pr.get("purchase_receipt_details")[0].warehouse})
+ {"warehouse": pr.get("purchase_receipt_details")[0].warehouse})
fixed_asset_account = frappe.db.get_value("Account",
- {"master_name": pr.get("purchase_receipt_details")[1].warehouse})
+ {"warehouse": pr.get("purchase_receipt_details")[1].warehouse})
expected_values = {
stock_in_hand_account: [375.0, 0.0],
diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
index 038606c..fb136f2 100644
--- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
@@ -48,7 +48,7 @@
mr.submit()
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
- "master_name": mr.get("mtn_details")[0].t_warehouse})
+ "warehouse": mr.get("mtn_details")[0].t_warehouse})
self.check_stock_ledger_entries("Stock Entry", mr.name,
[["_Test Item", "_Test Warehouse - _TC", 50.0]])
@@ -83,7 +83,7 @@
[["_Test Item", "_Test Warehouse - _TC", -40.0]])
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
- "master_name": mi.get("mtn_details")[0].s_warehouse})
+ "warehouse": mi.get("mtn_details")[0].s_warehouse})
self.check_gl_entries("Stock Entry", mi.name,
sorted([
@@ -119,10 +119,10 @@
[["_Test Item", "_Test Warehouse - _TC", -45.0], ["_Test Item", "_Test Warehouse 1 - _TC", 45.0]])
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
- "master_name": mtn.get("mtn_details")[0].s_warehouse})
+ "warehouse": mtn.get("mtn_details")[0].s_warehouse})
fixed_asset_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
- "master_name": mtn.get("mtn_details")[0].t_warehouse})
+ "warehouse": mtn.get("mtn_details")[0].t_warehouse})
self.check_gl_entries("Stock Entry", mtn.name,
@@ -174,7 +174,7 @@
repack.submit()
stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse",
- "master_name": repack.get("mtn_details")[1].t_warehouse})
+ "warehouse": repack.get("mtn_details")[1].t_warehouse})
self.check_gl_entries("Stock Entry", repack.name,
sorted([
diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py
index f50c184..b464083 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.py
+++ b/erpnext/stock/doctype/warehouse/warehouse.py
@@ -29,7 +29,7 @@
self.validate_parent_account()
warehouse_account = frappe.db.get_value("Account",
- {"account_type": "Warehouse", "company": self.company, "master_name": self.name},
+ {"account_type": "Warehouse", "company": self.company, "warehouse": self.name},
["name", "parent_account"])
if warehouse_account and warehouse_account[1] != self.create_account_under:
@@ -42,8 +42,7 @@
def create_account_head(self):
if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
- if not frappe.db.get_value("Account", {"account_type": "Warehouse",
- "master_name": self.name}):
+ if not self.get_account(self.name):
if self.get("__islocal") or not frappe.db.get_value(
"Stock Ledger Entry", {"warehouse": self.name}):
self.validate_parent_account()
@@ -54,7 +53,7 @@
'group_or_ledger':'Ledger',
'company':self.company,
"account_type": "Warehouse",
- "master_name": self.name,
+ "warehouse": self.name,
"freeze_account": "No"
})
ac_doc.ignore_permissions = True
@@ -89,8 +88,7 @@
else:
frappe.db.sql("delete from `tabBin` where name = %s", d['name'])
- warehouse_account = frappe.db.get_value("Account",
- {"account_type": "Warehouse", "master_name": self.name})
+ warehouse_account = self.get_account(self.name)
if warehouse_account:
frappe.delete_doc("Account", warehouse_account)
@@ -112,11 +110,33 @@
frappe.db.sql("delete from `tabBin` where warehouse=%s", olddn)
- from erpnext.accounts.utils import rename_account_for
- rename_account_for("Warehouse", olddn, newdn, merge, self.company)
+ self.rename_account_for(olddn, newdn, merge)
return new_warehouse
+ def rename_account_for(self, olddn, newdn, merge):
+ old_account = self.get_account(olddn)
+
+ if old_account:
+ new_account = None
+ if not merge:
+ if old_account == self.add_abbr_if_missing(olddn):
+ new_account = frappe.rename_doc("Account", old_account, newdn)
+ else:
+ existing_new_account = self.get_account(newdn)
+ new_account = frappe.rename_doc("Account", old_account,
+ existing_new_account or newdn, merge=True if existing_new_account else False)
+
+ frappe.db.set_value("Account", new_account or old_account, "warehouse", newdn)
+
+ def add_abbr_if_missing(self, dn):
+ from erpnext.setup.doctype.company.company import get_name_with_abbr
+ return get_name_with_abbr(dn, self.company)
+
+ def get_account(self, warehouse):
+ return frappe.db.get_value("Account", {"account_type": "Warehouse",
+ "warehouse": warehouse, "company": self.company})
+
def after_rename(self, olddn, newdn, merge=False):
if merge:
self.recalculate_bin_qty(newdn)