clinic/netforce_clinic/migrations/restore_picking.py

37 lines
1.1 KiB
Python

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.restore.picking"
_version="2.12.1"
def migrate(self):
set_active_user(1)
set_active_company(1)
#remove all good issued from dlz
total_del=0
for dlz in get_model('clinic.dialyzer').search_browse([]):
for pick in dlz.pickings:
print('del pick ',pick.number)
pick.delete()
total_del+=1
print('total delete ', total_del)
fmt='%Y-%m-%d %H:%M:%S'
datenow=time.strftime(fmt)
dom=[
['date','>=','2015-01-01'],
['date','<=',datenow],
]
for hdcase in get_model("clinic.hd.case").search_browse(dom):
if not hdcase.pickings:
print('gen picking for %s in %s'%(hdcase.number, hdcase.date))
ctx={
'migrate':True,
}
hdcase.make_pickings(context=ctx)
Migration.register()