[minor] save last company in multi-company scenario
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index 91c50b1..96a3d97 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -68,7 +68,10 @@
})
def validate_minimum_order_qty(self):
- itemwise_min_order_qty = frappe._dict(frappe.db.sql("select name, min_order_qty from tabItem"))
+ items = list(set([d.item_code for d in self.get("items")]))
+
+ itemwise_min_order_qty = frappe._dict(frappe.db.sql("""select name, min_order_qty
+ from tabItem where name in ({0})""".format(", ".join(["%s"] * len(items))), items))
itemwise_qty = frappe._dict()
for d in self.get("items"):
@@ -77,7 +80,8 @@
for item_code, qty in itemwise_qty.items():
if flt(qty) < flt(itemwise_min_order_qty.get(item_code)):
- frappe.throw(_("Item #{0}: Ordered qty can not less than item's minimum order qty (defined in item master).").format(item_code))
+ frappe.throw(_("Item {0}: Ordered qty {1} cannot be less than minimum order qty {2} (defined in Item).").format(item_code,
+ qty, itemwise_min_order_qty.get(item_code)))
def get_schedule_dates(self):
for d in self.get('items'):
@@ -217,15 +221,15 @@
def on_update(self):
pass
-
+
def before_recurring(self):
super(PurchaseOrder, self).before_recurring()
-
+
for field in ("per_received", "per_billed"):
self.set(field, None)
for d in self.get("items"):
- for field in ("received_qty", "billed_amt", "prevdoc_doctype", "prevdoc_docname",
+ for field in ("received_qty", "billed_amt", "prevdoc_doctype", "prevdoc_docname",
"prevdoc_detail_docname", "supplier_quotation", "supplier_quotation_item"):
d.set(field, None)
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index 968c115..4a4724b 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -320,8 +320,9 @@
# shortage
requested_qty = total_qty - flt(item_projected_qty.get(item))
# consider minimum order qty
- requested_qty = requested_qty > flt(so_item_qty[0][3]) and \
- requested_qty or flt(so_item_qty[0][3])
+
+ if requested_qty < flt(so_item_qty[0][3]):
+ requested_qty = flt(so_item_qty[0][3])
# distribute requested qty SO wise
for item_details in so_item_qty:
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 7ee342f..f62eed2 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -190,8 +190,11 @@
if (this.frm.doc.posting_date) var date = this.frm.doc.posting_date;
else var date = this.frm.doc.transaction_date;
erpnext.get_fiscal_year(this.frm.doc.company, date, fn);
-
erpnext.get_letter_head(this.frm.doc.company);
+
+ if(this.frm.doc.company) {
+ erpnext.last_selected_company = this.frm.doc.company;
+ }
},
transaction_date: function() {
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index 111ad6d..355fe7d 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -41,6 +41,8 @@
if(companies.length === 1) {
if(!cur_frm.doc.company) cur_frm.set_value("company", companies[0]);
cur_frm.toggle_display("company", false);
+ } else if(erpnext.last_selected_company) {
+ if(!cur_frm.doc.company) cur_frm.set_value("company", erpnext.last_selected_company);
}
}
},
@@ -76,8 +78,8 @@
"options": "Serial No",
"label": __("Serial No"),
"get_query": function () {
- return {
- filters: {
+ return {
+ filters: {
item_code:grid_row.doc.item_code ,
warehouse:grid_row.doc.warehouse
}