Skip to content

Commit

Permalink
Merge pull request #213 from its4nas/develop
Browse files Browse the repository at this point in the history
feat(transactions): add Template Path to request + add approve feature to inbox and request doctypes
  • Loading branch information
its4nas authored Jan 25, 2025
2 parents 987c88f + 2804f3e commit ff93711
Show file tree
Hide file tree
Showing 18 changed files with 590 additions and 117 deletions.
88 changes: 41 additions & 47 deletions academia/transactions/doctype/inbox_memo/inbox_memo.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,50 +90,14 @@ function add_redirect_action(frm) {

// فتح الرابط في نافذة جديدة
window.location.href = url;
// frappe.new_doc("Inbox Memo Action", {
// inbox_memo: frm.doc.name,
// type: "Redirected",
// from_company: frm.doc.start_from_company,
// from_department: frm.doc.start_from_department,
// from_designation: frm.doc.start_from_designation,
// // received: is_received,
// });
// // back to Transaction after save the transaction action
// frappe.ui.form.on("Inbox Memo Action", {
// on_submit: function () {
// if (frm.doc.inbox_memo) { frappe.msgprint(frm.doc.inbox_memo) }
// else { frappe.msgprint("")}
// frappe.call({
// method: "academia.transactions.doctype.inbox_memo.inbox_memo.update_share_permissions",
// args: {
// docname: frm.doc.name,
// user: frappe.session.user,
// permissions: {
// read: 1,
// write: 0,
// share: 0,
// submit: 0,
// },
// },
// callback: function (response) {
// if (response.message) {
// inbox_memo_action_doc = frappe.get_doc("Inbox Memo Action", frm.doc)
// // frappe.db.set_value(inbox_memo , 'current_action_maker')
// frappe.db.set_value("Inbox Memo", frm.doc.inbox_memo, "current_action_maker", inbox_memo_action_doc.recipients[0].recipient_email);
// // back to Transaction after save the transaction action
// frappe.set_route("Form", "Inbox Memo", frm.doc.name);
// location.reload();
// }
// },
// });
// },
// });

});
}

