Merge branch 'master' of github.com:webnotes/erpnext into wsgi

Conflicts:
	accounts/doctype/account/account.py
	accounts/doctype/gl_entry/gl_entry.py
	accounts/doctype/period_closing_voucher/period_closing_voucher.py
	stock/doctype/delivery_note/delivery_note.py
	stock/doctype/landed_cost_wizard/landed_cost_wizard.py
	stock/doctype/purchase_receipt/purchase_receipt.py
	stock/doctype/stock_ledger/stock_ledger.py
	stock/doctype/warehouse/warehouse.py
	stock/stock_ledger.py
This commit is contained in:
Anand Doshi
2013-09-25 19:55:41 +05:30
242 changed files with 3879 additions and 3910 deletions

View File

@@ -18,12 +18,22 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.toggle_display('account_name', doc.__islocal);
// hide fields if group
cur_frm.toggle_display(['account_type', 'master_type', 'master_name', 'freeze_account',
cur_frm.toggle_display(['account_type', 'master_type', 'master_name',
'credit_days', 'credit_limit', 'tax_rate'], doc.group_or_ledger=='Ledger')
// disable fields
cur_frm.toggle_enable(['account_name', 'debit_or_credit', 'group_or_ledger',
'is_pl_account', 'company'], false);
if(doc.group_or_ledger=='Ledger') {
wn.model.with_doc("Accounts Settings", "Accounts Settings", function (name) {
var accounts_settings = wn.model.get_doc("Accounts Settings", name);
var display = accounts_settings["frozen_accounts_modifier"]
&& in_list(user_roles, accounts_settings["frozen_accounts_modifier"]);
cur_frm.toggle_display('freeze_account', display);
});
}
// read-only for root accounts
if(!doc.parent_account) {
@@ -32,10 +42,10 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
} else {
// credit days and type if customer or supplier
cur_frm.set_intro(null);
cur_frm.toggle_display(['credit_days', 'credit_limit', 'master_name'],
in_list(['Customer', 'Supplier'], doc.master_type));
// hide tax_rate
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
@@ -44,7 +54,10 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
}
cur_frm.cscript.master_type = function(doc, cdt, cdn) {
cur_frm.toggle_display(['credit_days', 'credit_limit', 'master_name'],
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));
}
@@ -58,10 +71,10 @@ cur_frm.add_fetch('parent_account', 'is_pl_account', 'is_pl_account');
// -----------------------------------------
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_type', 'master_name'],
cstr(doc.account_type)=='');
cur_frm.toggle_display(['tax_rate'], doc.account_type == 'Tax');
cur_frm.toggle_display('master_type', cstr(doc.account_type)=='');
cur_frm.toggle_display('master_name', doc.account_type=='Warehouse' ||
in_list(['Customer', 'Supplier'], doc.master_type));
}
}
@@ -109,11 +122,15 @@ cur_frm.cscript.convert_to_group = function(doc, cdt, cdn) {
}
cur_frm.fields_dict['master_name'].get_query = function(doc) {
if (doc.master_type) {
if (doc.master_type || doc.account_type=="Warehouse") {
var dt = doc.master_type || "Warehouse";
return {
doctype: doc.master_type,
doctype: dt,
query: "accounts.doctype.account.account.get_master_name",
filters: { "master_type": doc.master_type }
filters: {
"master_type": dt,
"company": doc.company
}
}
}
}

View File

@@ -4,7 +4,7 @@
from __future__ import unicode_literals
import webnotes
from webnotes.utils import flt, fmt_money
from webnotes.utils import flt, fmt_money, cstr, cint
from webnotes import msgprint, _
get_value = webnotes.conn.get_value
@@ -15,13 +15,25 @@ class DocType:
self.nsm_parent_field = 'parent_account'
def autoname(self):
"""Append abbreviation to company on naming"""
self.doc.name = self.doc.account_name.strip() + ' - ' + \
webnotes.conn.get_value("Company", self.doc.company, "abbr")
def get_address(self):
address = webnotes.conn.get_value(self.doc.master_type, self.doc.master_name, "address")
return {'address': address}
return {
'address': webnotes.conn.get_value(self.doc.master_type,
self.doc.master_name, "address")
}
def validate(self):
self.validate_master_name()
self.validate_parent()
self.validate_duplicate_account()
self.validate_root_details()
self.validate_mandatory()
self.validate_frozen_accounts_modifier()
if not self.doc.parent_account:
self.doc.parent_account = ''
def validate_master_name(self):
"""Remind to add master name"""
@@ -70,6 +82,15 @@ class DocType:
if webnotes.conn.exists("Account", self.doc.name):
if not webnotes.conn.get_value("Account", self.doc.name, "parent_account"):
webnotes.msgprint("Root cannot be edited.", raise_exception=1)
def validate_frozen_accounts_modifier(self):
old_value = webnotes.conn.get_value("Account", self.doc.name, "freeze_account")
if old_value and old_value != self.doc.freeze_account:
frozen_accounts_modifier = webnotes.conn.get_value( 'Accounts Settings', None,
'frozen_accounts_modifier')
if not frozen_accounts_modifier or \
frozen_accounts_modifier not in webnotes.user.get_roles():
webnotes.throw(_("You are not authorized to set Frozen value"))
def convert_group_to_ledger(self):
if self.check_if_child_exists():
@@ -97,9 +118,7 @@ class DocType:
# Check if any previous balance exists
def check_gle_exists(self):
exists = webnotes.conn.sql("""select name from `tabGL Entry` where account = %s
and ifnull(is_cancelled, 'No') = 'No'""", self.doc.name)
return exists and exists[0][0] or ''
return webnotes.conn.get_value("GL Entry", {"account": self.doc.name})
def check_if_child_exists(self):
return webnotes.conn.sql("""select name from `tabAccount` where parent_account = %s
@@ -110,16 +129,25 @@ class DocType:
msgprint("Debit or Credit field is mandatory", raise_exception=1)
if not self.doc.is_pl_account:
msgprint("Is PL Account field is mandatory", raise_exception=1)
def validate(self):
self.validate_master_name()
self.validate_parent()
self.validate_duplicate_account()
self.validate_root_details()
self.validate_mandatory()
if not self.doc.parent_account:
self.doc.parent_account = ''
def validate_warehouse_account(self):
if not cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")):
return
if self.doc.account_type == "Warehouse":
old_warehouse = cstr(webnotes.conn.get_value("Account", self.doc.name, "master_name"))
if old_warehouse != cstr(self.doc.master_name):
if old_warehouse:
self.validate_warehouse(old_warehouse)
if self.doc.master_name:
self.validate_warehouse(self.doc.master_name)
else:
webnotes.throw(_("Master Name is mandatory if account type is Warehouse"))
def validate_warehouse(self, warehouse):
if webnotes.conn.get_value("Stock Ledger Entry", {"warehouse": warehouse}):
webnotes.throw(_("Stock transactions exist against warehouse ") + warehouse +
_(" .You can not assign / modify / remove Master Name"))
def update_nsm_model(self):
"""update lft, rgt indices for nested set model"""
@@ -172,10 +200,6 @@ class DocType:
self.validate_trash()
self.update_nsm_model()
# delete all cancelled gl entry of this account
webnotes.conn.sql("""delete from `tabGL Entry` where account = %s and
ifnull(is_cancelled, 'No') = 'Yes'""", self.doc.name)
def on_rename(self, new, old, merge=False):
company_abbr = webnotes.conn.get_value("Company", self.doc.company, "abbr")
parts = new.split(" - ")
@@ -203,9 +227,11 @@ class DocType:
return " - ".join(parts)
def get_master_name(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select name from `tab%s` where %s like %s
conditions = (" and company='%s'"% filters["company"]) if doctype == "Warehouse" else ""
return webnotes.conn.sql("""select name from `tab%s` where %s like %s %s
order by name limit %s, %s""" %
(filters["master_type"], searchfield, "%s", "%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):

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-01-30 12:49:46",
"docstatus": 0,
"modified": "2013-07-05 14:23:30",
"modified": "2013-09-24 11:22:18",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -23,7 +23,8 @@
"name": "__common__",
"parent": "Account",
"parentfield": "fields",
"parenttype": "DocType"
"parenttype": "DocType",
"permlevel": 0
},
{
"amend": 0,
@@ -45,14 +46,12 @@
"fieldname": "properties",
"fieldtype": "Section Break",
"label": "Account Details",
"oldfieldtype": "Section Break",
"permlevel": 0
"oldfieldtype": "Section Break"
},
{
"doctype": "DocField",
"fieldname": "column_break0",
"fieldtype": "Column Break",
"permlevel": 0,
"width": "50%"
},
{
@@ -64,7 +63,6 @@
"no_copy": 1,
"oldfieldname": "account_name",
"oldfieldtype": "Data",
"permlevel": 0,
"read_only": 1,
"reqd": 1,
"search_index": 1
@@ -77,7 +75,6 @@
"label": "Level",
"oldfieldname": "level",
"oldfieldtype": "Int",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
@@ -91,7 +88,6 @@
"oldfieldname": "group_or_ledger",
"oldfieldtype": "Select",
"options": "\nLedger\nGroup",
"permlevel": 0,
"read_only": 1,
"reqd": 1,
"search_index": 1
@@ -104,7 +100,6 @@
"label": "Debit or Credit",
"oldfieldname": "debit_or_credit",
"oldfieldtype": "Data",
"permlevel": 0,
"read_only": 1,
"search_index": 1
},
@@ -117,7 +112,6 @@
"oldfieldname": "is_pl_account",
"oldfieldtype": "Select",
"options": "Yes\nNo",
"permlevel": 0,
"read_only": 1,
"search_index": 1
},
@@ -130,7 +124,6 @@
"oldfieldname": "company",
"oldfieldtype": "Link",
"options": "Company",
"permlevel": 0,
"read_only": 1,
"reqd": 1,
"search_index": 1
@@ -139,7 +132,6 @@
"doctype": "DocField",
"fieldname": "column_break1",
"fieldtype": "Column Break",
"permlevel": 0,
"width": "50%"
},
{
@@ -150,7 +142,6 @@
"oldfieldname": "parent_account",
"oldfieldtype": "Link",
"options": "Account",
"permlevel": 0,
"search_index": 1
},
{
@@ -162,7 +153,7 @@
"label": "Account Type",
"oldfieldname": "account_type",
"oldfieldtype": "Select",
"options": "\nFixed Asset Account\nBank or Cash\nExpense Account\nTax\nIncome Account\nChargeable",
"options": "\nFixed Asset Account\nBank or Cash\nExpense Account\nTax\nIncome Account\nChargeable\nWarehouse",
"permlevel": 0,
"search_index": 0
},
@@ -175,19 +166,17 @@
"label": "Rate",
"oldfieldname": "tax_rate",
"oldfieldtype": "Currency",
"permlevel": 0,
"reqd": 0
},
{
"description": "If the account is frozen, entries are allowed for the \"Account Manager\" only.",
"description": "If the account is frozen, entries are allowed to restricted users.",
"doctype": "DocField",
"fieldname": "freeze_account",
"fieldtype": "Select",
"label": "Frozen",
"oldfieldname": "freeze_account",
"oldfieldtype": "Select",
"options": "No\nYes",
"permlevel": 2
"options": "No\nYes"
},
{
"doctype": "DocField",
@@ -197,7 +186,6 @@
"label": "Credit Days",
"oldfieldname": "credit_days",
"oldfieldtype": "Int",
"permlevel": 0,
"print_hide": 1
},
{
@@ -209,7 +197,6 @@
"oldfieldname": "credit_limit",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1
},
{
@@ -220,8 +207,7 @@
"label": "Master Type",
"oldfieldname": "master_type",
"oldfieldtype": "Select",
"options": "\nSupplier\nCustomer\nEmployee",
"permlevel": 0
"options": "\nSupplier\nCustomer\nEmployee"
},
{
"doctype": "DocField",
@@ -230,8 +216,7 @@
"label": "Master Name",
"oldfieldname": "master_name",
"oldfieldtype": "Link",
"options": "[Select]",
"permlevel": 0
"options": "[Select]"
},
{
"default": "1",
@@ -239,8 +224,7 @@
"doctype": "DocField",
"fieldname": "allow_negative_balance",
"fieldtype": "Check",
"label": "Allow Negative Balance",
"permlevel": 0
"label": "Allow Negative Balance"
},
{
"doctype": "DocField",
@@ -248,7 +232,6 @@
"fieldtype": "Int",
"hidden": 1,
"label": "Lft",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
@@ -258,7 +241,6 @@
"fieldtype": "Int",
"hidden": 1,
"label": "Rgt",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
@@ -268,7 +250,6 @@
"fieldtype": "Data",
"hidden": 1,
"label": "Old Parent",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},

View File

@@ -9,36 +9,38 @@ def make_test_records(verbose):
accounts = [
# [account_name, parent_account, group_or_ledger]
["_Test Account Bank Account", "Bank Accounts - _TC", "Ledger"],
["_Test Account Bank Account", "Bank Accounts", "Ledger"],
["_Test Account Stock Expenses", "Direct Expenses - _TC", "Group"],
["_Test Account Shipping Charges", "_Test Account Stock Expenses - _TC", "Ledger"],
["_Test Account Customs Duty", "_Test Account Stock Expenses - _TC", "Ledger"],
["_Test Account Stock Expenses", "Direct Expenses", "Group"],
["_Test Account Shipping Charges", "_Test Account Stock Expenses", "Ledger"],
["_Test Account Customs Duty", "_Test Account Stock Expenses", "Ledger"],
["_Test Account Tax Assets", "Current Assets - _TC", "Group"],
["_Test Account VAT", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Service Tax", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Tax Assets", "Current Assets", "Group"],
["_Test Account VAT", "_Test Account Tax Assets", "Ledger"],
["_Test Account Service Tax", "_Test Account Tax Assets", "Ledger"],
["_Test Account Reserves and Surplus", "Current Liabilities", "Ledger"],
["_Test Account Cost for Goods Sold", "Expenses - _TC", "Ledger"],
["_Test Account Excise Duty", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account Education Cess", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account S&H Education Cess", "_Test Account Tax Assets - _TC", "Ledger"],
["_Test Account CST", "Direct Expenses - _TC", "Ledger"],
["_Test Account Discount", "Direct Expenses - _TC", "Ledger"],
["_Test Account Cost for Goods Sold", "Expenses", "Ledger"],
["_Test Account Excise Duty", "_Test Account Tax Assets", "Ledger"],
["_Test Account Education Cess", "_Test Account Tax Assets", "Ledger"],
["_Test Account S&H Education Cess", "_Test Account Tax Assets", "Ledger"],
["_Test Account CST", "Direct Expenses", "Ledger"],
["_Test Account Discount", "Direct Expenses", "Ledger"],
# related to Account Inventory Integration
["_Test Account Stock In Hand", "Current Assets - _TC", "Ledger"],
["_Test Account Stock In Hand", "Current Assets", "Ledger"],
["_Test Account Fixed Assets", "Current Assets", "Ledger"],
]
test_objects = make_test_objects("Account", [[{
"doctype": "Account",
"account_name": account_name,
"parent_account": parent_account,
"company": "_Test Company",
"group_or_ledger": group_or_ledger
}] for account_name, parent_account, group_or_ledger in accounts])
webnotes.conn.set_value("Company", "_Test Company", "stock_in_hand_account",
"_Test Account Stock In Hand - _TC")
for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"]]:
test_objects = make_test_objects("Account", [[{
"doctype": "Account",
"account_name": account_name,
"parent_account": parent_account + " - " + abbr,
"company": company,
"group_or_ledger": group_or_ledger
}] for account_name, parent_account, group_or_ledger in accounts])
return test_objects