From 3e34a6d0e1329ead54c0ef65d2405b9e495daa26 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 4 Sep 2013 12:54:33 +0530 Subject: [PATCH 1/3] [fix] [minor] serial no status update for material transfer --- patches/patch_list.py | 1 + .../p02_fix_serial_no_status.py | 28 +++++++++++++++++++ stock/doctype/stock_entry/stock_entry.py | 6 +++- .../stock_ledger_entry/stock_ledger_entry.py | 9 +++--- 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 patches/september_2013/p02_fix_serial_no_status.py diff --git a/patches/patch_list.py b/patches/patch_list.py index 320614a23d..ff28031a8f 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -259,4 +259,5 @@ patch_list = [ "execute:webnotes.bean('Style Settings').save() #2013-08-20", "patches.september_2013.p01_fix_buying_amount_gl_entries", "patches.september_2013.p01_update_communication", + "patches.september_2013.p02_fix_serial_no_status", ] \ No newline at end of file diff --git a/patches/september_2013/p02_fix_serial_no_status.py b/patches/september_2013/p02_fix_serial_no_status.py new file mode 100644 index 0000000000..8c91d72fb9 --- /dev/null +++ b/patches/september_2013/p02_fix_serial_no_status.py @@ -0,0 +1,28 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import webnotes + +def execute(): + stock_entries = webnotes.conn.sql("""select ste_item.serial_no, ste.name + from `tabStock Entry Detail` ste_item, `tabStock Entry` ste + where ste.name = ste_item.parent + and ifnull(ste_item.serial_no, '') != '' + and ste.purpose='Material Transfer' + and ste.modified>='2013-08-14' + order by ste.posting_date desc, ste.posting_time desc, ste.name desc""", as_dict=1) + + for d in stock_entries: + serial_nos = d.serial_no.split("\n") + for serial_no in serial_nos: + serial_bean = webnotes.bean("Serial No", serial_no) + if serial_bean.doc.status == "Not Available": + latest_sle = webnotes.conn.sql("""select voucher_no from `tabStock Ledger Entry` + where item_code=%s and warehouse=%s and serial_no like %s + order by name desc limit 1""", + (serial_bean.doc.item_code, serial_bean.doc.warehouse, "%%%s%%" % serial_no)) + + if latest_sle and latest_sle[0][0] == d.name: + serial_bean.doc.status = "Available" + serial_bean.save() \ No newline at end of file diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py index e3fc67e0fc..6a61461ac5 100644 --- a/stock/doctype/stock_entry/stock_entry.py +++ b/stock/doctype/stock_entry/stock_entry.py @@ -343,10 +343,14 @@ class DocType(StockController): def update_stock_ledger(self, is_cancelled=0): self.values = [] for d in getlist(self.doclist, 'mtn_details'): - if cstr(d.s_warehouse): + if cstr(d.s_warehouse) and not is_cancelled: self.add_to_values(d, cstr(d.s_warehouse), -flt(d.transfer_qty), is_cancelled) + if cstr(d.t_warehouse): self.add_to_values(d, cstr(d.t_warehouse), flt(d.transfer_qty), is_cancelled) + + if cstr(d.s_warehouse) and is_cancelled: + self.add_to_values(d, cstr(d.s_warehouse), -flt(d.transfer_qty), is_cancelled) get_obj('Stock Ledger', 'Stock Ledger').update_stock(self.values, self.doc.amended_from and 'Yes' or 'No') diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index 58fc828f2d..2f365383fd 100644 --- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -119,13 +119,14 @@ class DocType(DocListController): if self.doc.actual_qty < 0: if sr.doc.warehouse!=self.doc.warehouse: - webnotes.throw(_("Warehouse does not belong to Item") + \ - (": %s (%s)" % (self.doc.item_code, serial_no)), SerialNoWarehouseError) + webnotes.throw(_("Serial No") + ": " + serial_no + + _(" does not belong to Warehouse") + ": " + self.doc.warehouse, + SerialNoWarehouseError) if self.doc.voucher_type in ("Delivery Note", "Sales Invoice") \ and sr.doc.status != "Available": - webnotes.throw(_("Serial No status must be 'Available' to Deliver") + \ - ": " + serial_no, SerialNoStatusError) + webnotes.throw(_("Serial No status must be 'Available' to Deliver") + + ": " + serial_no, SerialNoStatusError) sr.doc.warehouse = None From 2851bc051445c490f49896989ef918c044d00efe Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 4 Sep 2013 13:02:58 +0530 Subject: [PATCH 2/3] [minor] [tetscases] for serialized item --- stock/doctype/stock_entry/test_stock_entry.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stock/doctype/stock_entry/test_stock_entry.py b/stock/doctype/stock_entry/test_stock_entry.py index b9b32306d8..3beb61ddc8 100644 --- a/stock/doctype/stock_entry/test_stock_entry.py +++ b/stock/doctype/stock_entry/test_stock_entry.py @@ -648,6 +648,9 @@ class TestStockEntry(unittest.TestCase): self.assertTrue(webnotes.conn.exists("Serial No", "ABCD")) self.assertTrue(webnotes.conn.exists("Serial No", "EFGH")) + se.cancel() + self.assertFalse(webnotes.conn.get_value("Serial No", "ABCD", "warehouse")) + def test_serial_no_not_exists(self): se = webnotes.bean(copy=test_records[0]) se.doc.purpose = "Material Issue" @@ -699,6 +702,9 @@ class TestStockEntry(unittest.TestCase): se.insert() se.submit() self.assertTrue(webnotes.conn.get_value("Serial No", serial_no, "warehouse"), "_Test Warehouse 1 - _TC") + + se.cancel() + self.assertTrue(webnotes.conn.get_value("Serial No", serial_no, "warehouse"), "_Test Warehouse - _TC") def test_serial_warehouse_error(self): make_serialized_item() @@ -720,7 +726,6 @@ class TestStockEntry(unittest.TestCase): serial_no = get_serial_nos(se.doclist[1].serial_no)[0] self.assertFalse(webnotes.conn.get_value("Serial No", serial_no, "warehouse")) - self.assertTrue(webnotes.conn.get_value("Serial No", serial_no, "status"), "Not Available") def make_serialized_item(): se = webnotes.bean(copy=test_records[0]) From df1854f0b5f465eaf8bc5fb656d03362b8ef0cab Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 4 Sep 2013 13:07:17 +0530 Subject: [PATCH 3/3] [fix] [minor] serial no status update for material transfer --- .../p02_fix_serial_no_status.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/patches/september_2013/p02_fix_serial_no_status.py b/patches/september_2013/p02_fix_serial_no_status.py index 8c91d72fb9..714cd7a377 100644 --- a/patches/september_2013/p02_fix_serial_no_status.py +++ b/patches/september_2013/p02_fix_serial_no_status.py @@ -15,14 +15,16 @@ def execute(): for d in stock_entries: serial_nos = d.serial_no.split("\n") - for serial_no in serial_nos: - serial_bean = webnotes.bean("Serial No", serial_no) - if serial_bean.doc.status == "Not Available": - latest_sle = webnotes.conn.sql("""select voucher_no from `tabStock Ledger Entry` - where item_code=%s and warehouse=%s and serial_no like %s - order by name desc limit 1""", - (serial_bean.doc.item_code, serial_bean.doc.warehouse, "%%%s%%" % serial_no)) + for sr in serial_nos: + serial_no = sr.strip() + if serial_no: + serial_bean = webnotes.bean("Serial No", serial_no) + if serial_bean.doc.status == "Not Available": + latest_sle = webnotes.conn.sql("""select voucher_no from `tabStock Ledger Entry` + where item_code=%s and warehouse=%s and serial_no like %s + order by name desc limit 1""", (serial_bean.doc.item_code, + serial_bean.doc.warehouse, "%%%s%%" % serial_no)) - if latest_sle and latest_sle[0][0] == d.name: - serial_bean.doc.status = "Available" - serial_bean.save() \ No newline at end of file + if latest_sle and latest_sle[0][0] == d.name: + serial_bean.doc.status = "Available" + serial_bean.save() \ No newline at end of file