added deductions in generated je from payroll entry
This commit is contained in:
parent
aaf08e8dc8
commit
d7818af6b0
|
|
@ -0,0 +1,76 @@
|
|||
import frappe
|
||||
from frappe.utils import flt
|
||||
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
|
||||
|
||||
from hrms.payroll.doctype.payroll_entry.payroll_entry import PayrollEntry
|
||||
|
||||
|
||||
class CustomPayrollEntry(PayrollEntry):
|
||||
def make_bank_entry(self, for_withheld_salaries=False):
|
||||
self._bank_entry_deductions = {}
|
||||
|
||||
salary_details = self.get_salary_slip_details(for_withheld_salaries)
|
||||
for salary_detail in salary_details:
|
||||
if salary_detail.parentfield != "deductions":
|
||||
continue
|
||||
statistical_component = frappe.db.get_value(
|
||||
"Salary Component", salary_detail.salary_component, "statistical_component", cache=True
|
||||
)
|
||||
if not statistical_component:
|
||||
component = salary_detail.salary_component
|
||||
self._bank_entry_deductions[component] = (
|
||||
self._bank_entry_deductions.get(component, 0) + salary_detail.amount
|
||||
)
|
||||
|
||||
return super().make_bank_entry(for_withheld_salaries)
|
||||
|
||||
def set_accounting_entries_for_bank_entry(
|
||||
self, je_payment_amount, user_remark, employee_wise_accounting_enabled
|
||||
):
|
||||
bank_entry = super().set_accounting_entries_for_bank_entry(
|
||||
je_payment_amount, user_remark, employee_wise_accounting_enabled
|
||||
)
|
||||
|
||||
deductions = getattr(self, "_bank_entry_deductions", {})
|
||||
if not deductions:
|
||||
return bank_entry
|
||||
|
||||
precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency")
|
||||
company_currency = frappe.db.get_value("Company", self.company, "default_currency")
|
||||
accounting_dimensions = get_accounting_dimensions() or []
|
||||
currencies = [row.account_currency for row in bank_entry.accounts if row.get("account_currency")]
|
||||
|
||||
for salary_component, total_amount in deductions.items():
|
||||
if not total_amount:
|
||||
continue
|
||||
|
||||
deduction_account = self.get_salary_component_account(salary_component)
|
||||
|
||||
exchange_rate, amount = self.get_amount_and_exchange_rate_for_journal_entry(
|
||||
deduction_account, total_amount, company_currency, currencies
|
||||
)
|
||||
debit_row = {
|
||||
"account": deduction_account,
|
||||
"debit_in_account_currency": flt(amount, precision),
|
||||
"exchange_rate": flt(exchange_rate),
|
||||
"cost_center": self.cost_center,
|
||||
}
|
||||
self.update_accounting_dimensions(debit_row, accounting_dimensions)
|
||||
bank_entry.append("accounts", debit_row)
|
||||
|
||||
exchange_rate, amount = self.get_amount_and_exchange_rate_for_journal_entry(
|
||||
self.payment_account, total_amount, company_currency, currencies
|
||||
)
|
||||
credit_row = {
|
||||
"account": self.payment_account,
|
||||
"bank_account": self.bank_account,
|
||||
"credit_in_account_currency": flt(amount, precision),
|
||||
"exchange_rate": flt(exchange_rate),
|
||||
"cost_center": self.cost_center,
|
||||
}
|
||||
self.update_accounting_dimensions(credit_row, accounting_dimensions)
|
||||
bank_entry.append("accounts", credit_row)
|
||||
|
||||
bank_entry.save(ignore_permissions=True)
|
||||
return bank_entry
|
||||
|
|
@ -25,7 +25,8 @@ doctype_js = {
|
|||
}
|
||||
|
||||
override_doctype_class = {
|
||||
"Bulk Salary Structure Assignment": "jey_erp.custom.bulk_salary_structure_assignment.CustomBulkSalaryStructureAssignment"
|
||||
"Bulk Salary Structure Assignment": "jey_erp.custom.bulk_salary_structure_assignment.CustomBulkSalaryStructureAssignment",
|
||||
"Payroll Entry": "jey_erp.custom.payroll_entry.CustomPayrollEntry",
|
||||
}
|
||||
|
||||
doc_events = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue