[cleanup] a better message for insufficient stock
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index d90c0da..9c45770 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -3,7 +3,7 @@
frappe.provide("erpnext.buying");
-{% include 'erpnext/buying/doctype/purchase_common/purchase_common.js' %};
+{% include 'buying/doctype/purchase_common/purchase_common.js' %};
frappe.ui.form.on("Purchase Order", {
onload: function(frm) {
@@ -20,6 +20,7 @@
// this.frm.dashboard.reset();
var allow_receipt = false;
var is_drop_ship = false;
+
for (var i in cur_frm.doc.items) {
var item = cur_frm.doc.items[i];
if(item.delivered_by_supplier !== 1) {
@@ -46,7 +47,7 @@
if(is_drop_ship && doc.status!="Delivered"){
cur_frm.add_custom_button(__('Delivered'),
- this.delivered_by_supplier, __("Status"));
+ this.delivered_by_supplier, __("Status"));
cur_frm.page.set_inner_btn_group_as_primary(__("Status"));
}
@@ -60,7 +61,7 @@
}
}
- if(doc.docstatus == 1 && !in_list(["Closed", "Completed"], doc.status)) {
+ if(doc.docstatus == 1 && doc.status != "Closed") {
if(flt(doc.per_received, 2) < 100 && allow_receipt) {
cur_frm.add_custom_button(__('Receive'), this.make_purchase_receipt, __("Make"));
@@ -92,6 +93,15 @@
});
},
+ validate: function() {
+ // set default schedule date as today if missing.
+ (this.frm.doc.items || []).forEach(function(d) {
+ if(!d.schedule_date) {
+ d.schedule_date = frappe.datetime.nowdate();
+ }
+ })
+ },
+
make_stock_entry: function() {
var items = $.map(cur_frm.doc.items, function(d) { return d.bom ? d.item_code : false; });
var me = this;
diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py
index d3fa482..292bd61 100644
--- a/erpnext/stock/stock_ledger.py
+++ b/erpnext/stock/stock_ledger.py
@@ -141,7 +141,7 @@
"stock_value": self.stock_value
})
bin_doc.flags.via_stock_ledger_entry = True
-
+
bin_doc.save(ignore_permissions=True)
def process_sle(self, sle):
@@ -211,7 +211,7 @@
if incoming_rate < 0:
# wrong incoming rate
incoming_rate = self.valuation_rate
-
+
stock_value_change = 0
if incoming_rate:
stock_value_change = actual_qty * incoming_rate
@@ -334,11 +334,23 @@
def raise_exceptions(self):
deficiency = min(e["diff"] for e in self.exceptions)
- msg = _("Negative Stock Error ({6}) for Item {0} in Warehouse {1} on {2} {3} in {4} {5}").format(self.item_code,
- self.warehouse, self.exceptions[0]["posting_date"], self.exceptions[0]["posting_time"],
- _(self.exceptions[0]["voucher_type"]), self.exceptions[0]["voucher_no"], deficiency)
+
+
+
+ if frappe.local.flags.currently_saving.doctype==self.exceptions[0]["voucher_type"] \
+ and frappe.local.flags.currently_saving.name==self.exceptions[0]["voucher_no"]:
+ msg = _("{0} units of {1} needed in {2} to complete this transaction.").format(
+ abs(deficiency), frappe.get_desk_link('Item', self.item_code),
+ frappe.get_desk_link('Warehouse', self.warehouse))
+ else:
+ msg = _("{0} units of {1} needed in {2} on {3} {4} for {5} to complete this transaction.").format(
+ abs(deficiency), frappe.get_desk_link('Item', self.item_code),
+ frappe.get_desk_link('Warehouse', self.warehouse),
+ self.exceptions[0]["posting_date"], self.exceptions[0]["posting_time"],
+ frappe.get_desk_link(self.exceptions[0]["voucher_type"], self.exceptions[0]["voucher_no"]))
+
if self.verbose:
- frappe.throw(msg, NegativeStockError)
+ frappe.throw(msg, NegativeStockError, title='Insufficent Stock')
else:
raise NegativeStockError, msg