parent
e7e29b7f10
commit
d7ff9dca1d
@ -4,7 +4,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from frappe.utils import cint, nowdate, add_days, getdate, fmt_money, add_to_date, DATE_FORMAT
|
from frappe.utils import cint, flt, nowdate, add_days, getdate, fmt_money, add_to_date, DATE_FORMAT
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from erpnext.accounts.utils import get_fiscal_year
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
|
|
||||||
@ -260,85 +260,97 @@ class ProcessPayroll(Document):
|
|||||||
loan_amounts = self.get_total_salary_and_loan_amounts()
|
loan_amounts = self.get_total_salary_and_loan_amounts()
|
||||||
loan_accounts = self.get_loan_accounts()
|
loan_accounts = self.get_loan_accounts()
|
||||||
jv_name = ""
|
jv_name = ""
|
||||||
|
precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency")
|
||||||
|
|
||||||
if earnings or deductions:
|
if earnings or deductions:
|
||||||
journal_entry = frappe.new_doc('Journal Entry')
|
journal_entry = frappe.new_doc('Journal Entry')
|
||||||
journal_entry.voucher_type = 'Journal Entry'
|
journal_entry.voucher_type = 'Journal Entry'
|
||||||
journal_entry.user_remark = _('Accural Journal Entry for salaries from {0} to {1}').format(self.start_date,
|
journal_entry.user_remark = _('Accural Journal Entry for salaries from {0} to {1}')\
|
||||||
self.end_date)
|
.format(self.start_date, self.end_date)
|
||||||
journal_entry.company = self.company
|
journal_entry.company = self.company
|
||||||
journal_entry.posting_date = nowdate()
|
journal_entry.posting_date = nowdate()
|
||||||
|
|
||||||
account_amt_list = []
|
accounts = []
|
||||||
adjustment_amt = 0
|
payable_amount = 0
|
||||||
for acc, amt in earnings.items():
|
|
||||||
adjustment_amt = adjustment_amt+amt
|
# Earnings
|
||||||
account_amt_list.append({
|
for acc, amount in earnings.items():
|
||||||
|
payable_amount += flt(amount, precision)
|
||||||
|
accounts.append({
|
||||||
"account": acc,
|
"account": acc,
|
||||||
"debit_in_account_currency": amt,
|
"debit_in_account_currency": flt(amount, precision),
|
||||||
"cost_center": self.cost_center,
|
"cost_center": self.cost_center,
|
||||||
"project": self.project
|
"project": self.project
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Deductions
|
||||||
for acc, amt in deductions.items():
|
for acc, amt in deductions.items():
|
||||||
adjustment_amt = adjustment_amt-amt
|
payable_amount -= flt(amount, precision)
|
||||||
account_amt_list.append({
|
accounts.append({
|
||||||
"account": acc,
|
"account": acc,
|
||||||
"credit_in_account_currency": amt,
|
"credit_in_account_currency": flt(amount, precision),
|
||||||
"cost_center": self.cost_center,
|
"cost_center": self.cost_center,
|
||||||
"project": self.project
|
"project": self.project
|
||||||
})
|
})
|
||||||
#employee loan
|
|
||||||
|
# Employee loan
|
||||||
if loan_amounts.total_loan_repayment:
|
if loan_amounts.total_loan_repayment:
|
||||||
account_amt_list.append({
|
accounts.append({
|
||||||
"account": loan_accounts.employee_loan_account,
|
"account": loan_accounts.employee_loan_account,
|
||||||
"credit_in_account_currency": loan_amounts.total_principal_amount
|
"credit_in_account_currency": loan_amounts.total_principal_amount
|
||||||
})
|
})
|
||||||
account_amt_list.append({
|
accounts.append({
|
||||||
"account": loan_accounts.interest_income_account,
|
"account": loan_accounts.interest_income_account,
|
||||||
"credit_in_account_currency": loan_amounts.total_interest_amount,
|
"credit_in_account_currency": loan_amounts.total_interest_amount,
|
||||||
"cost_center": self.cost_center,
|
"cost_center": self.cost_center,
|
||||||
"project": self.project
|
"project": self.project
|
||||||
})
|
})
|
||||||
adjustment_amt = adjustment_amt-(loan_amounts.total_loan_repayment)
|
payable_amount -= flt(loan_amounts.total_loan_repayment, precision)
|
||||||
|
|
||||||
account_amt_list.append({
|
# Payable amount
|
||||||
"account": default_payroll_payable_account,
|
accounts.append({
|
||||||
"credit_in_account_currency": adjustment_amt
|
"account": default_payroll_payable_account,
|
||||||
})
|
"credit_in_account_currency": flt(payable_amount, precision)
|
||||||
journal_entry.set("accounts", account_amt_list)
|
})
|
||||||
|
|
||||||
|
journal_entry.set("accounts", accounts)
|
||||||
journal_entry.save()
|
journal_entry.save()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
journal_entry.submit()
|
journal_entry.submit()
|
||||||
jv_name = journal_entry.name
|
jv_name = journal_entry.name
|
||||||
self.update_salary_slip_status(jv_name = jv_name)
|
self.update_salary_slip_status(jv_name = jv_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
frappe.msgprint(e)
|
frappe.msgprint(e)
|
||||||
|
|
||||||
return jv_name
|
return jv_name
|
||||||
|
|
||||||
def make_payment_entry(self):
|
def make_payment_entry(self):
|
||||||
self.check_permission('write')
|
self.check_permission('write')
|
||||||
total_salary_amount = self.get_total_salary_and_loan_amounts()
|
total_salary_amount = self.get_total_salary_and_loan_amounts()
|
||||||
default_payroll_payable_account = self.get_default_payroll_payable_account()
|
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.rounded_total:
|
||||||
journal_entry = frappe.new_doc('Journal Entry')
|
journal_entry = frappe.new_doc('Journal Entry')
|
||||||
journal_entry.voucher_type = 'Bank Entry'
|
journal_entry.voucher_type = 'Bank Entry'
|
||||||
journal_entry.user_remark = _('Payment of salary from {0} to {1}').format(self.start_date,
|
journal_entry.user_remark = _('Payment of salary from {0} to {1}')\
|
||||||
self.end_date)
|
.format(self.start_date, self.end_date)
|
||||||
journal_entry.company = self.company
|
journal_entry.company = self.company
|
||||||
journal_entry.posting_date = nowdate()
|
journal_entry.posting_date = nowdate()
|
||||||
|
|
||||||
account_amt_list = []
|
payment_amount = flt(total_salary_amount.rounded_total, precision)
|
||||||
|
|
||||||
account_amt_list.append({
|
journal_entry.set("accounts", [
|
||||||
|
{
|
||||||
"account": self.payment_account,
|
"account": self.payment_account,
|
||||||
"credit_in_account_currency": total_salary_amount.rounded_total
|
"credit_in_account_currency": payment_amount
|
||||||
})
|
},
|
||||||
account_amt_list.append({
|
{
|
||||||
"account": default_payroll_payable_account,
|
"account": default_payroll_payable_account,
|
||||||
"debit_in_account_currency": total_salary_amount.rounded_total
|
"debit_in_account_currency": payment_amount
|
||||||
})
|
}
|
||||||
journal_entry.set("accounts", account_amt_list)
|
])
|
||||||
return journal_entry.as_dict()
|
return journal_entry.as_dict()
|
||||||
else:
|
else:
|
||||||
frappe.msgprint(
|
frappe.msgprint(
|
||||||
|
@ -16,10 +16,13 @@ class TestProcessPayroll(unittest.TestCase):
|
|||||||
fiscal_year = "_Test Fiscal Year 2016"
|
fiscal_year = "_Test Fiscal Year 2016"
|
||||||
|
|
||||||
for data in frappe.get_all('Salary Component', fields = ["name"]):
|
for data in frappe.get_all('Salary Component', fields = ["name"]):
|
||||||
if not frappe.db.get_value('Salary Component Account', {'parent': data.name, 'company': erpnext.get_default_company()}, 'name'):
|
if not frappe.db.get_value('Salary Component Account',
|
||||||
|
{'parent': data.name, 'company': erpnext.get_default_company()}, 'name'):
|
||||||
get_salary_component_account(data.name)
|
get_salary_component_account(data.name)
|
||||||
|
|
||||||
payment_account = frappe.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name")
|
payment_account = frappe.get_value('Account',
|
||||||
|
{'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name")
|
||||||
|
|
||||||
if not frappe.db.get_value("Salary Slip", {"start_date": "2016-11-01", "end_date": "2016-11-30"}):
|
if not frappe.db.get_value("Salary Slip", {"start_date": "2016-11-01", "end_date": "2016-11-30"}):
|
||||||
process_payroll = frappe.get_doc("Process Payroll", "Process Payroll")
|
process_payroll = frappe.get_doc("Process Payroll", "Process Payroll")
|
||||||
process_payroll.company = erpnext.get_default_company()
|
process_payroll.company = erpnext.get_default_company()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user