[cleanup] payment entry form view

This commit is contained in:
Rushabh Mehta 2016-07-11 16:07:06 +05:30
parent f366f4d915
commit 3ce24d64c2
11 changed files with 263 additions and 283 deletions

View File

@ -8,7 +8,7 @@ frappe.ui.form.on('Payment Entry', {
if (!frm.doc.paid_to) frm.set_value("paid_to_account_currency", null); if (!frm.doc.paid_to) frm.set_value("paid_to_account_currency", null);
} }
}, },
setup: function(frm) { setup: function(frm) {
frm.get_field('references').grid.editable_fields = [ frm.get_field('references').grid.editable_fields = [
{fieldname: 'reference_doctype', columns: 2}, {fieldname: 'reference_doctype', columns: 2},
@ -16,11 +16,11 @@ frappe.ui.form.on('Payment Entry', {
{fieldname: 'outstanding_amount', columns: 3}, {fieldname: 'outstanding_amount', columns: 3},
{fieldname: 'allocated_amount', columns: 3} {fieldname: 'allocated_amount', columns: 3}
]; ];
var party_account_type = frm.doc.party_type=="Customer" ? "Receivable" : "Payable"; var party_account_type = frm.doc.party_type=="Customer" ? "Receivable" : "Payable";
frm.set_query("paid_from", function() { frm.set_query("paid_from", function() {
var account_types = in_list(["Pay", "Internal Transfer"], frm.doc.payment_type) ? var account_types = in_list(["Pay", "Internal Transfer"], frm.doc.payment_type) ?
["Bank", "Cash"] : party_account_type; ["Bank", "Cash"] : party_account_type;
return { return {
@ -31,11 +31,11 @@ frappe.ui.form.on('Payment Entry', {
} }
} }
}); });
frm.set_query("paid_to", function() { frm.set_query("paid_to", function() {
var account_types = in_list(["Receive", "Internal Transfer"], frm.doc.payment_type) ? var account_types = in_list(["Receive", "Internal Transfer"], frm.doc.payment_type) ?
["Bank", "Cash"] : party_account_type; ["Bank", "Cash"] : party_account_type;
return { return {
filters: { filters: {
"account_type": ["in", account_types], "account_type": ["in", account_types],
@ -44,7 +44,7 @@ frappe.ui.form.on('Payment Entry', {
} }
} }
}); });
frm.set_query("account", "deductions", function() { frm.set_query("account", "deductions", function() {
return { return {
filters: { filters: {
@ -53,7 +53,7 @@ frappe.ui.form.on('Payment Entry', {
} }
} }
}); });
frm.set_query("cost_center", "deductions", function() { frm.set_query("cost_center", "deductions", function() {
return { return {
filters: { filters: {
@ -62,7 +62,7 @@ frappe.ui.form.on('Payment Entry', {
} }
} }
}); });
frm.set_query("reference_doctype", "references", function() { frm.set_query("reference_doctype", "references", function() {
if (frm.doc.party_type=="Customer") { if (frm.doc.party_type=="Customer") {
var doctypes = ["Sales Order", "Sales Invoice", "Journal Entry"]; var doctypes = ["Sales Order", "Sales Invoice", "Journal Entry"];
@ -71,60 +71,61 @@ frappe.ui.form.on('Payment Entry', {
} else { } else {
var doctypes = ["Journal Entry"]; var doctypes = ["Journal Entry"];
} }
return { return {
filters: { "name": ["in", doctypes] } filters: { "name": ["in", doctypes] }
}; };
}); });
}, },
refresh: function(frm) { refresh: function(frm) {
erpnext.hide_company();
frm.events.hide_unhide_fields(frm); frm.events.hide_unhide_fields(frm);
frm.events.set_dynamic_labels(frm); frm.events.set_dynamic_labels(frm);
frm.events.show_general_ledger(frm); frm.events.show_general_ledger(frm);
}, },
hide_unhide_fields: function(frm) { hide_unhide_fields: function(frm) {
var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
frm.toggle_display("source_exchange_rate", frm.toggle_display("source_exchange_rate",
(frm.doc.paid_amount && frm.doc.paid_from_account_currency != company_currency)); (frm.doc.paid_amount && frm.doc.paid_from_account_currency != company_currency));
frm.toggle_display("target_exchange_rate", (frm.doc.received_amount && frm.toggle_display("target_exchange_rate", (frm.doc.received_amount &&
frm.doc.paid_to_account_currency != company_currency && frm.doc.paid_to_account_currency != company_currency &&
frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency)); frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency));
frm.toggle_display("base_paid_amount", frm.doc.paid_from_account_currency != company_currency); frm.toggle_display("base_paid_amount", frm.doc.paid_from_account_currency != company_currency);
frm.toggle_display("base_received_amount", (frm.doc.paid_to_account_currency != company_currency && frm.toggle_display("base_received_amount", (frm.doc.paid_to_account_currency != company_currency &&
frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency)); frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency));
frm.toggle_display("received_amount", frm.toggle_display("received_amount",
frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency) frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency)
frm.toggle_display(["base_total_allocated_amount"], frm.toggle_display(["base_total_allocated_amount"],
(frm.doc.paid_amount && frm.doc.received_amount && frm.doc.base_total_allocated_amount && (frm.doc.paid_amount && frm.doc.received_amount && frm.doc.base_total_allocated_amount &&
((frm.doc.payment_type=="Receive" && frm.doc.paid_from_account_currency != company_currency) || ((frm.doc.payment_type=="Receive" && frm.doc.paid_from_account_currency != company_currency) ||
(frm.doc.payment_type=="Pay" && frm.doc.paid_to_account_currency != company_currency)))); (frm.doc.payment_type=="Pay" && frm.doc.paid_to_account_currency != company_currency))));
var party_amount = frm.doc.payment_type=="Receive" ? var party_amount = frm.doc.payment_type=="Receive" ?
frm.doc.paid_amount : frm.doc.received_amount; frm.doc.paid_amount : frm.doc.received_amount;
frm.toggle_display("write_off_difference_amount", (frm.doc.difference_amount && frm.doc.party && frm.toggle_display("write_off_difference_amount", (frm.doc.difference_amount && frm.doc.party &&
(frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency) && (frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency) &&
(frm.doc.total_allocated_amount > party_amount))); (frm.doc.total_allocated_amount > party_amount)));
frm.toggle_display("set_exchange_gain_loss", frm.toggle_display("set_exchange_gain_loss",
(frm.doc.paid_amount && frm.doc.received_amount && frm.doc.difference_amount && (frm.doc.paid_amount && frm.doc.received_amount && frm.doc.difference_amount &&
(frm.doc.paid_from_account_currency != company_currency || (frm.doc.paid_from_account_currency != company_currency ||
frm.doc.paid_to_account_currency != company_currency))); frm.doc.paid_to_account_currency != company_currency)));
frm.refresh_fields(); frm.refresh_fields();
}, },
set_dynamic_labels: function(frm) { set_dynamic_labels: function(frm) {
var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
var field_label_map = {}; var field_label_map = {};
var grid_field_label_map = {}; var grid_field_label_map = {};
@ -135,7 +136,7 @@ frappe.ui.form.on('Payment Entry', {
if(docfield) { if(docfield) {
var label = __(docfield.label || "").replace(/\([^\)]*\)/g, ""); var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
if(parentfield) { if(parentfield) {
grid_field_label_map[doctype + "-" + fname] = grid_field_label_map[doctype + "-" + fname] =
label.trim() + " (" + __(currency) + ")"; label.trim() + " (" + __(currency) + ")";
} else { } else {
field_label_map[fname] = label.trim() + " (" + currency + ")"; field_label_map[fname] = label.trim() + " (" + currency + ")";
@ -143,42 +144,42 @@ frappe.ui.form.on('Payment Entry', {
} }
}); });
} }
setup_field_label_map(["base_paid_amount", "base_received_amount", "base_total_allocated_amount", setup_field_label_map(["base_paid_amount", "base_received_amount", "base_total_allocated_amount",
"difference_amount"], company_currency); "difference_amount"], company_currency);
setup_field_label_map(["paid_amount"], frm.doc.paid_from_account_currency); setup_field_label_map(["paid_amount"], frm.doc.paid_from_account_currency);
setup_field_label_map(["received_amount"], frm.doc.paid_to_account_currency); setup_field_label_map(["received_amount"], frm.doc.paid_to_account_currency);
var party_account_currency = frm.doc.payment_type=="Receive" ? var party_account_currency = frm.doc.payment_type=="Receive" ?
frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency; frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency;
setup_field_label_map(["total_allocated_amount", "unallocated_amount"], party_account_currency); setup_field_label_map(["total_allocated_amount", "unallocated_amount"], party_account_currency);
$.each(field_label_map, function(fname, label) { $.each(field_label_map, function(fname, label) {
me.frm.fields_dict[fname].set_label(label); me.frm.fields_dict[fname].set_label(label);
}); });
setup_field_label_map(["total_amount", "outstanding_amount", "allocated_amount"], setup_field_label_map(["total_amount", "outstanding_amount", "allocated_amount"],
party_account_currency, "references"); party_account_currency, "references");
setup_field_label_map(["amount"], company_currency, "deductions"); setup_field_label_map(["amount"], company_currency, "deductions");
$.each(grid_field_label_map, function(fname, label) { $.each(grid_field_label_map, function(fname, label) {
fname = fname.split("-"); fname = fname.split("-");
var df = frappe.meta.get_docfield(fname[0], fname[1], me.frm.doc.name); var df = frappe.meta.get_docfield(fname[0], fname[1], me.frm.doc.name);
if(df) df.label = label; if(df) df.label = label;
}); });
cur_frm.set_df_property("source_exchange_rate", "description", cur_frm.set_df_property("source_exchange_rate", "description",
("1 " + frm.doc.paid_from_account_currency + " = [?] " + company_currency)); ("1 " + frm.doc.paid_from_account_currency + " = [?] " + company_currency));
cur_frm.set_df_property("target_exchange_rate", "description", cur_frm.set_df_property("target_exchange_rate", "description",
("1 " + frm.doc.paid_to_account_currency + " = [?] " + company_currency)); ("1 " + frm.doc.paid_to_account_currency + " = [?] " + company_currency));
frm.refresh_fields(); frm.refresh_fields();
}, },
show_general_ledger: function(frm) { show_general_ledger: function(frm) {
if(frm.doc.docstatus==1) { if(frm.doc.docstatus==1) {
frm.add_custom_button(__('Ledger'), function() { frm.add_custom_button(__('Ledger'), function() {
@ -193,27 +194,27 @@ frappe.ui.form.on('Payment Entry', {
}, "icon-table"); }, "icon-table");
} }
}, },
payment_type: function(frm) { payment_type: function(frm) {
if(frm.doc.payment_type == "Internal Transfer") { if(frm.doc.payment_type == "Internal Transfer") {
$.each(["party", "party_balance", "paid_from", "paid_to", $.each(["party", "party_balance", "paid_from", "paid_to",
"references", "total_allocated_amount"], function(i, field) { "references", "total_allocated_amount"], function(i, field) {
frm.set_value(field, null); frm.set_value(field, null);
}) })
} else { } else {
if(!frm.doc.party) if(!frm.doc.party)
frm.set_value("party_type", frm.doc.payment_type=="Receive" ? "Customer" : "Supplier"); frm.set_value("party_type", frm.doc.payment_type=="Receive" ? "Customer" : "Supplier");
else else
frm.events.party(frm); frm.events.party(frm);
if(frm.doc.mode_of_payment) if(frm.doc.mode_of_payment)
frm.events.mode_of_payment(frm); frm.events.mode_of_payment(frm);
} }
}, },
party_type: function(frm) { party_type: function(frm) {
if(frm.doc.party) { if(frm.doc.party) {
$.each(["party", "party_balance", "paid_from", "paid_to", $.each(["party", "party_balance", "paid_from", "paid_to",
"paid_from_account_currency", "paid_from_account_balance", "paid_from_account_currency", "paid_from_account_balance",
"paid_to_account_currency", "paid_to_account_balance", "paid_to_account_currency", "paid_to_account_balance",
"references", "total_allocated_amount"], function(i, field) { "references", "total_allocated_amount"], function(i, field) {
@ -221,17 +222,17 @@ frappe.ui.form.on('Payment Entry', {
}) })
} }
}, },
party: function(frm) { party: function(frm) {
if(frm.doc.payment_type && frm.doc.party_type && frm.doc.party) { if(frm.doc.payment_type && frm.doc.party_type && frm.doc.party) {
frm.set_party_account_based_on_party = true; frm.set_party_account_based_on_party = true;
return frappe.call({ return frappe.call({
method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_party_details", method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_party_details",
args: { args: {
company: frm.doc.company, company: frm.doc.company,
party_type: frm.doc.party_type, party_type: frm.doc.party_type,
party: frm.doc.party, party: frm.doc.party,
date: frm.doc.posting_date date: frm.doc.posting_date
}, },
callback: function(r, rt) { callback: function(r, rt) {
@ -255,7 +256,7 @@ frappe.ui.form.on('Payment Entry', {
}); });
} }
}, },
mode_of_payment: function(frm) { mode_of_payment: function(frm) {
return frappe.call({ return frappe.call({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account", method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
@ -271,28 +272,28 @@ frappe.ui.form.on('Payment Entry', {
} }
}); });
}, },
paid_from: function(frm) { paid_from: function(frm) {
if(frm.set_party_account_based_on_party) return; if(frm.set_party_account_based_on_party) return;
frm.events.set_account_currency_and_balance(frm, frm.doc.paid_from, frm.events.set_account_currency_and_balance(frm, frm.doc.paid_from,
"paid_from_account_currency", "paid_from_account_balance", function(frm) { "paid_from_account_currency", "paid_from_account_balance", function(frm) {
if(frm.doc.payment_type == "Receive") frm.events.get_outstanding_documents(frm); if(frm.doc.payment_type == "Receive") frm.events.get_outstanding_documents(frm);
} }
); );
}, },
paid_to: function(frm) { paid_to: function(frm) {
if(frm.set_party_account_based_on_party) return; if(frm.set_party_account_based_on_party) return;
frm.events.set_account_currency_and_balance(frm, frm.doc.paid_to, frm.events.set_account_currency_and_balance(frm, frm.doc.paid_to,
"paid_to_account_currency", "paid_to_account_balance", function(frm) { "paid_to_account_currency", "paid_to_account_balance", function(frm) {
if(frm.doc.payment_type == "Pay") frm.events.get_outstanding_documents(frm); if(frm.doc.payment_type == "Pay") frm.events.get_outstanding_documents(frm);
} }
); );
}, },
set_account_currency_and_balance: function(frm, account, currency_field, set_account_currency_and_balance: function(frm, account, currency_field,
balance_field, callback_function) { balance_field, callback_function) {
frappe.call({ frappe.call({
method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_account_details", method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_account_details",
@ -304,33 +305,33 @@ frappe.ui.form.on('Payment Entry', {
if(r.message) { if(r.message) {
frm.set_value(currency_field, r.message['account_currency']); frm.set_value(currency_field, r.message['account_currency']);
frm.set_value(balance_field, r.message['account_balance']); frm.set_value(balance_field, r.message['account_balance']);
if(frm.doc.payment_type=="Receive" && currency_field=="paid_to_account_currency") { if(frm.doc.payment_type=="Receive" && currency_field=="paid_to_account_currency") {
frm.toggle_reqd(["reference_no", "reference_date"], frm.toggle_reqd(["reference_no", "reference_date"],
(r.message['account_type'] == "Bank" ? 1 : 0)); (r.message['account_type'] == "Bank" ? 1 : 0));
if(!frm.doc.received_amount && frm.doc.paid_amount) if(!frm.doc.received_amount && frm.doc.paid_amount)
frm.events.paid_amount(frm); frm.events.paid_amount(frm);
} else if(frm.doc.payment_type=="Pay" && currency_field=="paid_from_account_currency") { } else if(frm.doc.payment_type=="Pay" && currency_field=="paid_from_account_currency") {
frm.toggle_reqd(["reference_no", "reference_date"], frm.toggle_reqd(["reference_no", "reference_date"],
(r.message['account_type'] == "Bank" ? 1 : 0)); (r.message['account_type'] == "Bank" ? 1 : 0));
if(!frm.doc.paid_amount && frm.doc.received_amount) if(!frm.doc.paid_amount && frm.doc.received_amount)
frm.events.received_amount(frm); frm.events.received_amount(frm);
} }
if(callback_function) callback_function(frm); if(callback_function) callback_function(frm);
frm.events.hide_unhide_fields(frm); frm.events.hide_unhide_fields(frm);
frm.events.set_dynamic_labels(frm); frm.events.set_dynamic_labels(frm);
} }
} }
}); });
}, },
paid_from_account_currency: function(frm) { paid_from_account_currency: function(frm) {
if(!frm.doc.paid_from_account_currency) return; if(!frm.doc.paid_from_account_currency) return;
var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
if (frm.doc.paid_from_account_currency == company_currency) { if (frm.doc.paid_from_account_currency == company_currency) {
frm.set_value("source_exchange_rate", 1); frm.set_value("source_exchange_rate", 1);
} else if (frm.doc.paid_from){ } else if (frm.doc.paid_from){
@ -345,20 +346,20 @@ frappe.ui.form.on('Payment Entry', {
} }
}) })
} else { } else {
frm.events.set_current_exchange_rate(frm, "source_exchange_rate", frm.events.set_current_exchange_rate(frm, "source_exchange_rate",
frm.doc.paid_from_account_currency, company_currency); frm.doc.paid_from_account_currency, company_currency);
} }
} }
}, },
paid_to_account_currency: function(frm) { paid_to_account_currency: function(frm) {
if(!frm.doc.paid_to_account_currency) return; if(!frm.doc.paid_to_account_currency) return;
var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
frm.events.set_current_exchange_rate(frm, "target_exchange_rate", frm.events.set_current_exchange_rate(frm, "target_exchange_rate",
frm.doc.paid_to_account_currency, company_currency); frm.doc.paid_to_account_currency, company_currency);
}, },
set_current_exchange_rate: function(frm, exchange_rate_field, from_currency, to_currency) { set_current_exchange_rate: function(frm, exchange_rate_field, from_currency, to_currency) {
frappe.call({ frappe.call({
method: "erpnext.setup.utils.get_exchange_rate", method: "erpnext.setup.utils.get_exchange_rate",
@ -371,24 +372,24 @@ frappe.ui.form.on('Payment Entry', {
} }
}) })
}, },
source_exchange_rate: function(frm) { source_exchange_rate: function(frm) {
if (frm.doc.paid_amount) { if (frm.doc.paid_amount) {
frm.set_value("base_paid_amount", flt(frm.doc.paid_amount) * flt(frm.doc.source_exchange_rate)); frm.set_value("base_paid_amount", flt(frm.doc.paid_amount) * flt(frm.doc.source_exchange_rate));
} }
}, },
target_exchange_rate: function(frm) { target_exchange_rate: function(frm) {
if (frm.doc.received_amount) { if (frm.doc.received_amount) {
frm.set_value("base_received_amount", frm.set_value("base_received_amount",
flt(frm.doc.received_amount) * flt(frm.doc.target_exchange_rate)); flt(frm.doc.received_amount) * flt(frm.doc.target_exchange_rate));
} }
}, },
paid_amount: function(frm) { paid_amount: function(frm) {
frm.set_value("base_paid_amount", flt(frm.doc.paid_amount) * flt(frm.doc.source_exchange_rate)); frm.set_value("base_paid_amount", flt(frm.doc.paid_amount) * flt(frm.doc.source_exchange_rate));
if(!frm.set_paid_amount_based_on_received_amount && if(!frm.set_paid_amount_based_on_received_amount &&
(frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency)) { (frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency)) {
frm.set_value("received_amount", frm.doc.paid_amount); frm.set_value("received_amount", frm.doc.paid_amount);
frm.set_value("target_exchange_rate", frm.doc.source_exchange_rate); frm.set_value("target_exchange_rate", frm.doc.source_exchange_rate);
@ -398,33 +399,33 @@ frappe.ui.form.on('Payment Entry', {
frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.paid_amount); frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.paid_amount);
else else
frm.events.set_difference_amount(frm); frm.events.set_difference_amount(frm);
frm.set_paid_amount_based_on_received_amount = false; frm.set_paid_amount_based_on_received_amount = false;
}, },
received_amount: function(frm) { received_amount: function(frm) {
frm.set_paid_amount_based_on_received_amount = true; frm.set_paid_amount_based_on_received_amount = true;
if(!frm.doc.paid_amount && frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency) { if(!frm.doc.paid_amount && frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency) {
frm.set_value("paid_amount", frm.doc.received_amount); frm.set_value("paid_amount", frm.doc.received_amount);
frm.set_value("source_exchange_rate", frm.doc.target_exchange_rate); frm.set_value("source_exchange_rate", frm.doc.target_exchange_rate);
frm.set_value("base_paid_amount", frm.doc.base_received_amount); frm.set_value("base_paid_amount", frm.doc.base_received_amount);
} }
frm.set_value("base_received_amount", frm.set_value("base_received_amount",
flt(frm.doc.received_amount) * flt(frm.doc.target_exchange_rate)); flt(frm.doc.received_amount) * flt(frm.doc.target_exchange_rate));
if(frm.doc.payment_type == "Pay") if(frm.doc.payment_type == "Pay")
frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.received_amount); frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.received_amount);
else else
frm.events.set_difference_amount(frm); frm.events.set_difference_amount(frm);
}, },
get_outstanding_documents: function(frm) { get_outstanding_documents: function(frm) {
frm.clear_table("references"); frm.clear_table("references");
if(!frm.doc.party) return; if(!frm.doc.party) return;
frm.events.check_mandatory_to_fetch(frm); frm.events.check_mandatory_to_fetch(frm);
var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
@ -443,7 +444,7 @@ frappe.ui.form.on('Payment Entry', {
if(r.message) { if(r.message) {
var total_positive_outstanding = 0; var total_positive_outstanding = 0;
var total_negative_outstanding = 0; var total_negative_outstanding = 0;
$.each(r.message, function(i, d) { $.each(r.message, function(i, d) {
var c = frm.add_child("references"); var c = frm.add_child("references");
c.reference_doctype = d.voucher_type; c.reference_doctype = d.voucher_type;
@ -456,8 +457,8 @@ frappe.ui.form.on('Payment Entry', {
else else
total_negative_outstanding += Math.abs(flt(d.outstanding_amount)); total_negative_outstanding += Math.abs(flt(d.outstanding_amount));
} }
var party_account_currency = frm.doc.payment_type=="Receive" ? var party_account_currency = frm.doc.payment_type=="Receive" ?
frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency; frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency;
if(party_account_currency != company_currency) { if(party_account_currency != company_currency) {
@ -469,51 +470,51 @@ frappe.ui.form.on('Payment Entry', {
c.due_date = d.due_date; c.due_date = d.due_date;
} }
}); });
if((frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") || if((frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") ||
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier")) { (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier")) {
if(total_positive_outstanding > total_negative_outstanding) if(total_positive_outstanding > total_negative_outstanding)
frm.set_value("paid_amount", frm.set_value("paid_amount",
total_positive_outstanding - total_negative_outstanding); total_positive_outstanding - total_negative_outstanding);
} else if (total_negative_outstanding && } else if (total_negative_outstanding &&
(total_positive_outstanding < total_negative_outstanding)) { (total_positive_outstanding < total_negative_outstanding)) {
frm.set_value("received_amount", frm.set_value("received_amount",
total_negative_outstanding - total_positive_outstanding); total_negative_outstanding - total_positive_outstanding);
} }
} }
frm.events.allocate_party_amount_against_ref_docs(frm, frm.events.allocate_party_amount_against_ref_docs(frm,
(frm.doc.payment_type=="Receive" ? frm.doc.paid_amount : frm.doc.received_amount)); (frm.doc.payment_type=="Receive" ? frm.doc.paid_amount : frm.doc.received_amount));
} }
}); });
}, },
allocate_party_amount_against_ref_docs: function(frm, paid_amount) { allocate_party_amount_against_ref_docs: function(frm, paid_amount) {
var total_positive_outstanding_including_order = 0; var total_positive_outstanding_including_order = 0;
var total_negative_outstanding = 0; var total_negative_outstanding = 0;
$.each(frm.doc.references || [], function(i, row) { $.each(frm.doc.references || [], function(i, row) {
if(flt(row.outstanding_amount) > 0) if(flt(row.outstanding_amount) > 0)
total_positive_outstanding_including_order += flt(row.outstanding_amount); total_positive_outstanding_including_order += flt(row.outstanding_amount);
else else
total_negative_outstanding += Math.abs(flt(row.outstanding_amount)); total_negative_outstanding += Math.abs(flt(row.outstanding_amount));
}) })
var allocated_negative_outstanding = 0; var allocated_negative_outstanding = 0;
if((frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") || if((frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") ||
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier")) { (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier")) {
if(total_positive_outstanding_including_order > paid_amount) { if(total_positive_outstanding_including_order > paid_amount) {
var remaining_outstanding = total_positive_outstanding_including_order - paid_amount; var remaining_outstanding = total_positive_outstanding_including_order - paid_amount;
allocated_negative_outstanding = total_negative_outstanding < remaining_outstanding ? allocated_negative_outstanding = total_negative_outstanding < remaining_outstanding ?
total_negative_outstanding : remaining_outstanding; total_negative_outstanding : remaining_outstanding;
} }
var allocated_positive_outstanding = paid_amount + allocated_negative_outstanding; var allocated_positive_outstanding = paid_amount + allocated_negative_outstanding;
} else { } else {
if(paid_amount > total_negative_outstanding) { if(paid_amount > total_negative_outstanding) {
if(total_negative_outstanding == 0) { if(total_negative_outstanding == 0) {
frappe.msgprint(__("Cannot {0} {1} {2} without any negative outstanding invoice", frappe.msgprint(__("Cannot {0} {1} {2} without any negative outstanding invoice",
[frm.doc.payment_type, [frm.doc.payment_type,
(frm.doc.party_type=="Customer" ? "to" : "from"), frm.doc.party_type])); (frm.doc.party_type=="Customer" ? "to" : "from"), frm.doc.party_type]));
return false return false
} else { } else {
@ -522,66 +523,66 @@ frappe.ui.form.on('Payment Entry', {
} }
} else { } else {
allocated_positive_outstanding = total_negative_outstanding - paid_amount; allocated_positive_outstanding = total_negative_outstanding - paid_amount;
allocated_negative_outstanding = paid_amount + allocated_negative_outstanding = paid_amount +
(total_positive_outstanding_including_order < allocated_positive_outstanding ? (total_positive_outstanding_including_order < allocated_positive_outstanding ?
total_positive_outstanding_including_order : allocated_positive_outstanding) total_positive_outstanding_including_order : allocated_positive_outstanding)
} }
} }
$.each(frm.doc.references || [], function(i, row) { $.each(frm.doc.references || [], function(i, row) {
row.allocated_amount = 0 row.allocated_amount = 0
if(row.outstanding_amount > 0 && allocated_positive_outstanding > 0) { if(row.outstanding_amount > 0 && allocated_positive_outstanding > 0) {
if(row.outstanding_amount >= allocated_positive_outstanding) if(row.outstanding_amount >= allocated_positive_outstanding)
row.allocated_amount = allocated_positive_outstanding; row.allocated_amount = allocated_positive_outstanding;
else row.allocated_amount = row.outstanding_amount; else row.allocated_amount = row.outstanding_amount;
allocated_positive_outstanding -= flt(row.allocated_amount); allocated_positive_outstanding -= flt(row.allocated_amount);
} else if (row.outstanding_amount < 0 && allocated_negative_outstanding) { } else if (row.outstanding_amount < 0 && allocated_negative_outstanding) {
if(Math.abs(row.outstanding_amount) >= allocated_negative_outstanding) if(Math.abs(row.outstanding_amount) >= allocated_negative_outstanding)
row.allocated_amount = -1*allocated_negative_outstanding; row.allocated_amount = -1*allocated_negative_outstanding;
else row.allocated_amount = row.outstanding_amount; else row.allocated_amount = row.outstanding_amount;
allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount)); allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
} }
}) })
frm.refresh_fields() frm.refresh_fields()
frm.events.set_total_allocated_amount(frm); frm.events.set_total_allocated_amount(frm);
}, },
set_total_allocated_amount: function(frm) { set_total_allocated_amount: function(frm) {
var total_allocated_amount = base_total_allocated_amount = 0.0; var total_allocated_amount = base_total_allocated_amount = 0.0;
$.each(frm.doc.references || [], function(i, row) { $.each(frm.doc.references || [], function(i, row) {
if (row.allocated_amount) { if (row.allocated_amount) {
total_allocated_amount += flt(row.allocated_amount); total_allocated_amount += flt(row.allocated_amount);
base_total_allocated_amount += flt(flt(row.allocated_amount)*flt(row.exchange_rate), base_total_allocated_amount += flt(flt(row.allocated_amount)*flt(row.exchange_rate),
precision("base_paid_amount")); precision("base_paid_amount"));
} }
}); });
frm.set_value("total_allocated_amount", Math.abs(total_allocated_amount)); frm.set_value("total_allocated_amount", Math.abs(total_allocated_amount));
frm.set_value("base_total_allocated_amount", Math.abs(base_total_allocated_amount)); frm.set_value("base_total_allocated_amount", Math.abs(base_total_allocated_amount));
frm.events.set_difference_amount(frm); frm.events.set_difference_amount(frm);
}, },
set_difference_amount: function(frm) { set_difference_amount: function(frm) {
var unallocated_amount = 0; var unallocated_amount = 0;
if(frm.doc.party) { if(frm.doc.party) {
var party_amount = frm.doc.payment_type=="Receive" ? var party_amount = frm.doc.payment_type=="Receive" ?
frm.doc.paid_amount : frm.doc.received_amount; frm.doc.paid_amount : frm.doc.received_amount;
if(frm.doc.total_allocated_amount < party_amount) if(frm.doc.total_allocated_amount < party_amount)
unallocated_amount = party_amount - frm.doc.total_allocated_amount; unallocated_amount = party_amount - frm.doc.total_allocated_amount;
} }
frm.set_value("unallocated_amount", unallocated_amount); frm.set_value("unallocated_amount", unallocated_amount);
var difference_amount = 0; var difference_amount = 0;
var base_unallocated_amount = flt(frm.doc.unallocated_amount) * var base_unallocated_amount = flt(frm.doc.unallocated_amount) *
(frm.doc.payment_type=="Receive" ? frm.doc.source_exchange_rate : frm.doc.target_exchange_rate); (frm.doc.payment_type=="Receive" ? frm.doc.source_exchange_rate : frm.doc.target_exchange_rate);
var base_party_amount = flt(frm.doc.base_total_allocated_amount) + base_unallocated_amount; var base_party_amount = flt(frm.doc.base_total_allocated_amount) + base_unallocated_amount;
if(frm.doc.payment_type == "Receive") { if(frm.doc.payment_type == "Receive") {
difference_amount = base_party_amount - flt(frm.doc.base_received_amount); difference_amount = base_party_amount - flt(frm.doc.base_received_amount);
} else if (frm.doc.payment_type == "Pay") { } else if (frm.doc.payment_type == "Pay") {
@ -589,26 +590,26 @@ frappe.ui.form.on('Payment Entry', {
} else { } else {
difference_amount = flt(frm.doc.base_paid_amount) - flt(frm.doc.base_received_amount); difference_amount = flt(frm.doc.base_paid_amount) - flt(frm.doc.base_received_amount);
} }
$.each(frm.doc.deductions || [], function(i, d) { $.each(frm.doc.deductions || [], function(i, d) {
if(d.amount) difference_amount -= flt(d.amount); if(d.amount) difference_amount -= flt(d.amount);
}) })
frm.set_value("difference_amount", difference_amount); frm.set_value("difference_amount", difference_amount);
frm.events.hide_unhide_fields(frm); frm.events.hide_unhide_fields(frm);
}, },
check_mandatory_to_fetch: function(frm) { check_mandatory_to_fetch: function(frm) {
$.each(["Company", "Party Type", "Party", "payment_type"], function(i, field) { $.each(["Company", "Party Type", "Party", "payment_type"], function(i, field) {
if(!frm.doc[frappe.model.scrub(field)]) { if(!frm.doc[frappe.model.scrub(field)]) {
frappe.msgprint(__("Please select {0} first", [field])); frappe.msgprint(__("Please select {0} first", [field]));
return false; return false;
} }
}); });
}, },
validate_reference_document: function(frm, row) { validate_reference_document: function(frm, row) {
var _validate = function(i, row) { var _validate = function(i, row) {
if (!row.reference_doctype) { if (!row.reference_doctype) {
@ -622,7 +623,7 @@ frappe.ui.form.on('Payment Entry', {
return false; return false;
} }
if(frm.doc.party_type=="Supplier" && !in_list(["Purchase Order", if(frm.doc.party_type=="Supplier" && !in_list(["Purchase Order",
"Purchase Invoice", "Journal Entry"], row.reference_doctype)) { "Purchase Invoice", "Journal Entry"], row.reference_doctype)) {
frappe.model.set_value(row.doctype, row.name, "against_voucher_type", null); frappe.model.set_value(row.doctype, row.name, "against_voucher_type", null);
frappe.msgprint(__("Row #{0}: Reference Document Type must be one of Purchase Order, Purchase Invoice or Journal Entry", [row.idx])); frappe.msgprint(__("Row #{0}: Reference Document Type must be one of Purchase Order, Purchase Invoice or Journal Entry", [row.idx]));
@ -636,15 +637,15 @@ frappe.ui.form.on('Payment Entry', {
$.each(frm.doc.vouchers || [], _validate); $.each(frm.doc.vouchers || [], _validate);
} }
}, },
write_off_difference_amount: function(frm) { write_off_difference_amount: function(frm) {
frm.events.set_deductions_entry(frm, "write_off_account"); frm.events.set_deductions_entry(frm, "write_off_account");
}, },
set_exchange_gain_loss: function(frm) { set_exchange_gain_loss: function(frm) {
frm.events.set_deductions_entry(frm, "exchange_gain_loss_account"); frm.events.set_deductions_entry(frm, "exchange_gain_loss_account");
}, },
set_deductions_entry: function(frm, account) { set_deductions_entry: function(frm, account) {
if(frm.doc.difference_amount) { if(frm.doc.difference_amount) {
frappe.call({ frappe.call({
@ -654,9 +655,9 @@ frappe.ui.form.on('Payment Entry', {
}, },
callback: function(r, rt) { callback: function(r, rt) {
if(r.message) { if(r.message) {
var write_off_row = $.map(frm.doc["deductions"] || [], function(t) { var write_off_row = $.map(frm.doc["deductions"] || [], function(t) {
return t.account==r.message[account] ? t : null; }); return t.account==r.message[account] ? t : null; });
if (!write_off_row.length) { if (!write_off_row.length) {
var row = frm.add_child("deductions"); var row = frm.add_child("deductions");
row.account = r.message[account]; row.account = r.message[account];
@ -664,10 +665,10 @@ frappe.ui.form.on('Payment Entry', {
} else { } else {
var row = write_off_row[0]; var row = write_off_row[0];
} }
row.amount = flt(row.amount) + flt(frm.doc.difference_amount); row.amount = flt(row.amount) + flt(frm.doc.difference_amount);
refresh_field("deductions"); refresh_field("deductions");
frm.events.set_difference_amount(frm); frm.events.set_difference_amount(frm);
} }
} }
@ -682,7 +683,7 @@ frappe.ui.form.on('Payment Entry Reference', {
var row = locals[cdt][cdn]; var row = locals[cdt][cdn];
frm.events.validate_reference_document(frm, row); frm.events.validate_reference_document(frm, row);
}, },
reference_name: function(frm, cdt, cdn) { reference_name: function(frm, cdt, cdn) {
var row = locals[cdt][cdn]; var row = locals[cdt][cdn];
return frappe.call({ return frappe.call({
@ -690,9 +691,9 @@ frappe.ui.form.on('Payment Entry Reference', {
args: { args: {
reference_doctype: row.reference_doctype, reference_doctype: row.reference_doctype,
reference_name: row.reference_name, reference_name: row.reference_name,
party_account_currency: frm.doc.payment_type=="Receive" ? party_account_currency: frm.doc.payment_type=="Receive" ?
frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency
}, },
callback: function(r, rt) { callback: function(r, rt) {
if(r.message) { if(r.message) {
$.each(r.message, function(field, value) { $.each(r.message, function(field, value) {
@ -703,11 +704,11 @@ frappe.ui.form.on('Payment Entry Reference', {
} }
}) })
}, },
allocated_amount: function(frm) { allocated_amount: function(frm) {
frm.events.set_total_allocated_amount(frm); frm.events.set_total_allocated_amount(frm);
}, },
references_remove: function(frm) { references_remove: function(frm) {
frm.events.set_total_allocated_amount(frm); frm.events.set_total_allocated_amount(frm);
} }
@ -717,7 +718,7 @@ frappe.ui.form.on('Payment Entry Deduction', {
amount: function(frm) { amount: function(frm) {
frm.events.set_difference_amount(frm); frm.events.set_difference_amount(frm);
}, },
deductions_remove: function(frm) { deductions_remove: function(frm) {
frm.events.set_difference_amount(frm); frm.events.set_difference_amount(frm);
} }

View File

@ -9,7 +9,33 @@
"docstatus": 0, "docstatus": 0,
"doctype": "DocType", "doctype": "DocType",
"document_type": "", "document_type": "",
"editable_grid": 0,
"fields": [ "fields": [
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "type_of_payment",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Type of Payment",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 1, "bold": 1,
@ -62,6 +88,60 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type)",
"fieldname": "party_type",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Party Type",
"length": 0,
"no_copy": 0,
"options": "Customer\nSupplier",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 1,
"collapsible": 0,
"depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type) && doc.party_type",
"fieldname": "party",
"fieldtype": "Dynamic Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Party",
"length": 0,
"no_copy": 0,
"options": "party_type",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@ -167,16 +247,15 @@
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 1,
"depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type)", "fieldname": "payment_accounts_section",
"fieldname": "party_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "", "label": "Accounts",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
@ -190,84 +269,6 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type)",
"fieldname": "party_type",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Party Type",
"length": 0,
"no_copy": 0,
"options": "Customer\nSupplier",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "column_break_10",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 1,
"collapsible": 0,
"depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type) && doc.party_type",
"fieldname": "party",
"fieldtype": "Dynamic Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Party",
"length": 0,
"no_copy": 0,
"options": "party_type",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@ -294,31 +295,6 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "payment_accounts_section",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 1, "bold": 1,
@ -518,7 +494,7 @@
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "", "label": "Amount",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
@ -729,7 +705,7 @@
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Reference Documents", "label": "Reference",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
@ -782,6 +758,7 @@
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Writeoff",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
@ -1040,7 +1017,7 @@
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Transaction References", "label": "Transaction ID",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
@ -1372,7 +1349,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-07-04 15:00:53.731584", "modified": "2016-07-11 06:25:00.248907",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Payment Entry", "name": "Payment Entry",

View File

@ -10,6 +10,10 @@ frappe.ui.form.on("Purchase Order", {
erpnext.queries.setup_queries(frm, "Warehouse", function() { erpnext.queries.setup_queries(frm, "Warehouse", function() {
return erpnext.queries.warehouse(frm.doc); return erpnext.queries.warehouse(frm.doc);
}); });
frm.set_indicator_formatter('item_code',
function(doc) { return (doc.qty<=doc.received_qty) ? "green" : "orange" })
} }
}); });

View File

@ -5,7 +5,7 @@ data = {
'fieldname': 'purchase_order', 'fieldname': 'purchase_order',
'transactions': [ 'transactions': [
{ {
'label': _('Related Documents'), 'label': _('Related'),
'items': ['Purchase Receipt', 'Purchase Invoice', 'Stock Entry'] 'items': ['Purchase Receipt', 'Purchase Invoice', 'Stock Entry']
}, },
] ]

View File

@ -5,7 +5,7 @@ data = {
'fieldname': 'request_for_quotation', 'fieldname': 'request_for_quotation',
'transactions': [ 'transactions': [
{ {
'label': _('Related Documents'), 'label': _('Related'),
'items': ['Supplier Quotation'] 'items': ['Supplier Quotation']
}, },
] ]

View File

@ -4,7 +4,7 @@ data = {
'fieldname': 'prevdoc_docname', 'fieldname': 'prevdoc_docname',
'transactions': [ 'transactions': [
{ {
'label': _('Related Documents'), 'label': _('Related'),
'items': ['Quotation'] 'items': ['Quotation']
}, },
] ]

View File

@ -147,6 +147,7 @@ def setup_item():
for i in items: for i in items:
item = frappe.new_doc('Item') item = frappe.new_doc('Item')
item.update(i) item.update(i)
item.min_order_qty = random.randint(10, 30)
item.default_warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1)[0].name item.default_warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1)[0].name
item.insert() item.insert()

View File

@ -29,11 +29,8 @@ def make_purchase_receipt():
pr.posting_date = frappe.flags.current_date pr.posting_date = frappe.flags.current_date
pr.insert() pr.insert()
try: pr.submit()
pr.submit() frappe.db.commit()
frappe.db.commit()
except (NegativeStockError):
frappe.db.rollback()
def make_delivery_note(): def make_delivery_note():
# make purchase requests # make purchase requests

View File

@ -14,8 +14,8 @@ $.extend(frappe.document_flow, {
"Purchase Invoice", "Payment Entry"] "Purchase Invoice", "Payment Entry"]
}, },
"Buying": { "Buying": {
"Purchase Order": ["Supplier Quotation", "Purchase Order", "Purchase Receipt", // "Purchase Order": ["Supplier Quotation", "Purchase Order", "Purchase Receipt",
"Purchase Invoice", "Payment Entry"], // "Purchase Invoice", "Payment Entry"],
"Supplier Quotation": ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Supplier Quotation": ["Supplier Quotation", "Purchase Order", "Purchase Receipt",
"Purchase Invoice", "Payment Entry"] "Purchase Invoice", "Payment Entry"]
}, },

View File

@ -21,8 +21,8 @@
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 1,
"label": "Warehouse Group", "label": "Check in (group)",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"options": "Warehouse", "options": "Warehouse",
@ -48,7 +48,7 @@
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Warehouse", "label": "Request for",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"options": "Warehouse", "options": "Warehouse",
@ -146,7 +146,7 @@
"issingle": 0, "issingle": 0,
"istable": 1, "istable": 1,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-07-11 03:19:14.851011", "modified": "2016-07-11 03:59:06.870780",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Item Reorder", "name": "Item Reorder",

View File

@ -5,7 +5,7 @@ data = {
'fieldname': 'material_request', 'fieldname': 'material_request',
'transactions': [ 'transactions': [
{ {
'label': _('Related Documents'), 'label': _('Related'),
'items': ['Request for Quotation', 'Supplier Quotation', 'Purchase Order'] 'items': ['Request for Quotation', 'Supplier Quotation', 'Purchase Order']
}, },
] ]