fix: Expense claim paid through employee advance getting fetched as outstanding in Payment Entry (#19427)

* fix: Expense claim paid through employee advance getting fetched as outstanding in Payment Entry

* fix: Codacy

* fix: Minor UX fixes

* fix: Also credit payable amount in case of advance payment

* fix: Against voucher in GL enrty
This commit is contained in:
Deepesh Garg 2019-11-12 14:32:50 +05:30 committed by Nabin Hait
parent 2689acfc8e
commit 3cc3b57926
4 changed files with 464 additions and 439 deletions

View File

@ -554,7 +554,7 @@ frappe.ui.form.on('Payment Entry', {
frappe.flags.allocate_payment_amount = true; frappe.flags.allocate_payment_amount = true;
frm.events.validate_filters_data(frm, filters); frm.events.validate_filters_data(frm, filters);
frm.events.get_outstanding_documents(frm, filters); frm.events.get_outstanding_documents(frm, filters);
}, __("Filters"), __("Get Outstanding Invoices")); }, __("Filters"), __("Get Outstanding Documents"));
}, },
validate_filters_data: function(frm, filters) { validate_filters_data: function(frm, filters) {

View File

@ -21,7 +21,7 @@ def get_data():
}, },
{ {
'label': _('Expense'), 'label': _('Expense'),
'items': ['Expense Claim', 'Travel Request'] 'items': ['Expense Claim', 'Travel Request', 'Employee Advance']
}, },
{ {
'label': _('Benefit'), 'label': _('Benefit'),

View File

@ -1,435 +1,436 @@
{ {
"allow_import": 1, "allow_import": 1,
"autoname": "naming_series:", "autoname": "naming_series:",
"creation": "2013-01-10 16:34:14", "creation": "2013-01-10 16:34:14",
"doctype": "DocType", "doctype": "DocType",
"document_type": "Setup", "document_type": "Setup",
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"naming_series", "naming_series",
"employee", "employee",
"employee_name", "employee_name",
"department", "department",
"column_break_5", "column_break_5",
"expense_approver", "expense_approver",
"approval_status", "approval_status",
"is_paid", "is_paid",
"expense_details", "expense_details",
"expenses", "expenses",
"sb1", "sb1",
"taxes", "taxes",
"transactions_section", "transactions_section",
"total_sanctioned_amount", "total_sanctioned_amount",
"total_taxes_and_charges", "total_taxes_and_charges",
"total_advance_amount", "total_advance_amount",
"column_break_17", "column_break_17",
"grand_total", "grand_total",
"total_claimed_amount", "total_claimed_amount",
"total_amount_reimbursed", "total_amount_reimbursed",
"section_break_16", "section_break_16",
"posting_date", "posting_date",
"vehicle_log", "vehicle_log",
"task", "task",
"cb1", "cb1",
"remark", "remark",
"title", "title",
"email_id", "email_id",
"accounting_details", "accounting_details",
"company", "company",
"mode_of_payment", "mode_of_payment",
"clearance_date", "clearance_date",
"column_break_24", "column_break_24",
"payable_account", "payable_account",
"accounting_dimensions_section", "accounting_dimensions_section",
"project", "project",
"dimension_col_break", "dimension_col_break",
"cost_center", "cost_center",
"more_details", "more_details",
"status", "status",
"amended_from", "amended_from",
"advance_payments", "advance_payments",
"advances" "advances"
], ],
"fields": [ "fields": [
{ {
"fieldname": "naming_series", "fieldname": "naming_series",
"fieldtype": "Select", "fieldtype": "Select",
"label": "Series", "label": "Series",
"no_copy": 1, "no_copy": 1,
"options": "HR-EXP-.YYYY.-", "options": "HR-EXP-.YYYY.-",
"print_hide": 1, "print_hide": 1,
"reqd": 1, "reqd": 1,
"set_only_once": 1 "set_only_once": 1
}, },
{ {
"fieldname": "employee", "fieldname": "employee",
"fieldtype": "Link", "fieldtype": "Link",
"in_global_search": 1, "in_global_search": 1,
"label": "From Employee", "label": "From Employee",
"oldfieldname": "employee", "oldfieldname": "employee",
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Employee", "options": "Employee",
"reqd": 1, "reqd": 1,
"search_index": 1 "search_index": 1
}, },
{ {
"fetch_from": "employee.employee_name", "fetch_from": "employee.employee_name",
"fieldname": "employee_name", "fieldname": "employee_name",
"fieldtype": "Data", "fieldtype": "Data",
"in_global_search": 1, "in_global_search": 1,
"label": "Employee Name", "label": "Employee Name",
"oldfieldname": "employee_name", "oldfieldname": "employee_name",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"read_only": 1, "read_only": 1,
"width": "150px" "width": "150px"
}, },
{ {
"fetch_from": "employee.department", "fetch_from": "employee.department",
"fieldname": "department", "fieldname": "department",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Department", "label": "Department",
"options": "Department", "options": "Department",
"read_only": 1 "read_only": 1
}, },
{ {
"fieldname": "column_break_5", "fieldname": "column_break_5",
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{ {
"fieldname": "expense_approver", "fieldname": "expense_approver",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Expense Approver", "label": "Expense Approver",
"options": "User" "options": "User"
}, },
{ {
"default": "Draft", "default": "Draft",
"fieldname": "approval_status", "fieldname": "approval_status",
"fieldtype": "Select", "fieldtype": "Select",
"label": "Approval Status", "label": "Approval Status",
"no_copy": 1, "no_copy": 1,
"options": "Draft\nApproved\nRejected", "options": "Draft\nApproved\nRejected",
"search_index": 1 "search_index": 1
}, },
{ {
"fieldname": "total_claimed_amount", "fieldname": "total_claimed_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"in_list_view": 1, "in_list_view": 1,
"label": "Total Claimed Amount", "label": "Total Claimed Amount",
"no_copy": 1, "no_copy": 1,
"oldfieldname": "total_claimed_amount", "oldfieldname": "total_claimed_amount",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"read_only": 1, "read_only": 1,
"width": "160px" "width": "160px"
}, },
{ {
"fieldname": "total_sanctioned_amount", "fieldname": "total_sanctioned_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Total Sanctioned Amount", "label": "Total Sanctioned Amount",
"no_copy": 1, "no_copy": 1,
"oldfieldname": "total_sanctioned_amount", "oldfieldname": "total_sanctioned_amount",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"read_only": 1, "read_only": 1,
"width": "160px" "width": "160px"
}, },
{ {
"default": "0", "default": "0",
"depends_on": "eval:(doc.docstatus==0 || doc.is_paid)", "depends_on": "eval:(doc.docstatus==0 || doc.is_paid)",
"fieldname": "is_paid", "fieldname": "is_paid",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Is Paid" "label": "Is Paid"
}, },
{ {
"fieldname": "expense_details", "fieldname": "expense_details",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"oldfieldtype": "Section Break" "oldfieldtype": "Section Break"
}, },
{ {
"fieldname": "expenses", "fieldname": "expenses",
"fieldtype": "Table", "fieldtype": "Table",
"label": "Expenses", "label": "Expenses",
"oldfieldname": "expense_voucher_details", "oldfieldname": "expense_voucher_details",
"oldfieldtype": "Table", "oldfieldtype": "Table",
"options": "Expense Claim Detail", "options": "Expense Claim Detail",
"reqd": 1 "reqd": 1
}, },
{ {
"fieldname": "sb1", "fieldname": "sb1",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"options": "Simple" "options": "Simple"
}, },
{ {
"default": "Today", "default": "Today",
"fieldname": "posting_date", "fieldname": "posting_date",
"fieldtype": "Date", "fieldtype": "Date",
"label": "Posting Date", "label": "Posting Date",
"oldfieldname": "posting_date", "oldfieldname": "posting_date",
"oldfieldtype": "Date", "oldfieldtype": "Date",
"reqd": 1 "reqd": 1
}, },
{ {
"fieldname": "vehicle_log", "fieldname": "vehicle_log",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Vehicle Log", "label": "Vehicle Log",
"options": "Vehicle Log", "options": "Vehicle Log",
"read_only": 1 "read_only": 1
}, },
{ {
"fieldname": "project", "fieldname": "project",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Project", "label": "Project",
"options": "Project" "options": "Project"
}, },
{ {
"fieldname": "task", "fieldname": "task",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Task", "label": "Task",
"options": "Task", "options": "Task",
"remember_last_selected_value": 1 "remember_last_selected_value": 1
}, },
{ {
"fieldname": "cb1", "fieldname": "cb1",
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{ {
"fieldname": "total_amount_reimbursed", "fieldname": "total_amount_reimbursed",
"fieldtype": "Currency", "fieldtype": "Currency",
"in_list_view": 1, "in_list_view": 1,
"label": "Total Amount Reimbursed", "label": "Total Amount Reimbursed",
"no_copy": 1, "no_copy": 1,
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"read_only": 1 "read_only": 1
}, },
{ {
"fieldname": "remark", "fieldname": "remark",
"fieldtype": "Small Text", "fieldtype": "Small Text",
"label": "Remark", "label": "Remark",
"no_copy": 1, "no_copy": 1,
"oldfieldname": "remark", "oldfieldname": "remark",
"oldfieldtype": "Small Text" "oldfieldtype": "Small Text"
}, },
{ {
"allow_on_submit": 1, "allow_on_submit": 1,
"default": "{employee_name}", "default": "{employee_name}",
"fieldname": "title", "fieldname": "title",
"fieldtype": "Data", "fieldtype": "Data",
"hidden": 1, "hidden": 1,
"label": "Title", "label": "Title",
"no_copy": 1 "no_copy": 1
}, },
{ {
"fieldname": "email_id", "fieldname": "email_id",
"fieldtype": "Data", "fieldtype": "Data",
"hidden": 1, "hidden": 1,
"label": "Employees Email Id", "label": "Employees Email Id",
"oldfieldname": "email_id", "oldfieldname": "email_id",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"print_hide": 1 "print_hide": 1
}, },
{ {
"fieldname": "accounting_details", "fieldname": "accounting_details",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Accounting Details" "label": "Accounting Details"
}, },
{ {
"fieldname": "company", "fieldname": "company",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Company", "label": "Company",
"oldfieldname": "company", "oldfieldname": "company",
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Company", "options": "Company",
"remember_last_selected_value": 1, "remember_last_selected_value": 1,
"reqd": 1 "reqd": 1
}, },
{ {
"depends_on": "is_paid", "depends_on": "is_paid",
"fieldname": "mode_of_payment", "fieldname": "mode_of_payment",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Mode of Payment", "label": "Mode of Payment",
"options": "Mode of Payment" "options": "Mode of Payment"
}, },
{ {
"fieldname": "clearance_date", "fieldname": "clearance_date",
"fieldtype": "Date", "fieldtype": "Date",
"label": "Clearance Date" "label": "Clearance Date"
}, },
{ {
"fieldname": "column_break_24", "fieldname": "column_break_24",
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{ {
"fieldname": "payable_account", "fieldname": "payable_account",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Payable Account", "label": "Payable Account",
"options": "Account" "options": "Account",
}, "reqd": 1
{ },
"fieldname": "cost_center", {
"fieldtype": "Link", "fieldname": "cost_center",
"label": "Cost Center", "fieldtype": "Link",
"options": "Cost Center" "label": "Cost Center",
}, "options": "Cost Center"
{ },
"collapsible": 1, {
"fieldname": "more_details", "collapsible": 1,
"fieldtype": "Section Break", "fieldname": "more_details",
"label": "More Details" "fieldtype": "Section Break",
}, "label": "More Details"
{ },
"default": "Draft", {
"fieldname": "status", "default": "Draft",
"fieldtype": "Select", "fieldname": "status",
"in_list_view": 1, "fieldtype": "Select",
"label": "Status", "in_list_view": 1,
"no_copy": 1, "label": "Status",
"options": "Draft\nPaid\nUnpaid\nRejected\nSubmitted\nCancelled", "no_copy": 1,
"print_hide": 1, "options": "Draft\nPaid\nUnpaid\nRejected\nSubmitted\nCancelled",
"read_only": 1 "print_hide": 1,
}, "read_only": 1
{ },
"fieldname": "amended_from", {
"fieldtype": "Link", "fieldname": "amended_from",
"ignore_user_permissions": 1, "fieldtype": "Link",
"label": "Amended From", "ignore_user_permissions": 1,
"no_copy": 1, "label": "Amended From",
"oldfieldname": "amended_from", "no_copy": 1,
"oldfieldtype": "Data", "oldfieldname": "amended_from",
"options": "Expense Claim", "oldfieldtype": "Data",
"print_hide": 1, "options": "Expense Claim",
"read_only": 1, "print_hide": 1,
"report_hide": 1, "read_only": 1,
"width": "160px" "report_hide": 1,
}, "width": "160px"
{ },
"fieldname": "advance_payments", {
"fieldtype": "Section Break", "fieldname": "advance_payments",
"label": "Advance Payments" "fieldtype": "Section Break",
}, "label": "Advance Payments"
{ },
"fieldname": "advances", {
"fieldtype": "Table", "fieldname": "advances",
"label": "Advances", "fieldtype": "Table",
"options": "Expense Claim Advance" "label": "Advances",
}, "options": "Expense Claim Advance"
{ },
"fieldname": "total_advance_amount", {
"fieldtype": "Currency", "fieldname": "total_advance_amount",
"label": "Total Advance Amount", "fieldtype": "Currency",
"options": "Company:company:default_currency", "label": "Total Advance Amount",
"read_only": 1 "options": "Company:company:default_currency",
}, "read_only": 1
{ },
"fieldname": "accounting_dimensions_section", {
"fieldtype": "Section Break", "fieldname": "accounting_dimensions_section",
"label": "Accounting Dimensions" "fieldtype": "Section Break",
}, "label": "Accounting Dimensions"
{ },
"fieldname": "dimension_col_break", {
"fieldtype": "Column Break" "fieldname": "dimension_col_break",
}, "fieldtype": "Column Break"
{ },
"fieldname": "taxes", {
"fieldtype": "Table", "fieldname": "taxes",
"label": "Expense Taxes and Charges", "fieldtype": "Table",
"options": "Expense Taxes and Charges" "label": "Expense Taxes and Charges",
}, "options": "Expense Taxes and Charges"
{ },
"fieldname": "section_break_16", {
"fieldtype": "Section Break" "fieldname": "section_break_16",
}, "fieldtype": "Section Break"
{ },
"fieldname": "transactions_section", {
"fieldtype": "Section Break" "fieldname": "transactions_section",
}, "fieldtype": "Section Break"
{ },
"fieldname": "grand_total", {
"fieldtype": "Currency", "fieldname": "grand_total",
"in_list_view": 1, "fieldtype": "Currency",
"label": "Grand Total", "in_list_view": 1,
"options": "Company:company:default_currency", "label": "Grand Total",
"read_only": 1 "options": "Company:company:default_currency",
}, "read_only": 1
{ },
"fieldname": "column_break_17", {
"fieldtype": "Column Break" "fieldname": "column_break_17",
}, "fieldtype": "Column Break"
{ },
"fieldname": "total_taxes_and_charges", {
"fieldtype": "Currency", "fieldname": "total_taxes_and_charges",
"label": "Total Taxes and Charges", "fieldtype": "Currency",
"options": "Company:company:default_currency", "label": "Total Taxes and Charges",
"read_only": 1 "options": "Company:company:default_currency",
} "read_only": 1
], }
"icon": "fa fa-money", ],
"idx": 1, "icon": "fa fa-money",
"is_submittable": 1, "idx": 1,
"modified": "2019-06-26 18:05:52.530462", "is_submittable": 1,
"modified_by": "Administrator", "modified": "2019-11-08 14:13:08.964547",
"module": "HR", "modified_by": "Administrator",
"name": "Expense Claim", "module": "HR",
"name_case": "Title Case", "name": "Expense Claim",
"owner": "harshada@webnotestech.com", "name_case": "Title Case",
"permissions": [ "owner": "harshada@webnotestech.com",
{ "permissions": [
"amend": 1, {
"cancel": 1, "amend": 1,
"create": 1, "cancel": 1,
"delete": 1, "create": 1,
"email": 1, "delete": 1,
"export": 1, "email": 1,
"print": 1, "export": 1,
"read": 1, "print": 1,
"report": 1, "read": 1,
"role": "HR Manager", "report": 1,
"share": 1, "role": "HR Manager",
"submit": 1, "share": 1,
"write": 1 "submit": 1,
}, "write": 1
{ },
"create": 1, {
"email": 1, "create": 1,
"print": 1, "email": 1,
"read": 1, "print": 1,
"report": 1, "read": 1,
"role": "Employee", "report": 1,
"share": 1, "role": "Employee",
"write": 1 "share": 1,
}, "write": 1
{ },
"amend": 1, {
"cancel": 1, "amend": 1,
"create": 1, "cancel": 1,
"delete": 1, "create": 1,
"email": 1, "delete": 1,
"print": 1, "email": 1,
"read": 1, "print": 1,
"report": 1, "read": 1,
"role": "Expense Approver", "report": 1,
"share": 1, "role": "Expense Approver",
"submit": 1, "share": 1,
"write": 1 "submit": 1,
}, "write": 1
{ },
"amend": 1, {
"cancel": 1, "amend": 1,
"create": 1, "cancel": 1,
"delete": 1, "create": 1,
"email": 1, "delete": 1,
"print": 1, "email": 1,
"read": 1, "print": 1,
"report": 1, "read": 1,
"role": "HR User", "report": 1,
"share": 1, "role": "HR User",
"submit": 1, "share": 1,
"write": 1 "submit": 1,
} "write": 1
], }
"search_fields": "employee,employee_name", ],
"show_name_in_global_search": 1, "search_fields": "employee,employee_name",
"sort_field": "modified", "show_name_in_global_search": 1,
"sort_order": "DESC", "sort_field": "modified",
"timeline_field": "employee", "sort_order": "DESC",
"title_field": "title" "timeline_field": "employee",
} "title_field": "title"
}

View File

@ -144,6 +144,33 @@ class ExpenseClaim(AccountsController):
"against_voucher": self.name "against_voucher": self.name
}) })
) )
gl_entry.append(
self.get_gl_dict({
"account": data.advance_account,
"debit": data.allocated_amount,
"debit_in_account_currency": data.allocated_amount,
"against": self.payable_account,
"party_type": "Employee",
"party": self.employee,
"against_voucher_type": self.doctype,
"against_voucher": self.name
})
)
gl_entry.append(
self.get_gl_dict({
"account": self.payable_account,
"credit": data.allocated_amount,
"credit_in_account_currency": data.allocated_amount,
"against": data.advance_account,
"party_type": "Employee",
"party": self.employee,
"against_voucher_type": "Employee Advance",
"against_voucher": data.employee_advance
})
)
self.add_tax_gl_entries(gl_entry) self.add_tax_gl_entries(gl_entry)
if self.is_paid and self.grand_total: if self.is_paid and self.grand_total:
@ -192,9 +219,6 @@ class ExpenseClaim(AccountsController):
if not self.cost_center: if not self.cost_center:
frappe.throw(_("Cost center is required to book an expense claim")) frappe.throw(_("Cost center is required to book an expense claim"))
if not self.payable_account:
frappe.throw(_("Please set default payable account for the company {0}").format(getlink("Company",self.company)))
if self.is_paid: if self.is_paid:
if not self.mode_of_payment: if not self.mode_of_payment:
frappe.throw(_("Mode of payment is required to make a payment").format(self.employee)) frappe.throw(_("Mode of payment is required to make a payment").format(self.employee))