labor cost
parent
287ef807f3
commit
c02a2b4a98
|
@ -3,7 +3,7 @@
|
|||
<field name="view_cls">multi_view</field>
|
||||
<field name="model">clinic.cycle.item</field>
|
||||
<field name="modes">list,form</field>
|
||||
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["Done",[["state","=","done"]]]]</field>
|
||||
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["Validated",[["state","=","validated"]]]]</field>
|
||||
<field name="menu">clinic_menu</field>
|
||||
<field name="limit">25</field>
|
||||
</action>
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<action>
|
||||
<field name="string">Labor Costs</field>
|
||||
<field name="view_cls">multi_view</field>
|
||||
<field name="model">clinic.labor.cost</field>
|
||||
<field name="menu">account_menu</field>
|
||||
</action>
|
|
@ -4,5 +4,5 @@
|
|||
<field name="model">clinic.report.nurse.fee.detail</field>
|
||||
<field name="report_template">report_nurse_fee_detail</field>
|
||||
<field name="report_template_xls">report_nurse_fee_detail</field>
|
||||
<field name="menu">clinic_menu</field>
|
||||
<field name="menu">account_menu</field>
|
||||
</action>
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
<field name="model">clinic.report.nurse.fee.sum</field>
|
||||
<field name="report_template">report_nurse_fee_sum</field>
|
||||
<field name="report_template_xls">report_nurse_fee_sum</field>
|
||||
<field name="menu">clinic_menu</field>
|
||||
<field name="menu">account_menu</field>
|
||||
</action>
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
<field name="string">Import Payment</field>
|
||||
<field name="view_cls">multi_view</field>
|
||||
<field name="model">import.clinic.payment</field>
|
||||
<field name="menu">clinic_menu</field>
|
||||
<field name="menu">account_menu</field>
|
||||
</action>
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
<form model="clinic.cycle.item" attrs='{"readonly":[["state","in",["done"]]]}' show_company="1">
|
||||
<form model="clinic.cycle.item" attrs='{"readonly":[["state","in",["validated"]]]}' show_company="1">
|
||||
<head>
|
||||
<field name="state"/>
|
||||
<button string="Options" dropdown="1">
|
||||
<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 Cycle Daily" method="view_cycle_daily"/>
|
||||
<item string="To Draft" method="to_draft" states="done" />
|
||||
<item string="To Draft" method="to_draft" states="validated" />
|
||||
</button>
|
||||
</head>
|
||||
|
||||
|
@ -21,36 +20,8 @@
|
|||
</list>
|
||||
</field>
|
||||
</tab>
|
||||
<tab string="Labor Cost">
|
||||
<group form_layout="stacked">
|
||||
<field name="var_k" span="3"/>
|
||||
<field name="var_pt" span="3"/>
|
||||
<field name="var_ptx" span="3"/>
|
||||
<field name="manual" span="3" help="Help"/>
|
||||
<field name="lines" nolabel="1">
|
||||
<list colors='{"red":[["state","=","fail"]]}'>
|
||||
<field name="level_id"/>
|
||||
<field name="qty"/>
|
||||
<field name="formular_org" readonly="1"/>
|
||||
<field name="formular" readonly="1"/>
|
||||
<field name="amount"/>
|
||||
</list>
|
||||
</field>
|
||||
</group>
|
||||
<group span="6" columns="1">
|
||||
<field name="var_fml1" span="6" offset="6"/>
|
||||
<field name="var_fml2" span="6" offset="6"/>
|
||||
<field name="var_fml3" span="6" offset="6"/>
|
||||
<field name="var_x" span="6" offset="6"/>
|
||||
</group>
|
||||
<group span="6" columns="1">
|
||||
<field name="total" span="6" offset="6"/>
|
||||
</group>
|
||||
</tab>
|
||||
<tab string="Validation">
|
||||
<tab string="Other">
|
||||
<field name="user_id"/>
|
||||
</tab>
|
||||
<tab string="Other Info">
|
||||
<field name="cycle_daily_id" domain="[['date','=',date]]"/>
|
||||
</tab>
|
||||
</tabs>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<list model="clinic.cycle.item" colors='{"#9f9":[["state","=","done"]]}'>
|
||||
<!--<field name="name"/>-->
|
||||
<list model="clinic.cycle.item" colors='{"#9f9":[["state","=","validated"]]}'>
|
||||
<field name="cycle_id"/>
|
||||
<field name="date"/>
|
||||
<!--<field name="sequence"/>-->
|
||||
<field name="state"/>
|
||||
</list>
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<form model="clinic.hospital">
|
||||
<field name="code"/>
|
||||
<field name="name"/>
|
||||
<related>
|
||||
<field name="addresses"/>
|
||||
</related>
|
||||
</form>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
<form model="clinic.labor.cost">
|
||||
<head>
|
||||
<button string="Options" dropdown="1">
|
||||
</button>
|
||||
</head>
|
||||
<tabs>
|
||||
<tab string="Computation">
|
||||
<group form_layout="stacked">
|
||||
<field name="var_k" span="3"/>
|
||||
<field name="var_pt" span="3"/>
|
||||
<field name="var_ptx" span="3"/>
|
||||
<field name="manual" span="3" help="Help"/>
|
||||
<field name="cycle_item_id" span="3"/>
|
||||
<field name="formulars" nolabel="1">
|
||||
<list colors='{"red":[["state","=","fail"]]}'>
|
||||
<field name="level_id"/>
|
||||
<field name="qty"/>
|
||||
<field name="formular_org" readonly="1"/>
|
||||
<field name="formular" readonly="1"/>
|
||||
<field name="amount"/>
|
||||
</list>
|
||||
</field>
|
||||
</group>
|
||||
<group span="6" columns="1">
|
||||
<field name="var_fml1" span="6" offset="6"/>
|
||||
<field name="var_fml2" span="6" offset="6"/>
|
||||
<field name="var_fml3" span="6" offset="6"/>
|
||||
<field name="var_x" span="6" offset="6"/>
|
||||
</group>
|
||||
<group span="6" columns="1">
|
||||
<field name="total" span="6" offset="6"/>
|
||||
</group>
|
||||
</tab>
|
||||
<tab string="Cost">
|
||||
<field name="lines" nolabel="1">
|
||||
<list>
|
||||
<field name="staff_id"/>
|
||||
<field name="level_id"/>
|
||||
<field name="qty"/>
|
||||
<field name="amount"/>
|
||||
</list>
|
||||
<form>
|
||||
<field name="staff_id"/>
|
||||
<field name="level_id"/>
|
||||
<field name="qty"/>
|
||||
<field name="amount"/>
|
||||
</form>
|
||||
</field>
|
||||
</tab>
|
||||
</tabs>
|
||||
<foot>
|
||||
<button string="Compute" icon="repeat" type="default" method="compute"/>
|
||||
</foot>
|
||||
</form>
|
|
@ -0,0 +1,3 @@
|
|||
<list model="clinic.labor.cost">
|
||||
<field name="cycle_item_id"/>
|
||||
</list>
|
|
@ -28,8 +28,8 @@
|
|||
<item string="Cycles">
|
||||
<item string="Cycles" action="clinic_cycle"/>
|
||||
<item string="Cycle Items" action="clinic_cycle_item"/>
|
||||
<item string="Cycle Daily" action="clinic_cycle_daily"/>
|
||||
<item string="Cycle Monthly" action="clinic_cycle_monthly"/>
|
||||
<!--<item string="Cycle Daily" action="clinic_cycle_daily"/>-->
|
||||
<!--<item string="Cycle Monthly" action="clinic_cycle_monthly"/>-->
|
||||
</item>
|
||||
<item string="Schedules" action="clinic_schedule">
|
||||
<item string="Schedules" action="clinic_schedule"/>
|
||||
|
@ -40,17 +40,22 @@
|
|||
<item string="Visit Board" action="clinic_visit_board"/>
|
||||
<item string="Generate Visit" action="clinic_gen_visit_form"/>
|
||||
</item>
|
||||
<item string="HD Cases" action="clinic_hd_case"/>
|
||||
<item string="Reports">
|
||||
<header string="HD CASE"/>
|
||||
<item string="HD Cases">
|
||||
<item string="HD Cases" action="clinic_hd_case"/>
|
||||
<item string="HD Case Expense" action="clinic_hd_case_expense"/>
|
||||
<divider/>
|
||||
<header string="REPORTS"/>
|
||||
<item string="HD Case Summary" action="clinic_report_hd_case_summary"/>
|
||||
<item string="Medical Summary" action="clinic_report_medical_summary"/>
|
||||
<item string="Recent Patient" action="clinic_report_recent_patient"/>
|
||||
<item string="Discontinue Patient" action="clinic_report_discontinue_patient"/>
|
||||
<divider/>
|
||||
<header string="LABOR COST"/>
|
||||
<item string="Nurse Fee Summary" action="clinic_report_nurse_fee_sum"/>
|
||||
<item string="Nurse Fee Detail" action="clinic_report_nurse_fee_detail"/>
|
||||
</item>
|
||||
<item string="Others">
|
||||
<header string="TESTING"/>
|
||||
<item string="Import Product" action="import_clinic_product"/>
|
||||
<item string="Import Patient" action="import_clinic_patient"/>
|
||||
<item string="Import Visit" action="import_clinic_visit"/>
|
||||
<item string="Import HD Case" action="import_clinic_hd_case"/>
|
||||
</item>
|
||||
<item string="Settings">
|
||||
<item string="Branch" action="clinic_branch"/>
|
||||
|
@ -59,13 +64,5 @@
|
|||
<item string="Nationalities" action="clinic_nation"/>
|
||||
<item string="Valcular Access" action="clinic_vascular_access"/>
|
||||
<item string="Clinic Settings" action="clinic_setting"/>
|
||||
<divider/>
|
||||
<header string="IMPORTS"/>
|
||||
<item string="Import Product" action="import_clinic_product"/>
|
||||
<item string="Import Patient" action="import_clinic_patient"/>
|
||||
<item string="Import Visit" action="import_clinic_visit"/>
|
||||
<item string="Import HD Case" action="import_clinic_hd_case"/>
|
||||
<item string="Import Payment" action="import_clinic_payment"/>
|
||||
<item string="Expenses" action="clinic_hd_case_expense"/>
|
||||
</item>
|
||||
</menu>
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
<inherit inherit="account_menu">
|
||||
<item string="Settings" position="before">
|
||||
<item string="Ratchawat">
|
||||
<item string="Labor Cost" action="clinic_labor_cost"/>
|
||||
<item string="Import Payment" action="import_clinic_payment"/>
|
||||
<divider/>
|
||||
<header string="REPORTS"/>
|
||||
<item string="Cost By Period" action="clinic_labor_cost"/>
|
||||
<item string="Nurse Fee Summary" action="clinic_report_nurse_fee_sum"/>
|
||||
<item string="Nurse Fee Detail" action="clinic_report_nurse_fee_detail"/>
|
||||
</item>
|
||||
</item>
|
||||
</inherit>
|
||||
|
|
|
@ -71,3 +71,7 @@ from . import import_visit
|
|||
from . import import_hd_case
|
||||
from . import vascular_access
|
||||
from . import hospital
|
||||
from . import labor_cost
|
||||
from . import labor_cost_formular
|
||||
from . import labor_cost_line
|
||||
from . import labor_cost_staff
|
||||
|
|
|
@ -17,28 +17,8 @@ class CycleItem(Model):
|
|||
if cycle:
|
||||
cycle_name=cycle.name
|
||||
name="%s-%s"%(cycle_name,obj.date)
|
||||
total_case=len(obj.hd_cases)
|
||||
total_a,total_b=0,0
|
||||
total=0.0
|
||||
for line in obj.lines:
|
||||
total+=line.amount or 0
|
||||
total_a+=line.var_a
|
||||
total_b+=line.var_b
|
||||
var_ptx=total_case*(obj.var_k or 0)
|
||||
var_fml1='PTxK=%sX%s'%(total_a,total_b)
|
||||
total_bstr=total_b < 0 and "+%s"%(abs(total_b)) or "-%s"%total_b
|
||||
var_x=0.0
|
||||
if total_a:
|
||||
var_x=eval('(%s%s)/%s'%(var_ptx,total_bstr,total_a))
|
||||
res[obj.id]={
|
||||
'name': name,
|
||||
'var_pt': total_case,
|
||||
'var_ptx': total_case*(obj.var_k or 0),
|
||||
'var_fml1': '%s'%(var_fml1),
|
||||
'var_fml2': '%s=%sX%s'%(var_ptx,total_a,total_b),
|
||||
'var_fml3': '(%s%s)/%s'%(var_ptx,total_bstr,total_a),
|
||||
'var_x': round(var_x,2),
|
||||
'total': total,
|
||||
}
|
||||
return res
|
||||
|
||||
|
@ -54,17 +34,8 @@ class CycleItem(Model):
|
|||
'nurse_id': fields.Many2One("clinic.staff","Nurse",domain=[['type','=','nurse']]), #XXX
|
||||
'sequence': fields.Char("Sequence"), # for sort item
|
||||
'company_id': fields.Many2One("company", "Company"),
|
||||
"state": fields.Selection([("draft","Draft"),("done","Done")],"Status",required=True),
|
||||
'var_k': fields.Float("K"),
|
||||
'var_pt': fields.Integer("PT", function="_get_all",function_multi=True),
|
||||
'var_ptx': fields.Char("PT x K:", function="_get_all",function_multi=True),
|
||||
'var_fml1': fields.Char("Step 1:",function="_get_all",function_multi=True),
|
||||
'var_fml2': fields.Char("Step 2:",function="_get_all",function_multi=True),
|
||||
'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",function="_get_all",function_multi=True),
|
||||
'manual': fields.Boolean("Manual"),
|
||||
'user_id': fields.Many2One("base.user","User"),
|
||||
"state": fields.Selection([("draft","Draft"),("validated","Validated")],"Status",required=True),
|
||||
'user_id': fields.Many2One("base.user","Validator"),
|
||||
}
|
||||
|
||||
def _get_vark(self,context={}):
|
||||
|
@ -103,8 +74,6 @@ class CycleItem(Model):
|
|||
def create(self, vals,**kw):
|
||||
date=vals['date']
|
||||
cycle_id=vals['cycle_id']
|
||||
vals['cycle_daily_id']=self.get_cycle_daily(date)
|
||||
|
||||
cycle=get_model("clinic.cycle").browse(cycle_id)
|
||||
vals['sequence']='%s-%s'%(date,cycle.sequence) #date-sequence
|
||||
obj_id=super().create(vals,**kw)
|
||||
|
@ -113,13 +82,32 @@ class CycleItem(Model):
|
|||
def write(self,ids,vals,**kw):
|
||||
obj=self.browse(ids)[0]
|
||||
cycle=obj.cycle_id
|
||||
date=vals.get('date') and vals.get('date') or obj.date
|
||||
vals['cycle_daily_id']=self.get_cycle_daily(date)
|
||||
vals['sequence']='%s-%s'%(obj.date,cycle.sequence) #date-sequence
|
||||
super().write(ids,vals,**kw)
|
||||
|
||||
def validate(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
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")
|
||||
if not lcost_ids:
|
||||
st=get_model("clinic.setting").browse(1)
|
||||
lc_id=labor_cost.create({
|
||||
'cycle_item_id': obj_id,
|
||||
'var_k': st.var_k,
|
||||
})
|
||||
lc=labor_cost.browse(lc_id)
|
||||
lc.compute()
|
||||
else:
|
||||
lc=labor_cost.search_browse([['cycle_item_id','=',obj.id]])
|
||||
if lc:
|
||||
lc.compute()
|
||||
obj.write({
|
||||
'state': 'validate',
|
||||
})
|
||||
|
||||
return
|
||||
|
||||
levels={}
|
||||
for line in obj.lines:
|
||||
level=line.level_id
|
||||
|
@ -257,149 +245,6 @@ class CycleItem(Model):
|
|||
'state': 'draft',
|
||||
})
|
||||
|
||||
def compute(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
if not obj.manual:
|
||||
for line in obj.lines:
|
||||
line.delete()
|
||||
|
||||
levels={}
|
||||
for level_id in get_model('clinic.staff.level').search([['type','=','nurse']]):
|
||||
vals={
|
||||
level_id: {
|
||||
'total': 0,
|
||||
}
|
||||
}
|
||||
levels.update(vals)
|
||||
|
||||
for ns in obj.nurses:
|
||||
level=ns.level_id
|
||||
if not level:
|
||||
raise Exception("Please specify level for %s"%ns.nurse_id.name)
|
||||
levels[level.id]['total']+=1
|
||||
|
||||
st_levels={}
|
||||
st=get_model("clinic.setting").browse(1)
|
||||
for line in st.levels:
|
||||
level=line.level_id
|
||||
st_levels[level.id]={
|
||||
'var_a': line.var_a or 0,
|
||||
'var_b': line.var_b or 0,
|
||||
'op': line.op or "",
|
||||
'formular': line.formular or "",
|
||||
}
|
||||
lines=[]
|
||||
total_a,total_b=0,0
|
||||
for level_id, value in levels.items():
|
||||
qty=value['total']
|
||||
st_level=st_levels.get(level_id,None)
|
||||
a,b=0,0
|
||||
state="fail"
|
||||
if st_level:
|
||||
state="success"
|
||||
var_a=float(st_level['var_a'] or "0")
|
||||
var_b=float(st_level['var_b'] or "0")
|
||||
fml_org=st_level['formular']
|
||||
a=qty*var_a
|
||||
a_str='%sX'%(a)
|
||||
total_a+=a
|
||||
|
||||
op=st_level['op']
|
||||
sign=op=='-' and -1 or 1
|
||||
op_str=sign==1 and op or ""
|
||||
|
||||
b=(qty*var_b)*sign
|
||||
b_str=(str(b) if b else "")
|
||||
total_b+=b
|
||||
else:
|
||||
# XXX prevent to show all level if not configuration from setting
|
||||
continue
|
||||
|
||||
fml=''.join([a_str, op_str, b_str])
|
||||
lines.append(('create',{
|
||||
'level_id': level_id,
|
||||
'var_a': a,
|
||||
'var_b': b,
|
||||
'qty': qty,
|
||||
'formular_org': fml_org,
|
||||
'formular': fml if qty else "0",
|
||||
'state': state,
|
||||
}))
|
||||
|
||||
if not obj.manual:
|
||||
var_pt=len(obj.hd_cases)
|
||||
var_ptx=var_pt*(obj.var_k or 0)
|
||||
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))
|
||||
for line in lines:
|
||||
vals=line[1]
|
||||
fml=vals['formular'].replace("X","*%s")
|
||||
vals['amount']=0
|
||||
if vals['var_a'] or vals['var_b']:
|
||||
vals['amount']=eval(fml%var_x)
|
||||
else:
|
||||
# update qty (a)
|
||||
lines=[]
|
||||
for line in obj.lines:
|
||||
level=line.level_id
|
||||
qty=line.qty or 0
|
||||
st_level=st_levels.get(level.id,None)
|
||||
a,b=0,0
|
||||
state="fail"
|
||||
if st_level:
|
||||
state="success"
|
||||
var_a=float(st_level['var_a'] or "0")
|
||||
var_b=float(st_level['var_b'] or "0")
|
||||
fml_org=st_level['formular']
|
||||
a=qty*var_a
|
||||
a_str='%sX'%(a)
|
||||
|
||||
op=st_level['op']
|
||||
sign=op=='-' and -1 or 1
|
||||
op_str=sign==1 and op or ""
|
||||
|
||||
b=(qty*var_b)*sign
|
||||
b_str=(str(b) if b else "")
|
||||
else:
|
||||
print("not found in setting ", level.id)
|
||||
|
||||
fml=''.join([a_str, op_str, b_str])
|
||||
lines.append(('write',[line.id],{
|
||||
'level_id': level.id,
|
||||
'var_a': a,
|
||||
'var_b': b,
|
||||
'qty': qty,
|
||||
'formular': fml if qty else "0",
|
||||
'formular_org': fml_org,
|
||||
'state': state,
|
||||
}))
|
||||
|
||||
obj.write({
|
||||
'lines': lines,
|
||||
})
|
||||
|
||||
if obj.manual:
|
||||
for line in obj.lines:
|
||||
fml=(line.formular or "").replace("X","*%s")
|
||||
if line.var_a or line.var_b:
|
||||
amt=eval(fml%obj.var_x)
|
||||
else:
|
||||
amt=0
|
||||
line.write({
|
||||
'amount': amt,
|
||||
})
|
||||
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_cycle_item',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash':'Compute successfully',
|
||||
}
|
||||
|
||||
def onchange_nurse(self,context={}):
|
||||
data=context["data"]
|
||||
path=context["path"]
|
||||
|
|
|
@ -8,6 +8,7 @@ class Hospital(Model):
|
|||
_fields={
|
||||
"code": fields.Char("Code",required=True,search=True),
|
||||
"name": fields.Char("Name",required=True,search=True),
|
||||
"addresses": fields.One2Many("address","related_id","Addresses"),
|
||||
}
|
||||
|
||||
def name_get(self,ids,context={}):
|
||||
|
|
|
@ -161,8 +161,6 @@ class ImportPayment(Model):
|
|||
return ''.join(h for h in hn if h.isdigit())
|
||||
|
||||
def import_payment_pks(self,ids,context={}):
|
||||
#fmt='%Y-%m-%d %H:%M:%S'
|
||||
#start_time=time.strftime(fmt)
|
||||
obj=self.browse(ids)[0]
|
||||
fname=obj.file
|
||||
fpath=get_file_path(fname)
|
||||
|
|
|
@ -0,0 +1,198 @@
|
|||
from netforce.model import Model, fields, get_model
|
||||
|
||||
class LaborCost(Model):
|
||||
_name="clinic.labor.cost"
|
||||
_string="Labor Cost"
|
||||
_name_field="cycle_item_id"
|
||||
_key=['cycle_item_id']
|
||||
|
||||
def _get_all(self,ids,context={}):
|
||||
res={}
|
||||
for obj in self.browse(ids):
|
||||
hd_cases=obj.cycle_item_id.hd_cases or []
|
||||
total_case=len(hd_cases)
|
||||
total_a,total_b=0,0
|
||||
total=0.0
|
||||
for line in obj.lines:
|
||||
total+=line.amount or 0
|
||||
total_a+=line.var_a or 0
|
||||
total_b+=line.var_b or 0
|
||||
var_ptx=total_case*(obj.var_k or 0)
|
||||
var_fml1='PTxK=%sX%s'%(total_a,total_b)
|
||||
total_bstr=total_b < 0 and "+%s"%(abs(total_b)) or "-%s"%total_b
|
||||
var_x=0.0
|
||||
if total_a:
|
||||
var_x=eval('(%s%s)/%s'%(var_ptx,total_bstr,total_a))
|
||||
res[obj.id]={
|
||||
'var_pt': total_case,
|
||||
'var_ptx': total_case*(obj.var_k or 0),
|
||||
'var_fml1': '%s'%(var_fml1),
|
||||
'var_fml2': '%s=%sX%s'%(var_ptx,total_a,total_b),
|
||||
'var_fml3': '(%s%s)/%s'%(var_ptx,total_bstr,total_a),
|
||||
'var_x': round(var_x,2),
|
||||
'total': total,
|
||||
}
|
||||
return res
|
||||
|
||||
_fields={
|
||||
"cycle_item_id": fields.Many2One("clinic.cycle.item","Cycle Item",required=True),
|
||||
'var_k': fields.Float("K"),
|
||||
'var_pt': fields.Integer("PT", function="_get_all",function_multi=True),
|
||||
'var_ptx': fields.Char("PT x K:", function="_get_all",function_multi=True),
|
||||
'var_fml1': fields.Char("Step 1:",function="_get_all",function_multi=True),
|
||||
'var_fml2': fields.Char("Step 2:",function="_get_all",function_multi=True),
|
||||
'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",function="_get_all",function_multi=True),
|
||||
'manual': fields.Boolean("Manual"),
|
||||
"formulars": fields.One2Many("clinic.labor.cost.formular", "labor_cost_id", "Formulars"),
|
||||
"staffs": fields.One2Many("clinic.labor.cost.staff", "labor_cost_id", "Staffs"),
|
||||
"lines": fields.One2Many("clinic.labor.cost.line", "labor_cost_id", "Lines"),
|
||||
}
|
||||
|
||||
def compute(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
if not obj.manual:
|
||||
for fline in obj.formulars:
|
||||
fline.delete()
|
||||
|
||||
levels={}
|
||||
for level_id in get_model('clinic.staff.level').search([['type','=','nurse']]):
|
||||
vals={
|
||||
level_id: {
|
||||
'total': 0,
|
||||
}
|
||||
}
|
||||
levels.update(vals)
|
||||
item=obj.cycle_item_id
|
||||
|
||||
for ns in item.nurses:
|
||||
level=ns.level_id
|
||||
if not level:
|
||||
raise Exception("Please specify level for %s"%ns.nurse_id.name)
|
||||
levels[level.id]['total']+=1
|
||||
|
||||
st_levels={}
|
||||
st=get_model("clinic.setting").browse(1)
|
||||
for line in st.levels:
|
||||
level=line.level_id
|
||||
st_levels[level.id]={
|
||||
'var_a': line.var_a or 0,
|
||||
'var_b': line.var_b or 0,
|
||||
'op': line.op or "",
|
||||
'formular': line.formular or "",
|
||||
}
|
||||
formulars=[]
|
||||
total_a,total_b=0,0
|
||||
for level_id, value in levels.items():
|
||||
qty=value['total']
|
||||
st_level=st_levels.get(level_id,None)
|
||||
a,b=0,0
|
||||
state="fail"
|
||||
if st_level:
|
||||
state="success"
|
||||
var_a=float(st_level['var_a'] or "0")
|
||||
var_b=float(st_level['var_b'] or "0")
|
||||
fml_org=st_level['formular']
|
||||
a=qty*var_a
|
||||
a_str='%sX'%(a)
|
||||
total_a+=a
|
||||
|
||||
op=st_level['op']
|
||||
sign=op=='-' and -1 or 1
|
||||
op_str=sign==1 and op or ""
|
||||
|
||||
b=(qty*var_b)*sign
|
||||
b_str=(str(b) if b else "")
|
||||
total_b+=b
|
||||
else:
|
||||
# XXX prevent to show all level if not configuration from setting
|
||||
continue
|
||||
|
||||
fml=''.join([a_str, op_str, b_str])
|
||||
formulars.append(('create',{
|
||||
'level_id': level_id,
|
||||
'var_a': a,
|
||||
'var_b': b,
|
||||
'qty': qty,
|
||||
'formular_org': fml_org,
|
||||
'formular': fml if qty else "0",
|
||||
'state': state,
|
||||
}))
|
||||
|
||||
if not obj.manual:
|
||||
var_pt=len(item.hd_cases)
|
||||
var_ptx=var_pt*(obj.var_k or 0)
|
||||
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))
|
||||
for fline in formulars:
|
||||
vals=fline[1]
|
||||
fml=vals['formular'].replace("X","*%s")
|
||||
vals['amount']=0
|
||||
if vals['var_a'] or vals['var_b']:
|
||||
vals['amount']=eval(fml%var_x)
|
||||
else:
|
||||
# update qty (a)
|
||||
formulars=[]
|
||||
for fline in obj.formulars:
|
||||
level=fline.level_id
|
||||
qty=fline.qty or 0
|
||||
st_level=st_levels.get(level.id,None)
|
||||
a,b=0,0
|
||||
state="fail"
|
||||
if st_level:
|
||||
state="success"
|
||||
var_a=float(st_level['var_a'] or "0")
|
||||
var_b=float(st_level['var_b'] or "0")
|
||||
fml_org=st_level['formular']
|
||||
a=qty*var_a
|
||||
a_str='%sX'%(a)
|
||||
|
||||
op=st_level['op']
|
||||
sign=op=='-' and -1 or 1
|
||||
op_str=sign==1 and op or ""
|
||||
|
||||
b=(qty*var_b)*sign
|
||||
b_str=(str(b) if b else "")
|
||||
else:
|
||||
print("not found in setting ", level.id)
|
||||
|
||||
fml=''.join([a_str, op_str, b_str])
|
||||
formulars.append(('write',[fline.id],{
|
||||
'level_id': level.id,
|
||||
'var_a': a,
|
||||
'var_b': b,
|
||||
'qty': qty,
|
||||
'formular': fml if qty else "0",
|
||||
'formular_org': fml_org,
|
||||
'state': state,
|
||||
}))
|
||||
|
||||
obj.write({
|
||||
'formulars': formulars,
|
||||
})
|
||||
|
||||
if obj.manual:
|
||||
for fline in obj.formulars:
|
||||
fml=(fline.formular or "").replace("X","*%s")
|
||||
if fline.var_a or fline.var_b:
|
||||
amt=eval(fml%obj.var_x)
|
||||
else:
|
||||
amt=0
|
||||
fline.write({
|
||||
'amount': amt,
|
||||
})
|
||||
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_labor_cost',
|
||||
'mode': 'form',
|
||||
'active_id': obj.id,
|
||||
},
|
||||
'flash':'Compute successfully',
|
||||
}
|
||||
|
||||
|
||||
LaborCost.register()
|
|
@ -0,0 +1,27 @@
|
|||
from netforce.model import Model, fields
|
||||
from netforce.access import get_active_company
|
||||
|
||||
class LaborCostFormular(Model):
|
||||
_name="clinic.labor.cost.formular"
|
||||
_string="Labor Cost Formular"
|
||||
_name_field="labor_cost_id"
|
||||
|
||||
_fields={
|
||||
"labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True),
|
||||
'level_id': fields.Many2One("clinic.staff.level", "Level",domain=[['type','=','nurse']]),
|
||||
'qty': fields.Integer("Qty"),
|
||||
'var_a': fields.Float("A"),
|
||||
'var_b': fields.Float("B"),
|
||||
'formular_org': fields.Char("FML1 (Setting)", size=100),
|
||||
'formular': fields.Char("FML2", size=100),
|
||||
'rate': fields.Float("Rate"),
|
||||
'amount': fields.Float("Result",scale=2),
|
||||
'company_id': fields.Many2One('company','Company'),
|
||||
"state": fields.Selection([["fail","Fail"],["success","Success"]],"Status",),
|
||||
}
|
||||
|
||||
_defaults={
|
||||
"company_id": lambda *a: get_active_company(),
|
||||
}
|
||||
|
||||
LaborCostFormular.register()
|
|
@ -0,0 +1,22 @@
|
|||
from netforce.model import Model, fields
|
||||
from netforce.access import get_active_company
|
||||
|
||||
class LaborCostLine(Model):
|
||||
_name="clinic.labor.cost.line"
|
||||
_string="Labor Cost Line"
|
||||
_name_field="labor_cost_id"
|
||||
|
||||
_fields={
|
||||
"labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True),
|
||||
'staff_id': fields.Many2One("clinic.staff", "Staff"),
|
||||
'level_id': fields.Many2One("clinic.staff.level", "Level"),
|
||||
'qty': fields.Integer("Qty"),
|
||||
'amount': fields.Float("Amount",scale=2),
|
||||
'company_id': fields.Many2One('company','Company'),
|
||||
}
|
||||
|
||||
_defaults={
|
||||
"company_id": lambda *a: get_active_company(),
|
||||
}
|
||||
|
||||
LaborCostLine.register()
|
|
@ -0,0 +1,20 @@
|
|||
from netforce.model import Model, fields
|
||||
from netforce.access import get_active_company
|
||||
|
||||
class LaborCostStaff(Model):
|
||||
_name="clinic.labor.cost.staff"
|
||||
_string="Labor Cost Staff"
|
||||
_name_field="labor_cost_id"
|
||||
|
||||
_fields={
|
||||
"labor_cost_id": fields.Many2One("clinic.labor.cost","Cycle Item",required=True),
|
||||
'staff_id': fields.Many2One("clinic.staff", "Staff"),
|
||||
'level_id': fields.Many2One("clinic.staff.level", "Level"),
|
||||
'company_id': fields.Many2One('company','Company'),
|
||||
}
|
||||
|
||||
_defaults={
|
||||
"company_id": lambda *a: get_active_company(),
|
||||
}
|
||||
|
||||
LaborCostStaff.register()
|
Loading…
Reference in New Issue