[fix] set Payment Amount in Payment Tool
This commit is contained in:
parent
0b031cdd6c
commit
12106725fb
@ -25,8 +25,14 @@ frappe.ui.form.on("Payment Tool", "onload", function(frm) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("against_voucher_type", "vouchers", function() {
|
frm.set_query("against_voucher_type", "vouchers", function() {
|
||||||
|
if (frm.doc.party_type=="Customer") {
|
||||||
|
var doctypes = ["Sales Order", "Sales Invoice", "Journal Entry"];
|
||||||
|
} else {
|
||||||
|
var doctypes = ["Purchase Order", "Purchase Invoice", "Journal Entry"];
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
filters: {"name": ["in", ["Sales Invoice", "Purchase Invoice", "Journal Entry", "Sales Order", "Purchase Order"]]}
|
filters: { "name": ["in", doctypes] }
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -135,6 +141,7 @@ frappe.ui.form.on("Payment Tool", "get_outstanding_vouchers", function(frm) {
|
|||||||
c.against_voucher_no = d.voucher_no;
|
c.against_voucher_no = d.voucher_no;
|
||||||
c.total_amount = d.invoice_amount;
|
c.total_amount = d.invoice_amount;
|
||||||
c.outstanding_amount = d.outstanding_amount;
|
c.outstanding_amount = d.outstanding_amount;
|
||||||
|
c.payment_amount = d.outstanding_amount;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
refresh_field("vouchers");
|
refresh_field("vouchers");
|
||||||
@ -145,25 +152,39 @@ frappe.ui.form.on("Payment Tool", "get_outstanding_vouchers", function(frm) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// validate against_voucher_type
|
// validate against_voucher_type
|
||||||
frappe.ui.form.on("Payment Tool Detail", "against_voucher_type", function(frm) {
|
frappe.ui.form.on("Payment Tool Detail", "against_voucher_type", function(frm, cdt, cdn) {
|
||||||
erpnext.payment_tool.validate_against_voucher(frm);
|
var row = frappe.model.get_doc(cdt, cdn);
|
||||||
|
erpnext.payment_tool.validate_against_voucher(frm, row);
|
||||||
});
|
});
|
||||||
|
|
||||||
erpnext.payment_tool.validate_against_voucher = function(frm) {
|
erpnext.payment_tool.validate_against_voucher = function(frm, row) {
|
||||||
$.each(frm.doc.vouchers || [], function(i, row) {
|
var _validate = function(i, row) {
|
||||||
|
if (!row.against_voucher_type) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(frm.doc.party_type=="Customer"
|
if(frm.doc.party_type=="Customer"
|
||||||
&& !in_list(["Sales Order", "Sales Invoice", "Journal Entry"], row.against_voucher_type)) {
|
&& !in_list(["Sales Order", "Sales Invoice", "Journal Entry"], row.against_voucher_type)) {
|
||||||
frappe.model.set_value(row.doctype, row.name, "against_voucher_type", "");
|
frappe.model.set_value(row.doctype, row.name, "against_voucher_type", "");
|
||||||
frappe.throw(__("Against Voucher Type must be one of Sales Order, Sales Invoice or Journal Entry"))
|
frappe.msgprint(__("Against Voucher Type must be one of Sales Order, Sales Invoice or Journal Entry"));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(frm.doc.party_type=="Supplier"
|
if(frm.doc.party_type=="Supplier"
|
||||||
&& !in_list(["Purchase Order", "Purchase Invoice", "Journal Entry"], row.against_voucher_type)) {
|
&& !in_list(["Purchase Order", "Purchase Invoice", "Journal Entry"], row.against_voucher_type)) {
|
||||||
frappe.model.set_value(row.doctype, row.name, "against_voucher_type", "");
|
frappe.model.set_value(row.doctype, row.name, "against_voucher_type", "");
|
||||||
frappe.throw(__("Against Voucher Type must be one of Purchase Order, Purchase Invoice or Journal Entry"))
|
frappe.msgprint(__("Against Voucher Type must be one of Purchase Order, Purchase Invoice or Journal Entry"));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (row) {
|
||||||
|
_validate(0, row);
|
||||||
|
} else {
|
||||||
|
$.each(frm.doc.vouchers || [], _validate);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate against_voucher_type
|
// validate against_voucher_type
|
||||||
@ -178,14 +199,16 @@ frappe.ui.form.on("Payment Tool Detail", "against_voucher_no", function(frm, cdt
|
|||||||
args: {
|
args: {
|
||||||
"against_voucher_type": row.against_voucher_type,
|
"against_voucher_type": row.against_voucher_type,
|
||||||
"against_voucher_no": row.against_voucher_no,
|
"against_voucher_no": row.against_voucher_no,
|
||||||
"party_account": self.party_account,
|
"party_account": frm.doc.party_account,
|
||||||
"company": self.company
|
"company": frm.doc.company
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if(!r.exc) {
|
if(!r.exc) {
|
||||||
$.each(r.message, function(k, v) {
|
$.each(r.message, function(k, v) {
|
||||||
frappe.model.set_value(cdt, cdn, k, v);
|
frappe.model.set_value(cdt, cdn, k, v);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
frappe.model.set_value(cdt, cdn, "payment_amount", r.message.outstanding_amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -208,7 +231,7 @@ erpnext.payment_tool.set_total_payment_amount = function(frm) {
|
|||||||
} else {
|
} else {
|
||||||
if(row.payment_amount < 0)
|
if(row.payment_amount < 0)
|
||||||
msgprint(__("Row {0}: Payment amount can not be negative", [row.idx]));
|
msgprint(__("Row {0}: Payment amount can not be negative", [row.idx]));
|
||||||
else if(row.payment_amount >= row.outstanding_amount)
|
else if(row.payment_amount > row.outstanding_amount)
|
||||||
msgprint(__("Row {0}: Payment Amount cannot be greater than Outstanding Amount", [__(row.idx)]));
|
msgprint(__("Row {0}: Payment Amount cannot be greater than Outstanding Amount", [__(row.idx)]));
|
||||||
|
|
||||||
frappe.model.set_value(row.doctype, row.name, "payment_amount", 0.0);
|
frappe.model.set_value(row.doctype, row.name, "payment_amount", 0.0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user