doctor cost

conv_bal
watcha.h 2014-10-26 22:17:56 +07:00
parent eca7ccf320
commit 26e8119935
14 changed files with 175 additions and 133 deletions

View File

@ -1,7 +1,7 @@
<action>
<field name="string">Nurse Categories</field>
<field name="string">Personal Categories</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.nurse.categ</field>
<field name="model">clinic.personal.categ</field>
<field name="modes">list,page,form</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -9,25 +9,48 @@
</head>
<field name="cycle_id" required="1"/>
<field name="date"/>
<field name="var_k"/>
<field name="var_x"/>
<field name="total_pt"/>
<field name="lines" nolabel="1">
<list>
<field name="nurse_categ" readonly="1"/>
<field name="formular" readonly="1"/>
<field name="qty" onchange="onchange_line"/>
<field name="rate" onchange="onchange_line"/>
<field name="amount"/>
</list>
</field>
<group span="8" columns="1">
</group>
<group span="4" columns="1">
<field name="total"/>
<field name="total_amount"/>
<field name="total_balance"/>
</group>
<tabs>
<tab string="Nurse Service">
<field name="var_k"/>
<field name="var_x"/>
<field name="total_pt"/>
<field name="nurse_lines" nolabel="1">
<list>
<field name="personal_categ" domain="[['type','=','nurse']]"/>
<field name="description"/>
<field name="formular"/>
<field name="qty" onchange="onchange_line"/>
<field name="rate" onchange="onchange_line"/>
<field name="amount"/>
</list>
</field>
<group span="8" columns="1">
</group>
<group span="4" columns="1">
<field name="total"/>
<field name="total_amount"/>
<field name="total_balance"/>
</group>
</tab>
<tab string="Doctor Service">
<field name="var_doctor"/>
<field name="doctor_lines" nolabel="1">
<list>
<field name="personal_categ" domain="[['type','=','doctor']]"/>
<field name="description"/>
<field name="formular"/>
<field name="qty" onchange="onchange_line"/>
<field name="rate" onchange="onchange_line"/>
<field name="amount"/>
</list>
</field>
<group span="8" columns="1">
</group>
<group span="4" columns="1">
<field name="total2"/>
</group>
</tab>
</tabs>
<foot>
<button string="Compute" type="default" icon="refresh" method="compute" states="draft"/>
</foot>

View File

@ -15,6 +15,7 @@
<field name="expiry_card"/>
<field name="birthday"/>
<field name="department_id"/>
<field name="categ_id"/>
</group>
<group span="6" columns="1">
<field name="picture"/>

View File

@ -5,7 +5,7 @@
<item string="Nurses" action="clinic_nurse"/>
<divider/>
<header string="CATEGORIES"/>
<item string="Nurse Categories" action="clinic_nurse_categ"/>
<item string="Personal Categories" action="clinic_personal_categ"/>
</item>
<item string="Patients">
<item string="Patients" action="clinic_patient"/>

View File

@ -1,6 +1,7 @@
<form model="clinic.nurse.categ">
<form model="clinic.personal.categ">
<field name="code"/>
<field name="name"/>
<field name="type"/>
<field name="formular"/>
<field name="sequence"/>
</form>

View File

@ -1,6 +1,7 @@
<list model="clinic.nurse.categ">
<list model="clinic.personal.categ">
<field name="code"/>
<field name="name"/>
<field name="type"/>
<field name="formular"/>
<field name="sequence"/>
</list>

View File

