From a1091416242d24a2f33811091ab0714cdf07931d Mon Sep 17 00:00:00 2001 From: tundebabzy Date: Fri, 19 May 2017 07:12:45 +0100 Subject: [PATCH] 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 --- __init__.py | 0 erpnext/__init__.py | 9 ++++- .../stock/doctype/warehouse/test_warehouse.py | 9 +++++ erpnext/tests/test_init.py | 40 +++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 __init__.py create mode 100644 erpnext/tests/test_init.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/__init__.py b/erpnext/__init__.py index f80b7bf4cc..fdbdaa8a86 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -4,6 +4,7 @@ import frappe __version__ = '8.0.29' + def get_default_company(user=None): '''Get default company for user''' from frappe.defaults import get_user_default_as_list @@ -19,12 +20,14 @@ def get_default_company(user=None): return default_company + def get_default_currency(): '''Returns the currency of the default company''' company = get_default_company() if company: return frappe.db.get_value('Company', company, 'default_currency') + def get_company_currency(company): '''Returns the default 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') return frappe.flags.company_currency[company] + def set_perpetual_inventory(enable=1): accounts_settings = frappe.get_doc("Accounts Settings") accounts_settings.auto_accounting_for_stock = enable accounts_settings.save() + def encode_company_abbr(name, company): '''Returns name encoded with company abbreviation''' 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(): parts.append(company_abbr) - return " - ".join([parts[0], company_abbr]) + return " - ".join(parts) + + diff --git a/erpnext/stock/doctype/warehouse/test_warehouse.py b/erpnext/stock/doctype/warehouse/test_warehouse.py index ec64bdd3bd..31d1926cfa 100644 --- a/erpnext/stock/doctype/warehouse/test_warehouse.py +++ b/erpnext/stock/doctype/warehouse/test_warehouse.py @@ -59,6 +59,15 @@ class TestWarehouse(unittest.TestCase): self.assertTrue(frappe.db.get_value("Account", 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): set_perpetual_inventory(1) diff --git a/erpnext/tests/test_init.py b/erpnext/tests/test_init.py new file mode 100644 index 0000000000..2baea97838 --- /dev/null +++ b/erpnext/tests/test_init.py @@ -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]) + )