def new_salary_structure(self): employee_name = self.employee_name if not self.employee_name: employee_name = self.name if self.date_of_joining: joining_date = self.date_of_joining else: joining_date = getdate(nowdate()) from erpnext.hr.doctype.payroll_entry.payroll_entry import get_end_date if self.payroll_frequency: end_date = get_end_date(cstr(joining_date), self.payroll_frequency)['end_date'] doc = frappe.new_doc('Salary Structure') doc.update({ 'name':_('Salary Structure')+'_'+ employee_name, 'employee_name':employee_name, 'salary_period':self.payroll_frequency, 'employees': [{ 'employee': self.name, 'base':self.basic_salary, 'from_date':joining_date, 'to_date':end_date, 'day_salary':self.day_salary, 'hour_cost':self.hour_cost, 'overtime_hour_cost': self.over_hrs }] }) doc.flags.ignore_links = True doc.save(ignore_permissions=True) doc.append('earnings',{ 'salary_component':'Basic', 'abbr': 'B', 'formula':'', 'amount': self.basic_salary, 'type': _('Earning') }) doc.save(ignore_permissions=True) for e in self.earnings: doc.append('earnings',{ 'salary_component':e.salary_component, 'abbr': e.abbr, 'formula': e.formula, 'amount': e.amount, 'type': e.type }) doc.save(ignore_permissions=True) for d in self.deductions: doc.append('deductions',{ 'salary_component':d.salary_component, 'abbr': d.abbr, 'formula': d.formula, 'amount': d.amount, 'type': d.type }) doc.save(ignore_permissions=True)
def test_get_end_date(self): self.assertEqual(get_end_date('2017-01-01', 'monthly'), {'end_date': '2017-01-31'}) self.assertEqual(get_end_date('2017-02-01', 'monthly'), {'end_date': '2017-02-28'}) self.assertEqual(get_end_date('2017-02-01', 'fortnightly'), {'end_date': '2017-02-14'}) self.assertEqual(get_end_date('2017-02-01', 'bimonthly'), {'end_date': ''}) self.assertEqual(get_end_date('2017-01-01', 'bimonthly'), {'end_date': ''}) self.assertEqual(get_end_date('2020-02-15', 'bimonthly'), {'end_date': ''}) self.assertEqual(get_end_date('2017-02-15', 'monthly'), {'end_date': '2017-03-14'}) self.assertEqual(get_end_date('2017-02-15', 'daily'), {'end_date': '2017-02-15'})