Skip to content

Instantly share code, notes, and snippets.

@ccfiel
Created May 31, 2016 09:22
Show Gist options
  • Save ccfiel/ee4aafd09c0ee9ce3576232cd67c1f46 to your computer and use it in GitHub Desktop.
Save ccfiel/ee4aafd09c0ee9ce3576232cd67c1f46 to your computer and use it in GitHub Desktop.
function toggle_fields(frm) {
frm.toggle_reqd("customer", frm.doc.transaction_type == "Rent");
frm.toggle_reqd("deposit_amount", frm.doc.transaction_type == "Rent");
frm.toggle_display("customer", frm.doc.transaction_type == "Rent");
frm.toggle_display("deposit_amount", frm.doc.transaction_type == "Rent");
frm.toggle_reqd("tenant", frm.doc.transaction_type == "Vacate");
frm.toggle_reqd("balance", frm.doc.transaction_type == "Vacate");
frm.toggle_display("tenant", frm.doc.transaction_type == "Vacate");
frm.toggle_display("balance", frm.doc.transaction_type == "Vacate");
if (frm.doc.docstatus == 0) {
frm.set_value("room", "");
frm.set_value("tenant", "");
frm.set_value("balance", "");
}
}
frappe.ui.form.on("Rental Transaction", "room", function(frm) {
return frappe.call({
method: "residences.residences.doctype.rental_transaction.rental_transaction.get_room_customer",
args: {
"room": frm.doc.room
},
callback: function(r, rt) {
if(r.message) {
cur_frm.set_value("tenant", r.message['customer']);
cur_frm.set_value("balance", r.message['deposit_amount']);
}
}
});
});
frappe.ui.form.on("Rental Transaction", {
validate: function(frm) {
frm.doc.room_name = frm.doc.building + ' Room #' + frm.doc.room_number;
},
transaction_type: function(frm) {
toggle_fields(frm);
}
});
frappe.ui.form.on("Rental Transaction", "onload", function(frm) {
toggle_fields(frm);
cur_frm.set_query("room", function() {
return {
"filters": {
"status": ((frm.doc.transaction_type == "Rent") ? 'Vacant' : 'Occupied')
}
};
});
cur_frm.set_query("customer", function() {
return {
query: "residences.residences.doctype.rental_transaction.rental_transaction.get_tenant_list"
};
});
});
cur_frm.cscript.custom_validate = function(doc) {
if(doc.transaction_type == "Rent" && !doc.customer) {
var msg = "Tenant should not be blank";
msgprint(msg);
throw msg;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment