multi department

conv_bal
watcha.h@almacom.co.th 2015-01-18 17:31:54 +07:00
parent c166295720
commit 8f6230e488
14 changed files with 96 additions and 43 deletions

View File

@ -3,6 +3,7 @@
<field name="state"/>
<button string="Options" dropdown="1">
<item string="Load Nurses" method="load_nurse_from_schedule" states='draft'/>
<item string="Load HDCase" method="update_hdcase" states="draft" />
<item string="View Schedule" method="view_schedule"/>
<item string="To Draft" method="to_draft" states="validated" />
</button>
@ -18,7 +19,7 @@
<tab string="Nurses">
<field name="lines" nolabel="1">
<list>
<field name="nurse_id" domain="[['type','=','nurse']]" onchange="onchange_nurse"/>
<field name="nurse_id" domain='[["type","=","nurse"]]' onchange="onchange_nurse"/>
<field name="level_id"/>
</list>
</field>

View File

@ -6,6 +6,7 @@
<field name="branch_id" required="1"/>
<field name="company_id" invisible="1"/>
<related>
<field name="staffs"/>
<field name="patients"/>
</related>
</form>

View File

@ -6,9 +6,9 @@
<field name="number"/>
<field name="trt_no"/>
<field name="name"/>
<field name="type_id"/>
<field name="branch_id"/>
<field name="department_id"/>
<field name="doctor_id"/>
<field name="type_id"/>
<field name="image" preview='1'/>
</list>

View File

@ -9,11 +9,11 @@
</top>
<field name="number"/>
<field name="name"/>
<field name="type"/>
<field name="branch_id"/>
<field name="department_id"/>
<field name="level_id"/>
<field name="categ_id"/>
<field name="type"/>
<field name="image" preview="1"/>
<field name="state"/>
</list>

View File

@ -17,7 +17,8 @@ class CycleItem(Model):
cycle_name=''
if cycle:
cycle_name=cycle.name
name="%s-%s"%(cycle_name,obj.date)
dpt=obj.department_id
name="%s-%s-%s"%(cycle_name,obj.date,dpt.name)
res[obj.id]={
'name': name,
'sequence':'%s-%s-%s-%s'%(obj.date,cycle.sequence,obj.branch_id.id,obj.department_id.id),
@ -168,21 +169,23 @@ class CycleItem(Model):
obj=self.browse(ids)[0]
#TODO check cycle number & date from schedule
schedules=get_model("clinic.schedule").search_browse([['date','=',obj.date]])
nurses=[]
lines=[]
for schedule in schedules:
for line in schedule.lines:
cycle=line.cycle_id
if obj.cycle_id.id==cycle.id:
nurse=line.nurse_id
level=line.level_id
nurses.append(('create',{
lines.append(('create',{
'nurse_id': nurse.id,
'level_id': level.id,
}))
for nurse in obj.nurses:
nurse.delete()
for line in obj.lines:
line.delete()
if not lines:
raise Exception("Nurse not found in schedule %s"%obj.date)
obj.write({
'nurses': nurses,
'lines': lines,
})
return {
@ -194,4 +197,35 @@ class CycleItem(Model):
'flash': 'Load nurse from schedule to cycle item successfully',
}
def update_hdcase(self,ids,context={}):
obj=self.browse(ids)[0]
dpt=obj.department_id
branch=obj.branch_id
cycle=obj.cycle_id
company=obj.company_id
date=obj.date
dom=[
['cycle_id','=',cycle.id],
['date','=',date],
['company_id','=',company.id],
['branch_id','=',branch.id],
['department_id','=',dpt.id],
]
for hdcase in get_model("clinic.hd.case").search_browse(dom):
hdcase.write({
'cycle_item_id': obj.id,
})
vs=hdcase.visit_id
vs.write({
'cycle_item_id': obj.id,
})
return {
'next': {
'name': 'clinic_cycle_item',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Update HDCase successfully',
}
CycleItem.register()

View File

@ -8,6 +8,7 @@ class CycleItemLine(Model):
'cycle_item_id': fields.Many2One("clinic.cycle.item", "Cycle Item"),
'level_id': fields.Many2One("clinic.staff.level", "Level",),
'nurse_id': fields.Many2One("clinic.staff",'Nurse',domain=[['type','=','nurse']]),
'department_id': fields.Many2One("clinic.department","Department"),
}
CycleItemLine.register()

View File

@ -14,6 +14,7 @@ class Department(Model):
'branch_id': fields.Many2One("clinic.branch","Branch"),
"pick_out_journal_id": fields.Many2One("stock.journal","Stock Journal",required=True),
'patients': fields.One2Many("clinic.patient","department_id","Patients"),
'staffs': fields.One2Many("clinic.staff","department_id","Staffs"),
}
def _get_branch(self,context={}):
@ -26,4 +27,6 @@ class Department(Model):
'branch_id': _get_branch,
}
_order="name"
Department.register()

View File

@ -96,10 +96,11 @@ class LaborCost(Model):
levels.update(vals)
item=obj.cycle_item_id
for ns in item.nurses:
level=ns.level_id
for line in item.lines:
level=line.level_id
nurse=line.nurse_id
if not level:
raise Exception("Please specify level for %s"%ns.nurse_id.name)
raise Exception("Please specify level for %s"%nurse.name)
levels[level.id]['total']+=1
st_levels={}
@ -236,9 +237,9 @@ class LaborCost(Model):
item=obj.cycle_item_id
lines=[]
# cost's nurses
for nr in item.nurses:
nurse=nr.nurse_id
level=nr.level_id
for line in item.lines:
nurse=line.nurse_id
level=line.level_id
vals=levels.get(level.id)
rate,amt,qty=0.0,0.0,0
level_id=level.id

View File

@ -7,7 +7,7 @@ class LaborCostFormular(Model):
_name_field="labor_cost_id"
_fields={
"labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True),
"labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True,on_delete="cascade"),
'level_id': fields.Many2One("clinic.staff.level", "Level",domain=[['type','=','nurse']]),
'qty': fields.Integer("Qty"),
'var_a': fields.Float("A"),

View File

@ -7,7 +7,7 @@ class LaborCostLine(Model):
_name_field="labor_cost_id"
_fields={
"labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True),
"labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True,on_delete="cascade"),
"type": fields.Selection([('staff','Staff'),("doctor","Doctor"),('nurse','Nurse')],"Type",required=True,search=True),
'staff_id': fields.Many2One("clinic.staff", "Staff",search=True),
'level_id': fields.Many2One("clinic.staff.level", "Level",search=True),

View File

@ -92,30 +92,42 @@ class ClinicSetting(Model):
def run_script(self,ids,context={}):
obj=self.browse(ids)[0]
################ update sickbed #############
#sickbed: update department
#for sb in get_model('clinic.sickbed').search_browse([]):
#hdcs=sorted(sb.hd_cases, key=lambda a: a.id)
#if hdcs:
#hdc=hdcs[0]
##patient=hdc.patient_id
#sb.write({
#'department_id': hdc.department_id.id,
#})
# create new cycle item
# TODO
# copy old schedule
# copy old nurse to schedule
# delete old cycle item
# confirm schedule
# set visit & hd case to cycle item
old_schd=[]
for schd in get_model("clinic.schedule").search_browse([]):
if schd.lines:
print("x")
pass
for citem in get_model("clinic.cycle.item").search_browse([]):
if citem.lines:
print("y")
for sb in get_model('clinic.sickbed').search_browse([]):
hdcs=sorted(sb.hd_cases, key=lambda a: a.id)
if hdcs:
hdc=hdcs[0]
#patient=hdc.patient_id
sb.write({
'department_id': hdc.department_id.id,
})
#print("Done!")
#return
#############################################
############### cycle item
for lc in get_model('clinic.labor.cost').search_browse([]):
lc.delete()
db=get_connection()
res=db.query("""
select cycle_item_id, nurse_id, level_id from clinic_cycle_item_nurse
""")
for rs in res:
item_id=rs['cycle_item_id']
nid=rs['nurse_id']
lid=rs['level_id']
if item_id:
item=get_model('clinic.cycle.item').browse(item_id)
item.write({
'lines': [('create',{'nurse_id': nid, 'level_id': lid})],
})
print('update ', item.name)
item.validate()
#return
#############################################
print("Done!")
def reset_last_import(self,ids,context={}):

View File

@ -58,7 +58,7 @@ class SickBed(Model):
'branch_id': _get_branch,
}
_order="sequence"
_order="sequence,name"
def copy(self,ids,context={}):
obj=self.browse(ids)[0]

View File

@ -97,7 +97,7 @@ class Staff(Model):
"nurse_visits": fields.One2Many("clinic.visit","nurse_id","Visits"),
"doctor_visits": fields.One2Many("clinic.visit","doctor_id","Visits"),
"company_id": fields.Many2One("company","Company",search=True),
"user_id": fields.Many2One("base.user","User"),
"user_id": fields.Many2One("base.user","User",search=True),
'image': fields.File("Image"),
'note': fields.Text("Note"),
'categ_id': fields.Many2One("clinic.staff.categ", "Category"),

View File

@ -1,7 +1,7 @@
todo:
- XXXX
- make a script to generate cycle item
- accounting
- make a sharing setting
- filter data
1. company