clinic/netforce_clinic/models/sickbed.py

72 lines
2.3 KiB
Python
Raw Normal View History

2014-12-19 16:57:34 +00:00
from netforce.model import Model, fields, get_model
2015-01-09 05:19:52 +00:00
from netforce.access import get_active_company
2014-12-19 16:57:34 +00:00
class SickBed(Model):
_name="clinic.sickbed"
_string="Sickbed"
2015-01-09 05:19:52 +00:00
def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
hd_case=None
patient_id=None
image=None
date=''
for hd_case in sorted(obj.hd_cases, key=lambda a: a.id):
patient=hd_case.patient_id
patient_id=patient.id
image=patient.image
date=hd_case.date
res[obj.id]={
'patient_id': patient_id,
'image': image,
'date': date,
}
return res
2014-12-19 16:57:34 +00:00
_fields={
"name": fields.Char("Name",required=True,search=True),
"available": fields.Boolean("Available"),
'hd_cases': fields.One2Many("clinic.hd.case",'sickbed_id','HDCases'),
2015-01-09 05:19:52 +00:00
'company_id': fields.Many2One("company","Company"),
'patient_id': fields.Many2One("clinic.patient","Lasted Patient",function="_get_all",function_multi=True),
'image': fields.File("Image",function="_get_all",function_multi=True),
2015-01-14 03:55:08 +00:00
'date': fields.Date("Lasted Date",function="_get_all",function_multi=True),
2015-01-09 05:19:52 +00:00
"state": fields.Selection([("available","Available"),("not_available","Not Available")],"Status"),
2015-01-09 07:48:01 +00:00
'sequence': fields.Integer("Sequence"),
2015-01-09 10:39:33 +00:00
'note': fields.Text("Note"),
2014-12-19 16:57:34 +00:00
}
_defaults={
'available': True,
2015-01-09 05:19:52 +00:00
"company_id": lambda *a: get_active_company(),
2015-01-09 07:48:01 +00:00
'sequence': 0,
2015-01-13 06:08:55 +00:00
'state': 'available',
2014-12-19 16:57:34 +00:00
}
2015-01-09 07:48:01 +00:00
_order="sequence"
2014-12-19 16:57:34 +00:00
def copy(self,ids,context={}):
obj=self.browse(ids)[0]
new_id=get_model("clinic.sickbed").create({
'name': '%s(copy)' % obj.name,
})
return {
'next': {
'name': 'clinic_sickbed',
'mode': 'form',
'active_id': new_id,
},
'flash': 'Copy succesfully',
}
2015-01-14 03:55:08 +00:00
def write(self,ids,vals,**kw):
if 'available' in vals.keys():
if vals['available']:
vals['state']='available'
else:
vals['state']='not_available'
super().write(ids,vals,**kw)
2014-12-19 16:57:34 +00:00
SickBed.register()