fix: salary structure assignment filter employee based on company (#20318)

* fix: pick company from employee salary structure

* fix: Salary structure assignment fetch company from enmployee

* Revert "fix: Salary structure assignment fetch company from enmployee"

This reverts commit ab2da691c79646d6d095f347ea3e273f466ee34f.

* fix: Salary structure assignment fetch company from enmployee

* fix: filter on company for salary structure assignment

* fix: minor changes

* fix: minor changes

* fix: added company to salary strucutre assignment
This commit is contained in:
Vishal Dhayagude
2020-01-17 11:44:11 +05:30
committed by Nabin Hait
parent e3afe8a73c
commit 2ae87876b6
2 changed files with 11 additions and 10 deletions

View File

@@ -75,6 +75,7 @@ frappe.ui.form.on('Salary Structure', {
title: __("Assign to Employees"), title: __("Assign to Employees"),
fields: [ fields: [
{fieldname: "sec_break", fieldtype: "Section Break", label: __("Filter Employees By (Optional)")}, {fieldname: "sec_break", fieldtype: "Section Break", label: __("Filter Employees By (Optional)")},
{fieldname: "company", fieldtype: "Link", options: "Company", label: __("Company"), default: frm.doc.company, read_only:1},
{fieldname: "grade", fieldtype: "Link", options: "Employee Grade", label: __("Employee Grade")}, {fieldname: "grade", fieldtype: "Link", options: "Employee Grade", label: __("Employee Grade")},
{fieldname:'department', fieldtype:'Link', options: 'Department', label: __('Department')}, {fieldname:'department', fieldtype:'Link', options: 'Department', label: __('Department')},
{fieldname:'designation', fieldtype:'Link', options: 'Designation', label: __('Designation')}, {fieldname:'designation', fieldtype:'Link', options: 'Designation', label: __('Designation')},
@@ -87,7 +88,6 @@ frappe.ui.form.on('Salary Structure', {
], ],
primary_action: function() { primary_action: function() {
var data = d.get_values(); var data = d.get_values();
frappe.call({ frappe.call({
doc: frm.doc, doc: frm.doc,
method: "assign_salary_structure", method: "assign_salary_structure",

View File

@@ -81,9 +81,9 @@ class SalaryStructure(Document):
return employees return employees
@frappe.whitelist() @frappe.whitelist()
def assign_salary_structure(self, grade=None, department=None, designation=None,employee=None, def assign_salary_structure(self, company=None, grade=None, department=None, designation=None,employee=None,
from_date=None, base=None,variable=None): from_date=None, base=None,variable=None):
employees = self.get_employees(grade= grade,department= department,designation= designation,name=employee) employees = self.get_employees(company= company, grade= grade,department= department,designation= designation,name=employee)
if employees: if employees:
if len(employees) > 20: if len(employees) > 20:
@@ -98,7 +98,7 @@ class SalaryStructure(Document):
def assign_salary_structure_for_employees(employees, salary_structure, from_date=None, base=None,variable=None): def assign_salary_structure_for_employees(employees, salary_structure, from_date=None, base=None,variable=None):
salary_structures_assignments = [] salary_structures_assignments = []
existing_assignments_for = get_existing_assignments(employees, salary_structure.name,from_date) existing_assignments_for = get_existing_assignments(employees, salary_structure, from_date)
count=0 count=0
for employee in employees: for employee in employees:
if employee in existing_assignments_for: if employee in existing_assignments_for:
@@ -117,6 +117,7 @@ def create_salary_structures_assignment(employee, salary_structure, from_date, b
assignment = frappe.new_doc("Salary Structure Assignment") assignment = frappe.new_doc("Salary Structure Assignment")
assignment.employee = employee assignment.employee = employee
assignment.salary_structure = salary_structure.name assignment.salary_structure = salary_structure.name
assignment.company = salary_structure.company
assignment.from_date = from_date assignment.from_date = from_date
assignment.base = base assignment.base = base
assignment.variable = variable assignment.variable = variable
@@ -129,8 +130,8 @@ def get_existing_assignments(employees, salary_structure,from_date):
salary_structures_assignments = frappe.db.sql_list(""" salary_structures_assignments = frappe.db.sql_list("""
select distinct employee from `tabSalary Structure Assignment` select distinct employee from `tabSalary Structure Assignment`
where salary_structure=%s and employee in (%s) where salary_structure=%s and employee in (%s)
and from_date=%s and docstatus=1 and from_date=%s and company= %s and docstatus=1
""" % ('%s', ', '.join(['%s']*len(employees)),'%s'), [salary_structure] + employees+[from_date]) """ % ('%s', ', '.join(['%s']*len(employees)),'%s', '%s'), [salary_structure.name] + employees+[from_date]+[salary_structure.company])
if salary_structures_assignments: if salary_structures_assignments:
frappe.msgprint(_("Skipping Salary Structure Assignment for the following employees, as Salary Structure Assignment records already exists against them. {0}") frappe.msgprint(_("Skipping Salary Structure Assignment for the following employees, as Salary Structure Assignment records already exists against them. {0}")
.format("\n".join(salary_structures_assignments))) .format("\n".join(salary_structures_assignments)))