Anand Doshi | 227b238 | 2016-06-09 16:29:12 +0530 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | from __future__ import unicode_literals |
Rushabh Mehta | 86a824c | 2016-04-15 16:44:44 +0530 | [diff] [blame] | 3 | import frappe |
| 4 | |
Nabin Hait | 8470b39 | 2017-05-04 12:50:31 +0600 | [diff] [blame^] | 5 | __version__ = '8.0.22' |
Anand Doshi | 227b238 | 2016-06-09 16:29:12 +0530 | [diff] [blame] | 6 | |
Rushabh Mehta | 86a824c | 2016-04-15 16:44:44 +0530 | [diff] [blame] | 7 | def 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 | |
| 22 | def get_default_currency(): |
| 23 | '''Returns the currency of the default company''' |
| 24 | company = get_default_company() |
| 25 | if company: |
Anand Doshi | 227b238 | 2016-06-09 16:29:12 +0530 | [diff] [blame] | 26 | return frappe.db.get_value('Company', company, 'default_currency') |
Rushabh Mehta | 6695830 | 2017-01-16 16:57:53 +0530 | [diff] [blame] | 27 | |
Rushabh Mehta | cc8b2b2 | 2017-03-31 12:44:29 +0530 | [diff] [blame] | 28 | def 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 Mehta | 6695830 | 2017-01-16 16:57:53 +0530 | [diff] [blame] | 36 | def 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 | |
| 41 | def 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]) |