blob: e801a9922908e069d75ecd1a04becff857dffb2f [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2# License: GNU General Public License v3. See license.txt
3
Anand Doshi3245a152012-10-01 11:35:49 +05304from __future__ import unicode_literals
Rushabh Mehtaf200c522012-09-21 15:19:40 +05305import webnotes
6def execute():
7 set_master_name_in_accounts()
8 set_customer_in_sales_invoices()
9 reset_lft_rgt()
Rushabh Mehta09d84b62012-09-21 19:46:24 +053010 add_analytics_role()
Rushabh Mehtaf200c522012-09-21 15:19:40 +053011
12def set_master_name_in_accounts():
13 accounts = webnotes.conn.sql("""select name, account_name, master_type from tabAccount
14 where ifnull(master_name, '')=''""", as_dict=1)
15 for acc in accounts:
16 if acc["master_type"] in ["Customer", "Supplier"]:
17 master = webnotes.conn.sql("""select name from `tab%s`
18 where name=%s """ % (acc["master_type"], "%s"), acc["account_name"])
19 if master:
20 webnotes.conn.sql("""update `tabAccount`
21 set master_name=%s where name=%s""", (master[0][0], acc["name"]))
22
23def set_customer_in_sales_invoices():
24 webnotes.conn.sql("""update `tabSales Invoice` si
25 set si.customer=(select a.master_name from `tabAccount` a where a.name=si.debit_to)
26 where ifnull(si.customer, '')=''""")
27
28def reset_lft_rgt():
29 from webnotes.utils.nestedset import rebuild_tree
Nabin Hait38200962012-10-02 16:17:00 +053030 dt = [
31 ["Item Group", "parent_item_group"],
32 ["Customer Group", "parent_customer_group"],
33 ["Territory", "parent_territory"],
34 ["Account", "parent_account"],
35 ["Cost Center", "parent_cost_center"],
36 ["Sales Person", "parent_sales_person"]
37 ]
38 for d in dt:
39 rebuild_tree(d[0], d[1])
40 webnotes.conn.commit()
41 webnotes.conn.begin()
Rushabh Mehta09d84b62012-09-21 19:46:24 +053042
43def add_analytics_role():
44 from webnotes.model.doc import Document
45 Document("Role", fielddata={
46 "name": "Analytics",
47 "role_name": "Analytics",
48 "module": "Setup",
49 }).save(1);