clinic/netforce_clinic/migrations/print_labor_cost.py

38 lines
1.3 KiB
Python
Raw Normal View History

2015-07-29 01:44:03 +00:00
import time
from netforce.model import get_model
from netforce import migration
from netforce.access import set_active_user, get_active_user, set_active_company, get_active_company
class Migration(migration.Migration):
_name="clinic.print.labor.cost"
_version="2.11.0"
def migrate(self):
user_id=get_active_user()
company_id=get_active_company()
set_active_company(1)
set_active_user(1)
date_from=get_model("clinic.report.labor.cost")._get_date_from()
date_to=get_model("clinic.report.labor.cost")._get_date_to()
yearnow=date_from.split("-")[0]
for period in get_model('clinic.period').search_browse([['name','=',yearnow]]):
for line in period.lines:
if line.state=='open':
period_id=line.id
date_from=line.date_start
date_to=line.date_stop
break
vals={
'period_id': period_id,
'date': time.strftime("%Y-%m-%d"),
'date_from': date_from,
'date_to': date_to,
}
get_model('clinic.print.labor.cost').create(vals)
set_active_company(company_id)
set_active_user(user_id)
return True
Migration.register()