brotherton-erpnext/erpnext/patches/v11_0/create_salary_structure_assignments.py
Anurag Mishra 289c82243f
feat: New Payroll module (#21990)
* feat: Moved Document to Payroll Module

* feat: Moved Reports to Payroll Module

* feat: Moved Print fromat With Patch

* feat: Moved Notifiction to Payroll Module and patches

* feat: added dashboard and desk page to Payroll

* feat: Payroll Dashboard

* feat: Module onboarding

* feat: Income tax Deductions Report

* feat: Ecs Checklist Report

* feat: Provident Fund Report

* feat: Professional Fund report and commonified Code

* feat: Total Payments Based On Payment Mode Report

* fix: refactor and added chart Total Payments Based On Payment Mode

* feat: Payroll Settings

* fix: Bank remittance Report

* feat(Payroll based on): Considered unmarked days

* feat: Added Help for condition an formula in Salary structure

* fix: requested changes

* fix: rename report Ecs checklist to salary_payments_via_ecs

* fix: renamed report report/total_payments_based_on_payment_mode

* fix: added role via setup.py for regional report

* feat: added All reports to desk page

* fix: frappe.reload doc in all patches

* fix: codacy

* fix: frappe.reload_doctype for patches

* patch: is_income_tax_component and component_type for salary component

* fix: uncommented code

* test: fixture

* fix: test

* test: test_payment_days_based_on_attendance
2020-06-19 19:17:57 +05:30

63 lines
2.4 KiB
Python

# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from datetime import datetime
from frappe.utils import getdate
from erpnext.payroll.doctype.salary_structure_assignment.salary_structure_assignment import DuplicateAssignment
def execute():
frappe.reload_doc('Payroll', 'doctype', 'salary_structure')
frappe.reload_doc("Payroll", "doctype", "salary_structure_assignment")
frappe.db.sql("""
delete from `tabSalary Structure Assignment`
where salary_structure in (select name from `tabSalary Structure` where is_active='No' or docstatus!=1)
""")
if frappe.db.table_exists('Salary Structure Employee'):
ss_details = frappe.db.sql("""
select sse.employee, sse.employee_name, sse.from_date, sse.to_date,
sse.base, sse.variable, sse.parent as salary_structure, ss.company
from `tabSalary Structure Employee` sse, `tabSalary Structure` ss
where ss.name = sse.parent AND ss.is_active='Yes'
AND sse.employee in (select name from `tabEmployee` where ifNull(status, '') != 'Left')""", as_dict=1)
else:
cols = ""
if "base" in frappe.db.get_table_columns("Salary Structure"):
cols = ", base, variable"
ss_details = frappe.db.sql("""
select name as salary_structure, employee, employee_name, from_date, to_date, company {0}
from `tabSalary Structure`
where is_active='Yes'
AND employee in (select name from `tabEmployee` where ifNull(status, '') != 'Left')
""".format(cols), as_dict=1)
for d in ss_details:
try:
joining_date, relieving_date = frappe.db.get_value("Employee", d.employee,
["date_of_joining", "relieving_date"])
from_date = d.from_date
if joining_date and getdate(from_date) < joining_date:
from_date = joining_date
elif relieving_date and getdate(from_date) > relieving_date:
continue
s = frappe.new_doc("Salary Structure Assignment")
s.employee = d.employee
s.employee_name = d.employee_name
s.salary_structure = d.salary_structure
s.from_date = from_date
s.to_date = d.to_date if isinstance(d.to_date, datetime) else None
s.base = d.get("base")
s.variable = d.get("variable")
s.company = d.company
# to migrate the data of the old employees
s.flags.old_employee = True
s.save()
s.submit()
except DuplicateAssignment:
pass
frappe.db.sql("update `tabSalary Structure` set docstatus=1")