27 lines
772 B
Python
27 lines
772 B
Python
from netforce.model import add_method,add_default
|
|
from netforce.log import app_log
|
|
from datetime import *
|
|
from dateutil.relativedelta import *
|
|
|
|
@add_method("hos.patient")
|
|
def get_age(self,ids,context={}):
|
|
app_log.info("get_age")
|
|
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={}):
|
|
app_log.info("set_done")
|
|
obj=self.browse(ids)[0]
|
|
obj.write({"state":"done"})
|
|
|
|
@add_default("hos.visit","date")
|
|
def get_date(self,context={}):
|
|
app_log.info("get_date")
|
|
return datetime.today().strftime("%Y-%m-%d") |