conv_bal
watcha.h 2014-10-03 02:12:52 +07:00
parent 31f10ca9c2
commit ab985439eb
12 changed files with 218 additions and 77 deletions

View File

@ -1,8 +1,8 @@
<action>
<field name="string">HD Cases</field>
<field name="string">HD Case Treatments</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.hd.case</field>
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["Confirmed",[["state","=","confirmed"]]],["Approved",[["state","=","approved"]]],["Validated",[["state","=","validated"]]],["Paid",[["state","=","paid"]]],["Cancelled",[["state","=","cancelled"]]]]</field>
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["Confirmed",[["state","=","confirmed"]]],["Approved",[["state","=","approved"]]],["Paid",[["state","=","paid"]]],["Cancelled",[["state","=","cancelled"]]]]</field>
<field name="modes">list,form</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -23,8 +23,8 @@
</group>
<foot>
<button string="Confirm" type="success" states="new" method="confirm"/>
<button string="Drop" type="danger" states="active" method="drop"/>
<button string="Cancel" type="default" states="active" method="cancel"/>
<button string="Drop" type="warning" states="active" method="drop"/>
<button string="Cancel" type="danger" states="active" method="cancel"/>
<button string="Renew" type="success" states="cancelled" method="renew"/>
</foot>
<related>

View File

@ -8,14 +8,15 @@
<group span="6" columns="1">
<field name="number"/>
<field name="date_start"/>
<field name="date_stop"/>
<field name="total_time"/>
<field name="department_id"/>
<field name="visit_id"/>
</group>
<group span="6" columns="1">
<field name="patient_id" onchange="onchange_patient"/>
<field name="date_stop"/>
<field name="doctor_id"/>
<field name="nurse_id"/>
<field name="department_id"/>
</group>
<tabs>
<tab string="Treatment Information">
@ -28,10 +29,10 @@
<field name="hct"/>
</tab>
</tabs>
<field name="lines" nolabel="1">
<field name="dialyzers" count="1" nolabel="1">
<list>
<field name="dialzer_id" onchange="onchange_dialyzer"/>
<field name="detail"/>
<field name="dialyzer_id" onchange="onchange_dialyzer"/>
<field name="description"/>
<field name="member_type"/>
<field name="dialyzer_type"/>
<field name="bid_flow_rate"/>
@ -41,7 +42,7 @@
<field name="state"/>
</list>
</field>
<field name="lines_detail" nolabel="1">
<field name="lines" count="4" nolabel="1">
<list>
<field name="product_id" onchange="onchange_product"/>
<field name="detail"/>
@ -51,20 +52,22 @@
<field name="total"/>
</list>
</field>
<group span="6" columns="1">
<field name="fee" onchange="onchange_product"/>
<!--<field name="include_fee" offset="1"/>-->
<group span="4" columns="1">
<field name="fee"/>
<!--<field name="fee_type" onchange="onchange_fee_type"/>-->
<field name="fee_partner_id" attrs='{"required":[["fee","!=",0]]}'/>
</group>
<group span="6" columns="1">
<group span="4" columns="1">
</group>
<group span="4" columns="1">
<field name="total"/>
<field name="amount"/>
</group>
<foot>
<button string="Confirm" type="success" method="confirmed" states="draft" />
<button string="Approve" type="success" method="approved" states="confirmed"/>
<button string="Confirm" type="success" method="confirm" states="draft" />
<button string="Approve" type="success" method="approve" states="confirmed"/>
<button string="Validate" type="success" method="validate" states="approved" />
<button string="Pay" type="success" method="paid" states="validated" />
<button string="Cancel" type="danger" method="cancelled" confirm="Are you sure to cancel this HD case?"/>
</foot>
<related>
<field name="invoices" click_action="view_invoice"/>

View File

@ -6,7 +6,8 @@
</button>
</head>
<field name="number"/>
<field name="type" onchange="onchange_type"/>
<!--<field name="type" onchange="onchange_type"/>-->
<field name="type"/>
<field name="name"/>
<field name="reg_date"/>
<field name="job"/>

View File

@ -3,7 +3,7 @@
<field name="state"/>
<button string="Print" icon="print" action="print_visit"/>
<button string="Options" dropdown="1">
<item string="Send Confirm visit"/>
<item string="Copy" method="copy"/>
</button>
</head>
<tabs>
@ -12,6 +12,7 @@
<field name="number"/>
<field name="visit_date"/>
<field name="cycle"/>
<field name="time_use"/>
</group>
<group span="6" columns="1">
<field name="department_id"/>

View File

@ -8,8 +8,8 @@ from . import doctor
from . import nurse
from . import visit
from . import hd_case
from . import hd_case_dialyzer
from . import hd_case_line
from . import hd_case_line_detail
from . import dialyzer
from . import department
from . import education

View File

