Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(UX): Salary Slip creation and submission via background job in Payroll Entry #31074

Merged
merged 12 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,4 @@ erpnext.patches.v14_0.delete_employee_transfer_property_doctype
erpnext.patches.v13_0.create_accounting_dimensions_in_orders
erpnext.patches.v13_0.set_per_billed_in_return_delivery_note
execute:frappe.delete_doc("DocType", "Naming Series")
erpnext.patches.v13_0.set_payroll_entry_status
16 changes: 16 additions & 0 deletions erpnext/patches/v13_0/set_payroll_entry_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import frappe
from frappe.query_builder import Case


def execute():
PayrollEntry = frappe.qb.DocType("Payroll Entry")

(
frappe.qb.update(PayrollEntry).set(
"status",
Case()
.when(PayrollEntry.docstatus == 0, "Draft")
.when(PayrollEntry.docstatus == 1, "Submitted")
.else_("Cancelled"),
)
).run()
70 changes: 55 additions & 15 deletions erpnext/payroll/doctype/payroll_entry/payroll_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,69 @@ frappe.ui.form.on('Payroll Entry', {
},

refresh: function (frm) {
if (frm.doc.docstatus == 0) {
if (!frm.is_new()) {
frm.page.clear_primary_action();
frm.add_custom_button(__("Get Employees"),
function () {
frm.events.get_employee_details(frm);
}
).toggleClass('btn-primary', !(frm.doc.employees || []).length);
}
if ((frm.doc.employees || []).length && !frappe.model.has_workflow(frm.doctype)) {
if (frm.doc.docstatus === 0 && !frm.is_new()) {
frm.page.clear_primary_action();
frm.add_custom_button(__("Get Employees"),
function () {
frm.events.get_employee_details(frm);
}
).toggleClass("btn-primary", !(frm.doc.employees || []).length);
}

if (
(frm.doc.employees || []).length
&& !frappe.model.has_workflow(frm.doctype)
&& !cint(frm.doc.salary_slips_created)
&& (frm.doc.docstatus != 2)
) {
if (frm.doc.docstatus == 0) {
frm.page.clear_primary_action();
frm.page.set_primary_action(__('Create Salary Slips'), () => {
frm.save('Submit').then(() => {
frm.page.set_primary_action(__("Create Salary Slips"), () => {
frm.save("Submit").then(() => {
frm.page.clear_primary_action();
frm.refresh();
frm.events.refresh(frm);
});
});
} else if (frm.doc.docstatus == 1 && frm.doc.status == "Failed") {
frm.add_custom_button(__("Create Salary Slip"), function () {
frm.call("create_salary_slips", {}, () => {
frm.reload_doc();
});
}).addClass("btn-primary");
}
}
if (frm.doc.docstatus == 1) {

if (frm.doc.docstatus == 1 && frm.doc.status == "Submitted") {
if (frm.custom_buttons) frm.clear_custom_buttons();
frm.events.add_context_buttons(frm);
}

if (frm.doc.status == "Failed" && frm.doc.error_message) {
const issue = `<a id="jump_to_error" style="text-decoration: underline;">issue</a>`;
let process = (cint(frm.doc.salary_slips_created)) ? "submission" : "creation";

frm.dashboard.set_headline(
__("Salary Slip {0} failed. You can resolve the {1} and retry {0}.", [process, issue])
);

$("#jump_to_error").on("click", (e) => {
e.preventDefault();
frappe.utils.scroll_to(
frm.get_field("error_message").$wrapper,
true,
30
);
});
}

frappe.realtime.on("completed_salary_slip_creation", function() {
frm.reload_doc();
});

frappe.realtime.on("completed_salary_slip_submission", function() {
frm.reload_doc();
});
},

get_employee_details: function (frm) {
Expand All @@ -88,7 +127,7 @@ frappe.ui.form.on('Payroll Entry', {
doc: frm.doc,
method: "create_salary_slips",
callback: function () {
frm.refresh();
frm.reload_doc();
frm.toolbar.refresh();
}
});
Expand All @@ -97,7 +136,7 @@ frappe.ui.form.on('Payroll Entry', {
add_context_buttons: function (frm) {
if (frm.doc.salary_slips_submitted || (frm.doc.__onload && frm.doc.__onload.submitted_ss)) {
frm.events.add_bank_entry_button(frm);
} else if (frm.doc.salary_slips_created) {
} else if (frm.doc.salary_slips_created && frm.doc.status != 'Queued') {
frm.add_custom_button(__("Submit Salary Slip"), function () {
submit_salary_slip(frm);
}).addClass("btn-primary");
Expand Down Expand Up @@ -331,6 +370,7 @@ const submit_salary_slip = function (frm) {
method: 'submit_salary_slips',
args: {},
callback: function () {
frm.reload_doc();
frm.events.refresh(frm);
},
doc: frm.doc,
Expand Down
50 changes: 40 additions & 10 deletions erpnext/payroll/doctype/payroll_entry/payroll_entry.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"engine": "InnoDB",
"field_order": [
"section_break0",
"column_break0",
"posting_date",
"payroll_frequency",
"company",
"column_break1",
"status",
"currency",
"exchange_rate",
"payroll_payable_account",
Expand Down Expand Up @@ -41,23 +41,21 @@
"cost_center",
"account",
"payment_account",
"amended_from",
"column_break_33",
"bank_account",
"salary_slips_created",
"salary_slips_submitted"
"salary_slips_submitted",
"failure_details_section",
"error_message",
"section_break_41",
"amended_from"
],
"fields": [
{
"fieldname": "section_break0",
"fieldtype": "Section Break",
"label": "Select Employees"
},
{
"fieldname": "column_break0",
"fieldtype": "Column Break",
"width": "50%"
},
{
"default": "Today",
"fieldname": "posting_date",
Expand Down Expand Up @@ -231,6 +229,7 @@
"fieldtype": "Check",
"hidden": 1,
"label": "Salary Slips Created",
"no_copy": 1,
"read_only": 1
},
{
Expand All @@ -239,6 +238,7 @@
"fieldtype": "Check",
"hidden": 1,
"label": "Salary Slips Submitted",
"no_copy": 1,
"read_only": 1
},
{
Expand Down Expand Up @@ -284,15 +284,44 @@
"label": "Payroll Payable Account",
"options": "Account",
"reqd": 1
},
{
"collapsible": 1,
"collapsible_depends_on": "error_message",
"depends_on": "eval:doc.status=='Failed';",
"fieldname": "failure_details_section",
"fieldtype": "Section Break",
"label": "Failure Details"
},
{
"depends_on": "eval:doc.status=='Failed';",
"fieldname": "error_message",
"fieldtype": "Small Text",
"label": "Error Message",
"no_copy": 1,
"read_only": 1
},
{
"fieldname": "section_break_41",
"fieldtype": "Section Break"
},
{
"fieldname": "status",
"fieldtype": "Select",
"label": "Status",
"options": "Draft\nSubmitted\nCancelled\nQueued\nFailed",
"print_hide": 1,
"read_only": 1
}
],
"icon": "fa fa-cog",
"is_submittable": 1,
"links": [],
"modified": "2020-12-17 15:13:17.766210",
"modified": "2022-03-16 12:45:21.662765",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Payroll Entry",
"naming_rule": "Expression (old style)",
"owner": "Administrator",
"permissions": [
{
Expand All @@ -308,5 +337,6 @@
}
],
"sort_field": "modified",
"sort_order": "DESC"
"sort_order": "DESC",
"states": []
}
Loading