@ -1,53 +0,0 @@
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_x(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
res[obj.id]=x
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_x"),
"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]
vals={
'lines': [],
}
for nurse_categ in get_model("clinic.nurse.categ").search_browse([]):
vals['lines'].append(('create',{
'nurse_categ': nurse_categ.id,
'formular': nurse_categ.formular or "",
'qty': 1,
}))
pass
obj.write(vals)
CycleItem.register()

View File

@ -7,7 +7,6 @@ from . import graduation
from . import morbidity
from . import nation
from . import nurse
from . import nurse_categ
from . import address
from . import patient
from . import patient_cause_line
@ -43,3 +42,4 @@ from . import import_data_sc
from . import translate
from . import payment
from . import account_payment
from . import personal_categ

View File

@ -19,14 +19,18 @@ class CycleItem(Model):
pt_k=pt*k
x=(pt_k + 1275)/13.5
total=0.0
for line in obj.lines:
for line in obj.nurse_lines:
total+=line.amount
total2=0.0
for line in obj.doctor_lines:
total2+=line.amount
res[obj.id]={
'name': name,
'var_x': x,
'total_pt': hd_total,
'total_amount': hd_total*k,
'total': total,
'total2': total2,
'total_balance': (hd_total*k)-total,
}
return res
@ -42,9 +46,12 @@ class CycleItem(Model):
'total_amount': fields.Float("PT*K", function="_get_all",function_multi=True),
'total_balance': fields.Float("Total Balance", function="_get_all",function_multi=True),
'total': fields.Float("Total", function="_get_all",function_multi=True),
'total2': 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'),
'nurse_lines': fields.One2Many('clinic.cycle.item.line', 'cycle_item_id', 'Nurse Lines',domain=[['type','=','nurse']]),
'doctor_lines': fields.One2Many('clinic.cycle.item.line', 'cycle_item_id', 'Doctor Lines',domain=[['type','=','doctor']]),
'var_doctor': fields.Float("K Doctor"),
}
_defaults={
@ -52,43 +59,70 @@ class CycleItem(Model):
'company_id': lambda *a: get_active_company(),
'date': lambda *a: time.strftime("%Y-%m-%d"),
'var_k': 450,
'var_doctor': 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={}
vals={
'nurse_lines': [],
'doctor_lines': [],
}
nurse_dict={}
doctor_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
if not nurse_dict.get(nurse_code):
nurse_dict[nurse_code]=0
nurse_dict[nurse_code]+=1
for line in obj.lines:
doctor_categ=hd_case.doctor_id.categ_id or ""
if not doctor_categ:
continue
doctor_name=hd_case.doctor_id.name or ""
key=(doctor_categ,doctor_name)
if not doctor_dict.get(key):
doctor_dict[key]=0
doctor_dict[key]+=1
for line in obj.nurse_lines:
line.delete()
for line in obj.doctor_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,
for k, v in doctor_dict.items():
categ=k[0]
name=k[1]
qty=v
vals['doctor_lines'].append(('create',{
'personal_categ': categ.id,
'description': name,
'type': 'doctor',
'formular': categ.formular,
'qty': qty,
'rate': obj.var_doctor or 0.0,
}))
print(nurse_dict)
for personal_categ in get_model("clinic.personal.categ").search_browse([]):
if personal_categ.type=='nurse':
formular=personal_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['nurse_lines'].append(('create',{
'personal_categ': personal_categ.id,
'type': 'nurse',
'formular': formular,
'qty': nurse_dict.get(personal_categ.code,0),
'rate': rate,
}))
obj.write(vals)
return {
@ -107,7 +141,7 @@ class CycleItem(Model):
#qty=line.get("qty")
#rate=line.get("rate")
total=0.0
for line in data['lines']:
for line in data['nurse_lines']:
line['amount']=(line['qty'] or 0) * (line['rate'] or 0.0)
total+=line['amount']
print(line)
@ -132,16 +166,27 @@ class CycleItem(Model):
'related_id': "clinic.cycle.item,%s"%obj.id,
'direct_lines': [],
}
for line in obj.lines:
for line in obj.nurse_lines:
if not line.amount:
continue
vals['direct_lines'].append(('create',{
'description': 'Payment; %s'%line.nurse_categ.name,
'description': 'Payment; %s'%line.personal_categ.name,
'account_id': account_id,
'qty': 1,
'unit_price': line.amount,
'amount': line.amount,
}))
for line in obj.doctor_lines:
if not line.amount:
continue
vals['direct_lines'].append(('create',{
'description': 'Payment; %s'%line.description,
'account_id': account_id,
'qty': line.qty,
'unit_price': line.amount,
'amount': line.amount,
}))
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
get_model("account.payment").browse(payment_id).post()
obj.write({

View File

@ -15,8 +15,10 @@ class CycleItemLine(Model):
_fields={
'cycle_item_id': fields.Many2One("clinic.cycle.item", "Cycle Item"),
'nurse_categ': fields.Many2One("clinic.nurse.categ", "Nurse Category"),
"type": fields.Selection([("doctor","Doctor"),("nurse","Nurse")],"Personal Type",required=True),
'personal_categ': fields.Many2One("clinic.personal.categ", "Nurse Category",),
'formular': fields.Char("Formular", size=100),
'description': fields.Char("Description"),
'qty': fields.Integer("Qty"),
'rate': fields.Float("Rate"),
'amount': fields.Float("Amount",function="all_amount", function_multi=True),

View File

@ -44,6 +44,7 @@ class Doctor(Model):
"user_id": fields.Many2One("base.user","User"),
'picture': fields.File("Picture"),
'note': fields.Text("Note"),
'categ_id': fields.Many2One("clinic.personal.categ", "Doctor Category", domain=[['type','=','doctor']]),
}

View File

@ -44,7 +44,7 @@ class Nurse(Model):
"user_id": fields.Many2One("base.user","User"),
'picture': fields.File("Picture"),
'note': fields.Text("Note"),
'categ_id': fields.Many2One("clinic.nurse.categ","Category"),
'categ_id': fields.Many2One("clinic.personal.categ", "Nurse Category", domain=[['type','=','nurse']]),
}
def _get_number(self,context={}):

View File

@ -1,22 +0,0 @@
from netforce.model import Model, fields
from netforce.access import get_active_company
class NurseCateg(Model):
_name="clinic.nurse.categ"
_string="Nurse Categ"
_fields={
"name": fields.Char("Name",required=True,search=True),
"code": fields.Char("Code",required=True,search=True),
'formular': fields.Text("Formular"),
'sequence': fields.Integer("Sequence"),
}
_defaults={
"company_id": lambda *a: get_active_company(),
'sequence': 0,
}
_order="sequence"
NurseCateg.register()

View File

@ -0,0 +1,43 @@
from netforce.model import Model, fields
from netforce.access import get_active_company
class NurseCateg(Model):
_name="clinic.personal.categ"
_string="Personal Category"
_fields={
"name": fields.Char("Name",required=True,search=True),
"code": fields.Char("Code",required=True,search=True),
'formular': fields.Text("Formular"),
'sequence': fields.Integer("Sequence"),
"type": fields.Selection([("doctor","Doctor"),("nurse","Nurse")],"Personal Type",required=True),
}
_defaults={
"company_id": lambda *a: get_active_company(),
'sequence': 0,
'type': 'doctor',
}
_order="sequence"
def name_get(self,ids,context={}):
vals=[]
for obj in self.browse(ids):
name="%s [%s]"%(obj.name,obj.code or "")
vals.append((obj.id,name))
return vals
def name_search(self,name,domain=None,context={},**kw):
dom=[["name","ilike","%"+name+"%"]]
if domain:
dom=[dom,domain]
ids1=self.search(dom)
dom=[["code","ilike","%"+name+"%"]]
if domain:
dom=[dom,domain]
ids2=self.search(dom)
ids=list(set(ids1+ids2))
return self.name_get(ids,context=context)
NurseCateg.register()