[fix] meeting

conv_bal
watcha.h 2015-03-05 16:55:22 +07:00
parent 0bbf685f22
commit 016bfd85b5
15 changed files with 176 additions and 27 deletions

View File

@ -28,6 +28,15 @@
<tab string="Validation">
<field name="user_id" span="3"/>
<button string="Validate" perm="clinic_cycle_item_validate" type="success" method="validate" icon="ok" size="small" states="draft" />
<group span="6" columns="1">
</group>
<group span="6" columns="1">
<template>
<div>
<p></p>
<b>Note: </b> HD Case State Accepted: <b style="color:green">'Finish Treatment', 'Waiting Payment', 'Paid'.</b></div>
</template>
</group>
</tab>
</tabs>
<related>

View File

@ -30,7 +30,8 @@
<field name="var_x" span="6" offset="6"/>
</group>
<group span="6" columns="1">
<field name="total" string="Total" span="6" offset="6"/>
<!--<field name="total" string="Total" span="6" offset="6"/>-->
<field name="total_formular" string="Total" span="6" offset="6"/>
</group>
</tab>
<tab string="Nurse Cost">
@ -41,9 +42,12 @@
<field name="description"/>
<field name="level_id"/>
<field name="categ_id"/>
<field name="amount"/>
<field name="qty"/>
<!--<field name="amount"/>-->
<field name="rate"/>
</list>
</field>
<field name="total_nqty" string="Qty" span="3" offset="9"/>
<field name="total_ncost" string="Total" span="3" offset="9"/>
</tab>
<tab string="Doctor Cost">
@ -60,6 +64,7 @@
<field name="amount"/>
</list>
</field>
<field name="total_dqty" string="Qty" span="3" offset="9"/>
<field name="total_dcost" string="Total" span="3" offset="9"/>
</tab>
</tabs>

View File

@ -19,6 +19,7 @@
<field name="categ_id"/>
<field name="branch_id" required="1"/>
<field name="department_id" required="1" domain='[["branch_id","=",branch_id]]'/>
<field name="is_walkin"/>
<field name="active" invisible="1"/>
<tabs>
<tab string="General">
@ -65,13 +66,14 @@
<group span="8" columns="1">
<field name="cycles" nolabel="1">
<list>
<field name="department_id"/>
<field name="cycle_id"/>
<field name="day"/>
</list>
</field>
</group>
<group span="4" columns="1">
<field name="cycle_id"/>
<!--<field name="cycle_id"/>-->
</group>
</tab>
<tab string="Accounting">

View File

@ -1,5 +1,7 @@
<form model="clinic.report.hd.case.summary">
<field name="date" span="3" mode="month" onchange="onchange_date"/>
<field name="date" span="2" mode="month" onchange="onchange_date"/>
<field name="date_from" span="2"/>
<field name="date_to" span="2"/>
<field name="branch_id" onchange="onchange_branch" span="3"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="3"/>
</form>

View File

@ -4,6 +4,8 @@
<field name="date_to" required="1" span="2"/>
<field name="staff_type" onchange="onchange_type" span="2"/>
<field name="staff_id" domain='[["type","=",staff_type]]' span="2"/>
<field name="branch_id" onchange="onchange_branch" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<field name="categ_id" span="2"/>
<field name="level_id" span="2"/>
<field name="only_value" span="2"/>

View File

@ -30,7 +30,7 @@
</tab>
<tab string="Development">
<button string="Click Me" type="default" method="run_script" perm="clinic_setting_test"/>
<button string="Remove Duplicate Visit" type="default" icon="arrow-right" method="remove_douplicate_visit" perm="clinic_setting_rm_dbl_visit"/>
<!--<button string="Remove Duplicate Visit" type="default" icon="arrow-right" method="remove_douplicate_visit" perm="clinic_setting_rm_dbl_visit"/>-->
</tab>
</tabs>
<foot>

View File

@ -97,6 +97,9 @@ class CycleItem(Model):
def validate(self,ids,context={}):
obj=self.browse(ids)[0]
for hdcase in obj.hd_cases:
if hdcase.state not in ('completed','waiting_payment','paid'):
raise Exception('Invalidate cycle item %s: HD Case %s is not completed' % (obj.name, hdcase.patient_id.name))
for obj_id in ids:
lcost_ids=get_model("clinic.labor.cost").search([['cycle_item_id','=',obj_id]])
labor_cost=get_model("clinic.labor.cost")
@ -128,6 +131,12 @@ class CycleItem(Model):
def to_draft(self,ids,context={}):
for obj in self.browse(ids):
dom=[
['cycle_item_id','=',obj.id]
]
for lcost in get_model("clinic.labor.cost").search_browse(dom):
print("labor cost of cycle item % s is deleted"%lcost.cycle_item_id.name)
lcost.delete()
obj.write({
'state': 'draft',
})

View File

@ -39,13 +39,22 @@ class LaborCost(Model):
if total_a:
var_x=eval('(%s%s)/%s'%(var_ptx,total_bstr,total_a))
total_nqty=0
total_formular=0
for line in obj.formulars:
total_nqty+=line.qty or 0
total_formular+=line.amount or 0
total_ncost=0.0
for line in obj.nurse_lines:
total_ncost+=line.amount or 0.0
#total_ncost+=line.amount or 0.0
total_ncost+=line.rate or 0.0
total_dcost=0.0
total_dqty=0.0
for line in obj.doctor_lines:
total_dcost+=line.amount or 0.0
total_dqty+=line.qty or 0.0
total_stcost=0.0
for line in obj.staff_lines:
@ -60,8 +69,11 @@ class LaborCost(Model):
'var_fml3': '(%s%s)/%s'%(var_ptx,total_bstr,total_a),
'var_x': round(var_x,2),
'total': total,
'total_formular': total_formular,
'total_ncost': total_ncost,
'total_nqty': total_nqty,
'total_dcost': total_dcost,
'total_dqty': total_dqty,
'total_stcost': total_stcost,
}
@ -77,8 +89,11 @@ class LaborCost(Model):
'var_fml3': fields.Char("X:",function="_get_all",function_multi=True),
'var_x': fields.Char("X:",function="_get_all",function_multi=True),
'total': fields.Float("Total (Baht)",function="_get_all",function_multi=True),
'total_formular': fields.Float("Total",function="_get_all",function_multi=True),
'total_ncost': fields.Float("Nurse Cost",function="_get_all",function_multi=True),
'total_nqty': fields.Float("Nurse Cost",function="_get_all",function_multi=True),
'total_dcost': fields.Float("Doctor Cost",function="_get_all",function_multi=True),
'total_dqty': fields.Float("Doctor Cost",function="_get_all",function_multi=True),
'total_stcost': fields.Float("Staff Cost",function="_get_all",function_multi=True),
'manual': fields.Boolean("Manual"),
"formulars": fields.One2Many("clinic.labor.cost.formular", "labor_cost_id", "Formulars"),
@ -280,6 +295,7 @@ class LaborCost(Model):
'categ_id': nurse.categ_id.id,
'rate': rate,
'type': 'nurse',
#'qty': qty,
'qty': 1,
}))
@ -301,7 +317,7 @@ class LaborCost(Model):
'base': 0,
'type': staff.type,
'categ_id': staff.categ_id.id,
'level_id': staff.level_id.id,
'level_id': staff.level_id.id, #XXX
'qty': 0,
}
if staff.type!='doctor':

View File

@ -132,6 +132,7 @@ class Patient(Model):
'cycles': fields.One2Many("clinic.patient.cycle","patient_id", "Cycles"),
"vascular_acc": fields.Many2One("clinic.vascular.access","Vascular Ac."),
'state': fields.Selection([['admit','Admit'],['dispose','Dispose']],'State'),
'is_walkin': fields.Boolean("Walk In"),
}
def _get_number(self,context={}):

View File

@ -53,6 +53,7 @@ class ReportHDCaseSummary(Model):
branch_id=obj.branch_id.id
department_id=obj.department_id.id
date=obj.date
crr_month=int(date[5:7]) #XXX
time_start='%s 00:00:00'%obj.date_from
time_stop='%s 23:59:59'%obj.date_to
year=int(date[0:4])
@ -90,6 +91,7 @@ class ReportHDCaseSummary(Model):
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
print('>> dom ', dom)
crr_total=len(get_model("clinic.hd.case").search(dom))
items={}
items['topic%s'%count]={

View File

@ -16,6 +16,7 @@ class ReportLaborCostSummary(Model):
'staff_id': fields.Many2One("clinic.staff","Staff"),
"staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
'department_id': fields.Many2One("clinic.department","Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"),
'level_id': fields.Many2One("clinic.staff.level","Level"),
'categ_id': fields.Many2One("clinic.staff.categ","Category"),
'only_value': fields.Boolean("Only Amount"),
@ -56,6 +57,8 @@ class ReportLaborCostSummary(Model):
only_value=res['only_value']
level_id=None
categ_id=None
branch_id=None
department_id=None
dom=[]
if ids:
obj=self.browse(ids)[0]
@ -65,6 +68,8 @@ class ReportLaborCostSummary(Model):
staff_type=obj.staff_type
level_id=obj.level_id.id
categ_id=obj.categ_id.id
branch_id=obj.branch_id.id
department_id=obj.department_id.id
only_value=obj.only_value
dom.append(['date','>=',date_from])
dom.append(['date','<=',date_to])
@ -76,11 +81,20 @@ class ReportLaborCostSummary(Model):
dom.append(['amount','!=',0])
if categ_id:
dom.append(['staff_id.categ_id','=',categ_id])
if branch_id:
dom.append(['labor_cost_id.cycle_item_id.branch_id','=',branch_id])
if department_id:
dom.append(['labor_cost_id.cycle_item_id.department_id','=',department_id])
staffs={}
citems={}
print('dom ', dom)
total_hdcase=0
for line in get_model("clinic.labor.cost.line").search_browse(dom):
lcost=line.labor_cost_id
citem=lcost.cycle_item_id
dpt=citem.department_id
qty=line.qty or 0 #XXX
total_hdcase+=qty
amt=line.amount or 0
staff=line.staff_id
categ_name=''
@ -95,7 +109,8 @@ class ReportLaborCostSummary(Model):
categ_id=categ.id
categ_name=categ.name or ""
if staff.level_id:
level_name=staff.level_id.name or ""
level=get_model("clinic.staff.level").browse(staff.level_id.id)
level_name=level.name or ""
if not staffs.get(staff.name):
staffs[staff.name]={
'number': staff.number or '',
@ -106,24 +121,35 @@ class ReportLaborCostSummary(Model):
'categ_id': categ_id,
dpt.name: {
'amt': 0,
'qty': qty,
},
}
if not staffs[staff.name].get(dpt.name):
staffs[staff.name].update({
dpt.name: {
'amt': 0,
'qty': qty,
}})
staffs[staff.name][dpt.name]['amt']+=amt
staffs[staff.name][dpt.name]['qty']+=qty
if not citems.get(citem.id):
qty=len([hdcase for hdcase in citem.hd_cases])
citems[citem.id]=qty
lines=[]
dpts=get_model("clinic.department").search_read([],['name'])
dom=[]
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dpt_name=get_model('clinic.department').browse(department_id).name
dom.append(['name','=',dpt_name])
dpts=get_model("clinic.department").search_read(dom,['name'])
dpts=sorted(dpts, key=lambda b: b['name'])
no=1
staff_types=set()
snames=sorted(staffs.keys()) #sort by staff name
for sname in snames:
vals=staffs[sname]
lvals={
'no': no,
'staff_name': sname,
'staff_id': vals.get('staff_id'),
'staff_type': vals.get('staff_type'),
@ -133,20 +159,24 @@ class ReportLaborCostSummary(Model):
'number': vals.get("number"),
}
total=0
total_qty=0
lvals['sub_lines']=[]
for dpt in dpts:
amt=0 #solve bug
qty=0
dname=dpt['name'] or ''
vals2=vals.get(dname)
if vals2:
amt=vals2.get("amt",0)
staff_type=vals2.get("type",'')
staff_types.update({staff_type})
lvals['sub_lines'].append({'amt': amt,'dpt_id': dpt['id']})
qty=vals2.get("qty",0)
_staff_type=vals2.get("type",'')
staff_types.update({_staff_type})
lvals['sub_lines'].append({'amt': amt,'qty': qty, 'dpt_id': dpt['id']})
total+=amt
total_qty+=qty
lvals['total']=total
lvals['qty']=qty
lines.append(lvals)
no+=1
title=''
for stype in list(staff_types):
@ -156,21 +186,44 @@ class ReportLaborCostSummary(Model):
title+='Nurse'
title=' and'.join(t for t in title.split(" "))
total_lines=[{'amt': 0} for dpt in dpts]
total_lines=[{'amt': 0, 'qty':0} for dpt in dpts]
for line in lines:
i=0
for sub_line in line['sub_lines']:
amt=sub_line['amt'] or 0
qty=sub_line['qty'] or 0
total_lines[i]['amt']+=amt
total_lines[i]['qty']+=qty
i+=1
total=0
total_qty=0
total_cost=0
for tline in total_lines:
amt=tline['amt'] or 0
qty=tline['qty'] or 0
total+=amt
total_cost+=amt
total_qty+=qty
total_lines.append({'amt': total})
company_id=get_active_company()
comp=get_model("company").browse(company_id)
#staff_type=staff_type or staff.type #XXX
print("staff_type ", staff_type)
if staff_type!='doctor':
total_hdcase=0
for k,hdcase_qty in citems.items():
total_hdcase+=hdcase_qty
print("total_hdcase ", total_hdcase)
# reset no
nlines=[]
no=1
for line in sorted(lines, key=lambda x: x['number']):
line['no']=no
nlines.append(line)
no+=1
data={
'title': title,
'date_from': date_from,
@ -178,8 +231,10 @@ class ReportLaborCostSummary(Model):
'dpts': dpts,
'comp_name': comp.name or 0,
'comp_span': len(dpts),
'lines': sorted(lines, key=lambda x: x['number']),
'lines': nlines,
'total_lines': total_lines,
'total_hdcase': total_hdcase or 0,
'total_cost': total_cost or 0,
}
return data
@ -197,4 +252,9 @@ class ReportLaborCostSummary(Model):
data['staff_id']=None
return data
def onchange_branch(self,context={}):
data=context['data']
data['department_id']=None
return data
ReportLaborCostSummary.register()

View File

@ -122,12 +122,32 @@ class ClinicSetting(Model):
print("Done!")
return
def update_cycle_item_level(self,ids,context={}):
for citem in get_model("clinic.cycle.item").search_browse([]):
for line in citem.lines:
nurse=line.nurse_id
if nurse.level_id:
line.write({
'level_id': nurse.level_id.id,
})
def run_script(self,ids,context={}):
user_id=get_active_user()
if user_id !=1:
print("Only admin!!")
return
#obj=self.browse(ids)[0]
#obj.update_staff_department()
#obj.remove_rotation()
#obj.update_staff_level()
#obj.update_cycle_item_level()
for st in get_model("clinic.staff").search_browse([]):
st.write({
'note': ' ',
})
print("Done!")
return
lines=[]
for pt in get_model("clinic.patient").search_browse([['state','=','admit']]):
partner_id=None
@ -173,7 +193,7 @@ class ClinicSetting(Model):
print("Done!")
return
def udpate_staff_level(self,ids,context={}):
def update_staff_level(self,ids,context={}):
user_id=get_active_user()
if user_id !=1:
print("Only admin!!")

View File

@ -129,13 +129,13 @@ class Staff(Model):
"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",function="_get_rotation",function_multi=True),
'level_id': fields.Many2One("clinic.staff.level", "Level", function="_get_rotation",function_multi=True),
'categ_id': fields.Many2One("clinic.staff.categ", "Category",function="_get_rotation",function_multi=True,store=True),
'level_id': fields.Many2One("clinic.staff.level", "Level", function="_get_rotation",function_multi=True,store=True),
'active': fields.Boolean("Active"),
'date': fields.Date("Register Date"),
'wage': fields.Float("Wage", function="_get_rotation",function_multi=True),
'max_cycle': fields.Integer("Max Cycle", function="_get_rotation",function_multi=True),
'ot_per_cycle': fields.Integer("OT Per Cycle", function="_get_rotation",function_multi=True),
'wage': fields.Float("Wage", function="_get_rotation",function_multi=True,store=True),
'max_cycle': fields.Integer("Max Cycle", function="_get_rotation",function_multi=True,store=True),
'ot_per_cycle': fields.Integer("OT Per Cycle", function="_get_rotation",function_multi=True,store=True),
'check_max_cycle': fields.Boolean("Check Max Cycle"),
'hire_date': fields.Date("Hire Date"),
'resign_date': fields.Date("Resign Date"),

