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;
frm.events.validate_filters_data(frm, filters);
frm.events.get_outstanding_documents(frm, filters);
}, __("Filters"), __("Get Outstanding Invoices"));
}, __("Filters"), __("Get Outstanding Documents"));
},
validate_filters_data: function(frm, filters) {

View File

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

View File

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

View File

@ -144,6 +144,33 @@ class ExpenseClaim(AccountsController):
"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)
if self.is_paid and self.grand_total:
@ -192,9 +219,6 @@ class ExpenseClaim(AccountsController):
if not self.cost_center:
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 not self.mode_of_payment:
frappe.throw(_("Mode of payment is required to make a payment").format(self.employee))