Rushabh Mehta | ad45e31 | 2013-11-20 12:59:58 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
Anand Doshi | 9d9aec1 | 2013-01-17 15:44:57 +0530 | [diff] [blame] | 3 | |
| 4 | from __future__ import unicode_literals |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 5 | import frappe |
Rushabh Mehta | a151647 | 2014-04-30 19:38:28 +0530 | [diff] [blame] | 6 | from frappe import _, throw |
Anand Doshi | 9d9aec1 | 2013-01-17 15:44:57 +0530 | [diff] [blame] | 7 | |
| 8 | def get_company_currency(company): |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 9 | currency = frappe.db.get_value("Company", company, "default_currency") |
Anand Doshi | 9d9aec1 | 2013-01-17 15:44:57 +0530 | [diff] [blame] | 10 | if not currency: |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 11 | currency = frappe.db.get_default("currency") |
Anand Doshi | 9d9aec1 | 2013-01-17 15:44:57 +0530 | [diff] [blame] | 12 | if not currency: |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 13 | throw(_('Please specify Default Currency in Company Master and Global Defaults')) |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 14 | |
Anand Doshi | f8f0c0d | 2013-01-17 20:20:56 +0530 | [diff] [blame] | 15 | return currency |
| 16 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 17 | def get_root_of(doctype): |
| 18 | """Get root element of a DocType with a tree structure""" |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 19 | result = frappe.db.sql_list("""select name from `tab%s` |
| 20 | where lft=1 and rgt=(select max(rgt) from `tab%s` where docstatus < 2)""" % |
Nabin Hait | 869913c | 2013-06-28 15:00:24 +0530 | [diff] [blame] | 21 | (doctype, doctype)) |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 22 | return result[0] if result else None |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 23 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 24 | def get_ancestors_of(doctype, name): |
| 25 | """Get ancestor elements of a DocType with a tree structure""" |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 26 | lft, rgt = frappe.db.get_value(doctype, name, ["lft", "rgt"]) |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 27 | result = frappe.db.sql_list("""select name from `tab%s` |
Anand Doshi | 99100a4 | 2013-07-04 17:13:53 +0530 | [diff] [blame] | 28 | where lft<%s and rgt>%s order by lft desc""" % (doctype, "%s", "%s"), (lft, rgt)) |
| 29 | return result or [] |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 30 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 31 | @frappe.whitelist() |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 32 | def get_price_list_currency(price_list): |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 33 | price_list_currency = frappe.db.get_value("Price List", {"name": price_list, |
Akhilesh Darjee | e82eee5 | 2014-01-20 16:09:45 +0530 | [diff] [blame] | 34 | "enabled": 1}, "currency") |
| 35 | |
| 36 | if not price_list_currency: |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 37 | throw(_("Price List {0} is disabled").format(price_list)) |
Akhilesh Darjee | e82eee5 | 2014-01-20 16:09:45 +0530 | [diff] [blame] | 38 | else: |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 39 | return {"price_list_currency": price_list_currency} |
Rushabh Mehta | a151647 | 2014-04-30 19:38:28 +0530 | [diff] [blame] | 40 | |
| 41 | def before_tests(): |
| 42 | # complete setup if missing |
| 43 | from erpnext.setup.page.setup_wizard.setup_wizard import setup_account |
| 44 | if not frappe.get_list("Item Group"): |
| 45 | setup_account({ |
| 46 | "currency" :"USD", |
| 47 | "first_name" :"Test", |
| 48 | "last_name" :"User", |
| 49 | "company_name" :"Wind Power LLC", |
| 50 | "timezone" :"America/New_York", |
| 51 | "company_abbr" :"WP", |
| 52 | "industry" :"Manufacturing", |
| 53 | "country" :"United States", |
| 54 | "fy_start_date" :"2014-01-01", |
| 55 | "fy_end_date" :"2014-12-31", |
| 56 | "language" :"english", |
| 57 | "company_tagline" :"Testing", |
| 58 | "email" :"test@erpnext.com", |
| 59 | "password" :"test" |
| 60 | }) |
| 61 | |
| 62 | frappe.db.sql("delete from `tabLeave Allocation`") |
| 63 | frappe.db.sql("delete from `tabLeave Application`") |
| 64 | frappe.db.sql("delete from `tabSalary Slip`") |
| 65 | frappe.db.sql("delete from `tabItem Price`") |
| 66 | frappe.db.commit() |