View File

@ -1,6 +1,13 @@
<p></p>
<p>
</p>
<table class="table table-condensed table-striped">
<thead>
<tr>
<th colspan="15" style="text-align:center">
<span class="label label-primary">HD Case: {{total_hdcase}}</span>
<span class="label label-success">Cost : ฿{{currency total_cost zero=""}}</span>
</th>
</tr>
<tr>
<th></th>
<th></th>
@ -20,7 +27,7 @@
<th style="text-align:right">{{name}}</th>
{{/each}}
</th>
<th rowspan="2" style="text-align:right;">รวม</th>
<th rowspan="2" style="text-align:right;">รายได้</th>
</tr>
</thead>
<tbody>
@ -53,6 +60,5 @@
{{#each total_lines}}
<th style="text-align:right;">{{currency amt zero=""}}</th>
{{/each}}
<th></th>
</tfoot>
</table>

View File

@ -2,6 +2,21 @@ todo:
- multi department access ***
- merge staff same name but different department
- doctor นายแพทย์ ทวีชัย
- tick
1. create profile for all department + branch (2)
- create sharing setting for all model
- branch
- deparment
- patient
- patient cycle
- cycle item
- visit
- hd case
- dialyzer
- shop
- sickbed
- staff
- staff rotation : only manager nurse
- run script
- update level's nurse
- report k. boy (sub detail) -> ok