ccf5dc66e2
* feat: multi-currency payroll * fix: refactor and added conditions * fix: uncommented code * style: removed comments * fix: missing argument * style: styling changes * fix: test cases * Update asset_value_adjustment.py * patch: update columns * style: formating * style: formatting * fix: 1st review * fix: refactor * Revert "fix: refactor" This reverts commit eca0e17d11a192d60f249b2af992971c625aec46. reverting to previous state * Revert "fix: 1st review" This reverts commit 7eac48b102157df4353598f73b2ea97308af436a. reverting before 1st review * fix: 2nd review changes * fix: test cases * fix: added call to fetch exchange rate * fix: remove unnecessary code * fix: refactor * fix: refactor patch * fix: refactor * fix: refactor * fix: clear test data * fix: slider * feat: multi-currency payroll * fix: refactor and added conditions * fix: uncommented code * style: removed comments * fix: missing argument * style: styling changes * fix: test cases * patch: update columns * Update asset_value_adjustment.py * style: formating * style: formatting * fix: 1st review * fix: refactor * Revert "fix: refactor" This reverts commit eca0e17d11a192d60f249b2af992971c625aec46. reverting to previous state * Revert "fix: 1st review" This reverts commit 7eac48b102157df4353598f73b2ea97308af436a. reverting before 1st review * fix: 2nd review changes * fix: test cases * fix: added call to fetch exchange rate * fix: remove unnecessary code * fix: refactor * fix: refactor patch * fix: refactor * fix: refactor * fix: clear test data * fix: slider * feat: Added company field in leave encashment and employee benefit * refactor: Refactored multi-currency payroll patch * fix: currency column in salary register * refactor: Refactored code for making bank and return entry against employee advance * fix: minor cleanup * fix: fixed translation * fix: removed salary component type * fix: fixed sider issues * fix: translation and slider * style: formatted msg * fix: fixed slider * fix: travis * fix: refactor * fix: slider * fix: slider * fix: slider * fix: travis * fix: patch * fix: patch * fix: travis * fix: travis * fix: travis * fix: travis * fix: travis * fix: travis * fix: re-run travis * fix: rerun travis * fix: rerun travis * fix: rerun travis * fix: travis rerun * fix: increased throttle_user_limit from 60 to 100 * fix: patch * fix: patch * fix: assign payroll payable account as default payroll payable account in SSA * fix: removed debugger * fix: slider Co-authored-by: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> Co-authored-by: Nabin Hait <nabinhait@gmail.com>
72 lines
2.8 KiB
Python
72 lines
2.8 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)
|
|
|
|
all_companies = frappe.db.get_all("Company", fields=["name", "default_currency"])
|
|
for d in all_companies:
|
|
company = d.name
|
|
company_currency = d.default_currency
|
|
|
|
frappe.db.sql("""update `tabSalary Structure` set currency = %s where company=%s""", (company_currency, company))
|
|
|
|
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
|
|
company_currency = frappe.db.get_value('Company', d.company, 'default_currency')
|
|
|
|
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
|
|
s.currency = company_currency
|
|
|
|
# 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") |