blob: 1b61ea9201e4c604e74b1f8d7573336e739f2e0c [file] [log] [blame]
Anand Doshi9d9aec12013-01-17 15:44:57 +05301# ERPNext - web based ERP (http://erpnext.com)
2# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17from __future__ import unicode_literals
18import webnotes
Anand Doshif8f0c0d2013-01-17 20:20:56 +053019from webnotes import _, msgprint
20import json
Anand Doshi9d9aec12013-01-17 15:44:57 +053021
22def get_company_currency(company):
23 currency = webnotes.conn.get_value("Company", company, "default_currency")
24 if not currency:
25 currency = webnotes.conn.get_default("currency")
26 if not currency:
27 msgprint(_('Please specify Default Currency in Company Master \
28 and Global Defaults'), raise_exception=True)
29
Anand Doshif8f0c0d2013-01-17 20:20:56 +053030 return currency
31
32@webnotes.whitelist()
33def get_price_list_currency(args):
34 """
35 args = {
36 "price_list_name": "Something",
37 "use_for": "buying" or "selling"
38 }
39 """
40 if isinstance(args, basestring):
41 args = json.loads(args)
42
43 result = webnotes.conn.sql("""select ref_currency from `tabItem Price`
44 where price_list_name=%s and `%s`=1""" % ("%s", args.get("use_for")),
45 (args.get("price_list_name"),))
46 if result and len(result)==1:
47 return {"price_list_currency": result[0][0]}
48 else:
Nabin Hait5b4c2942013-01-22 11:12:02 +053049 return {}