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 | 70c3f79 | 2017-03-27 12:57:38 +0600 | [diff] [blame] | 5 | __version__ = '7.2.31' |
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 | |
| 28 | def set_perpetual_inventory(enable=1): |
| 29 | accounts_settings = frappe.get_doc("Accounts Settings") |
| 30 | accounts_settings.auto_accounting_for_stock = enable |
| 31 | accounts_settings.save() |
| 32 | |
| 33 | def encode_company_abbr(name, company): |
| 34 | '''Returns name encoded with company abbreviation''' |
| 35 | company_abbr = frappe.db.get_value("Company", company, "abbr") |
| 36 | parts = name.rsplit(" - ", 1) |
| 37 | |
| 38 | if parts[-1].lower() != company_abbr.lower(): |
| 39 | parts.append(company_abbr) |
| 40 | |
| 41 | return " - ".join([parts[0], company_abbr]) |