clinic/netforce_clinic/models/cycle.py

60 lines
1.9 KiB
Python
Raw Normal View History

2014-11-30 13:05:14 +00:00
from datetime import datetime
2014-10-14 03:57:20 +00:00
from netforce.model import Model, fields
2014-10-24 18:04:36 +00:00
from netforce.access import get_active_company
2014-10-14 03:57:20 +00:00
class Cycle(Model):
_name="clinic.cycle"
_string="Cycle"
2014-11-26 11:35:44 +00:00
_key=["name"]
2014-11-30 13:05:14 +00:00
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
2014-10-14 03:57:20 +00:00
_fields={
"name": fields.Char("Name",required=True,search=True),
2014-11-30 13:05:14 +00:00
'duration': fields.Integer("Duration(Hour)",function="_get_duration"),
2014-10-14 07:07:37 +00:00
'sequence': fields.Integer("Sequence"),
2014-11-30 13:05:14 +00:00
'time_start': fields.Char("Start Time"),
'time_stop': fields.Char("End Time"),
2014-10-26 04:28:08 +00:00
'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"),
2014-10-26 08:48:51 +00:00
'cycle_items': fields.One2Many("clinic.cycle.item","cycle_id", "Cycle Items"),
2014-10-26 04:28:08 +00:00
'var_k': fields.Float("K"),
2014-10-28 13:39:29 +00:00
'color': fields.Char("Color"),
2014-11-30 13:05:14 +00:00
'note': fields.Text("Note"),
2014-10-14 03:57:20 +00:00
}
_defaults={
'duration': 1,
2014-10-14 07:07:37 +00:00
'sequence': 1,
2014-10-26 04:28:08 +00:00
'company_id': lambda *a: get_active_company(),
2014-10-14 03:57:20 +00:00
}
Cycle.register()