Skip to content

Commit

Permalink
Merge pull request #210 from Khtah2/develop
Browse files Browse the repository at this point in the history
feat(transactions): added approve and reject buttons in review transa…
  • Loading branch information
its4nas authored Jan 21, 2025
2 parents 10c28d6 + 2e7d9f3 commit 8541bba
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,57 @@
// For license information, please see license.txt

frappe.ui.form.on("Review Transactions", {
on_submit: function (frm){
frappe.call({
method: "frappe.client.get",
args: {
doctype: "Transaction New",
filters: {
name: frm.doc.transaction_reference,
},
},
callback: function (response) {
if (response.message) {
let transaction_new_doc = response.message;
transaction_new_doc.related_documents.push({
document_name: frm.doc.name,
document_type: frm.doc.doctype,
document_title: frm.doc.title,
document_status: frm.doc.status,
});
frappe.call({
method: "frappe.client.save",
args: {
doc: transaction_new_doc,
},
callback: function (save_response) {
if (save_response.message) {
frappe.set_route(
"Form",
"Transaction New",
frm.doc.transaction_reference
);
}
},
});
}
},
});
},
onload: function(frm) {
if (!frm.doc.start_from) {
// Fetch the Employee record where user_id matches the logged-in user
frappe.db.get_value('Employee', { 'user_id': frappe.session.user }, 'name', function(result) {
if (result && result.name) {
frm.set_value('start_from', result.name); // Set the employee field to the Employee name
}
});
}
// Set the current_action_maker field to the session user
if (!frm.doc.current_action_maker) {
frm.set_value('current_action_maker', frappe.session.user); // Set current_action_maker to session user
}
},
refresh: function (frm) {
// Set get_query for the child table field
frm.fields_dict["transactions_for_review"].grid.get_field("document_name").get_query = function () {
Expand All @@ -13,6 +64,13 @@ frappe.ui.form.on("Review Transactions", {
}
};
};
if (
frm.doc.docstatus == 1 &&
frm.doc.status == "Pending"
) {
add_approve_action(frm);
add_reject_action(frm);
}
}
});

Expand Down Expand Up @@ -51,3 +109,29 @@ frappe.ui.form.on("Transactions For Review", {
}
},
});

function add_approve_action(frm){
cur_frm.page.add_action_item(__("Approve"), function () {
frappe.db.set_value(
"Review Transactions",
frm.docname,
"status",
"Completed"
)
.then(() => {
location.reload();
});
})}

function add_reject_action(frm){
cur_frm.page.add_action_item(__("Reject"), function () {
frappe.db.set_value(
"Review Transactions",
frm.docname,
"status",
"Rejected"
)
.then(() => {
location.reload();
});
})}
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@
"reqd": 1
},
{
"allow_on_submit": 1,
"depends_on": "eval:!doc.__islocal",
"fieldname": "status",
"fieldtype": "Select",
"label": "Status",
"options": "Pending\nCompleted\nCanceled\nClosed\nRejected"
"options": "Pending\nCompleted\nCanceled\nClosed\nRejected",
"read_only": 1
},
{
"fieldname": "transaction_reference",
"fieldtype": "Link",
"label": "Transaction Reference",
"options": "Transaction New",
"read_only": 1,
"reqd": 1
},
{
Expand All @@ -88,6 +89,7 @@
{
"fieldname": "from_section",
"fieldtype": "Section Break",
"hidden": 1,
"label": "From"
},
{
Expand All @@ -96,7 +98,6 @@
"in_list_view": 1,
"label": "Start From",
"options": "Employee",
"read_only": 1,
"reqd": 1,
"set_only_once": 1
},
Expand Down Expand Up @@ -153,7 +154,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2025-01-21 13:28:02.161135",
"modified": "2025-01-21 16:01:54.639987",
"modified_by": "Administrator",
"module": "Transactions",
"name": "Review Transactions",
Expand All @@ -176,6 +177,27 @@
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"states": [
{
"color": "Blue",
"title": "Pending"
},
{
"color": "Green",
"title": "Completed"
},
{
"color": "Red",
"title": "Canceled"
},
{
"color": "Orange",
"title": "Closed"
},
{
"color": "Purple",
"title": "Rejected"
}
],
"track_seen": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ def get_documents(filters):
"docstatus": 1, # Only submitted documents
}
)

@frappe.whitelist()
def get_shared_reviews(user):
shared_reviews = frappe.get_all('DocShare', filters={'user': user, 'share_doctype': 'Review Transactions'}, fields=['share_name'])
reviews_names = [review['share_name'] for review in shared_reviews]
return reviews_names
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
frappe.listview_settings['Review Transactions'] = {
onload: function(listview) {
$('.btn-primary').filter(function () {
return $(this).text().trim() === 'Add Review Transactions';
}).hide();

if(!frappe.user_roles.includes('Transactions Manager')) {
frappe.call({
method: 'academia.transactions.doctype.review_transactions.review_transactions.get_shared_reviews',
args: {
user: frappe.session.user
},
callback: function(response) {
if (response.message) {
const allowed_reviews = response.message;
listview.filter_area.add([
['Review Transactions', 'name', 'in', allowed_reviews]
]);

$('.filter-selector').hide();
}
}
});
}
}
};
52 changes: 52 additions & 0 deletions academia/transactions/doctype/transaction_new/transaction_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,58 @@ frappe.ui.form.on("Transaction New", {
},
__("Add Document")
);
frm.add_custom_button(
__("Review Transactions"),
function () {
if (frm.doc.related_documents.length > 0) {
frappe.call({
method: "frappe.client.get_value",
args: {
doctype:
frm.doc.related_documents[frm.doc.related_documents.length - 1]
.document_type,
fieldname: "status",
filters: {
name: frm.doc.related_documents[
frm.doc.related_documents.length - 1
].document_name,
},
},
callback: function (response) {
if (response.message) {
if (response.message.status == "Pending") {
frappe.throw(
__("You can't create a new document while another document is still pending.")
);
} else {
const url = frappe.urllib.get_full_url(
"/app/review-transactions/new?transaction_reference=" +
frm.doc.name
);

window.location.href = url;
}
} else {
const url = frappe.urllib.get_full_url(
"/app/review-transactions/new?transaction_reference=" +
frm.doc.name
);

window.location.href = url;
}
},
});
} else {
const url = frappe.urllib.get_full_url(
"/app/review-transactions/new?transaction_reference=" +
frm.doc.name
);

window.location.href = url;
}
},
__("Add Document")
);
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Document Type",
"options": "Outbox Memo\nInbox Memo\nRequest\nSpecific Transaction Document",
"options": "Outbox Memo\nInbox Memo\nRequest\nSpecific Transaction Document\nReview Transactions",
"read_only": 1
},
{
Expand Down Expand Up @@ -46,7 +46,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-12-29 20:46:25.580921",
"modified": "2025-01-21 15:49:07.937680",
"modified_by": "Administrator",
"module": "Transactions",
"name": "Transaction Related Documents",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TransactionRelatedDocuments(Document):

document_name: DF.DynamicLink | None
document_title: DF.Data | None
document_type: DF.Literal["Outbox Memo", "Inbox Memo", "Request", "Specific Transaction Document"]
document_type: DF.Literal["Outbox Memo", "Inbox Memo", "Request", "Specific Transaction Document", "Review Transactions"]
parent: DF.Data
parentfield: DF.Data
parenttype: DF.Data
Expand Down

0 comments on commit 8541bba

Please sign in to comment.