blob: 802cbcd79c68387d9961f81a8345201b85366c13 [file] [log] [blame]
Anand Doshi3245a152012-10-01 11:35:49 +05301from __future__ import unicode_literals
Rushabh Mehtaf200c522012-09-21 15:19:40 +05302import webnotes
3def execute():
4 set_master_name_in_accounts()
5 set_customer_in_sales_invoices()
6 reset_lft_rgt()
Rushabh Mehta09d84b62012-09-21 19:46:24 +05307 add_analytics_role()
Rushabh Mehtaf200c522012-09-21 15:19:40 +05308
9def set_master_name_in_accounts():
10 accounts = webnotes.conn.sql("""select name, account_name, master_type from tabAccount
11 where ifnull(master_name, '')=''""", as_dict=1)
12 for acc in accounts:
13 if acc["master_type"] in ["Customer", "Supplier"]:
14 master = webnotes.conn.sql("""select name from `tab%s`
15 where name=%s """ % (acc["master_type"], "%s"), acc["account_name"])
16 if master:
17 webnotes.conn.sql("""update `tabAccount`
18 set master_name=%s where name=%s""", (master[0][0], acc["name"]))
19
20def set_customer_in_sales_invoices():
21 webnotes.conn.sql("""update `tabSales Invoice` si
22 set si.customer=(select a.master_name from `tabAccount` a where a.name=si.debit_to)
23 where ifnull(si.customer, '')=''""")
24
25def reset_lft_rgt():
26 from webnotes.utils.nestedset import rebuild_tree
Nabin Hait38200962012-10-02 16:17:00 +053027 dt = [
28 ["Item Group", "parent_item_group"],
29 ["Customer Group", "parent_customer_group"],
30 ["Territory", "parent_territory"],
31 ["Account", "parent_account"],
32 ["Cost Center", "parent_cost_center"],
33 ["Sales Person", "parent_sales_person"]
34 ]
35 for d in dt:
36 rebuild_tree(d[0], d[1])
37 webnotes.conn.commit()
38 webnotes.conn.begin()
Rushabh Mehta09d84b62012-09-21 19:46:24 +053039
40def add_analytics_role():
41 from webnotes.model.doc import Document
42 Document("Role", fielddata={
43 "name": "Analytics",
44 "role_name": "Analytics",
45 "module": "Setup",
46 }).save(1);