From 1b8c444a20ae8f12482ddc8c121b9aeff2fbe75f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 21 Nov 2013 23:18:29 +0530 Subject: [PATCH 1/4] [cleanup] [minor] update serial no status, sales and purchase info --- stock/doctype/serial_no/serial_no.py | 104 ++++++++++++++------------- 1 file changed, 56 insertions(+), 48 deletions(-) diff --git a/stock/doctype/serial_no/serial_no.py b/stock/doctype/serial_no/serial_no.py index db32ca06081..8dfed0116cf 100644 --- a/stock/doctype/serial_no/serial_no.py +++ b/stock/doctype/serial_no/serial_no.py @@ -74,23 +74,16 @@ class DocType(StockController): self.doc.item_name = item.item_name self.doc.brand = item.brand self.doc.warranty_period = item.warranty_period - - def set_status(self): - last_sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry` - where (serial_no like %s or serial_no like %s or serial_no=%s) - and item_code=%s and ifnull(is_cancelled, 'No')='No' - order by name desc limit 1""", - ("%%%s%%" % (self.doc.name+"\n"), "%%%s%%" % ("\n"+self.doc.name), self.doc.name, - self.doc.item_code), as_dict=1) + def set_status(self, last_sle): if last_sle: - if last_sle[0].voucher_type == "Stock Entry": - document_type = webnotes.conn.get_value("Stock Entry", last_sle[0].voucher_no, + if last_sle.voucher_type == "Stock Entry": + document_type = webnotes.conn.get_value("Stock Entry", last_sle.voucher_no, "purpose") else: - document_type = last_sle[0].voucher_type + document_type = last_sle.voucher_type - if last_sle[0].actual_qty > 0: + if last_sle.actual_qty > 0: if document_type == "Sales Return": self.doc.status = "Sales Returned" else: @@ -98,59 +91,73 @@ class DocType(StockController): else: if document_type == "Purchase Return": self.doc.status = "Purchase Returned" - elif last_sle[0].voucher_type in ("Delivery Note", "Sales Invoice"): + elif last_sle.voucher_type in ("Delivery Note", "Sales Invoice"): self.doc.status = "Delivered" else: self.doc.status = "Not Available" - def set_purchase_details(self): - purchase_sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry` - where (serial_no like %s or serial_no like %s or serial_no=%s) - and item_code=%s and actual_qty > 0 - and ifnull(is_cancelled, 'No')='No' order by name asc limit 1""", - ("%%%s%%" % (self.doc.name+"\n"), "%%%s%%" % ("\n"+self.doc.name), self.doc.name, - self.doc.item_code), as_dict=1) - + def set_purchase_details(self, purchase_sle): if purchase_sle: - self.doc.purchase_document_type = purchase_sle[0].voucher_type - self.doc.purchase_document_no = purchase_sle[0].voucher_no - self.doc.purchase_date = purchase_sle[0].posting_date - self.doc.purchase_time = purchase_sle[0].posting_time - self.doc.purchase_rate = purchase_sle[0].incoming_rate - if purchase_sle[0].voucher_type == "Purchase Receipt": + self.doc.purchase_document_type = purchase_sle.voucher_type + self.doc.purchase_document_no = purchase_sle.voucher_no + self.doc.purchase_date = purchase_sle.posting_date + self.doc.purchase_time = purchase_sle.posting_time + self.doc.purchase_rate = purchase_sle.incoming_rate + if purchase_sle.voucher_type == "Purchase Receipt": self.doc.supplier, self.doc.supplier_name = \ - webnotes.conn.get_value("Purchase Receipt", purchase_sle[0].voucher_no, + webnotes.conn.get_value("Purchase Receipt", purchase_sle.voucher_no, ["supplier", "supplier_name"]) else: for fieldname in ("purchase_document_type", "purchase_document_no", "purchase_date", "purchase_time", "purchase_rate", "supplier", "supplier_name"): self.doc.fields[fieldname] = None - def set_sales_details(self): - delivery_sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry` - where (serial_no like %s or serial_no like %s or serial_no=%s) - and item_code=%s and actual_qty<0 - and voucher_type in ('Delivery Note', 'Sales Invoice') - and ifnull(is_cancelled, 'No')='No' order by name desc limit 1""", - ("%%%s%%" % (self.doc.name+"\n"), "%%%s%%" % ("\n"+self.doc.name), self.doc.name, - self.doc.item_code), as_dict=1) + def set_sales_details(self, delivery_sle): if delivery_sle: - self.doc.delivery_document_type = delivery_sle[0].voucher_type - self.doc.delivery_document_no = delivery_sle[0].voucher_no - self.doc.delivery_date = delivery_sle[0].posting_date - self.doc.delivery_time = delivery_sle[0].posting_time + self.doc.delivery_document_type = delivery_sle.voucher_type + self.doc.delivery_document_no = delivery_sle.voucher_no + self.doc.delivery_date = delivery_sle.posting_date + self.doc.delivery_time = delivery_sle.posting_time self.doc.customer, self.doc.customer_name = \ - webnotes.conn.get_value(delivery_sle[0].voucher_type, delivery_sle[0].voucher_no, + webnotes.conn.get_value(delivery_sle.voucher_type, delivery_sle.voucher_no, ["customer", "customer_name"]) if self.doc.warranty_period: - self.doc.warranty_expiry_date = add_days(cstr(delivery_sle[0].posting_date), + self.doc.warranty_expiry_date = add_days(cstr(delivery_sle.posting_date), cint(self.doc.warranty_period)) else: for fieldname in ("delivery_document_type", "delivery_document_no", "delivery_date", "delivery_time", "customer", "customer_name", "warranty_expiry_date"): - self.doc.fields[fieldname] = None + self.doc.fields[fieldname] = None + + def get_last_sle(self): + entries = {} + for sle in self.get_stock_ledger_entries(): + if self.doc.name in sle.serial_no.split("\n"): + if not entries.get("last_sle"): + entries["last_sle"] = sle + + if not entries.get("purchase_sle") and sle.actual_qty > 0: + entries["purchase_sle"] = sle + elif not entries.get("delivery_sle") and sle.actual_qty < 0 \ + and sle.voucher_type in ('Delivery Note', 'Sales Invoice'): + entries["delivery_sle"] = sle + + if entries.get("last_sle") and entries.get("purchase_sle") \ + and entries.get("delivery_sle"): + break + + return entries + + def get_stock_ledger_entries(self): + return webnotes.conn.sql("""select * from `tabStock Ledger Entry` + where (serial_no like %s or serial_no like %s or serial_no like %s or serial_no=%s) + and item_code=%s and ifnull(is_cancelled, 'No')='No' + order by name desc""", + ("%s%%" % (self.doc.name+"\n"), "%%%s%%" % ("\n"+self.doc.name+"\n"), + "%%%s" % ("\n"+self.doc.name), self.doc.name, self.doc.item_code), as_dict=1) + def on_trash(self): if self.doc.status == 'Delivered': webnotes.throw(_("Delivered Serial No ") + self.doc.name + _(" can not be deleted")) @@ -177,9 +184,10 @@ class DocType(StockController): def on_stock_ledger_entry(self): if self.via_stock_ledger and not self.doc.fields.get("__islocal"): - self.set_status() - self.set_purchase_details() - self.set_sales_details() + last_sle = self.get_last_sle() + self.set_status(last_sle.get("last_sle")) + self.set_purchase_details(last_sle.get("purchase_sle")) + self.set_sales_details(last_sle.get("delivery_sle")) def process_serial_no(sle): item_det = get_item_details(sle.item_code) @@ -227,12 +235,12 @@ def validate_serial_no(sle, item_det): # transfer out webnotes.throw(_("Serial No must exist to transfer out.") + \ ": " + serial_no, SerialNoNotExistsError) - elif not item_det.serial_no_series: + elif sle.actual_qty < 0 or not item_det.serial_no_series: webnotes.throw(_("Serial Number Required for Serialized Item" + ": " + sle.item_code), SerialNoRequiredError) def update_serial_nos(sle, item_det): - if not sle.serial_no and sle.actual_qty > 0 and item_det.serial_no_series: + if sle.is_cancelled == "No" and not sle.serial_no and sle.actual_qty > 0 and item_det.serial_no_series: from webnotes.model.doc import make_autoname serial_nos = [] for i in xrange(cint(sle.actual_qty)): From f1faf2d285b234c67fcdbcd7878b7d4a0bb45c7c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 22 Nov 2013 16:59:28 +0530 Subject: [PATCH 2/4] [fix] [minor] print hide for purchase net and grand total --- .../purchase_taxes_and_charges_master.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js index b70e669d55d..ce772cdf913 100644 --- a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js +++ b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js @@ -12,6 +12,19 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { cur_frm.set_footnote(wn.markdown(cur_frm.meta.description)); } +// For customizing print +cur_frm.pformat.net_total_import = function(doc) { + return ''; +} + +cur_frm.pformat.grand_total_import = function(doc) { + return ''; +} + +cur_frm.pformat.in_words_import = function(doc) { + return ''; +} + cur_frm.pformat.purchase_tax_details= function(doc){ //function to make row of table @@ -40,9 +53,9 @@ cur_frm.pformat.purchase_tax_details= function(doc){ '; // main table - out +='' - if(!print_hide('net_total')) { - out += make_row('Net Total', convert_rate(doc.net_total), 1); + out +='
'; + if(!print_hide('net_total_import')) { + out += make_row('Net Total', doc.net_total_import, 1); } // add rows From 451b01cfe406861247e6a42519044d58400a59b2 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 22 Nov 2013 17:17:35 +0530 Subject: [PATCH 3/4] [fix] [minor] print hide for purchase net and grand total --- accounts/doctype/purchase_invoice/purchase_invoice.txt | 8 ++++---- buying/doctype/purchase_order/purchase_order.txt | 8 ++++---- buying/doctype/supplier_quotation/supplier_quotation.txt | 8 ++++---- stock/doctype/purchase_receipt/purchase_receipt.txt | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.txt b/accounts/doctype/purchase_invoice/purchase_invoice.txt index f5bdd939a88..089ba9f2e46 100755 --- a/accounts/doctype/purchase_invoice/purchase_invoice.txt +++ b/accounts/doctype/purchase_invoice/purchase_invoice.txt @@ -2,7 +2,7 @@ { "creation": "2013-05-21 16:16:39", "docstatus": 0, - "modified": "2013-08-09 14:45:35", + "modified": "2013-11-22 17:15:27", "modified_by": "Administrator", "owner": "Administrator" }, @@ -301,7 +301,7 @@ "oldfieldname": "net_total_import", "oldfieldtype": "Currency", "options": "currency", - "print_hide": 1, + "print_hide": 0, "read_only": 1 }, { @@ -401,7 +401,7 @@ "oldfieldname": "grand_total_import", "oldfieldtype": "Currency", "options": "currency", - "print_hide": 1, + "print_hide": 0, "read_only": 1 }, { @@ -411,7 +411,7 @@ "label": "In Words", "oldfieldname": "in_words_import", "oldfieldtype": "Data", - "print_hide": 1, + "print_hide": 0, "read_only": 1 }, { diff --git a/buying/doctype/purchase_order/purchase_order.txt b/buying/doctype/purchase_order/purchase_order.txt index d3c1620b51d..0289dd14497 100644 --- a/buying/doctype/purchase_order/purchase_order.txt +++ b/buying/doctype/purchase_order/purchase_order.txt @@ -2,7 +2,7 @@ { "creation": "2013-05-21 16:16:39", "docstatus": 0, - "modified": "2013-09-12 18:34:54", + "modified": "2013-11-22 17:15:58", "modified_by": "Administrator", "owner": "Administrator" }, @@ -269,7 +269,7 @@ "oldfieldname": "net_total_import", "oldfieldtype": "Currency", "options": "currency", - "print_hide": 1, + "print_hide": 0, "read_only": 1 }, { @@ -382,7 +382,7 @@ "oldfieldname": "grand_total_import", "oldfieldtype": "Currency", "options": "currency", - "print_hide": 1, + "print_hide": 0, "read_only": 1, "report_hide": 0 }, @@ -393,7 +393,7 @@ "label": "In Words", "oldfieldname": "in_words_import", "oldfieldtype": "Data", - "print_hide": 1, + "print_hide": 0, "read_only": 1 }, { diff --git a/buying/doctype/supplier_quotation/supplier_quotation.txt b/buying/doctype/supplier_quotation/supplier_quotation.txt index 36747d345a8..b2ae6e65ce7 100644 --- a/buying/doctype/supplier_quotation/supplier_quotation.txt +++ b/buying/doctype/supplier_quotation/supplier_quotation.txt @@ -2,7 +2,7 @@ { "creation": "2013-05-21 16:16:45", "docstatus": 0, - "modified": "2013-08-09 14:45:58", + "modified": "2013-11-22 17:16:16", "modified_by": "Administrator", "owner": "Administrator" }, @@ -265,7 +265,7 @@ "oldfieldname": "net_total_import", "oldfieldtype": "Currency", "options": "currency", - "print_hide": 1, + "print_hide": 0, "read_only": 1 }, { @@ -369,7 +369,7 @@ "oldfieldname": "grand_total_import", "oldfieldtype": "Currency", "options": "currency", - "print_hide": 1, + "print_hide": 0, "read_only": 1, "report_hide": 0 }, @@ -380,7 +380,7 @@ "label": "In Words", "oldfieldname": "in_words_import", "oldfieldtype": "Data", - "print_hide": 1, + "print_hide": 0, "read_only": 1 }, { diff --git a/stock/doctype/purchase_receipt/purchase_receipt.txt b/stock/doctype/purchase_receipt/purchase_receipt.txt index f228a147c3b..16e570cd2df 100755 --- a/stock/doctype/purchase_receipt/purchase_receipt.txt +++ b/stock/doctype/purchase_receipt/purchase_receipt.txt @@ -2,7 +2,7 @@ { "creation": "2013-05-21 16:16:39", "docstatus": 0, - "modified": "2013-10-11 13:20:13", + "modified": "2013-11-22 17:15:47", "modified_by": "Administrator", "owner": "Administrator" }, @@ -295,7 +295,7 @@ "oldfieldname": "net_total_import", "oldfieldtype": "Currency", "options": "currency", - "print_hide": 1, + "print_hide": 0, "read_only": 1 }, { @@ -402,7 +402,7 @@ "oldfieldname": "grand_total_import", "oldfieldtype": "Currency", "options": "currency", - "print_hide": 1, + "print_hide": 0, "read_only": 1 }, { @@ -412,7 +412,7 @@ "label": "In Words", "oldfieldname": "in_words_import", "oldfieldtype": "Data", - "print_hide": 1, + "print_hide": 0, "read_only": 1 }, { From 9f51ee4a84b1d812a5dac2503608c5a5483fd21e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Sun, 24 Nov 2013 16:03:40 +0530 Subject: [PATCH 4/4] [fix] [minor] serial no status update fix --- stock/doctype/serial_no/serial_no.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/stock/doctype/serial_no/serial_no.py b/stock/doctype/serial_no/serial_no.py index 8dfed0116cf..e196f6c7ee6 100644 --- a/stock/doctype/serial_no/serial_no.py +++ b/stock/doctype/serial_no/serial_no.py @@ -134,7 +134,7 @@ class DocType(StockController): entries = {} for sle in self.get_stock_ledger_entries(): - if self.doc.name in sle.serial_no.split("\n"): + if self.doc.name in get_serial_nos(sle.serial_no): if not entries.get("last_sle"): entries["last_sle"] = sle @@ -152,11 +152,8 @@ class DocType(StockController): def get_stock_ledger_entries(self): return webnotes.conn.sql("""select * from `tabStock Ledger Entry` - where (serial_no like %s or serial_no like %s or serial_no like %s or serial_no=%s) - and item_code=%s and ifnull(is_cancelled, 'No')='No' - order by name desc""", - ("%s%%" % (self.doc.name+"\n"), "%%%s%%" % ("\n"+self.doc.name+"\n"), - "%%%s" % ("\n"+self.doc.name), self.doc.name, self.doc.item_code), as_dict=1) + where serial_no like %s and item_code=%s and ifnull(is_cancelled, 'No')='No' + order by name desc""", ("%%%s%%" % self.doc.name, self.doc.item_code), as_dict=1) def on_trash(self): if self.doc.status == 'Delivered':