import time from netforce.model import get_model from netforce import migration from netforce.access import set_active_user, set_active_company class Migration(migration.Migration): _name="clinic.del.gi" _version="2.12.0" def migrate(self): set_active_user(1) set_active_company(1) #fmt='%Y-%m-%d %H:%M:%S' #datenow=time.strftime(fmt) dom=[ ['date','>=','2015-01-01 00:00:00'], ['date','<=','2015-06-30 23:59:59'], ['type','=','out'], ] count=0 for pick in get_model('stock.picking').search_browse(dom): print('del ', pick.date, pick.id, pick.number) pick.delete() count+=1 print("Delete From 2015-01-01 to 2015-06-30 Total is: ", count) rows=open("/tmp/del_gi.csv","r").read() ids=[] for row in rows.split("\n"): try: r=row.split(",") idtxt=r[1] if idtxt.isnumeric(): ids.append(int(idtxt)) except Exception as e: print("ERROR ", e) count=0 for id in ids: pick=get_model('stock.picking').browse(id) try: print('del ', pick.date, pick.id, pick.number) pick.delete() except Exception as e: print("ERROR ",e) count+=1 print("Delete from file Total: ",count) Migration.register()