From f1e274c8b47d34bdcb70631491a2a5830faa485d Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 7 Mar 2013 16:34:59 +0530 Subject: [PATCH] when cancelling stock ledger entry, change modified and modified by --- stock/doctype/stock_ledger/stock_ledger.py | 26 ++++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/stock/doctype/stock_ledger/stock_ledger.py b/stock/doctype/stock_ledger/stock_ledger.py index 05fc0e0642..5dff992ae4 100644 --- a/stock/doctype/stock_ledger/stock_ledger.py +++ b/stock/doctype/stock_ledger/stock_ledger.py @@ -17,7 +17,7 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import add_days, cstr, flt, nowdate, cint +from webnotes.utils import add_days, cstr, flt, nowdate, cint, now from webnotes.model.doc import Document from webnotes.model.bean import getlist from webnotes.model.code import get_obj @@ -49,7 +49,7 @@ class DocType: serial_nos = get_valid_serial_nos(d.serial_no) for s in serial_nos: s = s.strip() - sr_war = sql("select warehouse,name from `tabSerial No` where name = '%s'" % (s)) + sr_war = webnotes.conn.sql("select warehouse,name from `tabSerial No` where name = '%s'" % (s)) if not sr_war: msgprint("Serial No %s does not exists"%s, raise_exception = 1) elif not sr_war[0][0]: @@ -81,7 +81,7 @@ class DocType: def set_pur_serial_no_values(self, obj, serial_no, d, s, new_rec, rejected=None): - item_details = sql("""select item_group, warranty_period + item_details = webnotes.conn.sql("""select item_group, warranty_period from `tabItem` where name = '%s' and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now()) """ %(d.item_code), as_dict=1) @@ -112,7 +112,7 @@ class DocType: def update_serial_purchase_details(self, obj, d, serial_no, is_submit, purpose = '', rejected=None): - exists = sql("select name, status, docstatus from `tabSerial No` where name = '%s'" % (serial_no)) + exists = webnotes.conn.sql("select name, status, docstatus from `tabSerial No` where name = '%s'" % (serial_no)) if is_submit: if exists and exists[0][2] != 2 and purpose not in ['Material Transfer', 'Sales Return']: msgprint("Serial No: %s already %s" % (serial_no, exists and exists[0][1]), raise_exception = 1) @@ -126,15 +126,15 @@ class DocType: if exists and exists[0][1] == 'Delivered' and exists[0][2] != 2: msgprint("Serial No: %s is already delivered, you can not cancel the document." % serial_no, raise_exception=1) elif purpose == 'Material Transfer': - sql("update `tabSerial No` set status = 'In Store', purchase_document_type = '', purchase_document_no = '', warehouse = '%s' where name = '%s'" % (d.s_warehouse, serial_no)) + webnotes.conn.sql("update `tabSerial No` set status = 'In Store', purchase_document_type = '', purchase_document_no = '', warehouse = '%s' where name = '%s'" % (d.s_warehouse, serial_no)) elif purpose == 'Sales Return': - sql("update `tabSerial No` set status = 'Delivered', purchase_document_type = '', purchase_document_no = '' where name = '%s'" % serial_no) + webnotes.conn.sql("update `tabSerial No` set status = 'Delivered', purchase_document_type = '', purchase_document_no = '' where name = '%s'" % serial_no) else: - sql("update `tabSerial No` set docstatus = 2, status = 'Not in Use', purchase_document_type = '', purchase_document_no = '', purchase_date = null, purchase_rate = 0, supplier = null, supplier_name = '', supplier_address = '', warehouse = '' where name = '%s'" % serial_no) + webnotes.conn.sql("update `tabSerial No` set docstatus = 2, status = 'Not in Use', purchase_document_type = '', purchase_document_no = '', purchase_date = null, purchase_rate = 0, supplier = null, supplier_name = '', supplier_address = '', warehouse = '' where name = '%s'" % serial_no) def check_serial_no_exists(self, serial_no, item_code): - chk = sql("select name, status, docstatus, item_code from `tabSerial No` where name = %s", (serial_no), as_dict=1) + chk = webnotes.conn.sql("select name, status, docstatus, item_code from `tabSerial No` where name = %s", (serial_no), as_dict=1) if not chk: msgprint("Serial No: %s does not exists in the system" % serial_no, raise_exception=1) elif chk and chk[0]['item_code'] != item_code: @@ -169,7 +169,7 @@ class DocType: self.check_serial_no_exists(serial_no, d.item_code) self.set_delivery_serial_no_values(obj, serial_no) else: - sql("update `tabSerial No` set docstatus = 0, status = 'In Store', delivery_document_type = '', delivery_document_no = '', delivery_date = null, customer = null, customer_name = '', delivery_address = '', territory = null where name = '%s'" % (serial_no)) + webnotes.conn.sql("update `tabSerial No` set docstatus = 0, status = 'In Store', delivery_document_type = '', delivery_document_no = '', delivery_date = null, customer = null, customer_name = '', delivery_address = '', territory = null where name = '%s'" % (serial_no)) def update_serial_record(self, obj, fname, is_submit = 1, is_incoming = 0): @@ -202,8 +202,10 @@ class DocType: if v.get('is_cancelled') == 'Yes': v['actual_qty'] = -flt(v['actual_qty']) # cancel matching entry - sql("update `tabStock Ledger Entry` set is_cancelled='Yes' where voucher_no=%s \ - and voucher_type=%s", (v['voucher_no'], v['voucher_type'])) + webnotes.conn.sql("""update `tabStock Ledger Entry` set is_cancelled='Yes', + modified=%s, modified_by=%s + where voucher_no=%s and voucher_type=%s""", + (now(), webnotes.session.user, v['voucher_no'], v['voucher_type'])) if v.get("actual_qty"): sle_id = self.make_entry(v) @@ -230,5 +232,5 @@ class DocType: """ Repost everything! """ - for wh in sql("select name from tabWarehouse"): + for wh in webnotes.conn.sql("select name from tabWarehouse"): get_obj('Warehouse', wh[0]).repost_stock()