blob: d102c9e9cdec9de2fadf259922c58b2fbf68630a [file] [log] [blame]
Anand Doshi227b2382016-06-09 16:29:12 +05301# -*- coding: utf-8 -*-
2from __future__ import unicode_literals
Rushabh Mehta86a824c2016-04-15 16:44:44 +05303import frappe
4
Nabin Hait8470b392017-05-04 12:50:31 +06005__version__ = '8.0.22'
Anand Doshi227b2382016-06-09 16:29:12 +05306
Rushabh Mehta86a824c2016-04-15 16:44:44 +05307def get_default_company(user=None):
8 '''Get default company for user'''
9 from frappe.defaults import get_user_default_as_list
10
11 if not user:
12 user = frappe.session.user
13
14 companies = get_user_default_as_list(user, 'company')
15 if companies:
16 default_company = companies[0]
17 else:
18 default_company = frappe.db.get_single_value('Global Defaults', 'default_company')
19
20 return default_company
21
22def get_default_currency():
23 '''Returns the currency of the default company'''
24 company = get_default_company()
25 if company:
Anand Doshi227b2382016-06-09 16:29:12 +053026 return frappe.db.get_value('Company', company, 'default_currency')
Rushabh Mehta66958302017-01-16 16:57:53 +053027
Rushabh Mehtacc8b2b22017-03-31 12:44:29 +053028def get_company_currency(company):
29 '''Returns the default company currency'''
30 if not frappe.flags.company_currency:
31 frappe.flags.company_currency = {}
32 if not company in frappe.flags.company_currency:
33 frappe.flags.company_currency[company] = frappe.db.get_value('Company', company, 'default_currency')
34 return frappe.flags.company_currency[company]
35
Rushabh Mehta66958302017-01-16 16:57:53 +053036def set_perpetual_inventory(enable=1):
37 accounts_settings = frappe.get_doc("Accounts Settings")
38 accounts_settings.auto_accounting_for_stock = enable
39 accounts_settings.save()
40
41def encode_company_abbr(name, company):
42 '''Returns name encoded with company abbreviation'''
43 company_abbr = frappe.db.get_value("Company", company, "abbr")
44 parts = name.rsplit(" - ", 1)
45
46 if parts[-1].lower() != company_abbr.lower():
47 parts.append(company_abbr)
48
49 return " - ".join([parts[0], company_abbr])