mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
fix: linter issues
This commit is contained in:
@@ -1,31 +1,32 @@
|
|||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
frappe.reload_doc('payroll', 'doctype', 'employee_cost_center')
|
frappe.reload_doc('payroll', 'doctype', 'employee_cost_center')
|
||||||
frappe.reload_doc('payroll', 'doctype', 'salary_structure_assignment')
|
frappe.reload_doc('payroll', 'doctype', 'salary_structure_assignment')
|
||||||
|
|
||||||
employees = frappe.get_all("Employee", fields=["department", "payroll_cost_center", "name"])
|
employees = frappe.get_all("Employee", fields=["department", "payroll_cost_center", "name"])
|
||||||
|
|
||||||
employee_cost_center = {}
|
employee_cost_center = {}
|
||||||
for d in employees:
|
for d in employees:
|
||||||
cost_center = d.payroll_cost_center
|
cost_center = d.payroll_cost_center
|
||||||
if not cost_center and d.department:
|
if not cost_center and d.department:
|
||||||
cost_center = frappe.get_cached_value("Department", d.department, "payroll_cost_center")
|
cost_center = frappe.get_cached_value("Department", d.department, "payroll_cost_center")
|
||||||
|
|
||||||
if cost_center:
|
if cost_center:
|
||||||
employee_cost_center.setdefault(d.name, cost_center)
|
employee_cost_center.setdefault(d.name, cost_center)
|
||||||
|
|
||||||
salary_structure_assignments = frappe.get_all("Salary Structure Assignment",
|
|
||||||
filters = {"docstatus": ["!=", 2]},
|
|
||||||
fields=["name", "employee"])
|
|
||||||
|
|
||||||
for d in salary_structure_assignments:
|
salary_structure_assignments = frappe.get_all("Salary Structure Assignment",
|
||||||
cost_center = employee_cost_center.get(d.employee)
|
filters = {"docstatus": ["!=", 2]},
|
||||||
if cost_center:
|
fields=["name", "employee"])
|
||||||
assignment = frappe.get_doc("Salary Structure Assignment", d.name)
|
|
||||||
if not assignment.get("payroll_cost_centers"):
|
for d in salary_structure_assignments:
|
||||||
assignment.append("payroll_cost_centers", {
|
cost_center = employee_cost_center.get(d.employee)
|
||||||
"cost_center": cost_center,
|
if cost_center:
|
||||||
"percentage": 100
|
assignment = frappe.get_doc("Salary Structure Assignment", d.name)
|
||||||
})
|
if not assignment.get("payroll_cost_centers"):
|
||||||
assignment.save()
|
assignment.append("payroll_cost_centers", {
|
||||||
|
"cost_center": cost_center,
|
||||||
|
"percentage": 100
|
||||||
|
})
|
||||||
|
assignment.save()
|
||||||
@@ -4,5 +4,6 @@
|
|||||||
# import frappe
|
# import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
class EmployeeCostCenter(Document):
|
class EmployeeCostCenter(Document):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ class PayrollEntry(Document):
|
|||||||
if not self.employee_cost_centers.get(employee):
|
if not self.employee_cost_centers.get(employee):
|
||||||
ss_assignment_name = frappe.db.get_value("Salary Structure Assignment",
|
ss_assignment_name = frappe.db.get_value("Salary Structure Assignment",
|
||||||
{"employee": employee, "salary_structure": salary_structure, "docstatus": 1}, 'name')
|
{"employee": employee, "salary_structure": salary_structure, "docstatus": 1}, 'name')
|
||||||
|
|
||||||
if ss_assignment_name:
|
if ss_assignment_name:
|
||||||
cost_centers = dict(frappe.get_all("Employee Cost Center", {"parent": ss_assignment_name},
|
cost_centers = dict(frappe.get_all("Employee Cost Center", {"parent": ss_assignment_name},
|
||||||
["cost_center", "percentage"], as_list=1))
|
["cost_center", "percentage"], as_list=1))
|
||||||
@@ -244,7 +244,7 @@ class PayrollEntry(Document):
|
|||||||
default_cost_center = frappe.get_cached_value("Department", department, "payroll_cost_center")
|
default_cost_center = frappe.get_cached_value("Department", department, "payroll_cost_center")
|
||||||
if not default_cost_center:
|
if not default_cost_center:
|
||||||
default_cost_center = self.cost_center
|
default_cost_center = self.cost_center
|
||||||
|
|
||||||
cost_centers = {
|
cost_centers = {
|
||||||
default_cost_center: 100
|
default_cost_center: 100
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,14 +131,14 @@ class TestPayrollEntry(unittest.TestCase):
|
|||||||
frappe.db.set_value("Company", "_Test Company", "default_payroll_payable_account",
|
frappe.db.set_value("Company", "_Test Company", "default_payroll_payable_account",
|
||||||
"_Test Payroll Payable - _TC")
|
"_Test Payroll Payable - _TC")
|
||||||
currency=frappe.db.get_value("Company", "_Test Company", "default_currency")
|
currency=frappe.db.get_value("Company", "_Test Company", "default_currency")
|
||||||
|
|
||||||
make_salary_structure("_Test Salary Structure 1", "Monthly", employee1, company="_Test Company", currency=currency, test_tax=False)
|
make_salary_structure("_Test Salary Structure 1", "Monthly", employee1, company="_Test Company", currency=currency, test_tax=False)
|
||||||
ss = make_salary_structure("_Test Salary Structure 2", "Monthly", employee2, company="_Test Company", currency=currency, test_tax=False)
|
ss = make_salary_structure("_Test Salary Structure 2", "Monthly", employee2, company="_Test Company", currency=currency, test_tax=False)
|
||||||
|
|
||||||
# update cost centers in salary structure assignment for employee2
|
# update cost centers in salary structure assignment for employee2
|
||||||
ssa = frappe.db.get_value("Salary Structure Assignment",
|
ssa = frappe.db.get_value("Salary Structure Assignment",
|
||||||
{"employee": employee2, "salary_structure": ss.name, "docstatus": 1}, 'name')
|
{"employee": employee2, "salary_structure": ss.name, "docstatus": 1}, 'name')
|
||||||
|
|
||||||
ssa_doc = frappe.get_doc("Salary Structure Assignment", ssa)
|
ssa_doc = frappe.get_doc("Salary Structure Assignment", ssa)
|
||||||
ssa_doc.payroll_cost_centers = []
|
ssa_doc.payroll_cost_centers = []
|
||||||
ssa_doc.append("payroll_cost_centers", {
|
ssa_doc.append("payroll_cost_centers", {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import getdate, flt
|
from frappe.utils import flt, getdate
|
||||||
|
|
||||||
|
|
||||||
class DuplicateAssignment(frappe.ValidationError): pass
|
class DuplicateAssignment(frappe.ValidationError): pass
|
||||||
@@ -54,7 +54,7 @@ class SalaryStructureAssignment(Document):
|
|||||||
"account_name": _("Payroll Payable"), "company": self.company, "account_currency": frappe.db.get_value(
|
"account_name": _("Payroll Payable"), "company": self.company, "account_currency": frappe.db.get_value(
|
||||||
"Company", self.company, "default_currency"), "is_group": 0})
|
"Company", self.company, "default_currency"), "is_group": 0})
|
||||||
self.payroll_payable_account = payroll_payable_account
|
self.payroll_payable_account = payroll_payable_account
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def set_payroll_cost_centers(self):
|
def set_payroll_cost_centers(self):
|
||||||
self.payroll_cost_centers = []
|
self.payroll_cost_centers = []
|
||||||
@@ -69,7 +69,7 @@ class SalaryStructureAssignment(Document):
|
|||||||
payroll_cost_center = frappe.db.get_value("Employee", self.employee, "payroll_cost_center")
|
payroll_cost_center = frappe.db.get_value("Employee", self.employee, "payroll_cost_center")
|
||||||
if not payroll_cost_center and self.department:
|
if not payroll_cost_center and self.department:
|
||||||
payroll_cost_center = frappe.db.get_value("Department", self.department, "payroll_cost_center")
|
payroll_cost_center = frappe.db.get_value("Department", self.department, "payroll_cost_center")
|
||||||
|
|
||||||
return payroll_cost_center
|
return payroll_cost_center
|
||||||
|
|
||||||
def validate_cost_center_distribution(self):
|
def validate_cost_center_distribution(self):
|
||||||
@@ -77,8 +77,7 @@ class SalaryStructureAssignment(Document):
|
|||||||
total_percentage = sum([flt(d.percentage) for d in self.get("payroll_cost_centers", [])])
|
total_percentage = sum([flt(d.percentage) for d in self.get("payroll_cost_centers", [])])
|
||||||
if total_percentage != 100:
|
if total_percentage != 100:
|
||||||
frappe.throw(_("Total percentage against cost centers should be 100"))
|
frappe.throw(_("Total percentage against cost centers should be 100"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_assigned_salary_structure(employee, on_date):
|
def get_assigned_salary_structure(employee, on_date):
|
||||||
if not employee or not on_date:
|
if not employee or not on_date:
|
||||||
@@ -93,6 +92,7 @@ def get_assigned_salary_structure(employee, on_date):
|
|||||||
})
|
})
|
||||||
return salary_structure[0][0] if salary_structure else None
|
return salary_structure[0][0] if salary_structure else None
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_employee_currency(employee):
|
def get_employee_currency(employee):
|
||||||
employee_currency = frappe.db.get_value('Salary Structure Assignment', {'employee': employee}, 'currency')
|
employee_currency = frappe.db.get_value('Salary Structure Assignment', {'employee': employee}, 'currency')
|
||||||
|
|||||||
Reference in New Issue
Block a user