Anand Doshi | 3245a15 | 2012-10-01 11:35:49 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
Rushabh Mehta | f200c52 | 2012-09-21 15:19:40 +0530 | [diff] [blame] | 2 | import webnotes |
| 3 | def execute(): |
| 4 | set_master_name_in_accounts() |
| 5 | set_customer_in_sales_invoices() |
| 6 | reset_lft_rgt() |
Rushabh Mehta | 09d84b6 | 2012-09-21 19:46:24 +0530 | [diff] [blame] | 7 | add_analytics_role() |
Rushabh Mehta | f200c52 | 2012-09-21 15:19:40 +0530 | [diff] [blame] | 8 | |
| 9 | def 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 | |
| 20 | def 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 | |
| 25 | def reset_lft_rgt(): |
| 26 | from webnotes.utils.nestedset import rebuild_tree |
Nabin Hait | 3820096 | 2012-10-02 16:17:00 +0530 | [diff] [blame] | 27 | 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 Mehta | 09d84b6 | 2012-09-21 19:46:24 +0530 | [diff] [blame] | 39 | |
| 40 | def 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); |