@ -1,6 +1,8 @@
import time
from datetime import datetime
from netforce.model import Model, fields, get_model
from netforce.utils import get_data_path
import time
from netforce.access import get_active_user,set_active_user
from netforce.access import get_active_company
@ -10,6 +12,16 @@ class HDcase(Model):
_audit_log=True
_name_field="number"
_multi_company=True
def get_hrs(self,ids,context={}):
res={}
fmt="%Y-%m-%d %H:%M:%S"
for obj in self.browse(ids):
diff=datetime.strptime(obj.date_stop,fmt)-datetime.strptime(obj.date_start,fmt)
total_time=round(diff.seconds/3600,2)
res[obj.id]=total_time
return res
_fields={
"number": fields.Char("Number",required=True,search=True),
"patient_id": fields.Many2One("clinic.patient","Patient",required=True,search=True),
@ -25,12 +37,12 @@ class HDcase(Model):
"bp_stop": fields.Integer("BP mmHG stop"),
"per_bp_stop": fields.Integer("/Per stop"),
"hct": fields.Integer("HCT %"),
"state": fields.Selection([("draft","Draft"),("approved","Approved"),("confirmed","Confirmed"),("validated","Validated"),("cancelled","Cancelled"),("paid","Paid")],"Status",required=True),
"lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Details"),
"lines_detail": fields.One2Many("clinic.hd.case.line.detail","hd_case_id","Detail"),
"state": fields.Selection([("draft","Draft"),("confirmed","Confirmed"),("approved","Approved"),("cancelled","Cancelled"),("paid","Paid")],"Status",required=True),
"dialyzers": fields.One2Many("clinic.hd.case.dialyzer","hd_case_id","Dializers"),
"lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"),
"comments": fields.One2Many("message","related_id","Comments"),
"company_id": fields.Many2One("company","Company"),
"fee": fields.Float("HD Fee",required=True),
"fee": fields.Float("HD Fee"),
"amount": fields.Float("Amount",function="get_total",readonly=True,function_multi=True),
"total": fields.Float("Total",function="get_total",readonly=True,function_multi=True),
"reconcile_id": fields.Many2One("account.reconcile","Reconcile Id",readonly=True),
@ -38,7 +50,9 @@ class HDcase(Model):
"pickings": fields.One2Many("stock.picking","related_id","Pickings"),
"payments": fields.One2Many("account.payment","related_id","Payments"),
'visit_id': fields.Many2One("clinic.visit", "Visit"),
'include_fee': fields.Boolean("Include HD Fee"),
'total_time': fields.Integer("Total Time(Hrs)",function="get_hrs"),
"fee_type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)"),("personal","Personal"),("others","Others")],"Fee Type"),
'fee_partner_id': fields.Many2One("partner","Fee Contact"),
}
def _get_number(self,context={}):
@ -110,7 +124,12 @@ class HDcase(Model):
obj=self.browse(ids)[0]
obj.write({"state":"cancelled"})
def confirmed(self,ids,context={}):
def make_invoice(self,ids,context={}):
for obj in self.browse(ids):
if obj.fee:
pass
def confirm(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({"state":"confirmed"})
@ -118,6 +137,11 @@ class HDcase(Model):
obj=self.browse(ids)[0]
obj.write({"state":"paid"})
def approve(self,ids,context={}):
obj=self.browse(ids)[0]
obj.make_invoice()
obj.write({"state":"approved"})
def approved(self,ids,context={}):
for obj in self.browse(ids):
user_id=get_active_user()
@ -223,7 +247,7 @@ class HDcase(Model):
total=0
amt=0
fee=obj.fee or 0
for line in obj.lines_detail:
for line in obj.lines:
total+=line.total or 0
fee=0 # XXX
amt=total+fee
@ -244,7 +268,7 @@ class HDcase(Model):
def onchange_product(self,context={}):
data=context['data']
all_total=0.0
for line in data['lines_detail']:
for line in data['lines']:
qty=line['qty'] or 0
price=line['price'] or 0.0
total=qty*price
@ -256,4 +280,19 @@ class HDcase(Model):
data['amount']=all_total+fee_amt
return data
def delete(self,ids,context={}):
for obj in self.browse(ids):
if obj.state != 'draft':
raise Exception("Can not delete HD Case %s because state is not draft"%obj.number)
super().delete(ids)
def onchange_fee_type(self,context={}):
data=context['data']
fee_type=data.get("fee_type","")
if fee_type in ("mg","sc","nhso"):
data['fee']=1500
else:
data['fee']=0.0
return data
HDcase.register()

View File

@ -0,0 +1,19 @@
from netforce.model import Model, fields
class HdcaseDialyzer(Model):
_name="clinic.hd.case.dialyzer"
_fields={
"hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"),
"dialyzer_id": fields.Many2One("clinic.dialyzer","Dialzer",search=True),
"description": fields.Char("Description",search=True),
"use_time":fields.Integer("Use time"),
"max_use_time":fields.Integer("Max use time"),
"member_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Member Type",required=True),
"dialyzer_type": fields.Selection([("low","low flux"),("high","high flux"),("dbl","dbl hifulx")],"Member Type",required=True),
"bid_flow_rate": fields.Integer("Bid Flow Rate (ml/min)",required=True,search=True),
"ultrafittration": fields.Float("Ultrafittration Kg.",required=True,search=True),
"state":fields.Selection([("draft","New"),("active","Active"),("drop","Drop")],"Status"),
}
HdcaseDialyzer.register()

