[fix] cleanup stop-resume code

This commit is contained in:
Rushabh Mehta 2015-11-03 18:20:39 +05:30
parent 7d23e4286e
commit 5951692db0
10 changed files with 100 additions and 134 deletions

View File

@ -25,11 +25,11 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
cur_frm.add_custom_button(__('Stop'), this.stop_purchase_order);
cur_frm.add_custom_button(__('Close'), this.close_purchase_order);
if(doc.delivered_by_supplier && doc.status!="Delivered"){
cur_frm.add_custom_button(__('Delivered By Supplier'), this.delivered_by_supplier);
}
if(flt(doc.per_billed)==0) {
cur_frm.add_custom_button(__('Payment'), cur_frm.cscript.make_bank_entry);
}
@ -51,8 +51,8 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
cur_frm.cscript.add_from_mappers();
}
if(doc.docstatus == 1 && doc.status == 'Stopped')
cur_frm.add_custom_button(__('Unstop'), this.unstop_purchase_order);
if(doc.docstatus == 1 && (doc.status === 'Stopped' || doc.status === "Closed"))
cur_frm.add_custom_button(__('Re-open'), this.unstop_purchase_order);
},
make_stock_entry: function() {
@ -167,7 +167,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
cur_frm.cscript.update_status('Stop', 'Stopped')
},
unstop_purchase_order: function(){
cur_frm.cscript.update_status('Resume', 'Submitted')
cur_frm.cscript.update_status('Re-open', 'Submitted')
},
close_purchase_order: function(){
cur_frm.cscript.update_status('Close', 'Closed')
@ -193,19 +193,18 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
$.extend(cur_frm.cscript, new erpnext.buying.PurchaseOrderController({frm: cur_frm}));
cur_frm.cscript.update_status= function(label, status){
var doc = cur_frm.doc;
var check = confirm(__("Do you really want to {0} {1}",[label, doc.name]));
if (check) {
frappe.call({
method: "erpnext.buying.doctype.purchase_order.purchase_order.update_status",
args:{status: status, name: doc.name},
callback:function(r){
cur_frm.set_value("status", status);
cur_frm.reload_doc();
}
})
}
frappe.ui.form.is_saving = true;
frappe.call({
method: "erpnext.buying.doctype.purchase_order.purchase_order.update_status",
args: {status: status, name: cur_frm.doc.name},
callback: function(r) {
cur_frm.set_value("status", status);
cur_frm.reload_doc();
},
always: function() {
frappe.ui.form.is_saving = false;
}
})
}
cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) {

View File

@ -164,7 +164,7 @@ class PurchaseOrder(BuyingController):
def on_submit(self):
if self.delivered_by_supplier == 1:
self.update_status_updater()
super(PurchaseOrder, self).on_submit()
purchase_controller = frappe.get_doc("Purchase Common")
@ -181,7 +181,7 @@ class PurchaseOrder(BuyingController):
def on_cancel(self):
if self.delivered_by_supplier == 1:
self.update_status_updater()
pc_obj = frappe.get_doc('Purchase Common')
self.check_for_stopped_or_closed_status(pc_obj)
@ -219,7 +219,7 @@ class PurchaseOrder(BuyingController):
for field in ("received_qty", "billed_amt", "prevdoc_doctype", "prevdoc_docname",
"prevdoc_detail_docname", "supplier_quotation", "supplier_quotation_item"):
d.set(field, None)
def update_status_updater(self):
self.status_updater[0].update({
"target_parent_dt": "Sales Order",
@ -227,7 +227,7 @@ class PurchaseOrder(BuyingController):
'target_field': 'ordered_qty',
"target_parent_field": ''
})
@frappe.whitelist()
def stop_or_unstop_purchase_orders(names, status):
if not frappe.has_permission("Purchase Order", "write"):
@ -241,7 +241,7 @@ def stop_or_unstop_purchase_orders(names, status):
if po.status not in ("Stopped", "Cancelled", "Closed") and (po.per_received < 100 or po.per_billed < 100):
po.update_status(status)
else:
if po.status == "Stopped":
if po.status in ("Stopped", "Closed"):
po.update_status("Draft")
frappe.local.message_log = []
@ -344,22 +344,20 @@ def make_stock_entry(purchase_order, item_code):
def update_status(status, name):
po = frappe.get_doc("Purchase Order", name)
po.update_status(status)
@frappe.whitelist()
def delivered_by_supplier(purchase_order):
po = frappe.get_doc("Purchase Order", purchase_order)
update_delivered_qty(po)
po.update_status("Delivered")
def update_delivered_qty(purchase_order):
sales_order_list = []
so_name = ''
for item in purchase_order.items:
if item.prevdoc_doctype == "Sales Order":
so_name = item.prevdoc_docname
so = frappe.get_doc("Sales Order", so_name)
so.update_delivery_status(purchase_order.name)
so.set_status(update=True)
so.notify_update()

View File

@ -25,16 +25,16 @@ frappe.listview_settings['Purchase Order'] = {
onload: function(listview) {
var method = "erpnext.buying.doctype.purchase_order.purchase_order.stop_or_unstop_purchase_orders";
listview.page.add_menu_item(__("Set as Stopped"), function() {
listview.page.add_menu_item(__("Close"), function() {
listview.call_for_selected_items(method, {"status": "Closed"});
});
listview.page.add_menu_item(__("Stop"), function() {
listview.call_for_selected_items(method, {"status": "Stopped"});
});
listview.page.add_menu_item(__("Set as Unstopped"), function() {
listview.page.add_menu_item(__("Re-open"), function() {
listview.call_for_selected_items(method, {"status": "Submitted"});
});
listview.page.add_menu_item(__("Set as Closed"), function() {
listview.call_for_selected_items(method, {"status": "Closed"});
});
}
};

View File

@ -25,8 +25,8 @@ cur_frm.cscript.create_salary_slip = function(doc, cdt, cdn) {
cur_frm.cscript.submit_salary_slip = function(doc, cdt, cdn) {
cur_frm.cscript.display_activity_log("");
var check = confirm(__("Do you really want to Submit all Salary Slip for month {0} and year {1}", [doc.month, doc.fiscal_year]));
if(check){
frappe.confirm(__("Do you really want to Submit all Salary Slip for month {0} and year {1}", [doc.month, doc.fiscal_year]), function() {
// clear all in locals
if(locals["Salary Slip"]) {
$.each(locals["Salary Slip"], function(name, d) {
@ -40,7 +40,7 @@ cur_frm.cscript.submit_salary_slip = function(doc, cdt, cdn) {
}
return $c('runserverobj', args={'method':'submit_salary_slip','docs':doc},callback);
}
});
}
cur_frm.cscript.make_bank_entry = function(doc,cdt,cdn){

View File

@ -83,7 +83,7 @@ erpnext.production_order = {
frm.add_custom_button(__('Stop'), cur_frm.cscript['Stop Production Order'],
"icon-exclamation", "btn-default");
} else if (doc.status == 'Stopped') {
frm.add_custom_button(__('Unstop'), cur_frm.cscript['Unstop Production Order'],
frm.add_custom_button(__('Re-open'), cur_frm.cscript['Unstop Production Order'],
"icon-check", "btn-default");
}
@ -239,18 +239,11 @@ $.extend(cur_frm.cscript, {
});
cur_frm.cscript['Stop Production Order'] = function() {
var doc = cur_frm.doc;
var check = confirm(__("Do you really want to stop production order: " + doc.name));
if (check) {
return $c_obj(doc, 'stop_unstop', 'Stopped', function(r, rt) {cur_frm.refresh();});
}
$c_obj(cur_frm.doc, 'stop_unstop', 'Stopped', function(r, rt) {cur_frm.refresh();});
}
cur_frm.cscript['Unstop Production Order'] = function() {
var doc = cur_frm.doc;
var check = confirm(__("Do really want to unstop production order: " + doc.name));
if (check)
return $c_obj(doc, 'stop_unstop', 'Unstopped', function(r, rt) {cur_frm.refresh();});
$c_obj(cur_frm.doc, 'stop_unstop', 'Unstopped', function(r, rt) {cur_frm.refresh();});
}
cur_frm.cscript['Transfer Raw Materials'] = function() {

View File

@ -17,10 +17,10 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
this.frm.dashboard.reset();
var is_delivered_by_supplier = false;
var is_delivery_note = false;
if(doc.docstatus==1) {
if(doc.status != 'Stopped' && doc.status != 'Closed') {
$.each(cur_frm.doc.items, function(i, item){
if(item.delivered_by_supplier == 1 || item.supplier){
if(item.qty > item.ordered_qty)
@ -49,8 +49,8 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
if(flt(doc.per_delivered, 2) < 100 || flt(doc.per_billed) < 100) {
cur_frm.add_custom_button(__('Stop'), this.stop_sales_order)
}
cur_frm.add_custom_button(__('Close'), this.close_sales_order)
// maintenance
@ -67,14 +67,13 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
if(flt(doc.per_billed, 2) < 100) {
cur_frm.add_custom_button(__('Invoice'), this.make_sales_invoice).addClass("btn-primary");
}
if(flt(doc.per_delivered, 2) < 100 && is_delivered_by_supplier)
cur_frm.add_custom_button(__('Make Purchase Order'), cur_frm.cscript.make_purchase_order).addClass("btn-primary");
} else {
// un-stop
if( doc.status != 'Closed')
cur_frm.add_custom_button(__('Unstop'), cur_frm.cscript['Unstop Sales Order']);
cur_frm.add_custom_button(__('Re-open'), cur_frm.cscript['Unstop Sales Order']);
}
}
@ -206,10 +205,10 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
dialog.show();
},
stop_sales_order: function(){
cur_frm.cscript.update_status("Stop", "Stopped")
cur_frm.cscript.update_status("Stop", "Stopped")
},
close_sales_order: function(){
cur_frm.cscript.update_status("Close", "Closed")
cur_frm.cscript.update_status("Close", "Closed")
}
});
@ -235,32 +234,27 @@ cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) {
cur_frm.cscript.update_status = function(label, status){
var doc = cur_frm.doc;
var check = confirm(__("Do you really want to {0} {1}",[label, doc.name]));
if (check) {
frappe.call({
method: "erpnext.selling.doctype.sales_order.sales_order.update_status",
args:{status: status, name: doc.name},
callback:function(r){
cur_frm.reload_doc();
}
})
}
frappe.ui.form.is_saving = true;
frappe.call({
method: "erpnext.selling.doctype.sales_order.sales_order.update_status",
args: {status: status, name: doc.name},
callback: function(r){
cur_frm.reload_doc();
},
always: function() {
frappe.ui.form.is_saving = false;
}
});
}
cur_frm.cscript['Unstop Sales Order'] = function() {
var doc = cur_frm.doc;
var check = confirm(__("Are you sure you want to UNSTOP ") + doc.name);
if (check) {
return $c('runserverobj', {
'method':'unstop_sales_order',
'docs': doc
}, function(r,rt) {
cur_frm.refresh();
});
}
return $c('runserverobj', {
'method':'unstop_sales_order',
'docs': doc
}, function(r,rt) {
cur_frm.refresh();
});
}
cur_frm.cscript.on_submit = function(doc, cdt, cdn) {

View File

@ -258,23 +258,23 @@ class SalesOrder(SellingController):
def on_update(self):
pass
def before_update_after_submit(self):
self.validate_drop_ship()
self.validate_drop_ship()
self.validate_po()
def validate_po(self):
exc_list = []
for item in self.items:
supplier = frappe.db.get_value("Sales Order Item", {"parent": self.name, "item_code": item.item_code},
supplier = frappe.db.get_value("Sales Order Item", {"parent": self.name, "item_code": item.item_code},
"supplier")
if item.ordered_qty > 0.0 and item.supplier != supplier:
exc_list.append("Row #{0}: Not allowed to change supplier as Purchase Order already exists".format(item.idx))
if exc_list:
if exc_list:
frappe.throw('\n'.join(exc_list))
def update_delivery_status(self, po_name):
tot_qty, delivered_qty = 0.0, 0.0
@ -282,12 +282,12 @@ class SalesOrder(SellingController):
if item.delivered_by_supplier:
delivered_qty = frappe.db.get_value("Purchase Order Item", {"parent": po_name, "item_code": item.item_code}, "qty")
frappe.db.set_value("Sales Order Item", item.name, "delivered_qty", delivered_qty)
delivered_qty += item.delivered_qty
tot_qty += item.qty
frappe.db.set_value("Sales Order", self.name, "per_delivered", flt(delivered_qty/tot_qty) * 100)
def get_list_context(context=None):
from erpnext.controllers.website_list_for_contact import get_list_context
list_context = get_list_context(context)
@ -307,7 +307,7 @@ def stop_or_unstop_sales_orders(names, status):
if so.status not in ("Stopped", "Cancelled", "Closed") and (so.per_delivered < 100 or so.per_billed < 100):
so.stop_sales_order(status)
else:
if so.status == "Stopped":
if so.status in ("Stopped", "Closed"):
so.unstop_sales_order()
frappe.local.message_log = []
@ -525,14 +525,14 @@ def get_events(start, end, filters=None):
return data
@frappe.whitelist()
def make_purchase_order_for_drop_shipment(source_name, for_supplier, target_doc=None):
def make_purchase_order_for_drop_shipment(source_name, for_supplier, target_doc=None):
def set_missing_values(source, target):
target.supplier = for_supplier
default_price_list = frappe.get_value("Supplier", for_supplier, "default_price_list")
if default_price_list:
target.buying_price_list = default_price_list
target.delivered_by_supplier = 1
target.run_method("set_missing_values")
target.run_method("calculate_taxes_and_totals")
@ -552,10 +552,10 @@ def make_purchase_order_for_drop_shipment(source_name, for_supplier, target_doc=
"contact_person": "customer_contact_person"
},
"field_no_map": [
"address_display",
"contact_display",
"contact_mobile",
"contact_email",
"address_display",
"contact_display",
"contact_mobile",
"contact_email",
"contact_person"
],
"validation": {
@ -579,7 +579,7 @@ def make_purchase_order_for_drop_shipment(source_name, for_supplier, target_doc=
"condition": lambda doc: doc.ordered_qty < doc.qty and doc.supplier == for_supplier
}
}, target_doc, set_missing_values)
return doclist
@frappe.whitelist()
@ -615,4 +615,3 @@ def get_supplier(doctype, txt, searchfield, start, page_len, filters):
def update_status(status, name):
so = frappe.get_doc("Sales Order", name)
so.stop_sales_order(status)

View File

@ -7,7 +7,7 @@ frappe.listview_settings['Sales Order'] = {
} else if(doc.status==="Closed"){
return [__("Closed"), "green", "status,=,Closed"];
} else if (doc.order_type !== "Maintenance"
&& flt(doc.per_delivered, 2) < 100 && frappe.datetime.get_diff(doc.delivery_date) < 0) {
// to bill & overdue
@ -44,17 +44,17 @@ frappe.listview_settings['Sales Order'] = {
onload: function(listview) {
var method = "erpnext.selling.doctype.sales_order.sales_order.stop_or_unstop_sales_orders";
listview.page.add_menu_item(__("Set as Stopped"), function() {
listview.call_for_selected_items(method, {"status": "Stoped"});
});
listview.page.add_menu_item(__("Set as Unstopped"), function() {
listview.call_for_selected_items(method, {"status": "Unstop"});
});
listview.page.add_menu_item(__("Set as Closed"), function() {
listview.page.add_menu_item(__("Close"), function() {
listview.call_for_selected_items(method, {"status": "Closed"});
});
listview.page.add_menu_item(__("Stop"), function() {
listview.call_for_selected_items(method, {"status": "Stoped"});
});
listview.page.add_menu_item(__("Re-open"), function() {
listview.call_for_selected_items(method, {"status": "Unstop"});
});
}
};
};

View File

@ -28,14 +28,6 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
refresh: function(doc) {
this._super();
// dashboard
cur_frm.dashboard.reset();
if(doc.docstatus===1) {
if(doc.status==="Stopped") {
cur_frm.dashboard.set_headline_alert(__("Stopped"), "alert-danger", "octicon octicon-circle-slash")
}
}
if(doc.docstatus==0) {
cur_frm.add_custom_button(__("Get Items from BOM"),
cur_frm.cscript.get_items_from_bom, "icon-sitemap", "btn-default");
@ -84,7 +76,7 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
}
if(doc.docstatus == 1 && doc.status == 'Stopped')
cur_frm.add_custom_button(__('Unstop Material Request'),
cur_frm.add_custom_button(__('Re-open'),
cur_frm.cscript['Unstop Material Request'], "icon-check");
},
@ -175,24 +167,16 @@ $.extend(cur_frm.cscript, new erpnext.buying.MaterialRequestController({frm: cur
cur_frm.cscript['Stop Material Request'] = function() {
var doc = cur_frm.doc;
var check = confirm(__("Do you really want to STOP this Material Request?"));
if (check) {
return $c('runserverobj', args={'method':'update_status', 'arg': 'Stopped', 'docs': doc}, function(r,rt) {
cur_frm.refresh();
});
}
$c('runserverobj', args={'method':'update_status', 'arg': 'Stopped', 'docs': doc}, function(r,rt) {
cur_frm.refresh();
});
};
cur_frm.cscript['Unstop Material Request'] = function(){
var doc = cur_frm.doc;
var check = confirm(__("Do you really want to UNSTOP this Material Request?"));
if (check) {
return $c('runserverobj', args={'method':'update_status', 'arg': 'Submitted','docs': doc}, function(r,rt) {
cur_frm.refresh();
});
}
$c('runserverobj', args={'method':'update_status', 'arg': 'Submitted','docs': doc}, function(r,rt) {
cur_frm.refresh();
});
};

View File

@ -98,7 +98,6 @@ class MaterialRequest(BuyingController):
self.check_modified_date()
frappe.db.set(self, 'status', cstr(status))
self.update_requested_qty()
frappe.msgprint(_("Status updated to {0}").format(_(status)))
def on_cancel(self):
pc_obj = frappe.get_doc('Purchase Common')