diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js index c5ae4315eb8..0c47148bf66 100644 --- a/stock/doctype/delivery_note/delivery_note.js +++ b/stock/doctype/delivery_note/delivery_note.js @@ -29,7 +29,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend( refresh: function(doc, dt, dn) { this._super(); - if(flt(doc.per_billed, 2) < 100 && doc.docstatus==1) cur_frm.add_custom_button('Make Invoice', this.make_sales_invoice); + if(!doc.__billing_complete && doc.docstatus==1) cur_frm.add_custom_button('Make Invoice', this.make_sales_invoice); if(flt(doc.per_installed, 2) < 100 && doc.docstatus==1) cur_frm.add_custom_button('Make Installation Note', this.make_installation_note); diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py index 7ea512daad5..81c4b6cedbf 100644 --- a/stock/doctype/delivery_note/delivery_note.py +++ b/stock/doctype/delivery_note/delivery_note.py @@ -50,6 +50,13 @@ class DocType(SellingController): 'keyword': 'Delivered' }] + def onload(self): + billed_qty = webnotes.conn.sql("""select sum(ifnull(qty, 0)) from `tabSales Invoice Item` + where delivery_note=%s""", self.doc.name) + if billed_qty: + total_qty = sum((item.qty for item in self.doclist.get({"parentfield": "delivery_note_details"}))) + self.doc.fields["__billing_complete"] = billed_qty[0][0] == total_qty + def get_contact_details(self): return get_obj('Sales Common').get_contact_details(self,0) diff --git a/stock/doctype/purchase_receipt/purchase_receipt.js b/stock/doctype/purchase_receipt/purchase_receipt.js index 8705143cf2c..b393907bee2 100644 --- a/stock/doctype/purchase_receipt/purchase_receipt.js +++ b/stock/doctype/purchase_receipt/purchase_receipt.js @@ -28,7 +28,7 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend this._super(); if(this.frm.doc.docstatus == 1) { - if(flt(this.frm.doc.per_billed, 2) < 100) { + if(!this.frm.doc.__billing_complete) { cur_frm.add_custom_button('Make Purchase Invoice', this.make_purchase_invoice); } diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py index 62b7a4f352a..703929ce81a 100644 --- a/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/stock/doctype/purchase_receipt/purchase_receipt.py @@ -44,6 +44,13 @@ class DocType(BuyingController): 'source_field': 'qty', 'percent_join_field': 'prevdoc_docname', }] + + def onload(self): + billed_qty = webnotes.conn.sql("""select sum(ifnull(qty, 0)) from `tabPurchase Invoice Item` + where purchase_receipt=%s""", self.doc.name) + if billed_qty: + total_qty = sum((item.qty for item in self.doclist.get({"parentfield": "purchase_receipt_details"}))) + self.doc.fields["__billing_complete"] = billed_qty[0][0] == total_qty # get available qty at warehouse def get_bin_details(self, arg = ''):