cycle item

conv_bal
watcha.h 2014-11-23 22:39:41 +07:00
parent e129ccf370
commit 90cc5bcf8f
5 changed files with 70 additions and 12 deletions

View File

@ -12,14 +12,20 @@
<list> <list>
<field name="cycle_id"/> <field name="cycle_id"/>
<field name="personal_id"/> <field name="personal_id"/>
<field name="level_id"/>
<field name="type"/> <field name="type"/>
<field name="paid_amount"/> <field name="qty"/>
<field name="rate"/>
<field name="amount"/>
</list> </list>
<form> <form>
<field name="cycle_id"/> <field name="cycle_id"/>
<field name="personal_id"/> <field name="personal_id"/>
<field name="level_id"/>
<field name="type"/> <field name="type"/>
<field name="paid_amount"/> <field name="qty"/>
<field name="rate"/>
<field name="amount"/>
</form> </form>
</field> </field>
<group span="12"> <group span="12">

View File

@ -2,7 +2,8 @@
<head> <head>
<field name="state"/> <field name="state"/>
<button string="Options" dropdown="1"> <button string="Options" dropdown="1">
<item string="Compute Labor Cost" method="compute"/> <item string="Load Nurses" method="load_nurse_from_schedule" states='draft'/>
<item string="Compute Labor Cost" method="compute" states='draft'/>
<item string="View Schedule" method="view_schedule"/> <item string="View Schedule" method="view_schedule"/>
</button> </button>
</head> </head>

View File

@ -12,7 +12,7 @@ class CycleDialy(Model):
for obj in self.browse(ids): for obj in self.browse(ids):
total=0.0 total=0.0
for line in obj.lines: for line in obj.lines:
total+=(line.paid_amount or 0) total+=(line.amount or 0)
res[obj.id]={ res[obj.id]={
'total': total, 'total': total,
} }

View File

@ -9,7 +9,10 @@ class CycleDialyLine(Model):
"cycle_dialy_id": fields.Many2One("clinic.cycle.dialy","Cycle Dialy"), "cycle_dialy_id": fields.Many2One("clinic.cycle.dialy","Cycle Dialy"),
'cycle_id': fields.Many2One("clinic.cycle", "Cycle"), 'cycle_id': fields.Many2One("clinic.cycle", "Cycle"),
'personal_id': fields.Many2One("clinic.personal", "Personal"), 'personal_id': fields.Many2One("clinic.personal", "Personal"),
'paid_amount': fields.Float("Paid Amount"), 'level_id': fields.Many2One("clinic.personal.level", "Level"),
'qty': fields.Integer("Qty"),
'rate': fields.Float("Rate"),
'amount': fields.Float("Amount"),
'company_id': fields.Many2One("company","Company"), 'company_id': fields.Many2One("company","Company"),
"type": fields.Selection([("doctor","Doctor"),('nurse','Nurse'),("personal","Personal")],"Type",required=True), "type": fields.Selection([("doctor","Doctor"),('nurse','Nurse'),("personal","Personal")],"Type",required=True),
} }

View File

@ -129,8 +129,10 @@ class CycleItem(Model):
lines.append(('create',{ lines.append(('create',{
'cycle_id': obj.cycle_id.id, 'cycle_id': obj.cycle_id.id,
'personal_id': nurse.id, 'personal_id': nurse.id,
'paid_amount': levels[level.id] or 0.0, 'level_id': nurse.level_id.id,
'rate': levels[level.id] or 0.0,
'type': 'nurse', 'type': 'nurse',
'qty': 1,
})) }))
# cost's doctor # cost's doctor
@ -147,17 +149,24 @@ class CycleItem(Model):
if not personal_total.get(personal.id): if not personal_total.get(personal.id):
personal_total[personal.id]={ personal_total[personal.id]={
'base': 0, 'base': 0,
'level_id': personal.level_id.id,
'type': ps.type, 'type': ps.type,
'qty': 0,
} }
personal_total[personal.id]['base']+=base personal_total[personal.id]['base']=base
personal_total[personal.id]['qty']+=1
for doctor_id, value in personal_total.items(): for doctor_id, value in personal_total.items():
base=value['base'] base=value['base']
type=value['type'] type=value['type']
qty=value['qty']
level_id=value['level_id']
lines.append(('create',{ lines.append(('create',{
'cycle_id': obj.cycle_id.id, 'cycle_id': obj.cycle_id.id,
'personal_id': doctor_id, 'personal_id': doctor_id,
'paid_amount': base, 'level_id': level_id,
'rate': base,
'qty': qty,
'type': type, 'type': type,
})) }))
@ -174,15 +183,22 @@ class CycleItem(Model):
mode,vals=line mode,vals=line
cycle_id=vals['cycle_id'] cycle_id=vals['cycle_id']
personal_id=vals['personal_id'] personal_id=vals['personal_id']
paid_amount=vals['paid_amount'] or 0 #amount=vals['amount'] or 0
rate=vals['rate'] or 0
qty=vals['qty'] or 0
amount=qty*rate
key=(cycle_id,personal_id) key=(cycle_id,personal_id)
if not key in glines.keys(): if not key in glines.keys():
glines[key]={ glines[key]={
'paid_amount': paid_amount, 'amount': amount,
'type': vals['type'], 'type': vals['type'],
'level_id': vals['level_id'],
'rate': rate,
'qty': qty,
} }
continue continue
glines[key]['paid_amount']+=paid_amount glines[key]['amount']+=amount
glines[key]['qty']+=qty
lines=[] lines=[]
for key,vals in glines.items(): for key,vals in glines.items():
@ -286,6 +302,8 @@ class CycleItem(Model):
var_pt=len(obj.hd_cases) var_pt=len(obj.hd_cases)
var_ptx=var_pt*(obj.var_k or 0) var_ptx=var_pt*(obj.var_k or 0)
total_bstr=total_b < 0 and "+%s"%(abs(total_b)) or "-%s"%total_b total_bstr=total_b < 0 and "+%s"%(abs(total_b)) or "-%s"%total_b
var_x=0
if total_a:
var_x=eval('(%s%s)/%s'%(var_ptx,total_bstr,total_a)) var_x=eval('(%s%s)/%s'%(var_ptx,total_bstr,total_a))
for line in lines: for line in lines:
vals=line[1] vals=line[1]
@ -378,4 +396,34 @@ class CycleItem(Model):
} }
} }
def load_nurse_from_schedule(self,ids,context={}):
obj=self.browse(ids)[0]
#TODO check cycle number & date from schedule
schedules=get_model("clinic.schedule").search_browse([['date','=',obj.date]])
nurses=[]
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',{
'nurse_id': nurse.id,
'level_id': level.id,
}))
for nurse in obj.nurses:
nurse.delete()
obj.write({
'nurses': nurses,
})
return {
'next': {
'name': 'clinic_cycle_item',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Load nurse from schedule to cycle item successfully',
}
CycleItem.register() CycleItem.register()