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 |
Anand Doshi | 9d9aec1 | 2013-01-17 15:44:57 +0530 | [diff] [blame] | 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | import webnotes |
Anand Doshi | f8f0c0d | 2013-01-17 20:20:56 +0530 | [diff] [blame] | 6 | from webnotes import _, msgprint |
| 7 | import json |
Anand Doshi | 9d9aec1 | 2013-01-17 15:44:57 +0530 | [diff] [blame] | 8 | |
| 9 | def get_company_currency(company): |
| 10 | currency = webnotes.conn.get_value("Company", company, "default_currency") |
| 11 | if not currency: |
| 12 | currency = webnotes.conn.get_default("currency") |
| 13 | if not currency: |
| 14 | msgprint(_('Please specify Default Currency in Company Master \ |
| 15 | and Global Defaults'), raise_exception=True) |
| 16 | |
Anand Doshi | f8f0c0d | 2013-01-17 20:20:56 +0530 | [diff] [blame] | 17 | return currency |
| 18 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 19 | def get_root_of(doctype): |
| 20 | """Get root element of a DocType with a tree structure""" |
| 21 | result = webnotes.conn.sql_list("""select name from `tab%s` |
Nabin Hait | 869913c | 2013-06-28 15:00:24 +0530 | [diff] [blame] | 22 | where lft=1 and rgt=(select max(rgt) from `tab%s` where docstatus < 2)""" % |
| 23 | (doctype, doctype)) |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 24 | return result[0] if result else None |
| 25 | |
| 26 | def get_ancestors_of(doctype, name): |
| 27 | """Get ancestor elements of a DocType with a tree structure""" |
| 28 | lft, rgt = webnotes.conn.get_value(doctype, name, ["lft", "rgt"]) |
| 29 | result = webnotes.conn.sql_list("""select name from `tab%s` |
Anand Doshi | 99100a4 | 2013-07-04 17:13:53 +0530 | [diff] [blame] | 30 | where lft<%s and rgt>%s order by lft desc""" % (doctype, "%s", "%s"), (lft, rgt)) |
| 31 | return result or [] |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 32 | |
Anand Doshi | f8f0c0d | 2013-01-17 20:20:56 +0530 | [diff] [blame] | 33 | @webnotes.whitelist() |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 34 | def get_price_list_currency(price_list): |
| 35 | return {"price_list_currency": webnotes.conn.get_value("Price List", price_list, |
Nabin Hait | 48a0bd3 | 2013-07-23 15:31:39 +0530 | [diff] [blame] | 36 | "currency")} |