Skip to content

Commit

Permalink
fix: zervalidate o and -ve quantity to return
Browse files Browse the repository at this point in the history
  • Loading branch information
eliusmgani committed Mar 22, 2022
1 parent e038915 commit f3d8aff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ frappe.ui.form.on('Service Job Card', {
is_return: 0
}
}).then(records => {
if (!records){
} else {
if (records.length > 0){
let d = new frappe.ui.Dialog({
title: "Select Item to Unbill",
fields: [
Expand Down Expand Up @@ -100,12 +99,14 @@ frappe.ui.form.on('Service Job Card', {
});

if (items.length > 0) {
console.log(items)
frappe.call("servicems.service_management.doctype.service_job_card.service_job_card.get_selected_items", {
items: items
}).then(r => {
frm.reload_doc()
});
d.hide();

} else {
frappe.msgprint({
title: __('Message'),
Expand All @@ -119,6 +120,21 @@ frappe.ui.form.on('Service Job Card', {
});

d.show();

} else {
let d = new frappe.ui.Dialog({
title: "Select Items Unbill",
fields: [{fieldname: "html",fieldtype: "HTML"}]
});
d.fields_dict.html.$wrapper.append(`<div class="multiselect-empty-state"
style="border: 1px solid #d1d8dd; border-radius: 3px; height: 200px; overflow: auto;">
<span class="text-center" style="margin-top: -40px;">
<i class="fa fa-2x fa-heartbeat text-extra-muted"></i>
<p class="text-extra-muted text-center" style="font-size: 16px; font-weight: bold;">
No Item(s) to unbill</p>
</span>
</div>`);
d.show()
};
});
}
Expand Down Expand Up @@ -155,30 +171,30 @@ var get_qty_to_return = function(wrapper) {
$("<input type='number' id='return' style='border: 3px solid red'>")
.appendTo($(this).parent().siblings().last());

$("#return").on("input", function() {
$("#return").focusout("input", function() {
let row_qty = $(this).parent().siblings().eq(-2).text();

if ($("#return").val() <= row_qty) {
$(this).parent().siblings().last().attr("data-qty_to_return", $("#return").val());
if (parseInt($("#return").val()) <= parseInt(row_qty) && parseInt($("#return").val()) > 0) {
// store data to qty_to_return
$(this).parent().siblings().last().attr("data-qty_to_return", $("#return").val())
$("#return").css("border", "1px solid blue");

} else {
$("#return").css({ "border": "4px solid red", "font-weight": "bold" }).val(0);
$("#return").css({ "border": "4px solid red", "font-weight": "bold" }).val("");
frappe.msgprint({
title: __('Message'),
indicator: 'red',
message: __(
'<h4 class="text-center" style="background-color: orange; font-weight: bold;">\
Qty to return cannot be greater than Qty<h4>'
'<h4 class="text-center" style="background-color: orange; font-size: 13pt; font-weight: bold;">\
Qty to return cannot be Negative, cannot be Zero(0) or Empty<br>\
and cannot be greater than Qty<h4>'
)
});
};
});
}
} else {
if ($("input:checkbox").is(":checked") == false) {
$(this).parent().siblings().last().html("");
}
$(this).parent().siblings().last().html("");
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ def updated_supplied_parts(doc, selected_items, name):
row.qty = cint(d.get("qty")) - cint(d.get("qty_to_return"))
row.return_stock_enty = name
if (cint(d.get("qty")) - cint(d.get("qty_to_return"))) == 0:
frappe.msgprint(str("yes"))
row.is_billable = 0
row.is_return = 1
doc.save()
doc.reload()
frappe.throw(str("Done"))

0 comments on commit f3d8aff

Please sign in to comment.