View File

@ -1,22 +1,16 @@
from netforce.model import Model, fields, get_model
from netforce.utils import get_data_path
import time
from netforce.access import get_active_user
from netforce.access import get_active_company
from netforce.model import Model, fields
class Hdcaseline(Model):
_name="clinic.hd.case.line"
_fields={
"hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"),
"dialzer_id": fields.Many2One("clinic.dialyzer","Dialzer",search=True),
"detail": fields.Char("description",search=True),
"use_time":fields.Integer("Use time"),
"max_use_time":fields.Integer("Max use time"),
"member_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Member Type",required=True),
"dialyzer_type": fields.Selection([("low","low flux"),("high","high flux"),("dbl","dbl hifulx")],"Member Type",required=True),
"bid_flow_rate": fields.Integer("Bid Flow Rate (ml/min)",required=True,search=True),
"ultrafittration": fields.Float("Ultrafittration Kg.",required=True,search=True),
"state":fields.Selection([("draft","New"),("active","Active"),("drop","Drop")],"Status DZ"),
"product_id": fields.Many2One("product","Product",search=True),
"detail": fields.Char("Description",search=True),
"qty":fields.Integer("QTY"),
"uom_id": fields.Many2One("uom","UOM",required=True,search=True),
"price":fields.Float("Price"),
"total":fields.Float("Total"),
}
Hdcaseline.register()

View File

@ -1,19 +0,0 @@
from netforce.model import Model, fields, get_model
from netforce.utils import get_data_path
import time
from netforce.access import get_active_user
from netforce.access import get_active_company
class HdcaselineDetail(Model):
_name="clinic.hd.case.line.detail"
_fields={
"hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"),
"product_id": fields.Many2One("product","Product",search=True),
"detail": fields.Char("Description",search=True),
"qty":fields.Integer("QTY"),
"uom_id": fields.Many2One("uom","UOM",required=True,search=True),
"price":fields.Float("Price"),
"total":fields.Float("Total"),
}
HdcaselineDetail.register()

View File

@ -139,7 +139,7 @@ class Patient(Model):
data['partner_id']=partner_id
return data
def create(self,vals,**kw):
def _create(self,vals,**kw):
obj_id=super(Patient,self).create(vals,**kw)
obj=self.browse(obj_id)
partner_id=self.get_partner_id(patient_type=obj.type,data={'name': obj.name})
@ -148,7 +148,34 @@ class Patient(Model):
})
return obj_id
def create(self,vals,**kw):
obj_id=super(Patient,self).create(vals,**kw)
obj=self.browse(obj_id)
partner_id=obj.partner_id
if not partner_id:
for partner in get_model("partner").search_browse([['name', '=', obj.name]]):
if partner.name==obj.name:
partner_id=partner.id
break
if not partner_id:
partner_id=get_model("partner").create({
'name': obj.name,
'last_name': obj.name,
'type': 'person',
})
obj.write({
'partner_id': partner_id,
})
return obj_id
def delete(self,ids,context={}):
partner_ids=[]
for obj in self.browse(ids):
partner_ids.append(obj.partner_id.id)
get_model("partner").delete(partner_ids)
super().delete(ids)
def _delete(self,ids,context={}):
partner_ids=[]
for obj in self.browse(ids):
if obj.type not in ("mg","nhso","sc"):
@ -156,11 +183,19 @@ class Patient(Model):
get_model("partner").delete(partner_ids)
super().delete(ids)
def _write(self,ids,vals,**kw):
partner_id=vals.get('partner_id')
if not partner_id:
obj=self.browse(ids[0])
vals['partner_id']=self.get_partner_id(patient_type=obj.type,data={'name': obj.name})
def write(self,ids,vals,**kw):
for obj in self.browse(ids):
if not obj.partner_id:
for partner in get_model("partner").search_browse([['name', '=', obj.name]]):
if partner.name==obj.name:
partner_id=partner.id
break
if not partner_id:
partner_id=get_model("partner").create({
'name': obj.name,
'type': 'person',
})
vals['partner_id']=partner_id
super().write(ids,vals,**kw)
Patient.register()

View File

