From 55410e03e41f8859faf18d6ac4af319a3a0ae6b4 Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Wed, 15 Apr 2020 12:57:55 +0530 Subject: [PATCH] fix: tests depending on global default company --- erpnext/accounts/doctype/subscription/subscription.py | 4 ++++ .../clinical_procedure/test_clinical_procedure.py | 2 ++ erpnext/healthcare/doctype/patient/test_patient.py | 2 ++ .../test_patient_medical_record.py | 2 ++ erpnext/hr/doctype/employee/test_employee.py | 2 +- .../test_employee_tax_exemption_declaration.py | 8 ++++---- erpnext/hr/doctype/leave_period/test_leave_period.py | 4 ++-- erpnext/hr/doctype/payroll_entry/test_payroll_entry.py | 6 +++--- erpnext/hr/doctype/salary_slip/test_salary_slip.py | 10 +++++----- .../doctype/salary_structure/test_salary_structure.py | 4 ++-- 10 files changed, 27 insertions(+), 17 deletions(-) diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py index 0933c7e8b8..fbdaf1bc95 100644 --- a/erpnext/accounts/doctype/subscription/subscription.py +++ b/erpnext/accounts/doctype/subscription/subscription.py @@ -238,6 +238,10 @@ class Subscription(Document): Creates a `Sales Invoice`, submits it and returns it """ invoice = frappe.new_doc('Sales Invoice') + + if not invoice.company: + invoice.company = frappe.db.get_value('Global Defaults', None, 'default_company') + invoice.set_posting_time = 1 invoice.posting_date = self.current_invoice_start invoice.customer = self.customer diff --git a/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py index 207351ff20..100addc9ba 100644 --- a/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py +++ b/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py @@ -18,6 +18,7 @@ class TestClinicalProcedure(unittest.TestCase): self.assertEquals(frappe.db.get_value('Item', procedure_template.item, 'disabled'), 1) def test_consumables(self): + frappe.db.set_value('Global Defaults', None, 'default_company', '_Test Company') patient, medical_department, practitioner = create_healthcare_docs() procedure_template = create_clinical_procedure_template() procedure_template.allow_stock_consumption = 1 @@ -38,6 +39,7 @@ class TestClinicalProcedure(unittest.TestCase): result = procedure.complete_procedure() # check consumption self.assertTrue(frappe.db.exists('Stock Entry', result)) + frappe.db.set_value('Global Defaults', None, 'default_company', None) def create_consumable(): diff --git a/erpnext/healthcare/doctype/patient/test_patient.py b/erpnext/healthcare/doctype/patient/test_patient.py index 9274b6f5e8..dfe61bd6c1 100644 --- a/erpnext/healthcare/doctype/patient/test_patient.py +++ b/erpnext/healthcare/doctype/patient/test_patient.py @@ -15,6 +15,7 @@ class TestPatient(unittest.TestCase): self.assertTrue(frappe.db.get_value('Patient', patient, 'customer')) def test_patient_registration(self): + frappe.db.set_value('Global Defaults', None, 'default_company', '_Test Company') frappe.db.sql("""delete from `tabPatient`""") settings = frappe.get_single('Healthcare Settings') settings.collect_registration_fee = 1 @@ -32,3 +33,4 @@ class TestPatient(unittest.TestCase): settings.collect_registration_fee = 0 settings.save() + frappe.db.set_value('Global Defaults', None, 'default_company', None) diff --git a/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py b/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py index e5a5e4c010..4de90bc09f 100644 --- a/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py +++ b/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py @@ -13,6 +13,7 @@ class TestPatientMedicalRecord(unittest.TestCase): frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1) def test_medical_record(self): + frappe.db.set_value('Global Defaults', None, 'default_company', '_Test Company') patient, medical_department, practitioner = create_healthcare_docs() appointment = create_appointment(patient, practitioner, nowdate(), invoice=1) encounter = create_encounter(appointment) @@ -38,6 +39,7 @@ class TestPatientMedicalRecord(unittest.TestCase): # check for lab test medical_rec = frappe.db.exists('Patient Medical Record', {'status': 'Open', 'reference_name': lab_test.name}) self.assertTrue(medical_rec) + frappe.db.set_value('Global Defaults', None, 'default_company', None) def create_procedure(appointment): diff --git a/erpnext/hr/doctype/employee/test_employee.py b/erpnext/hr/doctype/employee/test_employee.py index eff382d973..755393ea04 100644 --- a/erpnext/hr/doctype/employee/test_employee.py +++ b/erpnext/hr/doctype/employee/test_employee.py @@ -55,7 +55,7 @@ def make_employee(user, company=None): "roles": [{"doctype": "Has Role", "role": "Employee"}] }).insert() - if not frappe.db.get_value("Employee", { "user_id": user, "company": company or erpnext.get_default_company() }): + if not frappe.db.get_value("Employee", { "user_id": user, "company": company or erpnext.get_default_company() or 'Wind Power LLC' }): employee = frappe.get_doc({ "doctype": "Employee", "naming_series": "EMP-", diff --git a/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py b/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py index d53f6a706d..4dc77ccc51 100644 --- a/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py +++ b/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py @@ -20,7 +20,7 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase): declaration = frappe.get_doc({ "doctype": "Employee Tax Exemption Declaration", "employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"), - "company": erpnext.get_default_company(), + "company": erpnext.get_default_company() or 'Wind Power LLC', "payroll_period": "_Test Payroll Period", "declarations": [ dict(exemption_sub_category = "_Test Sub Category", @@ -37,7 +37,7 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase): declaration = frappe.get_doc({ "doctype": "Employee Tax Exemption Declaration", "employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"), - "company": erpnext.get_default_company(), + "company": erpnext.get_default_company() or 'Wind Power LLC', "payroll_period": "_Test Payroll Period", "declarations": [ dict(exemption_sub_category = "_Test Sub Category", @@ -52,7 +52,7 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase): duplicate_declaration = frappe.get_doc({ "doctype": "Employee Tax Exemption Declaration", "employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"), - "company": erpnext.get_default_company(), + "company": erpnext.get_default_company() or 'Wind Power LLC', "payroll_period": "_Test Payroll Period", "declarations": [ dict(exemption_sub_category = "_Test Sub Category", @@ -68,7 +68,7 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase): declaration = frappe.get_doc({ "doctype": "Employee Tax Exemption Declaration", "employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"), - "company": erpnext.get_default_company(), + "company": erpnext.get_default_company() or 'Wind Power LLC', "payroll_period": "_Test Payroll Period", "declarations": [ dict(exemption_sub_category = "_Test Sub Category", diff --git a/erpnext/hr/doctype/leave_period/test_leave_period.py b/erpnext/hr/doctype/leave_period/test_leave_period.py index 1762cf917a..06e5836738 100644 --- a/erpnext/hr/doctype/leave_period/test_leave_period.py +++ b/erpnext/hr/doctype/leave_period/test_leave_period.py @@ -45,7 +45,7 @@ class TestLeavePeriod(unittest.TestCase): def create_leave_period(from_date, to_date, company=None): leave_period = frappe.db.get_value('Leave Period', - dict(company=company or erpnext.get_default_company(), + dict(company=company or erpnext.get_default_company() or 'Wind Power LLC', from_date=from_date, to_date=to_date, is_active=1), 'name') @@ -54,7 +54,7 @@ def create_leave_period(from_date, to_date, company=None): leave_period = frappe.get_doc({ "doctype": "Leave Period", - "company": company or erpnext.get_default_company(), + "company": company or erpnext.get_default_company() or 'Wind Power LLC', "from_date": from_date, "to_date": to_date, "is_active": 1 diff --git a/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py b/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py index 49671d5e22..52fb69f1a4 100644 --- a/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py +++ b/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py @@ -26,7 +26,7 @@ class TestPayrollEntry(unittest.TestCase): frappe.db.set_value("HR Settings", None, "email_salary_slip_to_employee", 0) def test_payroll_entry(self): # pylint: disable=no-self-use - company = erpnext.get_default_company() + company = erpnext.get_default_company() or 'Wind Power LLC' for data in frappe.get_all('Salary Component', fields = ["name"]): if not frappe.db.get_value('Salary Component Account', {'parent': data.name, 'company': company}, 'name'): @@ -109,7 +109,7 @@ def make_payroll_entry(**args): args = frappe._dict(args) payroll_entry = frappe.new_doc("Payroll Entry") - payroll_entry.company = args.company or erpnext.get_default_company() + payroll_entry.company = args.company or erpnext.get_default_company() or 'Wind Power LLC' payroll_entry.start_date = args.start_date or "2016-11-01" payroll_entry.end_date = args.end_date or "2016-11-30" payroll_entry.payment_account = get_payment_account() @@ -133,7 +133,7 @@ def make_payroll_entry(**args): def get_payment_account(): return frappe.get_value('Account', - {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name") + {'account_type': 'Cash', 'company': erpnext.get_default_company() or 'Wind Power LLC', 'is_group':0}, "name") def make_holiday(holiday_list_name): if not frappe.db.exists('Holiday List', holiday_list_name): diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py index cd73b94719..ac91aec282 100644 --- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py @@ -26,7 +26,7 @@ class TestSalarySlip(unittest.TestCase): self.make_holiday_list() - frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Slip Test Holiday List") + frappe.db.set_value("Company", erpnext.get_default_company() or 'Wind Power LLC', "default_holiday_list", "Salary Slip Test Holiday List") frappe.db.set_value("HR Settings", None, "email_salary_slip_to_employee", 0) def tearDown(self): @@ -175,7 +175,7 @@ class TestSalarySlip(unittest.TestCase): self.assertEqual(ss.net_pay, (flt(ss.gross_pay) - (flt(ss.total_deduction) + flt(ss.total_loan_repayment)))) def test_payroll_frequency(self): - fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company())[0] + fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company() or 'Wind Power LLC')[0] month = "%02d" % getdate(nowdate()).month m = get_month_details(fiscal_year, month) @@ -295,7 +295,7 @@ class TestSalarySlip(unittest.TestCase): frappe.db.rollback() def make_holiday_list(self): - fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company()) + fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company() or 'Wind Power LLC') if not frappe.db.get_value("Holiday List", "Salary Slip Test Holiday List"): holiday_list = frappe.get_doc({ "doctype": "Holiday List", @@ -499,7 +499,7 @@ def create_exemption_declaration(employee, payroll_period): "doctype": "Employee Tax Exemption Declaration", "employee": employee, "payroll_period": payroll_period, - "company": erpnext.get_default_company() + "company": erpnext.get_default_company() or 'Wind Power LLC' }) declaration.append("declarations", { "exemption_sub_category": "_Test Sub Category", @@ -588,7 +588,7 @@ def create_additional_salary(employee, payroll_period, amount): frappe.get_doc({ "doctype": "Additional Salary", "employee": employee, - "company": erpnext.get_default_company(), + "company": erpnext.get_default_company() or 'Wind Power LLC', "salary_component": "Performance Bonus", "payroll_date": salary_date, "amount": amount, diff --git a/erpnext/hr/doctype/salary_structure/test_salary_structure.py b/erpnext/hr/doctype/salary_structure/test_salary_structure.py index e465d04f4d..17087d14cf 100644 --- a/erpnext/hr/doctype/salary_structure/test_salary_structure.py +++ b/erpnext/hr/doctype/salary_structure/test_salary_structure.py @@ -21,7 +21,7 @@ class TestSalaryStructure(unittest.TestCase): frappe.db.sql("delete from `tab%s`" % dt) self.make_holiday_list() - frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Structure Test Holiday List") + frappe.db.set_value("Company", erpnext.get_default_company() or 'Wind Power LLC', "default_holiday_list", "Salary Structure Test Holiday List") make_employee("test_employee@salary.com") make_employee("test_employee_2@salary.com") @@ -145,7 +145,7 @@ def create_salary_structure_assignment(employee, salary_structure, from_date=Non salary_structure_assignment.variable = 5000 salary_structure_assignment.from_date = from_date or add_months(nowdate(), -1) salary_structure_assignment.salary_structure = salary_structure - salary_structure_assignment.company = company or erpnext.get_default_company() + salary_structure_assignment.company = company or erpnext.get_default_company() or 'Wind Power LLC' salary_structure_assignment.save(ignore_permissions=True) salary_structure_assignment.submit() return salary_structure_assignment