feat: Custom button to create return entry from Employee Advance

This commit is contained in:
deepeshgarg007 2019-12-17 11:03:22 +05:30
parent c05bd1964f
commit 83ecaefd4c
2 changed files with 58 additions and 2 deletions

View File

@ -45,6 +45,15 @@ frappe.ui.form.on('Employee Advance', {
__('Create')
);
}
if (frm.doc.docstatus === 1
&& (flt(frm.doc.claimed_amount) < flt(frm.doc.paid_amount))
&& frappe.model.can_create("Journal Entry")) {
frm.add_custom_button(__("Return"), function() {
frm.trigger('make_return_entry');
}, __('Create'));
}
},
make_payment_entry: function(frm) {
@ -83,6 +92,24 @@ frappe.ui.form.on('Employee Advance', {
});
},
make_return_entry: function(frm) {
frappe.call({
method: 'erpnext.hr.doctype.employee_advance.employee_advance.make_return_entry',
args: {
'employee_name': frm.doc.employee,
'company': frm.doc.company,
'employee_advance_name': frm.doc.name,
'return_amount': flt(frm.doc.paid_amount - frm.doc.claimed_amount),
'mode_of_payment': frm.doc.mode_of_payment,
'advance_account': frm.doc.advance_account
},
callback: function(r) {
const doclist = frappe.model.sync(r.message);
frappe.set_route('Form', doclist[0].doctype, doclist[0].name);
}
})
},
employee: function (frm) {
if (frm.doc.employee) {
return frappe.call({

View File

@ -7,6 +7,7 @@ import frappe, erpnext
from frappe import _
from frappe.model.document import Document
from frappe.utils import flt, nowdate
from erpnext.accounts.doctype.journal_entry.journal_entry import get_default_bank_cash_account
class EmployeeAdvanceOverPayment(frappe.ValidationError):
pass
@ -102,8 +103,6 @@ def get_due_advance_amount(employee, posting_date):
@frappe.whitelist()
def make_bank_entry(dt, dn):
from erpnext.accounts.doctype.journal_entry.journal_entry import get_default_bank_cash_account
doc = frappe.get_doc(dt, dn)
payment_account = get_default_bank_cash_account(doc.company, account_type="Cash",
mode_of_payment=doc.mode_of_payment)
@ -132,3 +131,33 @@ def make_bank_entry(dt, dn):
})
return je.as_dict()
@frappe.whitelist()
def make_return_entry(employee_name, company, employee_advance_name, return_amount, mode_of_payment, advance_account):
return_account = get_default_bank_cash_account(company, account_type='Cash', mode_of_payment = mode_of_payment)
je = frappe.new_doc('Journal Entry')
je.posting_date = nowdate()
je.voucher_type = 'Bank Entry'
je.company = company
je.remark = 'Return against Employee Advance: ' + employee_advance_name
je.append('accounts', {
'account': advance_account,
'credit_in_account_currency': return_amount,
'reference_type': 'Employee Advance',
'reference_name': employee_advance_name,
'party_type': 'Employee',
'party': employee_name,
'is_advance': 'Yes'
})
je.append("accounts", {
"account": return_account.account,
"debit_in_account_currency": return_amount,
"account_currency": return_account.account_currency,
"account_type": return_account.account_type
})
return je.as_dict()