-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from resilient-tech/version-14-hotfix
chore: release v14
- Loading branch information
Showing
44 changed files
with
1,841 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 101 additions & 19 deletions
120
india_compliance/gst_india/client_scripts/sales_invoice_list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,111 @@ | ||
const erpnext_onload = frappe.listview_settings["Sales Invoice"].onload; | ||
frappe.listview_settings["Sales Invoice"].onload = function (list_view) { | ||
const DOCTYPE = "Sales Invoice"; | ||
const erpnext_onload = frappe.listview_settings[DOCTYPE].onload; | ||
frappe.listview_settings[DOCTYPE].onload = function (list_view) { | ||
if (erpnext_onload) { | ||
erpnext_onload(list_view); | ||
} | ||
|
||
const action = async () => { | ||
if (!frappe.perm.has_perm(DOCTYPE, 0, "submit")) return; | ||
|
||
if (gst_settings.enable_e_waybill) | ||
add_bulk_action_for_submitted_invoices( | ||
list_view, | ||
__("Generate e-Waybill JSON"), | ||
generate_e_waybill_json | ||
); | ||
|
||
if (ic.is_e_invoice_enabled()) | ||
add_bulk_action_for_submitted_invoices( | ||
list_view, | ||
__("Enqueue Bulk e-Invoice Generation"), | ||
enqueue_bulk_e_invoice_generation | ||
); | ||
}; | ||
|
||
function add_bulk_action_for_submitted_invoices(list_view, label, callback) { | ||
list_view.page.add_actions_menu_item(label, async () => { | ||
const selected_docs = list_view.get_checked_items(); | ||
const docnames = list_view.get_checked_items(true); | ||
|
||
for (let doc of selected_docs) { | ||
if (doc.docstatus !== 1) { | ||
frappe.throw( | ||
__("e-Waybill JSON can only be generated from a submitted document") | ||
); | ||
} | ||
const submitted_docs = await validate_if_submitted(selected_docs); | ||
if (submitted_docs) callback(submitted_docs); | ||
}); | ||
} | ||
|
||
async function generate_e_waybill_json(docnames) { | ||
const ewb_data = await frappe.xcall( | ||
"india_compliance.gst_india.utils.e_waybill.generate_e_waybill_json", | ||
{ doctype: DOCTYPE, docnames } | ||
); | ||
|
||
trigger_file_download(ewb_data, get_e_waybill_file_name()); | ||
} | ||
|
||
async function enqueue_bulk_e_invoice_generation(docnames) { | ||
const now = frappe.datetime.system_datetime(); | ||
|
||
const job_id = await frappe.xcall( | ||
"india_compliance.gst_india.utils.e_invoice.enqueue_bulk_e_invoice_generation", | ||
{ docnames } | ||
); | ||
|
||
const creation_filter = `[">", "${now}"]`; | ||
const api_requests_link = frappe.utils.generate_route({ | ||
type: "doctype", | ||
name: "Integration Request", | ||
route_options: { | ||
integration_request_service: "India Compliance API", | ||
creation: creation_filter, | ||
}, | ||
}); | ||
const error_logs_link = frappe.utils.generate_route({ | ||
type: "doctype", | ||
name: "Error Log", | ||
route_options: { | ||
creation: creation_filter, | ||
}, | ||
}); | ||
|
||
frappe.msgprint( | ||
__( | ||
`Bulk e-Invoice Generation has been queued. You can track the | ||
<a href='{0}'>Background Job</a>, | ||
<a href='{1}'>API Request(s)</a>, | ||
and <a href='{2}'>Error Log(s)</a>.`, | ||
[ | ||
frappe.utils.get_form_link("RQ Job", job_id), | ||
api_requests_link, | ||
error_logs_link, | ||
] | ||
) | ||
); | ||
} | ||
|
||
async function validate_if_submitted(selected_docs) { | ||
const valid_docs = []; | ||
const invalid_docs = []; | ||
|
||
for (const doc of selected_docs) { | ||
if (doc.docstatus != 1) { | ||
invalid_docs.push(doc.name); | ||
} else { | ||
valid_docs.push(doc.name); | ||
} | ||
} | ||
|
||
const ewb_data = await frappe.xcall( | ||
"india_compliance.gst_india.utils.e_waybill.generate_e_waybill_json", | ||
{ doctype: list_view.doctype, docnames } | ||
); | ||
if (!invalid_docs.length) return valid_docs; | ||
|
||
trigger_file_download(ewb_data, get_e_waybill_file_name()); | ||
}; | ||
if (!valid_docs.length) { | ||
frappe.throw(__("This action can only be performed on submitted documents")); | ||
} | ||
|
||
list_view.page.add_actions_menu_item(__("Generate e-Waybill JSON"), action, false); | ||
const confirmed = await new Promise(resolve => { | ||
frappe.confirm( | ||
__( | ||
"This action can only be performed on submitted documents. Do you want to continue without the following documents?<br><br><strong>{0}</strong>", | ||
[invalid_docs.join("<br>")] | ||
), | ||
() => resolve(true) | ||
); | ||
}); | ||
|
||
}; | ||
return confirmed ? valid_docs : false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.