Issue 8842 (#8869)
* adds test that confirms #8842 * fixes #8842 and adds tests * fixes new test case * adds test for `encode_company_abbr` * adds six as a requirement * fixes six.moves.range import * fixes duplicate company used in test * fresh commit of test * fixes failing test - company not saving * fixes failing test * Revert "adds six as a requirement" This reverts commit 80454d98dc5859c37dbf589a4152663d2d644906. * replaces whitespace indentation with tabs
This commit is contained in:
parent
064530d11f
commit
a109141624
0
__init__.py
Normal file
0
__init__.py
Normal file
@ -4,6 +4,7 @@ import frappe
|
|||||||
|
|
||||||
__version__ = '8.0.29'
|
__version__ = '8.0.29'
|
||||||
|
|
||||||
|
|
||||||
def get_default_company(user=None):
|
def get_default_company(user=None):
|
||||||
'''Get default company for user'''
|
'''Get default company for user'''
|
||||||
from frappe.defaults import get_user_default_as_list
|
from frappe.defaults import get_user_default_as_list
|
||||||
@ -19,12 +20,14 @@ def get_default_company(user=None):
|
|||||||
|
|
||||||
return default_company
|
return default_company
|
||||||
|
|
||||||
|
|
||||||
def get_default_currency():
|
def get_default_currency():
|
||||||
'''Returns the currency of the default company'''
|
'''Returns the currency of the default company'''
|
||||||
company = get_default_company()
|
company = get_default_company()
|
||||||
if company:
|
if company:
|
||||||
return frappe.db.get_value('Company', company, 'default_currency')
|
return frappe.db.get_value('Company', company, 'default_currency')
|
||||||
|
|
||||||
|
|
||||||
def get_company_currency(company):
|
def get_company_currency(company):
|
||||||
'''Returns the default company currency'''
|
'''Returns the default company currency'''
|
||||||
if not frappe.flags.company_currency:
|
if not frappe.flags.company_currency:
|
||||||
@ -33,11 +36,13 @@ def get_company_currency(company):
|
|||||||
frappe.flags.company_currency[company] = frappe.db.get_value('Company', company, 'default_currency')
|
frappe.flags.company_currency[company] = frappe.db.get_value('Company', company, 'default_currency')
|
||||||
return frappe.flags.company_currency[company]
|
return frappe.flags.company_currency[company]
|
||||||
|
|
||||||
|
|
||||||
def set_perpetual_inventory(enable=1):
|
def set_perpetual_inventory(enable=1):
|
||||||
accounts_settings = frappe.get_doc("Accounts Settings")
|
accounts_settings = frappe.get_doc("Accounts Settings")
|
||||||
accounts_settings.auto_accounting_for_stock = enable
|
accounts_settings.auto_accounting_for_stock = enable
|
||||||
accounts_settings.save()
|
accounts_settings.save()
|
||||||
|
|
||||||
|
|
||||||
def encode_company_abbr(name, company):
|
def encode_company_abbr(name, company):
|
||||||
'''Returns name encoded with company abbreviation'''
|
'''Returns name encoded with company abbreviation'''
|
||||||
company_abbr = frappe.db.get_value("Company", company, "abbr")
|
company_abbr = frappe.db.get_value("Company", company, "abbr")
|
||||||
@ -46,4 +51,6 @@ def encode_company_abbr(name, company):
|
|||||||
if parts[-1].lower() != company_abbr.lower():
|
if parts[-1].lower() != company_abbr.lower():
|
||||||
parts.append(company_abbr)
|
parts.append(company_abbr)
|
||||||
|
|
||||||
return " - ".join([parts[0], company_abbr])
|
return " - ".join(parts)
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,6 +59,15 @@ class TestWarehouse(unittest.TestCase):
|
|||||||
self.assertTrue(frappe.db.get_value("Account",
|
self.assertTrue(frappe.db.get_value("Account",
|
||||||
filters={"warehouse": "Test Warehouse for Renaming 3 - _TC"}))
|
filters={"warehouse": "Test Warehouse for Renaming 3 - _TC"}))
|
||||||
|
|
||||||
|
# Another rename with multiple dashes
|
||||||
|
if frappe.db.exists("Warehouse", "Test - Warehouse - Company - _TC"):
|
||||||
|
frappe.delete_doc("Warehouse", "Test - Warehouse - Company - _TC")
|
||||||
|
rename_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC", "Test - Warehouse - Company")
|
||||||
|
|
||||||
|
self.assertTrue(frappe.db.exists("Account", "Test - Warehouse - Company - _TC"))
|
||||||
|
self.assertTrue(frappe.db.get_value("Account", filters={"warehouse": "Test - Warehouse - Company - _TC"}))
|
||||||
|
self.assertFalse(frappe.db.get_value("Account", filters={"warehouse": "Test Warehouse for Renaming 3 - _TC"}))
|
||||||
|
|
||||||
def test_warehouse_merging(self):
|
def test_warehouse_merging(self):
|
||||||
set_perpetual_inventory(1)
|
set_perpetual_inventory(1)
|
||||||
|
|
||||||
|
40
erpnext/tests/test_init.py
Normal file
40
erpnext/tests/test_init.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
from erpnext import encode_company_abbr
|
||||||
|
from six.moves import range
|
||||||
|
|
||||||
|
test_records = frappe.get_test_records('Company')
|
||||||
|
|
||||||
|
|
||||||
|
class TestInit(unittest.TestCase):
|
||||||
|
def test_encode_company_abbr(self):
|
||||||
|
company = frappe.new_doc("Company")
|
||||||
|
company.company_name = "New from Existing Company For Test"
|
||||||
|
company.abbr = "NFECT"
|
||||||
|
company.default_currency = "INR"
|
||||||
|
company.save()
|
||||||
|
|
||||||
|
abbr = company.abbr
|
||||||
|
|
||||||
|
names = [
|
||||||
|
"Warehouse Name", "ERPNext Foundation India", "Gold - Member - {a}".format(a=abbr),
|
||||||
|
" - {a}".format(a=abbr), "ERPNext - Foundation - India",
|
||||||
|
"ERPNext Foundation India - {a}".format(a=abbr),
|
||||||
|
"No-Space-{a}".format(a=abbr), "- Warehouse"
|
||||||
|
]
|
||||||
|
|
||||||
|
expected_names = [
|
||||||
|
"Warehouse Name - {a}".format(a=abbr), "ERPNext Foundation India - {a}".format(a=abbr),
|
||||||
|
"Gold - Member - {a}".format(a=abbr), " - {a}".format(a=abbr),
|
||||||
|
"ERPNext - Foundation - India - {a}".format(a=abbr),
|
||||||
|
"ERPNext Foundation India - {a}".format(a=abbr), "No-Space-{a} - {a}".format(a=abbr),
|
||||||
|
"- Warehouse - {a}".format(a=abbr)
|
||||||
|
]
|
||||||
|
|
||||||
|
for i in range(len(names)):
|
||||||
|
enc_name = encode_company_abbr(names[i], company.name)
|
||||||
|
self.assertTrue(
|
||||||
|
enc_name == expected_names[i],
|
||||||
|
"{enc} is not same as {exp}".format(enc=enc_name, exp=expected_names[i])
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user