Merge pull request #26178 from deepeshgarg007/payroll_accounting_dimension_develop
fix: Accounting Dimensions for payroll entry accrual Journal Entry
This commit is contained in:
commit
5b119ac4a4
@ -11,6 +11,7 @@ from frappe import _
|
|||||||
from erpnext.accounts.utils import get_fiscal_year
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
|
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
|
||||||
from frappe.desk.reportview import get_match_cond, get_filters_cond
|
from frappe.desk.reportview import get_match_cond, get_filters_cond
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
|
||||||
|
|
||||||
class PayrollEntry(Document):
|
class PayrollEntry(Document):
|
||||||
def onload(self):
|
def onload(self):
|
||||||
@ -41,7 +42,7 @@ class PayrollEntry(Document):
|
|||||||
emp_with_sal_slip.append(employee_details.employee)
|
emp_with_sal_slip.append(employee_details.employee)
|
||||||
|
|
||||||
if len(emp_with_sal_slip):
|
if len(emp_with_sal_slip):
|
||||||
frappe.throw(_("Salary Slip already exists for {0} ").format(comma_and(emp_with_sal_slip)))
|
frappe.throw(_("Salary Slip already exists for {0}").format(comma_and(emp_with_sal_slip)))
|
||||||
|
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
frappe.delete_doc("Salary Slip", frappe.db.sql_list("""select name from `tabSalary Slip`
|
frappe.delete_doc("Salary Slip", frappe.db.sql_list("""select name from `tabSalary Slip`
|
||||||
@ -211,7 +212,7 @@ class PayrollEntry(Document):
|
|||||||
return account_dict
|
return account_dict
|
||||||
|
|
||||||
def make_accrual_jv_entry(self):
|
def make_accrual_jv_entry(self):
|
||||||
self.check_permission('write')
|
self.check_permission("write")
|
||||||
earnings = self.get_salary_component_total(component_type = "earnings") or {}
|
earnings = self.get_salary_component_total(component_type = "earnings") or {}
|
||||||
deductions = self.get_salary_component_total(component_type = "deductions") or {}
|
deductions = self.get_salary_component_total(component_type = "deductions") or {}
|
||||||
payroll_payable_account = self.payroll_payable_account
|
payroll_payable_account = self.payroll_payable_account
|
||||||
@ -219,12 +220,13 @@ class PayrollEntry(Document):
|
|||||||
precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency")
|
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 = _('Accrual Journal Entry for salaries from {0} to {1}')\
|
journal_entry.user_remark = _("Accrual Journal Entry for salaries from {0} to {1}")\
|
||||||
.format(self.start_date, self.end_date)
|
.format(self.start_date, self.end_date)
|
||||||
journal_entry.company = self.company
|
journal_entry.company = self.company
|
||||||
journal_entry.posting_date = self.posting_date
|
journal_entry.posting_date = self.posting_date
|
||||||
|
accounting_dimensions = get_accounting_dimensions() or []
|
||||||
|
|
||||||
accounts = []
|
accounts = []
|
||||||
currencies = []
|
currencies = []
|
||||||
@ -236,37 +238,34 @@ class PayrollEntry(Document):
|
|||||||
for acc_cc, amount in earnings.items():
|
for acc_cc, amount in earnings.items():
|
||||||
exchange_rate, amt = self.get_amount_and_exchange_rate_for_journal_entry(acc_cc[0], amount, company_currency, currencies)
|
exchange_rate, amt = self.get_amount_and_exchange_rate_for_journal_entry(acc_cc[0], amount, company_currency, currencies)
|
||||||
payable_amount += flt(amount, precision)
|
payable_amount += flt(amount, precision)
|
||||||
accounts.append({
|
accounts.append(self.update_accounting_dimensions({
|
||||||
"account": acc_cc[0],
|
"account": acc_cc[0],
|
||||||
"debit_in_account_currency": flt(amt, precision),
|
"debit_in_account_currency": flt(amt, precision),
|
||||||
"exchange_rate": flt(exchange_rate),
|
"exchange_rate": flt(exchange_rate),
|
||||||
"party_type": '',
|
|
||||||
"cost_center": acc_cc[1] or self.cost_center,
|
"cost_center": acc_cc[1] or self.cost_center,
|
||||||
"project": self.project
|
"project": self.project
|
||||||
})
|
}, accounting_dimensions))
|
||||||
|
|
||||||
# Deductions
|
# Deductions
|
||||||
for acc_cc, amount in deductions.items():
|
for acc_cc, amount in deductions.items():
|
||||||
exchange_rate, amt = self.get_amount_and_exchange_rate_for_journal_entry(acc_cc[0], amount, company_currency, currencies)
|
exchange_rate, amt = self.get_amount_and_exchange_rate_for_journal_entry(acc_cc[0], amount, company_currency, currencies)
|
||||||
payable_amount -= flt(amount, precision)
|
payable_amount -= flt(amount, precision)
|
||||||
accounts.append({
|
accounts.append(self.update_accounting_dimensions({
|
||||||
"account": acc_cc[0],
|
"account": acc_cc[0],
|
||||||
"credit_in_account_currency": flt(amt, precision),
|
"credit_in_account_currency": flt(amt, precision),
|
||||||
"exchange_rate": flt(exchange_rate),
|
"exchange_rate": flt(exchange_rate),
|
||||||
"cost_center": acc_cc[1] or self.cost_center,
|
"cost_center": acc_cc[1] or self.cost_center,
|
||||||
"party_type": '',
|
|
||||||
"project": self.project
|
"project": self.project
|
||||||
})
|
}, accounting_dimensions))
|
||||||
|
|
||||||
# Payable amount
|
# Payable amount
|
||||||
exchange_rate, payable_amt = self.get_amount_and_exchange_rate_for_journal_entry(payroll_payable_account, payable_amount, company_currency, currencies)
|
exchange_rate, payable_amt = self.get_amount_and_exchange_rate_for_journal_entry(payroll_payable_account, payable_amount, company_currency, currencies)
|
||||||
accounts.append({
|
accounts.append(self.update_accounting_dimensions({
|
||||||
"account": payroll_payable_account,
|
"account": payroll_payable_account,
|
||||||
"credit_in_account_currency": flt(payable_amt, precision),
|
"credit_in_account_currency": flt(payable_amt, precision),
|
||||||
"exchange_rate": flt(exchange_rate),
|
"exchange_rate": flt(exchange_rate),
|
||||||
"party_type": '',
|
|
||||||
"cost_center": self.cost_center
|
"cost_center": self.cost_center
|
||||||
})
|
}, accounting_dimensions))
|
||||||
|
|
||||||
journal_entry.set("accounts", accounts)
|
journal_entry.set("accounts", accounts)
|
||||||
if len(currencies) > 1:
|
if len(currencies) > 1:
|
||||||
@ -286,6 +285,12 @@ class PayrollEntry(Document):
|
|||||||
|
|
||||||
return jv_name
|
return jv_name
|
||||||
|
|
||||||
|
def update_accounting_dimensions(self, row, accounting_dimensions):
|
||||||
|
for dimension in accounting_dimensions:
|
||||||
|
row.update({dimension: self.get(dimension)})
|
||||||
|
|
||||||
|
return row
|
||||||
|
|
||||||
def get_amount_and_exchange_rate_for_journal_entry(self, account, amount, company_currency, currencies):
|
def get_amount_and_exchange_rate_for_journal_entry(self, account, amount, company_currency, currencies):
|
||||||
conversion_rate = 1
|
conversion_rate = 1
|
||||||
exchange_rate = self.exchange_rate
|
exchange_rate = self.exchange_rate
|
||||||
|
Loading…
Reference in New Issue
Block a user