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.update.invoice" _version="2.12.4" def migrate(self): set_active_company(1) set_active_user(1) db=get_connection() for ptype_id in get_model("clinic.patient.type").search([]): pids=get_model('clinic.patient').search([['type_id','=',ptype_id]]) if pids: db.execute(""" update account_invoice set patient_type_id=%s where patient_id in %s """,ptype_id,tuple(pids)) print("update type %s to invoice -> Done"%(ptype_id)) Migration.register()