2014-10-02 19:12:52 +00:00
|
|
|
import time
|
|
|
|
from datetime import datetime
|
|
|
|
|
2014-08-21 07:29:37 +00:00
|
|
|
from netforce.model import Model, fields, get_model
|
|
|
|
from netforce.utils import get_data_path
|
2014-09-11 03:21:52 +00:00
|
|
|
from netforce.access import get_active_user,set_active_user
|
2014-08-21 07:29:37 +00:00
|
|
|
from netforce.access import get_active_company
|
|
|
|
|
2014-10-01 06:51:36 +00:00
|
|
|
class HDcase(Model):
|
2014-08-21 07:29:37 +00:00
|
|
|
_name="clinic.hd.case"
|
|
|
|
_string="HD Case Treatment"
|
|
|
|
_audit_log=True
|
|
|
|
_name_field="number"
|
|
|
|
_multi_company=True
|
2014-10-02 19:12:52 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-08-21 07:29:37 +00:00
|
|
|
_fields={
|
|
|
|
"number": fields.Char("Number",required=True,search=True),
|
2014-10-02 00:34:58 +00:00
|
|
|
"patient_id": fields.Many2One("clinic.patient","Patient",required=True,search=True),
|
|
|
|
"doctor_id": fields.Many2One("clinic.doctor","Doctor", required=True,search=True),
|
|
|
|
"nurse_id": fields.Many2One("clinic.nurse","Nurse", required=True,search=True),
|
2014-10-02 07:36:13 +00:00
|
|
|
"date_start": fields.DateTime("Time start",required=True,search=True),
|
|
|
|
"date_stop": fields.DateTime("Time stop",required=True,search=True),
|
2014-10-02 00:34:58 +00:00
|
|
|
"department_id": fields.Many2One("clinic.department", "Department",search=True),
|
|
|
|
"wh_start": fields.Float("Wt.Kg start"),
|
|
|
|
"wh_stop": fields.Float("Wt.Kg stop"),
|
|
|
|
"bp_start": fields.Integer("BP mmHG start"),
|
|
|
|
"per_bp_start": fields.Integer("/Per start"),
|
|
|
|
"bp_stop": fields.Integer("BP mmHG stop"),
|
|
|
|
"per_bp_stop": fields.Integer("/Per stop"),
|
|
|
|
"hct": fields.Integer("HCT %"),
|
2014-10-02 19:12:52 +00:00
|
|
|
"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"),
|
2014-08-21 07:29:37 +00:00
|
|
|
"comments": fields.One2Many("message","related_id","Comments"),
|
|
|
|
"company_id": fields.Many2One("company","Company"),
|
2014-10-02 19:12:52 +00:00
|
|
|
"fee": fields.Float("HD Fee"),
|
2014-09-11 03:21:52 +00:00
|
|
|
"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),
|
2014-10-01 07:40:18 +00:00
|
|
|
"invoices": fields.One2Many("account.invoice","related_id","Invoices"),
|
|
|
|
"pickings": fields.One2Many("stock.picking","related_id","Pickings"),
|
|
|
|
"payments": fields.One2Many("account.payment","related_id","Payments"),
|
2014-10-02 02:02:22 +00:00
|
|
|
'visit_id': fields.Many2One("clinic.visit", "Visit"),
|
2014-10-02 19:12:52 +00:00
|
|
|
'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"),
|
2014-08-21 07:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def _get_number(self,context={}):
|
|
|
|
while 1:
|
2014-10-02 01:12:46 +00:00
|
|
|
seq_id=get_model("sequence").find_sequence(name="Clinic HD Case")
|
|
|
|
num=get_model("sequence").get_next_number(seq_id,context=context)
|
2014-08-21 07:29:37 +00:00
|
|
|
if not num:
|
|
|
|
return None
|
2014-10-02 01:12:46 +00:00
|
|
|
user_id=get_active_user()
|
|
|
|
set_active_user(1)
|
2014-08-21 07:29:37 +00:00
|
|
|
res=self.search([["number","=",num]])
|
2014-10-02 01:12:46 +00:00
|
|
|
set_active_user(user_id)
|
2014-08-21 07:29:37 +00:00
|
|
|
if not res:
|
|
|
|
return num
|
2014-10-02 01:12:46 +00:00
|
|
|
get_model("sequence").increment_number(seq_id,context=context)
|
2014-08-21 07:29:37 +00:00
|
|
|
|
2014-10-02 00:34:58 +00:00
|
|
|
def _get_nurse(self,context={}):
|
|
|
|
user_id=get_active_user()
|
|
|
|
print("user_id ",user_id)
|
|
|
|
nurse_ids=get_model("clinic.nurse").search([['user_id','=',user_id]])
|
|
|
|
if nurse_ids:
|
|
|
|
return nurse_ids[0]
|
|
|
|
return None
|
|
|
|
|
|
|
|
_defaults={
|
|
|
|
"state": "draft",
|
|
|
|
"date_start": lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
"date_stop": lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
'nurse_id': _get_nurse,
|
|
|
|
"number": _get_number,
|
|
|
|
"company_id": lambda *a: get_active_company(),
|
|
|
|
"fee": 1500,
|
|
|
|
}
|
|
|
|
_order="date_start desc,number desc"
|
|
|
|
|
2014-08-28 11:20:49 +00:00
|
|
|
def onchange_dialyzer(self,context={}):
|
|
|
|
data=context["data"]
|
|
|
|
path=context["path"]
|
|
|
|
line=get_data_path(data,path,parent=True)
|
|
|
|
dialyzer_id=line.get("dialzer_id")
|
|
|
|
if not dialyzer_id:
|
|
|
|
return {}
|
|
|
|
dialyzer=get_model("clinic.dialyzer").browse(dialyzer_id)
|
|
|
|
line["detail"]=dialyzer.detail
|
|
|
|
line["use_time"]=dialyzer.use_time
|
|
|
|
line["max_use_time"]=dialyzer.max_use_time
|
|
|
|
line["member_type"]=dialyzer.member_type
|
|
|
|
line["dialyzer_type"]=dialyzer.dialyzer_type
|
|
|
|
line["bid_flow_rate"]=dialyzer.bid_flow_rate
|
|
|
|
line["ultrafittration"]=dialyzer.ultrafittration
|
|
|
|
line["state"]=dialyzer.state
|
|
|
|
return data
|
2014-08-21 07:29:37 +00:00
|
|
|
|
2014-10-02 00:34:58 +00:00
|
|
|
def onchange_patient(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
patient_id=data['patient_id']
|
|
|
|
hd_cases=self.search_browse([['patient_id','=',patient_id]])
|
|
|
|
if hd_cases:
|
|
|
|
hd_case=hd_cases[-1]
|
|
|
|
data['doctor_id']=hd_case.doctor_id.id
|
|
|
|
data['department_id']=hd_case.department_id.id
|
|
|
|
else:
|
|
|
|
data['doctor_id']=None
|
|
|
|
data['department_id']=None
|
|
|
|
|
|
|
|
return data
|
2014-08-21 07:29:37 +00:00
|
|
|
|
2014-10-02 00:34:58 +00:00
|
|
|
def cancelled(self,ids,context={}):
|
2014-08-21 07:29:37 +00:00
|
|
|
obj=self.browse(ids)[0]
|
2014-10-02 00:34:58 +00:00
|
|
|
obj.write({"state":"cancelled"})
|
2014-08-21 07:29:37 +00:00
|
|
|
|
2014-10-02 19:12:52 +00:00
|
|
|
def make_invoice(self,ids,context={}):
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
if obj.fee:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def confirm(self,ids,context={}):
|
2014-09-11 03:21:52 +00:00
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({"state":"confirmed"})
|
|
|
|
|
2014-10-02 00:34:58 +00:00
|
|
|
def paid(self,ids,context={}):
|
2014-09-11 03:21:52 +00:00
|
|
|
obj=self.browse(ids)[0]
|
2014-10-02 00:34:58 +00:00
|
|
|
obj.write({"state":"paid"})
|
2014-10-02 19:12:52 +00:00
|
|
|
|
|
|
|
def approve(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.make_invoice()
|
|
|
|
obj.write({"state":"approved"})
|
2014-09-11 03:21:52 +00:00
|
|
|
|
|
|
|
def approved(self,ids,context={}):
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
user_id=get_active_user()
|
|
|
|
try:
|
|
|
|
set_active_user(1)
|
|
|
|
settings=get_model("clinic.setting").browse(1)
|
|
|
|
reconcile_id=get_model("account.reconcile").create({})
|
|
|
|
if obj.patient_id.type == 'mg':
|
|
|
|
vals={
|
|
|
|
"narration": obj.number,
|
|
|
|
"lines": [
|
|
|
|
("create",{
|
|
|
|
"description": obj.number,
|
|
|
|
"account_id": settings.ar_mg_id.id,
|
|
|
|
"debit": obj.amount,
|
|
|
|
"credit": 0,
|
|
|
|
"partner_id": settings.mg_partner_id.id,
|
|
|
|
"due_date": obj.date,
|
|
|
|
"reconcile_id":reconcile_id,
|
|
|
|
}),
|
|
|
|
("create",{
|
|
|
|
"description": obj.number,
|
|
|
|
"account_id": settings.ap_mg_id.id,
|
|
|
|
"debit": 0,
|
|
|
|
"credit": obj.amount,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
"state": "posted",
|
|
|
|
"date_posted": obj.date,
|
|
|
|
"date": obj.date,
|
|
|
|
}
|
|
|
|
get_model("account.move").create(vals)
|
|
|
|
elif obj.patient_id.type == 'sc':
|
|
|
|
vals={
|
|
|
|
"narration": obj.number,
|
|
|
|
"lines": [
|
|
|
|
("create",{
|
|
|
|
"description": obj.number,
|
|
|
|
"account_id": settings.ar_sc_id.id,
|
|
|
|
"debit": obj.amount,
|
|
|
|
"credit": 0,
|
|
|
|
"partner_id": settings.sc_partner_id.id,
|
|
|
|
"due_date": obj.date,
|
|
|
|
"reconcile_id":reconcile_id,
|
|
|
|
}),
|
|
|
|
("create",{
|
|
|
|
"description": obj.number,
|
|
|
|
"account_id": settings.ap_sc_id.id,
|
|
|
|
"debit": 0,
|
|
|
|
"credit": obj.amount,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
"state": "posted",
|
|
|
|
"date_posted": obj.date,
|
|
|
|
"date": obj.date,
|
|
|
|
}
|
|
|
|
get_model("account.move").create(vals)
|
|
|
|
elif obj.patient_id.type == 'nhso':
|
|
|
|
vals={
|
|
|
|
"narration": obj.number,
|
|
|
|
"lines": [
|
|
|
|
("create",{
|
|
|
|
"description": obj.number,
|
|
|
|
"account_id": settings.ar_nhso_id.id,
|
|
|
|
"debit": obj.amount,
|
|
|
|
"credit": 0,
|
|
|
|
"partner_id": settings.nhso_partner_id.id,
|
|
|
|
"due_date": obj.date,
|
|
|
|
"reconcile_id":reconcile_id,
|
|
|
|
}),
|
|
|
|
("create",{
|
|
|
|
"description": obj.number,
|
|
|
|
"account_id": settings.ap_nhso_id.id,
|
|
|
|
"debit": 0,
|
|
|
|
"credit": obj.amount,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
"state": "posted",
|
|
|
|
"date_posted": obj.date,
|
|
|
|
"date": obj.date,
|
|
|
|
}
|
|
|
|
get_model("account.move").create(vals)
|
|
|
|
finally:
|
|
|
|
set_active_user(user_id)
|
|
|
|
obj.write({"state":"approved","reconcile_id":reconcile_id})
|
|
|
|
|
|
|
|
def journal_report(self,ids,context={}):
|
|
|
|
obj=self.browse(ids[0])
|
|
|
|
move_id = get_model("account.move").search([["narration","=",obj.number]])
|
|
|
|
if not move_id:
|
|
|
|
raise Exception("Order is not post or nove have jounal entry.")
|
|
|
|
return {
|
|
|
|
"next": {
|
|
|
|
"name": "journal_entry",
|
|
|
|
"mode":"form",
|
|
|
|
"active_id":move_id[0],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_total(self,ids,context={}):
|
|
|
|
vals={}
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
total=0
|
|
|
|
amt=0
|
2014-10-01 07:47:50 +00:00
|
|
|
fee=obj.fee or 0
|
2014-10-02 19:12:52 +00:00
|
|
|
for line in obj.lines:
|
2014-10-01 07:47:50 +00:00
|
|
|
total+=line.total or 0
|
2014-10-02 07:36:13 +00:00
|
|
|
fee=0 # XXX
|
2014-09-11 03:21:52 +00:00
|
|
|
amt=total+fee
|
|
|
|
vals[obj.id]={
|
|
|
|
"total": total,
|
|
|
|
"amount": amt,
|
|
|
|
}
|
|
|
|
return vals
|
|
|
|
|
2014-10-01 10:52:21 +00:00
|
|
|
def view_hdcase(self,ids,context={}):
|
|
|
|
return {
|
|
|
|
'name': 'clinic_hd_case',
|
|
|
|
'mode': 'form',
|
|
|
|
'form_view_xml': 'clinic_hd_case_form',
|
|
|
|
'active_id': ids[0],
|
|
|
|
}
|
2014-10-02 07:36:13 +00:00
|
|
|
|
|
|
|
def onchange_product(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
all_total=0.0
|
2014-10-02 19:12:52 +00:00
|
|
|
for line in data['lines']:
|
2014-10-02 07:36:13 +00:00
|
|
|
qty=line['qty'] or 0
|
|
|
|
price=line['price'] or 0.0
|
|
|
|
total=qty*price
|
|
|
|
line['total']=total
|
|
|
|
all_total+=total
|
|
|
|
fee_amt=data['fee'] or 0.0
|
|
|
|
fee_amt=0.0 # XXX
|
|
|
|
data['total']=all_total
|
|
|
|
data['amount']=all_total+fee_amt
|
|
|
|
return data
|
2014-10-02 19:12:52 +00:00
|
|
|
|
|
|
|
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
|
2014-10-01 10:52:21 +00:00
|
|
|
|
2014-10-01 06:51:36 +00:00
|
|
|
HDcase.register()
|