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"/> <field name="state"/>
<button string="Options" dropdown="1"> <button string="Options" dropdown="1">
<item string="Load Nurses" method="load_nurse_from_schedule" states='draft'/> <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="View Schedule" method="view_schedule"/>
<item string="To Draft" method="to_draft" states="validated" /> <item string="To Draft" method="to_draft" states="validated" />
</button> </button>
@ -18,7 +19,7 @@
<tab string="Nurses"> <tab string="Nurses">
<field name="lines" nolabel="1"> <field name="lines" nolabel="1">
<list> <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"/> <field name="level_id"/>
</list> </list>
</field> </field>

View File

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

View File

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

View File

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

View File

@ -17,7 +17,8 @@ class CycleItem(Model):
cycle_name='' cycle_name=''
if cycle: if cycle:
cycle_name=cycle.name 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]={ res[obj.id]={
'name': name, 'name': name,
'sequence':'%s-%s-%s-%s'%(obj.date,cycle.sequence,obj.branch_id.id,obj.department_id.id), '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] obj=self.browse(ids)[0]
#TODO check cycle number & date from schedule #TODO check cycle number & date from schedule
schedules=get_model("clinic.schedule").search_browse([['date','=',obj.date]]) schedules=get_model("clinic.schedule").search_browse([['date','=',obj.date]])
nurses=[] lines=[]
for schedule in schedules: for schedule in schedules:
for line in schedule.lines: for line in schedule.lines:
cycle=line.cycle_id cycle=line.cycle_id
if obj.cycle_id.id==cycle.id: if obj.cycle_id.id==cycle.id:
nurse=line.nurse_id nurse=line.nurse_id
level=line.level_id level=line.level_id
nurses.append(('create',{ lines.append(('create',{
'nurse_id': nurse.id, 'nurse_id': nurse.id,
'level_id': level.id, 'level_id': level.id,
})) }))
for nurse in obj.nurses: for line in obj.lines:
nurse.delete() line.delete()
if not lines:
raise Exception("Nurse not found in schedule %s"%obj.date)
obj.write({ obj.write({
'nurses': nurses, 'lines': lines,
}) })
return { return {
@ -193,5 +196,36 @@ class CycleItem(Model):
}, },
'flash': 'Load nurse from schedule to cycle item successfully', '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() CycleItem.register()

View File

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

View File

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

View File

@ -96,10 +96,11 @@ class LaborCost(Model):
levels.update(vals) levels.update(vals)
item=obj.cycle_item_id item=obj.cycle_item_id
for ns in item.nurses: for line in item.lines:
level=ns.level_id level=line.level_id
nurse=line.nurse_id
if not level: 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 levels[level.id]['total']+=1
st_levels={} st_levels={}
@ -236,9 +237,9 @@ class LaborCost(Model):
item=obj.cycle_item_id item=obj.cycle_item_id
lines=[] lines=[]
# cost's nurses # cost's nurses
for nr in item.nurses: for line in item.lines:
nurse=nr.nurse_id nurse=line.nurse_id
level=nr.level_id level=line.level_id
vals=levels.get(level.id) vals=levels.get(level.id)
rate,amt,qty=0.0,0.0,0 rate,amt,qty=0.0,0.0,0
level_id=level.id level_id=level.id

View File

@ -7,7 +7,7 @@ class LaborCostFormular(Model):
_name_field="labor_cost_id" _name_field="labor_cost_id"
_fields={ _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']]), 'level_id': fields.Many2One("clinic.staff.level", "Level",domain=[['type','=','nurse']]),
'qty': fields.Integer("Qty"), 'qty': fields.Integer("Qty"),
'var_a': fields.Float("A"), 'var_a': fields.Float("A"),

View File

@ -7,7 +7,7 @@ class LaborCostLine(Model):
_name_field="labor_cost_id" _name_field="labor_cost_id"
_fields={ _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), "type": fields.Selection([('staff','Staff'),("doctor","Doctor"),('nurse','Nurse')],"Type",required=True,search=True),
'staff_id': fields.Many2One("clinic.staff", "Staff",search=True), 'staff_id': fields.Many2One("clinic.staff", "Staff",search=True),
'level_id': fields.Many2One("clinic.staff.level", "Level",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={}): def run_script(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
################ update sickbed #############
#sickbed: update department #sickbed: update department
#for sb in get_model('clinic.sickbed').search_browse([]): for sb in get_model('clinic.sickbed').search_browse([]):
#hdcs=sorted(sb.hd_cases, key=lambda a: a.id) hdcs=sorted(sb.hd_cases, key=lambda a: a.id)
#if hdcs: if hdcs:
#hdc=hdcs[0] hdc=hdcs[0]
##patient=hdc.patient_id #patient=hdc.patient_id
#sb.write({ sb.write({
#'department_id': hdc.department_id.id, 'department_id': hdc.department_id.id,
#}) })
# create new cycle item #print("Done!")
# TODO #return
# copy old schedule
# copy old nurse to schedule #############################################
# delete old cycle item
# confirm schedule ############### cycle item
# set visit & hd case to cycle item for lc in get_model('clinic.labor.cost').search_browse([]):
old_schd=[] lc.delete()
for schd in get_model("clinic.schedule").search_browse([]):
if schd.lines: db=get_connection()
print("x") res=db.query("""
pass select cycle_item_id, nurse_id, level_id from clinic_cycle_item_nurse
for citem in get_model("clinic.cycle.item").search_browse([]): """)
if citem.lines: for rs in res:
print("y") 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!") print("Done!")
def reset_last_import(self,ids,context={}): def reset_last_import(self,ids,context={}):

View File

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

View File

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

View File

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