Skip to content

Commit

Permalink
Merge pull request #34 from navariltd/service-request
Browse files Browse the repository at this point in the history
Service request
  • Loading branch information
muruthigitau authored Nov 21, 2024
2 parents 375e72e + 04260d0 commit 8a44654
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,60 @@ function addActionButtons(frm) {
frm.add_custom_button(
__("BOM"),
function () {
frappe.model.with_doctype("BOM", function () {
const bom = frappe.model.get_new_doc("BOM");
bom.utility_service_request = frm.doc.name;
frappe.set_route("Form", "BOM", bom.name);
const dialog = new frappe.ui.Dialog({
title: __("Select or Create BOM"),
fields: [
{
fieldname: "selected_bom",
label: __("Select BOM"),
fieldtype: "Link",
options: "BOM",
},
],
primary_action_label: __("New BOM"),
primary_action: function () {
const new_bom = frappe.model.get_new_doc("BOM");
new_bom.utility_service_request = frm.doc.name;

frappe.set_route("Form", "BOM", new_bom.name);
},
secondary_action_label: __("New Version"),
secondary_action: function () {
const selected_bom = dialog.get_value("selected_bom");
if (selected_bom) {
frappe.call({
method: "utility_billing.utility_billing.doctype.utility_service_request.utility_service_request.bom_new_version",
args: {
bom: selected_bom,
},
callback: function (response) {
if (response && response.message) {
const new_bom = response.message;
new_bom.utility_service_request = frm.doc.name;
frappe.db
.insert(new_bom)
.then((doc) => {
frappe.set_route("Form", "BOM", doc.name);
})
.catch((err) => {
frappe.msgprint({
title: __("Error"),
message:
__("Failed to save the BOM: ") +
err.message,
indicator: "red",
});
});
}
},
});
} else {
frappe.msgprint(__("Please select a BOM to create a new version."));
}
},
});

dialog.show();
},
__("Create")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-11-11 14:41:13.705665",
"modified": "2024-11-21 09:15:24.699016",
"modified_by": "Administrator",
"module": "Utility Billing",
"name": "Utility Service Request",
Expand All @@ -450,7 +450,10 @@
"write": 1
}
],
"search_fields": "customer_name,customer_group,territory,property,request_type,nrcpassport_no",
"sort_field": "creation",
"sort_order": "DESC",
"states": []
"states": [],
"title_field": "customer_name",
"translated_doctype": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,9 @@ def get_item_details(item_code, price_list=None):
item_details["rate"] = item_price

return item_details


@frappe.whitelist()
def bom_new_version(bom):
bom = frappe.get_doc("BOM", bom)
return frappe.copy_doc(bom)

0 comments on commit 8a44654

Please sign in to comment.