hospital_demo_py/scripts/hospital.py

27 lines
754 B
Python
Raw Normal View History

2014-08-19 06:11:57 +00:00
from netforce.model import add_method,add_default
2014-08-19 05:49:02 +00:00
from datetime import *
from dateutil.relativedelta import *
2014-08-19 06:11:57 +00:00
import logging
2014-08-19 05:49:02 +00:00
@add_method("hos.patient")
def get_age(self,ids,context={}):
2014-08-19 06:11:57 +00:00
logging.info("get_age")
2014-08-19 05:49:02 +00:00
vals={}
for obj in self.browse(ids):
if obj.birth_date:
age=relativedelta(datetime.today(),datetime.strptime(obj.birth_date,"%Y-%m-%d")).years
else:
age=None
vals[obj.id]=age
return vals
@add_method("hos.visit")
def set_done(self,ids,context={}):
2014-08-19 06:11:57 +00:00
logging.info("set_done")
2014-08-19 05:49:02 +00:00
obj=self.browse(ids)[0]
obj.write({"state":"done"})
@add_default("hos.visit","date")
def get_date(self,context={}):
2014-08-19 06:11:57 +00:00
logging.info("get_date")
2014-08-19 05:49:02 +00:00
return datetime.today().strftime("%Y-%m-%d")