update account root type patch
This commit is contained in:
parent
4efc5d74d4
commit
27b12ef1b6
@ -82,20 +82,6 @@
|
||||
"permlevel": 0,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "root_type",
|
||||
"fieldtype": "Select",
|
||||
"label": "Root Type",
|
||||
"options": "\nAsset\nLiability\nIncome\nExpense\nEquity",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "report_type",
|
||||
"fieldtype": "Select",
|
||||
"label": "Report Type",
|
||||
"options": "\nBalance Sheet\nProfit and Loss",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"description": "Setting Account Type helps in selecting this Account in transactions.",
|
||||
"fieldname": "account_type",
|
||||
@ -176,6 +162,22 @@
|
||||
"options": "\nDebit\nCredit",
|
||||
"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,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "lft",
|
||||
"fieldtype": "Int",
|
||||
@ -207,7 +209,7 @@
|
||||
"icon": "icon-money",
|
||||
"idx": 1,
|
||||
"in_create": 1,
|
||||
"modified": "2014-05-20 11:44:53.012945",
|
||||
"modified": "2014-05-21 11:42:47.255511",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Account",
|
||||
|
@ -9,12 +9,15 @@ def execute():
|
||||
|
||||
account_table_columns = frappe.db.get_table_columns("Account")
|
||||
if "debit_or_credit" in account_table_columns and "is_pl_account" in account_table_columns:
|
||||
frappe.db.sql("""UPDATE tabAccount SET root_type = CASE
|
||||
WHEN (debit_or_credit='Debit' and is_pl_account = 'No') THEN 'Asset'
|
||||
WHEN (debit_or_credit='Credit' and is_pl_account = 'No') THEN 'Liability'
|
||||
WHEN (debit_or_credit='Debit' and is_pl_account = 'Yes') THEN 'Expense'
|
||||
WHEN (debit_or_credit='Credit' and is_pl_account = 'Yes') THEN 'Income'
|
||||
END""")
|
||||
frappe.db.sql("""UPDATE tabAccount
|
||||
SET root_type = CASE
|
||||
WHEN (debit_or_credit='Debit' and is_pl_account = 'No') THEN 'Asset'
|
||||
WHEN (debit_or_credit='Credit' and is_pl_account = 'No') THEN 'Liability'
|
||||
WHEN (debit_or_credit='Debit' and is_pl_account = 'Yes') THEN 'Expense'
|
||||
WHEN (debit_or_credit='Credit' and is_pl_account = 'Yes') THEN 'Income'
|
||||
END
|
||||
WHERE ifnull(parent_account, '') = ''
|
||||
""")
|
||||
|
||||
else:
|
||||
frappe.db.sql("""UPDATE tabAccount
|
||||
@ -24,11 +27,13 @@ def execute():
|
||||
WHEN name like '%%expense%%' THEN 'Expense'
|
||||
WHEN name like '%%income%%' THEN 'Income'
|
||||
END
|
||||
WHERE
|
||||
ifnull(parent_account, '') = ''
|
||||
WHERE ifnull(parent_account, '') = ''
|
||||
""")
|
||||
|
||||
for root in frappe.db.sql("""SELECT lft, rgt, root_type FROM `tabAccount`
|
||||
WHERE ifnull(parent_account, '')=''""", as_dict=True):
|
||||
for root in frappe.db.sql("""SELECT name, lft, rgt, root_type FROM `tabAccount`
|
||||
WHERE ifnull(parent_account, '')=''""", as_dict=True):
|
||||
if root.root_type:
|
||||
frappe.db.sql("""UPDATE tabAccount SET root_type=%s WHERE lft>%s and rgt<%s""",
|
||||
(root.root_type, root.lft, root.rgt))
|
||||
else:
|
||||
print "Root type not found for {0}".format(root.name)
|
||||
|
Loading…
Reference in New Issue
Block a user