2015-02-21 13:38:21 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from netforce.model import get_model
|
|
|
|
from netforce import migration
|
|
|
|
from netforce.database import get_connection
|
|
|
|
#from netforce.access import set_active_user, get_active_user
|
|
|
|
|
|
|
|
class Migration(migration.Migration):
|
|
|
|
_name="clinic.remove.conv.bal"
|
|
|
|
_version="2.11.0"
|
|
|
|
|
|
|
|
def migrate(self):
|
|
|
|
db=get_connection()
|
|
|
|
res=db.query("""
|
|
|
|
select id, amount_due, state,date from account_invoice where extract(year from date)=2014;
|
|
|
|
""")
|
|
|
|
inv_ids=[r['id'] for r in res]
|
2015-02-25 13:19:50 +00:00
|
|
|
|
|
|
|
res=db.query("""
|
|
|
|
select id, amount_due, state,date from account_invoice where extract(year from date)=2013;
|
|
|
|
""")
|
|
|
|
for r in res:
|
|
|
|
inv_ids.append(r['id'])
|
|
|
|
|
|
|
|
res=db.query("""
|
|
|
|
select id, amount_due, state,date from account_invoice where extract(year from date)=2012;
|
|
|
|
""")
|
|
|
|
for r in res:
|
|
|
|
inv_ids.append(r['id'])
|
|
|
|
|
2015-02-21 13:38:21 +00:00
|
|
|
for inv in get_model("account.invoice").browse(inv_ids):
|
|
|
|
inv.to_draft()
|
|
|
|
print('%s is deleted'%(inv.number))
|
|
|
|
inv.delete()
|
|
|
|
start=datetime.now()
|
|
|
|
stop=datetime.now()
|
|
|
|
finish=stop-start
|
|
|
|
print(finish.seconds/60)
|
|
|
|
return True
|
|
|
|
|
|
|
|
Migration.register()
|