97 lines
3.3 KiB
Python
97 lines
3.3 KiB
Python
|
import time
|
||
|
|
||
|
from netforce.model import Model, fields, get_model
|
||
|
from netforce.access import get_active_company
|
||
|
|
||
|
class CycleItem(Model):
|
||
|
_name="clinic.cycle.item"
|
||
|
_string="Cycle Item"
|
||
|
|
||
|
def _get_all(self,ids,context):
|
||
|
res={}
|
||
|
for obj in self.browse(ids):
|
||
|
hd_total=len([hd_case for hd_case in obj.hd_cases if hd_case.state=='completed']) # XXX
|
||
|
pt=(hd_total or 0.0)
|
||
|
k=(obj.var_k or 0.0)
|
||
|
pt_k=pt*k
|
||
|
x=(pt_k + 1275)/13.5
|
||
|
total=0.0
|
||
|
for line in obj.lines:
|
||
|
total+=line.amount
|
||
|
res[obj.id]={
|
||
|
'var_x': x,
|
||
|
'total_pt': hd_total,
|
||
|
'total_amount': hd_total*k,
|
||
|
'total': total,
|
||
|
}
|
||
|
return res
|
||
|
|
||
|
_fields={
|
||
|
'company_id': fields.Many2One("company", "Company"),
|
||
|
'cycle_id': fields.Many2One("clinic.cycle", "Cycle",search=True),
|
||
|
'date': fields.Date("Date",search=True),
|
||
|
'var_k': fields.Float("K"),
|
||
|
'var_x': fields.Float("X", function="_get_all",function_multi=True),
|
||
|
'total_pt': fields.Float("PT", function="_get_all",function_multi=True),
|
||
|
'total_amount': fields.Float("PT*K", function="_get_all",function_multi=True),
|
||
|
'total': fields.Float("Total", function="_get_all",function_multi=True),
|
||
|
"state": fields.Selection([("draft","Draft"),("done","Done")],"Status",required=True),
|
||
|
'hd_cases': fields.One2Many("clinic.hd.case","cycle_item_id", "HD Cases"),
|
||
|
'lines': fields.One2Many('clinic.cycle.item.line', 'cycle_item_id', 'Lines'),
|
||
|
}
|
||
|
|
||
|
_defaults={
|
||
|
'state': 'draft',
|
||
|
'company_id': lambda *a: get_active_company(),
|
||
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
||
|
'var_k': 450,
|
||
|
}
|
||
|
|
||
|
def compute(self,ids,context={}):
|
||
|
for obj in self.browse(ids):
|
||
|
#nurer_categ_ids=[line.nurse_categ.id for line in obj.lines]
|
||
|
# XXX
|
||
|
vals_dict={}
|
||
|
for hd_case in obj.hd_cases:
|
||
|
if hd_case.state=='completed':
|
||
|
nurse_code=hd_case.nurse_id.categ_id.code or ""
|
||
|
print("nurse_code ", nurse_code)
|
||
|
if not vals_dict.get(nurse_code):
|
||
|
vals_dict[nurse_code]=0
|
||
|
vals_dict[nurse_code]+=1
|
||
|
|
||
|
for line in obj.lines:
|
||
|
line.delete()
|
||
|
|
||
|
vals={
|
||
|
'lines': [],
|
||
|
}
|
||
|
print(vals_dict)
|
||
|
for nurse_categ in get_model("clinic.nurse.categ").search_browse([]):
|
||
|
formular=nurse_categ.formular or ""
|
||
|
rate=0
|
||
|
try:
|
||
|
var_x="%s"%(round(obj.var_x,2))
|
||
|
formulared=formular.replace("x",var_x)
|
||
|
rate=eval(formulared)
|
||
|
except:
|
||
|
rate=0
|
||
|
vals['lines'].append(('create',{
|
||
|
'nurse_categ': nurse_categ.id,
|
||
|
'formular': formular,
|
||
|
'qty': vals_dict.get(nurse_categ.code,0),
|
||
|
'rate': rate,
|
||
|
}))
|
||
|
obj.write(vals)
|
||
|
|
||
|
return {
|
||
|
'next': {
|
||
|
'name': 'clinic_cycle_item',
|
||
|
'mode': 'form',
|
||
|
'active_id': obj.id,
|
||
|
},
|
||
|
'flash': 'Compute OK',
|
||
|
}
|
||
|
|
||
|
CycleItem.register()
|