From 5ac22ce6a1b010a4096b4bf794d1f43622fe70f8 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 19 Jan 2016 18:30:02 +0530 Subject: [PATCH] [fix] Close button visible in all sumitted PR and DN --- erpnext/stock/doctype/delivery_note/delivery_note.js | 8 +++----- erpnext/stock/doctype/delivery_note/delivery_note.py | 4 ---- .../stock/doctype/purchase_receipt/purchase_receipt.js | 7 +++---- .../stock/doctype/purchase_receipt/purchase_receipt.py | 10 ---------- 4 files changed, 6 insertions(+), 23 deletions(-) diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js index d4e7932d0c..0b6f47e09f 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note.js @@ -50,14 +50,12 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend( if (cint(frappe.defaults.get_default("auto_accounting_for_stock"))) { this.show_general_ledger(); } - if (this.frm.has_perm("submit") && (doc.status !== "Closed") - && this.frm.doc.__onload && this.frm.doc.__onload.has_return_entry) { - cur_frm.add_custom_button(__("Close"), this.close_delivery_note, __("Status")) + if (this.frm.has_perm("submit") && doc.status !== "Closed") { + cur_frm.add_custom_button(__("Close"), this.close_delivery_note, __("Status")) } } - if(doc.__onload && !doc.__onload.billing_complete && doc.docstatus==1 - && !doc.is_return && doc.status!="Closed") { + if(doc.docstatus==1 && !doc.is_return && doc.status!="Closed" && flt(doc.per_billed) < 100) { // show Make Invoice button only if Delivery Note is not created from Sales Invoice var from_sales_invoice = false; from_sales_invoice = cur_frm.doc.items.some(function(item) { diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index b553054c5a..7cb855fd67 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -61,10 +61,6 @@ class DeliveryNote(SellingController): 'extra_cond': """ and exists (select name from `tabDelivery Note` where name=`tabDelivery Note Item`.parent and is_return=1)""" }] - def onload(self): - self.set_onload("has_return_entry", len(frappe.db.exists({"doctype": "Delivery Note", - "is_return": 1, "return_against": self.name, "docstatus": 1}))) - def before_print(self): def toggle_print_hide(meta, fieldname): df = meta.get_field(fieldname) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js index d66f1a1324..7cf7ae9f88 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js @@ -55,14 +55,13 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend } if(this.frm.doc.docstatus == 1 && this.frm.doc.status!="Closed") { - if (this.frm.has_perm("submit") && - this.frm.doc.__onload && this.frm.doc.__onload.has_return_entry) { - cur_frm.add_custom_button(__("Close"), this.close_purchase_receipt, __("Status")) + if (this.frm.has_perm("submit")) { + cur_frm.add_custom_button(__("Close"), this.close_purchase_receipt, __("Status")) } cur_frm.add_custom_button(__('Return'), this.make_purchase_return, __("Make")); - if(this.frm.doc.__onload && !this.frm.doc.__onload.billing_complete) { + if(flt(this.frm.doc.per_billed) < 100) { cur_frm.add_custom_button(__('Invoice'), this.make_purchase_invoice, __("Make")); } cur_frm.page.set_inner_btn_group_as_primary(__("Make")); diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index df62f7d246..1d872388f3 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -46,16 +46,6 @@ class PurchaseReceipt(BuyingController): 'extra_cond': """ and exists (select name from `tabPurchase Receipt` where name=`tabPurchase Receipt Item`.parent and is_return=1)""" }] - def onload(self): - billed_qty = frappe.db.sql("""select sum(qty) from `tabPurchase Invoice Item` - where purchase_receipt=%s and docstatus=1""", self.name) - if billed_qty: - total_qty = sum((item.qty for item in self.get("items"))) - self.set_onload("billing_complete", (billed_qty[0][0] == total_qty)) - - self.set_onload("has_return_entry", len(frappe.db.exists({"doctype": "Purchase Receipt", - "is_return": 1, "return_against": self.name, "docstatus": 1}))) - def validate(self): super(PurchaseReceipt, self).validate()