clinic/netforce_clinic/migrations/rename_dbl_hdcase_number.py

29 lines
923 B
Python
Raw Normal View History

2015-12-18 06:55:19 +00:00
import time
from netforce.model import get_model
from netforce import migration
from netforce.access import set_active_user, set_active_company
from netforce.database import get_connection
class Migration(migration.Migration):
_name="clinic.rename.dbl.hdcase.number"
_version="2.12.2"
def migrate(self):
db=get_connection()
res=db.query("""
select c, number from (select count(number) as c,number from clinic_hd_case group by number order by number) as r1 where c > 1;
""")
for r in res:
number=r['number']
if number!='/':
count=1
for hdcase in get_model('clinic.hd.case').search_browse([['number','=',number]]):
hdcase.write({
'number': number+"."+str(count),
})
count+=1
print(r)
Migration.register()