Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Anand Doshi | 3245a15 | 2012-10-01 11:35:49 +0530 | [diff] [blame] | 4 | from __future__ import unicode_literals |
Rushabh Mehta | f200c52 | 2012-09-21 15:19:40 +0530 | [diff] [blame] | 5 | import webnotes |
| 6 | def execute(): |
| 7 | set_master_name_in_accounts() |
| 8 | set_customer_in_sales_invoices() |
| 9 | reset_lft_rgt() |
Rushabh Mehta | 09d84b6 | 2012-09-21 19:46:24 +0530 | [diff] [blame] | 10 | add_analytics_role() |
Rushabh Mehta | f200c52 | 2012-09-21 15:19:40 +0530 | [diff] [blame] | 11 | |
| 12 | def 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 | |
| 23 | def 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 | |
| 28 | def reset_lft_rgt(): |
| 29 | from webnotes.utils.nestedset import rebuild_tree |
Nabin Hait | 3820096 | 2012-10-02 16:17:00 +0530 | [diff] [blame] | 30 | 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 Mehta | 09d84b6 | 2012-09-21 19:46:24 +0530 | [diff] [blame] | 42 | |
| 43 | def 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); |