clinic/netforce_clinic/models/period_line.py

50 lines
1.4 KiB
Python
Raw Normal View History

2014-12-15 17:46:43 +00:00
from datetime import datetime
2014-11-27 15:14:31 +00:00
from netforce.model import Model, fields
class PeriodLine(Model):
_name="clinic.period.line"
_string="Period Line"
2014-12-16 09:53:36 +00:00
2014-12-15 17:46:43 +00:00
def _get_total(self,ids,context={}):
res={}
fmt='%Y-%m-%d'
for obj in self.browse(ids):
start=datetime.strptime(obj.date_start,fmt)
stop=datetime.strptime(obj.date_stop,fmt)
days=(stop-start).days
res[obj.id]=days
return res
2014-12-16 09:53:36 +00:00
def _get_name(self,ids,context={}):
res={}
for obj in self.browse(ids):
res[obj.id]='%s - %s'%(obj.date_start, obj.date_stop)
return res
2014-11-27 15:14:31 +00:00
_fields={
2014-12-16 09:53:36 +00:00
'name': fields.Char("Name",function="_get_name",store=True),
2014-11-27 15:14:31 +00:00
"period_id": fields.Many2One("clinic.period", "Period"),
2014-12-15 17:46:43 +00:00
'date_start': fields.Date("Date Start"),
'date_stop': fields.Date("Date Stop"),
2014-12-16 09:53:36 +00:00
'day_total': fields.Integer("Duration (Day)",function="_get_total"),
2014-11-27 15:14:31 +00:00
'state': fields.Selection([['draft','Draft'],['done','Done']],"State"),
2014-12-15 17:46:43 +00:00
'close': fields.Boolean("Close"),
2014-11-27 15:14:31 +00:00
}
_defaults={
'state': 'draft',
2014-12-15 17:46:43 +00:00
'close': False,
2014-11-27 15:14:31 +00:00
}
2014-12-16 09:53:36 +00:00
def create(self,vals,**kw):
id=super().create(vals,**kw)
self.function_store([id])
return id
def write(self,ids,vals,**kw):
super().write(ids,vals,**kw)
self.function_store(ids)
2014-11-27 15:14:31 +00:00
PeriodLine.register()