clinic/netforce_clinic/models/staff_rotation.py

75 lines
2.5 KiB
Python

import time
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
class StaffRotation(Model):
_name="clinic.staff.rotation"
_string="Staff Rotation"
_multi_company=True
def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
staff=obj.staff_id
res[obj.id]={
'staff_name': staff.name or "",
}
return res
_fields={
"type": fields.Selection([['staff','Staff'],["doctor","Doctor"],["nurse","Nurse"]],"Type",search=True),
"staff_id": fields.Many2One("clinic.staff","Staff", search=True),
'categ_id': fields.Many2One("clinic.staff.categ","Category",search=True),
"level_id": fields.Many2One("clinic.staff.level","Level", search=True),
"hire_date": fields.Date("Date", search=True),
"resign_date": fields.Date("Resign Date", search=True),
"wage": fields.Float("Salary"),
"max_cycle": fields.Integer("Max Cycle"),
"ot_per_cycle": fields.Float("OT/Cycle"),
"note": fields.Text("Note"),
'company_id': fields.Many2One("company","Company"),
'state': fields.Selection([['draft','Draft'],['approved','Approved']],'State'),
'staff_name': fields.Char("Staff Name", function="_get_all",function_multi=True,store=True), #XXX
'department_id': fields.Many2One("clinic.department", "Department"), #XXX
}
_defaults={
"company_id": lambda *a: get_active_company(),
'hire_date': time.strftime("%Y-%m-%d"),
'state': 'draft',
'type': 'nurse',
}
_order="hire_date desc"
def to_draft(self,ids,context={}):
for obj in self.browse(ids):
obj.write({
'state': 'draft',
})
def approve(self,ids,context={}):
for obj in self.browse(ids):
if obj.state=='approved':
continue
obj.write({
'state': 'approved',
})
def create(self,vals,**kw):
id=super().create(vals,**kw)
self.function_store([id])
get_model("clinic.staff").function_store([vals['staff_id']])
return id
def write(self,ids,vals,**kw):
super().write(ids,vals,**kw)
self.function_store(ids)
staff_ids=[]
for obj in self.browse(ids):
staff_ids.append(obj.staff_id.id)
get_model("clinic.staff").function_store(staff_ids)
StaffRotation.register()