clinic/netforce_clinic/models/cycle.py

60 lines
1.9 KiB
Python

from datetime import datetime
from netforce.model import Model, fields
from netforce.access import get_active_company
class Cycle(Model):
_name="clinic.cycle"
_string="Cycle"
_key=["name"]
def _get_duration(self,ids,context={}):
res={}
fmt="%Y-%m-%d %H:%M"
date=datetime.now().strftime(fmt)[0:10]
for obj in self.browse(ids):
tstart=obj.time_start
tstop=obj.time_stop
if not tstart:
tstart='00:00'
if not tstop:
tstop='00:00'
# recheck
tstart=tstart.replace(".",":")
tstop=tstop.replace(".",":")
if len(tstart.split(":"))!=2:
tstart="00:00"
if len(tstop.split(":"))!=2:
tstop="00:00"
dstart='%s %s'%(date,tstart)
dstop='%s %s'%(date,tstop)
diff=datetime.strptime(dstop,fmt)-datetime.strptime(dstart,fmt)
total_time=round(diff.seconds/3600,2)
res[obj.id]=total_time
return res
_fields={
"name": fields.Char("Name",required=True,search=True),
'duration': fields.Integer("Duration(Hour)",function="_get_duration"),
'sequence': fields.Integer("Sequence"),
'time_start': fields.Char("Start Time"),
'time_stop': fields.Char("End Time"),
'company_id': fields.Many2One("company", "Company"),
'hd_cases': fields.One2Many("clinic.hd.case","cycle_id", "HD Cases"),
'visits': fields.One2Many("clinic.visit","cycle_id", "Visits"),
'cycle_items': fields.One2Many("clinic.cycle.item","cycle_id", "Cycle Items"),
'var_k': fields.Float("K"),
'color': fields.Char("Color"),
'note': fields.Text("Note"),
}
_defaults={
'duration': 1,
'sequence': 1,
'company_id': lambda *a: get_active_company(),
}
Cycle.register()