added changes from process payroll

This commit is contained in:
Shreya 2017-11-03 14:28:21 +05:30
parent d1defa5fc7
commit b5dff03453
5 changed files with 62 additions and 27 deletions

View File

@ -474,6 +474,35 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "data_19",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -788,7 +817,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-10-27 12:44:07.378315",
"modified": "2017-11-30 12:11:30.985647",
"modified_by": "Administrator",
"module": "HR",
"name": "Payroll Entry",

View File

@ -156,23 +156,28 @@ class PayrollEntry(Document):
return create_submit_log(submitted_ss, not_submitted_ss, jv_name)
def get_total_salary_and_loan_amounts(self):
def get_loan_details(self):
"""
Get total loan principal, loan interest and salary amount from submitted salary slip based on selected criteria
Get loan details from submitted salary slip based on selected criteria
"""
cond = self.get_filter_condition()
totals = frappe.db.sql("""
select sum(principal_amount) as total_principal_amount, sum(interest_amount) as total_interest_amount,
sum(total_loan_repayment) as total_loan_repayment, sum(rounded_total) as rounded_total from `tabSalary Slip` t1
return frappe.db.sql(""" select eld.employee_loan_account,
eld.interest_income_account, eld.principal_amount, eld.interest_amount, eld.total_payment
from
`tabSalary Slip` t1, `tabSalary Slip Loan` eld
where
t1.docstatus = 1 and t1.name = eld.parent and start_date >= %s and end_date <= %s %s
""" % ('%s', '%s', cond), (self.start_date, self.end_date), as_dict=True) or []
def get_total_salary_amount(self):
"""
Get total salary amount from submitted salary slip based on selected criteria
"""
cond = self.get_filter_condition()
totals = frappe.db.sql(""" select sum(rounded_total) as rounded_total from `tabSalary Slip` t1
where t1.docstatus = 1 and start_date >= %s and end_date <= %s %s
""" % ('%s', '%s', cond), (self.start_date, self.end_date), as_dict=True)
return totals[0]
def get_loan_accounts(self):
loan_accounts = frappe.get_all("Employee Loan", fields=["employee_loan_account", "interest_income_account"],
filters = {"company": self.company, "docstatus":1})
if loan_accounts:
return loan_accounts[0]
return totals and totals[0] or None
def get_salary_component_account(self, salary_component):
account = frappe.db.get_value("Salary Component Account",
@ -223,8 +228,7 @@ class PayrollEntry(Document):
earnings = self.get_salary_component_total(component_type = "earnings") or {}
deductions = self.get_salary_component_total(component_type = "deductions") or {}
default_payroll_payable_account = self.get_default_payroll_payable_account()
loan_amounts = self.get_total_salary_and_loan_amounts()
loan_accounts = self.get_loan_accounts()
loan_details = self.get_loan_details()
jv_name = ""
precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency")
@ -260,18 +264,18 @@ class PayrollEntry(Document):
})
# Employee loan
if loan_amounts.total_loan_repayment:
for data in loan_details:
accounts.append({
"account": loan_accounts.employee_loan_account,
"credit_in_account_currency": loan_amounts.total_principal_amount
"account": data.employee_loan_account,
"credit_in_account_currency": data.principal_amount
})
accounts.append({
"account": loan_accounts.interest_income_account,
"credit_in_account_currency": loan_amounts.total_interest_amount,
"account": data.interest_income_account,
"credit_in_account_currency": data.interest_amount,
"cost_center": self.cost_center,
"project": self.project
})
payable_amount -= flt(loan_amounts.total_loan_repayment, precision)
payable_amount -= flt(data.total_payment, precision)
# Payable amount
accounts.append({
@ -293,11 +297,11 @@ class PayrollEntry(Document):
def make_payment_entry(self):
self.check_permission('write')
total_salary_amount = self.get_total_salary_and_loan_amounts()
total_salary_amount = self.get_total_salary_amount()
default_payroll_payable_account = self.get_default_payroll_payable_account()
precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency")
if total_salary_amount.rounded_total:
if total_salary_amount and total_salary_amount.rounded_total:
journal_entry = frappe.new_doc('Journal Entry')
journal_entry.voucher_type = 'Bank Entry'
journal_entry.user_remark = _('Payment of salary from {0} to {1}')\
@ -413,9 +417,11 @@ def get_month_details(year, month):
else:
frappe.throw(_("Fiscal Year {0} not found").format(year))
@frappe.whitelist()
def create_log(ss_list):
if not ss_list or len(ss_list) < 1:
frappe.throw(_("No employee for the above selected criteria OR salary slip already created"))
return ss_list
def format_as_links(salary_slip):
return ['<a href="#Form/Salary Slip/{0}">{0}</a>'.format(salary_slip)]

View File

@ -37,7 +37,7 @@ frappe.ui.form.on("Salary Slip", {
set_end_date: function(frm){
frappe.call({
method: 'erpnext.hr.doctype.process_payroll.process_payroll.get_end_date',
method: 'erpnext.hr.doctype.payroll_entry.payroll_entry.get_end_date',
args: {
frequency: frm.doc.payroll_frequency,
start_date: frm.doc.start_date

View File

@ -8,7 +8,7 @@ from frappe.utils import add_days, cint, cstr, flt, getdate, rounded, date_diff,
from frappe.model.naming import make_autoname
from frappe import msgprint, _
from erpnext.hr.doctype.process_payroll.process_payroll import get_start_end_dates
from erpnext.hr.doctype.payroll_entry.payroll_entry import get_start_end_dates
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
from erpnext.utilities.transaction_base import TransactionBase
from frappe.utils.background_jobs import enqueue

View File

@ -9,8 +9,8 @@ import calendar
from erpnext.accounts.utils import get_fiscal_year
from frappe.utils import getdate, nowdate, add_days, add_months, flt
from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
from erpnext.hr.doctype.process_payroll.test_process_payroll import get_salary_component_account
from erpnext.hr.doctype.process_payroll.process_payroll import get_month_details
from erpnext.hr.doctype.payroll_entry.payroll_entry import get_salary_component_account
from erpnext.hr.doctype.payroll_entry.payroll_entry import get_month_details
class TestSalarySlip(unittest.TestCase):
def setUp(self):