Skip to content

Commit

Permalink
test: remove unnecessary creation of companies #28965 (#28967)
Browse files Browse the repository at this point in the history
test: remove unnecessary creation of companies
(cherry picked from commit d7148ad)

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Dec 20, 2021
1 parent 87e53e9 commit ef47570
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 36 deletions.
4 changes: 2 additions & 2 deletions erpnext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def set_perpetual_inventory(enable=1, company=None):
company.enable_perpetual_inventory = enable
company.save()

def encode_company_abbr(name, company):
def encode_company_abbr(name, company=None, abbr=None):
'''Returns name encoded with company abbreviation'''
company_abbr = frappe.get_cached_value('Company', company, "abbr")
company_abbr = abbr or frappe.get_cached_value('Company', company, "abbr")
parts = name.rsplit(" - ", 1)

if parts[-1].lower() != company_abbr.lower():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def make_company():
company.company_name = "_Test Opening Invoice Company"
company.abbr = "_TOIC"
company.default_currency = "INR"
company.country = "India"
company.country = "Pakistan"
company.insert()
return company

Expand Down
6 changes: 3 additions & 3 deletions erpnext/setup/doctype/company/test_records.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"abbr": "_TC3",
"company_name": "_Test Company 3",
"is_group": 1,
"country": "India",
"country": "Pakistan",
"default_currency": "INR",
"doctype": "Company",
"domain": "Manufacturing",
Expand All @@ -49,7 +49,7 @@
"company_name": "_Test Company 4",
"parent_company": "_Test Company 3",
"is_group": 1,
"country": "India",
"country": "Pakistan",
"default_currency": "INR",
"doctype": "Company",
"domain": "Manufacturing",
Expand All @@ -61,7 +61,7 @@
"abbr": "_TC5",
"company_name": "_Test Company 5",
"parent_company": "_Test Company 4",
"country": "India",
"country": "Pakistan",
"default_currency": "INR",
"doctype": "Company",
"domain": "Manufacturing",
Expand Down
29 changes: 6 additions & 23 deletions erpnext/stock/doctype/shipment/test_shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def create_test_delivery_note():
"description": 'Test delivery note for shipment',
"qty": 5,
"uom": 'Nos',
"warehouse": 'Stores - SC',
"warehouse": 'Stores - _TC',
"rate": item.standard_rate,
"cost_center": 'Main - SC'
"cost_center": 'Main - _TC'
}
)
delivery_note.insert()
Expand Down Expand Up @@ -127,13 +127,7 @@ def get_shipment_company_address(company_name):
return create_shipment_address(address_title, company_name, 80331)

def get_shipment_company():
company_name = 'Shipment Company'
abbr = 'SC'
companies = frappe.get_all("Company", fields=["name"], filters = {"company_name": company_name})
if len(companies):
return companies[0]
else:
return create_shipment_company(company_name, abbr)
return frappe.get_doc("Company", "_Test Company")

def get_shipment_item(company_name):
item_name = 'Testing Shipment item'
Expand Down Expand Up @@ -182,17 +176,6 @@ def create_customer_contact(fname, lname):
customer.insert()
return customer


def create_shipment_company(company_name, abbr):
company = frappe.new_doc("Company")
company.company_name = company_name
company.abbr = abbr
company.default_currency = 'EUR'
company.country = 'Germany'
company.enable_perpetual_inventory = 0
company.insert()
return company

def create_shipment_customer(customer_name):
customer = frappe.new_doc("Customer")
customer.customer_name = customer_name
Expand All @@ -211,12 +194,12 @@ def create_material_receipt(item, company):
stock.posting_date = posting_date.strftime("%Y-%m-%d")
stock.append('items',
{
"t_warehouse": 'Stores - SC',
"t_warehouse": 'Stores - _TC',
"item_code": item.name,
"qty": 5,
"uom": 'Nos',
"basic_rate": item.standard_rate,
"cost_center": 'Main - SC'
"cost_center": 'Main - _TC'
}
)
stock.insert()
Expand All @@ -233,7 +216,7 @@ def create_shipment_item(item_name, company_name):
item.append('item_defaults',
{
"company": company_name,
"default_warehouse": 'Stores - SC'
"default_warehouse": 'Stores - _TC'
}
)
item.insert()
Expand Down
9 changes: 2 additions & 7 deletions erpnext/tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@

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
abbr = "NFECT"

names = [
"Warehouse Name", "ERPNext Foundation India", "Gold - Member - {a}".format(a=abbr),
Expand All @@ -34,7 +29,7 @@ def test_encode_company_abbr(self):
]

for i in range(len(names)):
enc_name = encode_company_abbr(names[i], company.name)
enc_name = encode_company_abbr(names[i], abbr=abbr)
self.assertTrue(
enc_name == expected_names[i],
"{enc} is not same as {exp}".format(enc=enc_name, exp=expected_names[i])
Expand Down

0 comments on commit ef47570

Please sign in to comment.