frappe.ui.form.on("Inbox Memo", {
before_submit: function (frm) {
frm.set_value("current_action_maker", frm.doc.recipients[0].recipient_email);
current_action_maker = frm.doc.using_path_template ?frm.doc.recipients_path[0].recipient_email : frm.doc.recipients[0].recipient_email;
frm.set_value("current_action_maker", current_action_maker);
frappe.call({
method: "academia.transactions.doctype.inbox_memo.inbox_memo.update_share_permissions",
args: {
Expand All @@ -149,14 +113,7 @@ frappe.ui.form.on("Inbox Memo", {
callback: function (response) {
if (response.message) {
// frappe.db.set_value(inbox_memo , 'current_action_maker')
frappe.db.set_value(
"Inbox Memo",
frm.doc.name,
"current_action_maker",
inbox_memo_action_doc.recipients[0].recipient_email
);
// back to Transaction after save the transaction action
location.reload();
console.log(response.message);
}
},
});
Expand Down Expand Up @@ -233,6 +190,7 @@ frappe.ui.form.on("Inbox Memo", {

// Hide 'add row' button
frm.get_field("recipients").grid.cannot_add_rows = true;
// frm.get_field("recipients_path").grid.cannot_add_rows = true;
// Stop 'add below' & 'add above' options
frm.get_field("recipients").grid.only_sortable();
frm.refresh_field("recipients");
Expand Down Expand Up @@ -392,6 +350,42 @@ frappe.ui.form.on("Inbox Memo", {
frm.clear_table("recipients");
frm.refresh_field("recipients");
},

template_name: function(frm) {
if(!frm.doc.template_name)
{
// Clear if template_name is empty
frm.doc.recipients_path = [];
frm.refresh_field('recipients_path');
}
else
{
frappe.call({
method: 'academia.transactions.doctype.inbox_memo.inbox_memo.copy_template_paths',
args: {
template_docname: frm.doc.template_name
},
callback: function(r) {
if (r.message) {
// Clear existing entries in the recipients_path child table
frm.clear_table('recipients_path');

// Add new entries
r.message.forEach(function(item) {
let child = frm.add_child('recipients_path');
frappe.model.set_value(child.doctype, child.name, 'step', item.step);
frappe.model.set_value(child.doctype, child.name, 'recipient_company', item.recipient_company);
frappe.model.set_value(child.doctype, child.name, 'recipient_department', item.recipient_department);
frappe.model.set_value(child.doctype, child.name, 'recipient_designation', item.recipient_designation);
});

frm.refresh_field('recipients_path');
}
}
});
}
},

});

frappe.ui.form.on("Inbox Memo", {
Expand Down
124 changes: 76 additions & 48 deletions academia/transactions/doctype/inbox_memo/inbox_memo.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "naming_series:",
"creation": "2024-12-22 19:48:14.182885",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"actions": [],
"allow_rename": 1,
"autoname": "naming_series:",
"creation": "2024-12-22 19:48:14.182885",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"section_break_g9lf",
"amended_from",
"current_action_maker",
"is_received",
"title",
"status",
"inbox_from",
"using_path_template",
"full_electronic",
"transaction_reference",
"naming_series",
Expand All @@ -35,6 +36,10 @@
"recipients",
"get_recipients",
"clear_recipients",
"section_break_wdkm",
"template_name",
"template_is_active",
"recipients_path",
"attachments_tab",
"attachments",
"related_actions_tab",
Expand Down Expand Up @@ -186,6 +191,7 @@
"label": "Full Electronic"
},
{
"depends_on": "eval:doc.using_path_template == 0",
"fieldname": "to_section",
"fieldtype": "Section Break",
"label": "To"
Expand All @@ -194,7 +200,7 @@
"fieldname": "recipients",
"fieldtype": "Table",
"label": "Recipients",
"mandatory_depends_on": "eval: doc.inbox_from",
"mandatory_depends_on": "eval:doc.using_path_template == 0",
"options": "Transaction Recipients New"
},
{
Expand Down Expand Up @@ -240,27 +246,63 @@
"fieldtype": "HTML",
"label": "Related Actions",
"read_only": 1
},
{
"allow_on_submit": 1,
"default": "1",
"fieldname": "is_received",
"fieldtype": "Check",
"label": "Is Received",
"read_only": 1
},
{
"fieldname": "naming_series",
"fieldtype": "Select",
"hidden": 1,
"label": "Naming Series",
"options": "INBOX-.YY.-.MM.-"
},
{
"allow_on_submit": 1,
"default": "1",
"fieldname": "is_received",
"fieldtype": "Check",
"label": "Is Received",
"read_only": 1
},
{
"fieldname": "naming_series",
"fieldtype": "Select",
"hidden": 1,
"label": "Naming Series",
"options": "INBOX-.YY.-.MM.-"
},
{
"depends_on": "using_path_template",
"fieldname": "section_break_wdkm",
"fieldtype": "Section Break"
},
{
"allow_on_submit": 1,
"depends_on": "using_path_template",
"fieldname": "recipients_path",
"fieldtype": "Table",
"label": "Recipients Path",
"mandatory_depends_on": "using_path_template",
"options": "Recipient Path"
},
{
"default": "0",
"fieldname": "using_path_template",
"fieldtype": "Check",
"label": "Using Path Template"
},
{
"allow_on_submit": 1,
"fieldname": "template_name",
"fieldtype": "Link",
"label": "Template Name",
"mandatory_depends_on": "using_path_template",
"options": "Transaction Path Template",
"read_only_depends_on": "template_is_active"
},
{
"allow_on_submit": 1,
"default": "0",
"fieldname": "template_is_active",
"fieldtype": "Check",
"label": "Template Is Active"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2025-01-18 14:04:51.951537",
"modified": "2025-01-23 23:55:22.277041",
"modified_by": "Administrator",
"module": "Transactions",
"name": "Inbox Memo",
Expand All @@ -281,37 +323,23 @@
"write": 1
},
{
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Transactions User",
"share": 1,
"write": 1
},
{
"create": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Faculty Dean",
"share": 1,
"submit": 1,
"write": 1
},
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "transactions user",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "transactions user",
"select": 1,
"role": "Faculty Dean",
"share": 1,
"submit": 1,
"write": 1
Expand Down
Loading

0 comments on commit ff93711

Please sign in to comment.