@ -2,7 +2,7 @@ import time
import datetime
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company, get_active_user
from netforce.access import get_active_company, get_active_user, set_active_user
class Visit(Model):
_name="clinic.visit"
@ -21,17 +21,22 @@ class Visit(Model):
"state": fields.Selection([("pending","Pending"),("confirmed","Confirmed"),("cancelled","Cancelled")],"Status",required=True),
"comments": fields.One2Many("message","related_id","Comments"),
"company_id": fields.Many2One("company","Company"),
'time_use': fields.Integer("Time Use(hrs)"),
}
def _get_number(self,context={}):
while 1:
num=get_model("sequence").get_number("sale_order")
seq_id=get_model("sequence").find_sequence(name="Clinic Visit")
num=get_model("sequence").get_next_number(seq_id,context=context)
if not num:
return None
user_id=get_active_user()
set_active_user(1)
res=self.search([["number","=",num]])
set_active_user(user_id)
if not res:
return num
get_model("sequence").increment("sale_order")
get_model("sequence").increment_number(seq_id,context=context)
def _get_nurse(self,context={}):
user_id=get_active_user()
@ -48,9 +53,12 @@ class Visit(Model):
"number": _get_number,
"company_id": lambda *a: get_active_company(),
'nurse_id': _get_nurse,
'time_use': 1,
}
_order="date,cycle"
def get_dialyzer(self):
return
def confirm(self,ids,context={}):
obj=self.browse(ids)[0]
@ -59,11 +67,12 @@ class Visit(Model):
fmt_date="%Y-%m-%d %H:%M:%S"
timenow=dt.now().strftime("%H:%M:%S")
date_from=dt.strptime("%s %s"%(obj.visit_date,timenow),fmt_date)
to=3600
date_to=date_from+datetime.timedelta(seconds=to)
seconds=(obj.time_use or 1)*3600
date_to=date_from+datetime.timedelta(seconds=seconds)
date_to=date_to.strftime(fmt_date)
date_from=date_from.strftime(fmt_date)
hd_case_id=hd_case_obj.create({
include_fee=obj.patient_id.type in ('mg','sc','nhso') and True or False
vals={
'patient_id': obj.patient_id.id,
'doctor_id': obj.doctor_id.id,
'nurse_id': obj.nurse_id.id,
@ -71,7 +80,46 @@ class Visit(Model):
'date_start': date_from,
'date_stop': date_to,
'visit_id': obj.id,
})
'fee': include_fee and 1500.00 or 0.0,
'fee_type': obj.patient_id.type,
'lines':[],
'dialyzers': [],
}
patient_type={
"mg":"Medical Government",
"sc":"Social Security",
"nhso":"NHSO (30฿)",
"personal": "Personal",
"others": "Others",
}
categ_name=patient_type.get(obj.patient_id.type)
categ_ids=get_model("partner.categ").search([['name','=',categ_name]])
if not categ_ids:
raise Exception("Category: %s not found"%categ_name)
partner_id=None
if obj.patient_id.type in ("mg","sc","nhso"):
partner_obj=get_model("partner")
for partner in partner_obj.search_browse([]):
if partner.categ_id.id in categ_ids:
partner_id=partner.id
vals['fee_partner_id']=partner_id
break
# find dialyser
for dlz in get_model("clinic.dialyzer").search_browse([['patient_id','=',obj.patient_id.id],['state','=','active']]):
vals['dialyzers'].append({
"dialzer_id": dlz.id,
"description": dlz.description,
"use_time": dlz.use_time,
"max_use_time": dlz.max_use_time,
"member_type": dlz.member_type,
"dialyzer_type": dlz.dialyzer_type,
"bid_flow_rate": dlz.bid_flow_rate,
"ultrafittration": dlz.ultrafittration,
})
hd_case_id=hd_case_id=hd_case_obj.create(vals)
obj.write({"state":"confirmed"})
return {
'next': {
@ -79,7 +127,7 @@ class Visit(Model):
'mode': 'form',
'active_id': hd_case_id,
},
'flash': 'Visit %s confirmed'%obj.number,
'flash': 'Visit %s has been confirmed'%obj.number,
}
def cancel(self,ids,context={}):
@ -103,4 +151,24 @@ class Visit(Model):
data['department_id']=None
return data
def copy(self,ids,context={}):
obj=self.browse(ids[0])
vals={
'patient_id': obj.patient_id.id,
'doctor_id': obj.doctor_id.id,
'nurse_id': obj.nurse_id.id,
'department_id': obj.department_id.id,
}
new_id=self.create(vals,context=context)
new_obj=self.browse(new_id)
return {
'next':{
'name': 'clinic_visit',
'mode': 'form',
'active_id': new_id,
},
'flash': 'Visit %s is copy to %s'%(obj.number,new_obj.number),
}
Visit.register()