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.conv.bal" _version="2.10.0" def migrate(self): set_active_user(1) set_active_company(1) #for mv in get_model("account.move").search_browse([['number','ilike', 'OPEN']]): #mv.to_draft() #mv.delete() # delete old account payable dom=[ ['memo','=','Conversion balance 2015-06-30'], ['type','=','in'], ['state','=','waiting_payment'], ] for inv in get_model('account.invoice').search_browse(dom): print('delete invoice... ', inv.number) inv.to_draft() inv.delete() # delete old account rereivable dom=[ ['memo','=','Conversion balance 2015-06-30'], ['type','=','out'], ['state','=','waiting_payment'], ] for inv in get_model('account.invoice').search_browse(dom): print('delete invoice... ', inv.number) inv.to_draft() inv.delete() # remove journal entry dom=[ ['number','=','OPENING ENTRY'], ] for move in get_model('account.move').search_browse(dom): print('delete accout.move... ', move.number) move.to_draft() move.delete() cbv_id=24 cbv=get_model("conv.bal").browse(cbv_id) cbv.write({ 'date_fmt': '%Y-%m-%d', 'file': 'tb.csv', 'date': '2015-06-30', }) print("import acc file (step 1) running ...") get_model("conv.bal").import_acc_file([cbv.id],context={}) get_model("conv.bal").import_acc([cbv.id],context={}) print("import sale file (step 2)running ...") del_ids=get_model("conv.sale.invoice").search([["conv_id","=",cbv.id]]) get_model('conv.sale.invoice').delete(del_ids) for ar_file in ['ar_fee','ar_epo','ar_srv','ar_other']: cbv.write({ 'date_fmt': '%d/%m/%Y', 'file': '%s.csv'%(ar_file), }) ctx={ 'is_append': True, } get_model("conv.bal").import_sale_file([cbv.id],context=ctx) get_model("conv.bal").import_sale([cbv.id],context={}) print("import purch file (step 3) running ...") cbv.write({ 'file': 'ap.csv', #'date_fmt': '%d/%m/%Y', 'date_fmt': '%Y-%m-%d', }) get_model("conv.bal").import_purch_file([cbv.id],context={}) get_model("conv.bal").import_purch([cbv.id],context={}) cbv.write({ 'date_fmt': '%Y-%m-%d', }) print(">> next 3") print("create_open_entry...") cbv.create_open_entry() print("create_sale_invoices...") cbv.create_sale_invoices() print("create_purch_invoices...") cbv.create_purch_invoices() print("Done!") return True Migration.register()