fix: test cases and codacy

This commit is contained in:
Rohit Waghchaure 2019-03-18 10:53:43 +05:30
parent 01086ff60c
commit d4e4316d0b
4 changed files with 81 additions and 69 deletions

View File

@ -116,6 +116,8 @@ class Account(NestedSet):
doc.update({"company": company, "account_currency": None, doc.update({"company": company, "account_currency": None,
"parent": acc_name_map[company], "parent_account": acc_name_map[company]}) "parent": acc_name_map[company], "parent_account": acc_name_map[company]})
doc.save() doc.save()
frappe.msgprint(_("Account {0} is added in the child company {1}")
.format(doc.name, company))
def validate_group_or_ledger(self): def validate_group_or_ledger(self):
if self.get("__islocal"): if self.get("__islocal"):

View File

@ -20,6 +20,7 @@ class StaffingPlan(Document):
self.total_estimated_budget = 0 self.total_estimated_budget = 0
for detail in self.get("staffing_details"): for detail in self.get("staffing_details"):
self.set_vacancies(detail)
self.validate_overlap(detail) self.validate_overlap(detail)
self.validate_with_subsidiary_plans(detail) self.validate_with_subsidiary_plans(detail)
self.validate_with_parent_plan(detail) self.validate_with_parent_plan(detail)
@ -39,6 +40,15 @@ class StaffingPlan(Document):
else: detail.vacancies = detail.number_of_positions = detail.total_estimated_cost = 0 else: detail.vacancies = detail.number_of_positions = detail.total_estimated_cost = 0
self.total_estimated_budget += detail.total_estimated_cost self.total_estimated_budget += detail.total_estimated_cost
def set_vacancies(self, row):
if not row.vacancies:
current_openings = 0
for field in ['current_count', 'current_openings']:
if row.get(field):
current_openings += row.get(field)
row.vacancies = row.number_of_positions - current_openings
def validate_overlap(self, staffing_plan_detail): def validate_overlap(self, staffing_plan_detail):
# Validate if any submitted Staffing Plan exist for any Designations in this plan # Validate if any submitted Staffing Plan exist for any Designations in this plan
# and spd.vacancies>0 ? # and spd.vacancies>0 ?

View File

@ -18,7 +18,7 @@ class TestStaffingPlan(unittest.TestCase):
if frappe.db.exists("Staffing Plan", "Test"): if frappe.db.exists("Staffing Plan", "Test"):
return return
staffing_plan = frappe.new_doc("Staffing Plan") staffing_plan = frappe.new_doc("Staffing Plan")
staffing_plan.company = "_Test Company 3" staffing_plan.company = "_Test Company 10"
staffing_plan.name = "Test" staffing_plan.name = "Test"
staffing_plan.from_date = nowdate() staffing_plan.from_date = nowdate()
staffing_plan.to_date = add_days(nowdate(), 10) staffing_plan.to_date = add_days(nowdate(), 10)
@ -67,7 +67,7 @@ class TestStaffingPlan(unittest.TestCase):
if frappe.db.exists("Staffing Plan", "Test 1"): if frappe.db.exists("Staffing Plan", "Test 1"):
return return
staffing_plan = frappe.new_doc("Staffing Plan") staffing_plan = frappe.new_doc("Staffing Plan")
staffing_plan.company = "_Test Company 3" staffing_plan.company = "_Test Company 10"
staffing_plan.name = "Test 1" staffing_plan.name = "Test 1"
staffing_plan.from_date = nowdate() staffing_plan.from_date = nowdate()
staffing_plan.to_date = add_days(nowdate(), 10) staffing_plan.to_date = add_days(nowdate(), 10)
@ -85,11 +85,11 @@ def _set_up():
make_company() make_company()
def make_company(): def make_company():
if frappe.db.exists("Company", "_Test Company 3"): if frappe.db.exists("Company", "_Test Company 10"):
return return
company = frappe.new_doc("Company") company = frappe.new_doc("Company")
company.company_name = "_Test Company 3" company.company_name = "_Test Company 10"
company.abbr = "_TC3" company.abbr = "_TC10"
company.parent_company = "_Test Company" company.parent_company = "_Test Company"
company.default_currency = "INR" company.default_currency = "INR"
company.country = "India" company.country = "India"