|
|
@ -11,6 +11,7 @@ from frappe import _ |
|
|
|
from erpnext.accounts.utils import get_fiscal_year |
|
|
|
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee |
|
|
|
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): |
|
|
|
def onload(self): |
|
|
@ -211,7 +212,7 @@ class PayrollEntry(Document): |
|
|
|
return account_dict |
|
|
|
|
|
|
|
def make_accrual_jv_entry(self): |
|
|
|
self.check_permission('write') |
|
|
|
self.check_permission("write") |
|
|
|
earnings = self.get_salary_component_total(component_type = "earnings") or {} |
|
|
|
deductions = self.get_salary_component_total(component_type = "deductions") or {} |
|
|
|
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") |
|
|
|
|
|
|
|
if earnings or deductions: |
|
|
|
journal_entry = frappe.new_doc('Journal Entry') |
|
|
|
journal_entry.voucher_type = 'Journal Entry' |
|
|
|
journal_entry.user_remark = _('Accrual Journal Entry for salaries from {0} to {1}')\ |
|
|
|
journal_entry = frappe.new_doc("Journal Entry") |
|
|
|
journal_entry.voucher_type = "Journal Entry" |
|
|
|
journal_entry.user_remark = _("Accrual Journal Entry for salaries from {0} to {1}")\ |
|
|
|
.format(self.start_date, self.end_date) |
|
|
|
journal_entry.company = self.company |
|
|
|
journal_entry.posting_date = self.posting_date |
|
|
|
accounting_dimensions = get_accounting_dimensions() or [] |
|
|
|
|
|
|
|
accounts = [] |
|
|
|
currencies = [] |
|
|
@ -236,37 +238,34 @@ class PayrollEntry(Document): |
|
|
|
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) |
|
|
|
payable_amount += flt(amount, precision) |
|
|
|
accounts.append({ |
|
|
|
accounts.append(self.update_accounting_dimensions({ |
|
|
|
"account": acc_cc[0], |
|
|
|
"debit_in_account_currency": flt(amt, precision), |
|
|
|
"exchange_rate": flt(exchange_rate), |
|
|
|
"party_type": '', |
|
|
|
"cost_center": acc_cc[1] or self.cost_center, |
|
|
|
"project": self.project |
|
|
|
}) |
|
|
|
}, accounting_dimensions)) |
|
|
|
|
|
|
|
# Deductions |
|
|
|
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) |
|
|
|
payable_amount -= flt(amount, precision) |
|
|
|
accounts.append({ |
|
|
|
accounts.append(self.update_accounting_dimensions({ |
|
|
|
"account": acc_cc[0], |
|
|
|
"credit_in_account_currency": flt(amt, precision), |
|
|
|
"exchange_rate": flt(exchange_rate), |
|
|
|
"cost_center": acc_cc[1] or self.cost_center, |
|
|
|
"party_type": '', |
|
|
|
"project": self.project |
|
|
|
}) |
|
|
|
}, accounting_dimensions)) |
|
|
|
|
|
|
|
# Payable amount |
|
|
|
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, |
|
|
|
"credit_in_account_currency": flt(payable_amt, precision), |
|
|
|
"exchange_rate": flt(exchange_rate), |
|
|
|
"party_type": '', |
|
|
|
"cost_center": self.cost_center |
|
|
|
}) |
|
|
|
}, accounting_dimensions)) |
|
|
|
|
|
|
|
journal_entry.set("accounts", accounts) |
|
|
|
if len(currencies) > 1: |
|
|
@ -286,6 +285,12 @@ class PayrollEntry(Document): |
|
|
|
|
|
|
|
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): |
|
|
|
conversion_rate = 1 |
|
|
|
exchange_rate = self.exchange_rate |
|
|
|