26 lines
1009 B
Python
26 lines
1009 B
Python
|
import webnotes
|
||
|
from webnotes.utils import cstr
|
||
|
from stock.stock_ledger import update_entries_after
|
||
|
|
||
|
def execute():
|
||
|
pr_items = webnotes.conn.sql("""select item_code, warehouse, serial_no, valuation_rate, name
|
||
|
from `tabPurchase Receipt Item` where ifnull(serial_no, '') != '' and docstatus = 1""",
|
||
|
as_dict=True)
|
||
|
|
||
|
item_warehouse = []
|
||
|
|
||
|
for item in pr_items:
|
||
|
serial_nos = cstr(item.serial_no).strip().split("\n")
|
||
|
serial_nos = map(lambda x: x.strip(), serial_nos)
|
||
|
|
||
|
webnotes.conn.sql("""update `tabPurchase Receipt Item` set serial_no = %s
|
||
|
where name = %s""", ("\n".join(serial_nos), item.name))
|
||
|
|
||
|
webnotes.conn.sql("""update `tabSerial No` set purchase_rate = %s where name in (%s)""" %
|
||
|
('%s', ', '.join(['%s']*len(serial_nos))), tuple([item.valuation_rate] + serial_nos))
|
||
|
|
||
|
if [item.item_code, item.warehouse] not in item_warehouse:
|
||
|
item_warehouse.append([item.item_code, item.warehouse])
|
||
|
|
||
|
for d in item_warehouse:
|
||
|
update_entries_after({"item_code": d[0], "warehouse": d[1] })
|