Update Serial No details through serial_no controller

This commit is contained in:
Nabin Hait
2013-10-08 17:11:33 +05:30
parent 8f05c05bfb
commit 77f37e6b7c
11 changed files with 250 additions and 274 deletions

View File

@@ -6,35 +6,12 @@ import webnotes
from webnotes.utils import flt
def execute():
serial_nos = webnotes.conn.sql("""select name, item_code, status from `tabSerial No`
where status!='Not in Use'""", as_dict=1)
serial_nos = webnotes.conn.sql("""select name from `tabSerial No` where status!='Not in Use'
and docstatus=0""")
for sr in serial_nos:
last_sle = webnotes.conn.sql("""select voucher_type, voucher_no, actual_qty
from `tabStock Ledger Entry` where serial_no like %s and item_code=%s
order by name desc limit 1""",
("%%%s%%" % sr.name, sr.item_code), as_dict=1)
if flt(last_sle[0].actual_qty) > 0:
if last_sle[0].voucher_type == "Stock Entry" and webnotes.conn.get_value("Stock Entry",
last_sle[0].voucher_no, "purpose") == "Sales Return":
status = "Sales Returned"
else:
status = "Available"
else:
if last_sle[0].voucher_type == "Stock Entry":
purpose = webnotes.conn.get_value("Stock Entry", last_sle[0].voucher_no, "purpose")
if purpose == "Purchase Return":
status = "Purchase Returned"
else:
status = "Not Available"
else:
status = "Delivered"
if sr.status != status:
webnotes.conn.sql("""update `tabSerial No` set status=%s where name=%s""",
(status, sr.name))
sr_bean = webnotes.bean("Serial No", sr[0])
sr_bean.make_controller().via_stock_ledger = True
sr_bean.save()
webnotes.conn.sql("""update `tabSerial No` set warehouse=''
where status in ('Delivered', 'Purchase Returned')""")
webnotes.conn.sql("""update `tabSerial No` set warehouse='' where status in
('Delivered', 'Purchase Returned')""")

View File

@@ -29,9 +29,10 @@ def execute():
cost_center = "Default CC Ledger - NISL"
for bin in webnotes.conn.sql("""select * from tabBin bin where ifnull(item_code, '')!=''
and ifnull(warehouse, '')!='' and ifnull(actual_qty, 0) != 0
and (select company from tabWarehouse where name=bin.warehouse)=%s""",
company[0], as_dict=1):
and ifnull(warehouse, '') in (%s) and ifnull(actual_qty, 0) != 0
and (select company from tabWarehouse where name=bin.warehouse)=%s""" %
(', '.join(['%s']*len(warehouse_map)), '%s'),
(warehouse_map.keys() + [company[0]]), as_dict=1):
item_details = item_map[bin.item_code]
new_warehouse = warehouse_map[bin.warehouse].get("fixed_asset_warehouse") \
if cstr(item_details.is_asset_item) == "Yes" \
@@ -40,7 +41,8 @@ def execute():
if item_details.has_serial_no == "Yes":
serial_no = "\n".join([d[0] for d in webnotes.conn.sql("""select name
from `tabSerial No` where item_code = %s and warehouse = %s
and status='Available'""", (bin.item_code, bin.warehouse))])
and status in ('Available', 'Sales Returned')""",
(bin.item_code, bin.warehouse))])
else:
serial_no = None