clinic/netforce_clinic/models/hd_case.py

1618 lines
60 KiB
Python
Raw Normal View History

2014-10-02 19:12:52 +00:00
import time
2015-02-03 14:09:53 +00:00
from datetime import datetime, timedelta
2014-08-21 07:29:37 +00:00
from netforce.model import Model, fields, get_model
2014-10-23 08:21:29 +00:00
from netforce.utils import get_data_path, get_file_path
2015-03-17 00:56:55 +00:00
from netforce.access import get_active_user,set_active_user, get_active_company
from . import utils
2014-08-21 07:29:37 +00:00
2014-10-23 04:43:39 +00:00
class HDCase(Model):
2014-08-21 07:29:37 +00:00
_name="clinic.hd.case"
2014-11-01 03:48:22 +00:00
_string="HD Case"
2014-08-21 07:29:37 +00:00
_audit_log=True
_name_field="number"
_multi_company=True
2014-10-02 19:12:52 +00:00
2014-11-30 13:05:14 +00:00
def _get_duration(self,ids,context={}):
2014-10-02 19:12:52 +00:00
res={}
fmt="%Y-%m-%d %H:%M:%S"
for obj in self.browse(ids):
2014-10-05 05:47:19 +00:00
diff=datetime.strptime(obj.time_stop,fmt)-datetime.strptime(obj.time_start,fmt)
2014-10-02 19:12:52 +00:00
total_time=round(diff.seconds/3600,2)
res[obj.id]=total_time
return res
2014-11-30 13:05:14 +00:00
def _get_pay_amount(self,ids,context={}):
2014-10-22 08:55:57 +00:00
res={}
for obj in self.browse(ids):
res[obj.id]=obj.amount
return res
2014-11-28 04:54:21 +00:00
2014-12-19 18:19:19 +00:00
def _get_all(self,ids,context={}):
2014-11-28 04:54:21 +00:00
vals={}
for obj in self.browse(ids):
2014-12-20 18:55:26 +00:00
total_amt=0
rmb_amt=0
2014-11-28 04:54:21 +00:00
due_amt=0
for line in obj.lines:
2014-12-21 02:54:45 +00:00
if line.reimbursable=='yes':
2014-12-20 18:55:26 +00:00
rmb_amt+=line.amount or 0.0
else:
due_amt+=line.amount or 0.0
total_amt+=line.amount or 0.0
2014-11-28 04:54:21 +00:00
for line in obj.payment_lines:
due_amt-=line.amount or 0.0
vals[obj.id]={
2014-12-20 18:55:26 +00:00
"total_amount": total_amt,
"due_amount": due_amt,
'rmb_amount': rmb_amt,
2014-12-19 18:19:19 +00:00
'hd_case_id': obj.id,
2014-11-28 04:54:21 +00:00
}
return vals
2014-10-22 08:55:57 +00:00
2014-11-29 14:56:15 +00:00
def _get_patient_type(self,ids,context={}):
res={}
for obj in self.browse(ids):
patient=obj.patient_id
2014-12-19 16:57:34 +00:00
res[obj.id]=patient.type_id.id
2014-11-29 14:56:15 +00:00
return res
2015-01-13 07:56:30 +00:00
def _get_store(self,ids,context={}):
2015-01-13 07:56:30 +00:00
res={}
for obj in self.browse(ids):
include=False
type_code=obj.patient_id.type_id.code
2015-01-13 07:56:30 +00:00
if obj.patient_id.type_id.hct_include:
include=True
2015-04-29 16:15:11 +00:00
staff_id=None
for sline in obj.staffs:
staff=sline.staff_id
if staff and sline.priop=='personal':
staff_id=staff.id
break
res[obj.id]={
'hct_include': include,
'type_code': type_code,
2015-04-29 16:15:11 +00:00
'doctor_id2': staff_id,
}
2015-01-13 07:56:30 +00:00
return res
2014-11-29 14:56:15 +00:00
2015-03-13 16:31:58 +00:00
def _get_expense(self,ids,context={}):
2015-02-23 00:50:19 +00:00
res={}
2015-03-13 16:42:01 +00:00
user_id=get_active_user()
set_active_user(1)
2015-03-26 07:55:16 +00:00
reimbursable_ctx=context.get('reimbursable')
2015-04-07 06:14:25 +00:00
no=0
2015-02-23 00:50:19 +00:00
for obj in self.browse(ids):
2015-04-07 06:14:25 +00:00
if not obj.doctor_id:
print('obj.date ', obj.date)
no+=1
2015-03-13 16:31:58 +00:00
dlz_use=0
dlz_max=0
dlz_name=[]
dlz_id=None
for dlz in obj.dialyzers:
dz=dlz.dialyzer_id
dlz_id=dz.id
2015-03-18 10:35:49 +00:00
prod=dz.product_id
2015-03-26 07:55:16 +00:00
name=""
if prod:
name=prod.description or ""
2015-03-13 16:31:58 +00:00
dlz_name.append(name)
dlz_use+=dlz.use_time or 0
dlz_max+=dlz.max_use_time or 0
dlz_name=','.join([dlz for dlz in dlz_name])
epo_names=[]
mdc_names=[]
2015-08-08 15:34:21 +00:00
iron_names=[]
2015-03-13 16:31:58 +00:00
fee=0
2015-03-18 16:30:26 +00:00
lab=0
misc=0
2015-03-26 07:11:04 +00:00
dlz_price=0
2015-04-24 06:48:11 +00:00
srv=0
mdc=0
2015-02-23 00:50:19 +00:00
for line in obj.lines:
2015-03-13 16:31:58 +00:00
amt=line.amount or 0
2015-02-23 00:50:19 +00:00
prod=line.product_id
2015-08-08 15:34:21 +00:00
prod_name=prod.description or prod.name or ""
2015-02-23 00:50:19 +00:00
categ=line.product_categ_id
2015-03-18 10:35:49 +00:00
if categ and prod:
2015-03-18 11:22:14 +00:00
sign=1
if line.reimbursable=='yes':
sign=-1
if categ.parent_id:
if categ.parent_id.code=='MDC':
if reimbursable_ctx:
if reimbursable_ctx==line.reimbursable:
mdc+=amt
2015-08-08 15:34:21 +00:00
mdc_names.append(prod_name or "")
else:
mdc+=amt
mdc_names.append(name or "")
2015-02-23 00:50:19 +00:00
if categ.code=='EPO':
2015-08-08 15:34:21 +00:00
epo_names.append(prod_name.title())
elif categ.code=='IVR':
iron_names.append(prod_name.title())
2015-03-13 16:31:58 +00:00
elif categ.code=='FEE':
2015-03-18 10:35:49 +00:00
fee+=amt*sign
2015-03-26 07:11:04 +00:00
elif categ.code=='DLZ':
dlz_price+=amt
2015-04-24 06:48:11 +00:00
elif categ.code=='SRV':
2015-04-24 08:43:08 +00:00
srv+=amt
2015-03-18 16:30:26 +00:00
elif categ.code=="LAB":
2015-03-26 07:55:16 +00:00
if reimbursable_ctx:
if reimbursable_ctx==line.reimbursable:
lab+=amt
else:
lab+=amt
2015-03-18 16:30:26 +00:00
else:
2015-03-26 07:55:16 +00:00
if reimbursable_ctx:
if reimbursable_ctx==line.reimbursable:
misc+=amt
else:
misc+=amt
2015-03-13 16:31:58 +00:00
res[obj.id]={
'epo': ','.join([n for n in epo_names]),
2015-08-08 15:34:21 +00:00
'mdc_name': ','.join([n for n in mdc_names]),
'iron_name': ','.join([n for n in iron_names]),
2015-03-13 16:31:58 +00:00
'fee': fee,
2015-03-18 16:30:26 +00:00
'lab': lab,
'misc': misc,
'mdc': mdc,
2015-04-24 06:48:11 +00:00
'srv': srv,
2015-03-13 16:31:58 +00:00
'dlz_id': dlz_id,
2015-03-26 07:11:04 +00:00
'dlz_price': dlz_price,
2015-03-13 16:31:58 +00:00
'dlz_name': dlz_name,
'dlz_use': dlz_use,
'dlz_max': dlz_max,
}
2015-03-13 16:42:01 +00:00
set_active_user(user_id)
2015-02-23 00:50:19 +00:00
return res
2015-08-13 06:27:46 +00:00
def _get_req_button(self,ids,context={}):
2015-03-20 09:00:51 +00:00
res={}
for obj in self.browse(ids):
total_amt=0
rmb_amt=0
for line in obj.lines:
amt=line.amount or 0
if line.reimbursable=='yes':
rmb_amt+=amt
total_amt+=amt
pm_amt=0
for pline in obj.payment_lines:
pm_amt+=pline.amount or 0
due_amt=total_amt-pm_amt-rmb_amt
paid=0
if due_amt>0:
paid=1
2015-08-13 06:27:46 +00:00
res[obj.id]={
'to_pay': 0,
'to_claim': 0,
'req_fee': paid,
}
print("res ", res)
2015-03-20 09:00:51 +00:00
return res
def _get_hct_msg(self,ids,context={}):
res={}
for obj in self.browse(ids):
msg=""
hct=obj.hct or 0
if(hct<=36):
msg="สามารถเบิกค่ายาสูงสุดไม่เกิน 1,125บาท ต่อ สัปดาห์"
elif(hct>36 and hct<=39):
msg="สามารถเบิกค่ายาสูงสุดไม่เกิน 750บาท ต่อ สัปดาห์"
elif(hct> 39):
msg="ไม่สามารถเบิกค่ายาฉีดได้ทุกตัว"
res[obj.id]=msg
return res
2014-08-21 07:29:37 +00:00
_fields={
"number": fields.Char("Number",required=True,search=True),
2015-03-13 16:31:58 +00:00
"epo": fields.Char("EPO",function="_get_expense",function_multi=True),
"fee": fields.Float("Fee",function="_get_expense",function_multi=True),
2015-03-18 16:30:26 +00:00
"lab": fields.Float("Fee",function="_get_expense",function_multi=True),
"misc": fields.Float("Fee",function="_get_expense",function_multi=True),
2015-03-13 16:31:58 +00:00
"dlz_name": fields.Float("DZ",function="_get_expense",function_multi=True),
2015-03-26 07:11:04 +00:00
"dlz_price": fields.Float("DZ",function="_get_expense",function_multi=True),
2015-03-13 16:31:58 +00:00
"dlz_use": fields.Float("DZ Use",function="_get_expense",function_multi=True),
"dlz_max": fields.Float("DZ Max",function="_get_expense",function_multi=True),
"dlz_id": fields.Integer("DZ ID",function="_get_expense",function_multi=True),
"mdc": fields.Float("MDC",function="_get_expense",function_multi=True),
2015-04-24 06:48:11 +00:00
"srv": fields.Float("Service",function="_get_expense",function_multi=True),
"mdc_name": fields.Float("MDC Name",function="_get_expense",function_multi=True),
2015-01-14 04:31:24 +00:00
'sickbed_id': fields.Many2One("clinic.sickbed",'Sickbed'),
2014-11-29 14:56:15 +00:00
"ref": fields.Char("Ref",search=True),
2015-01-15 07:37:36 +00:00
"time_start": fields.DateTime("Start Time",required=True),
"time_stop": fields.DateTime("Finish Time",required=True),
2014-11-21 16:11:57 +00:00
"date": fields.Date("Date",required=True,search=True),
2015-03-02 04:03:07 +00:00
"patient_id": fields.Many2One("clinic.patient","Patient",domain=[['state','=','admit']],required=True,search=True),
2015-01-30 11:15:13 +00:00
"patient_type_id": fields.Many2One("clinic.patient.type", "Type"),
"nurse_id": fields.Many2One("clinic.staff","Approve By", domain=[['type','=','nurse']]),
2014-10-02 00:34:58 +00:00
"department_id": fields.Many2One("clinic.department", "Department",search=True),
2014-12-19 18:19:19 +00:00
"wt_start": fields.Float("Start Wt (kg.)"),
"wt_stop": fields.Float("Finish Wt (kg.)"),
2014-12-19 17:16:01 +00:00
"bp_start": fields.Char("Start BP"),
2014-12-19 18:19:19 +00:00
"bp_stop": fields.Char("Finish BP"),
2015-01-23 04:29:50 +00:00
"membrane_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Membrane Type"),
2015-01-13 09:25:51 +00:00
"hd_acc": fields.Selection([("o","OPD"),("i","IPD")],"HD Acc"),
2015-01-23 04:29:50 +00:00
"hd_mode": fields.Selection([("chronic","Chronic"),("acute","Acute")],"HD Mode"),
2014-12-19 16:57:34 +00:00
"vascular_acc": fields.Many2One("clinic.vascular.access","Vascular Ac."),
2015-01-23 04:29:50 +00:00
"bid_flow_rate": fields.Integer("BFR (ml/min)"),
"ultrafittration": fields.Float("Ultrafiltration (kg.)"),
2015-02-03 14:09:53 +00:00
"hct": fields.Integer("Hct"),
2015-03-20 09:00:51 +00:00
"hct_msg" : fields.Char("",function="_get_hct_msg",store=True),
'hct_include': fields.Boolean("HCT Include", function="_get_store", function_multi=True,store=True),
'type_code': fields.Char("Product Code", function="_get_store", function_multi=True,store=True),
2015-04-29 16:15:11 +00:00
'doctor_id2': fields.Many2One("clinic.staff","Doctor2", function="_get_store", function_multi=True,store=True),
"state": fields.Selection([("draft","Draft"),('waiting_treatment','Waiting Treatment'),("in_progress","In Progress"),("completed","Finish Treatment"),('paid','Paid'),("waiting_payment","Waiting Payment"),("discountinued","Discountinued"),("cancelled","Cancelled")],"Status",required=True),
"staffs": fields.One2Many("clinic.hd.case.staff","hd_case_id","Staffs"),
2014-10-24 18:04:36 +00:00
"comments": fields.One2Many("message","related_id","Comments"), "company_id": fields.Many2One("company","Company"),
2014-12-04 14:08:29 +00:00
"dialyzers": fields.One2Many("clinic.hd.case.dialyzer","hd_case_id","Dialyzers"),
"lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"),
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-20 11:49:54 +00:00
"payment_lines": fields.One2Many("clinic.payment","hd_case_id","Payment Lines"),
2014-12-04 14:08:29 +00:00
"expenes": fields.One2Many("clinic.hd.case.expense","hd_case_id","Expenses"),
2014-10-02 02:02:22 +00:00
'visit_id': fields.Many2One("clinic.visit", "Visit"),
2014-12-19 16:57:34 +00:00
'duration': fields.Integer("Duration (Hours)",function="_get_duration"),
2014-12-20 18:55:26 +00:00
"total_amount": fields.Float("Total",function="_get_all",readonly=True,function_multi=True),
"rmb_amount": fields.Float("Reimbursable",function="_get_all",readonly=True,function_multi=True),
"due_amount": fields.Float("Due Amount",function="_get_all",readonly=True,function_multi=True),
2014-10-06 00:48:42 +00:00
'fee_partner_id': fields.Many2One("partner","Contact Fee"),
2014-10-05 09:43:28 +00:00
'note': fields.Text("Note"),
2014-11-30 06:30:09 +00:00
'complication': fields.Text("Complication"),
2014-10-14 03:57:20 +00:00
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
2015-01-14 03:55:08 +00:00
'cycle_item_id': fields.Many2One("clinic.cycle.item","Cycle Item (Nurses)"), # on_delete="cascade" -> will rm visit from cycle item
2014-11-30 13:05:14 +00:00
'pay_amount': fields.Float("Amount",function="_get_pay_amount"),
2014-10-20 11:49:54 +00:00
'pay_date': fields.Date("Pay Date"),
'pay_account_id': fields.Many2One("account.account","Account"),
2014-10-23 08:21:29 +00:00
'payment_id': fields.Many2One("account.payment","Payment"), # for print
2014-10-26 00:15:13 +00:00
'dlz_id': fields.Many2One("clinic.dialyzer","Dialyzer"), # for link
"total_doctor": fields.Integer("Total Doctor",function="get_staff",function_multi=True),
"total_nurse": fields.Integer("Total Nurse",function="get_staff",function_multi=True),
'doctor_id': fields.Many2One("clinic.staff","Doctor",domain=[['type','=','doctor']],function="get_staff",function_multi=True),
2014-11-26 11:22:17 +00:00
'nu': fields.Char("N/U"),
2014-11-28 04:54:21 +00:00
"invoice_policy": fields.Selection([("fee","Only Fee"),("fee_mdc","Fee & Medicine")],"Government pay for:"),
"invoice_option": fields.Selection([("fee_mdc_plus","Combine Fee & Medicine"),("fee_mdc_split","Split Fee & Medicine")],"Invoice:"),
2015-08-13 06:27:46 +00:00
'req_fee': fields.Integer("Request Expense",function="_get_req_button",function_multi=True,store=True),
'to_pay': fields.Integer("Request Expense",function="_get_req_button",function_multi=True,store=True),
'to_claim': fields.Integer("Request Expense",function="_get_req_button",function_multi=True,store=True),
2014-12-19 18:19:19 +00:00
'hd_case_id': fields.Many2One("clinic.hd.case","HD",function="_get_all",function_multi=True), # XXX
2015-01-09 05:19:52 +00:00
'company_id': fields.Many2One("company","Company"),
2015-01-14 11:00:14 +00:00
'branch_id': fields.Many2One("clinic.branch","Branch"),
2014-08-21 07:29:37 +00:00
}
def _get_number(self,context={}):
while 1:
2015-03-17 15:51:56 +00:00
seq_id=get_model("sequence").find_sequence(type="clinic_hdcase")
2014-10-02 01:12:46 +00:00
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
2015-04-01 10:31:43 +00:00
def _get_number_invoice_noclaim(self,context={}):
while 1:
2015-08-11 05:30:58 +00:00
seq_id=get_model("sequence").find_sequence(type="clinic_invoice_noclaim",name=None,context=context)
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)
2015-05-11 03:54:36 +00:00
res=get_model('account.invoice').search([["number","=",num]])
set_active_user(user_id)
if not res:
return num
get_model("sequence").increment_number(seq_id,context=context)
2014-10-02 00:34:58 +00:00
_defaults={
"state": "draft",
2014-10-05 05:47:19 +00:00
"date": lambda *a: time.strftime("%Y-%m-%d"),
"time_start": lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
"time_stop": lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
2014-12-19 18:43:56 +00:00
'number': '/',
2014-10-02 00:34:58 +00:00
"company_id": lambda *a: get_active_company(),
2014-12-19 16:57:34 +00:00
'hd_acc': 'o',
'hd_mode': 'chronic',
2014-11-18 06:02:47 +00:00
'hct_msg': "สามารถเบิกค่ายาสูงสุดไม่เกิน 1,125บาท ต่อ สัปดาห์",
2014-11-28 04:54:21 +00:00
'invoice_option': 'fee',
'invoice_policy': 'fee',
2014-12-05 02:31:48 +00:00
'req_fee': 0,
2015-01-14 03:55:08 +00:00
'hct_include': False,
2014-10-02 00:34:58 +00:00
}
2014-10-05 05:47:19 +00:00
_order="date desc,number desc"
2014-10-02 00:34:58 +00:00
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)
2014-10-04 18:33:18 +00:00
dialyzer_id=line.get("dialyzer_id")
2014-08-28 11:20:49 +00:00
if not dialyzer_id:
return {}
dialyzer=get_model("clinic.dialyzer").browse(dialyzer_id)
2014-10-15 07:52:15 +00:00
use_time=dialyzer.use_time or 0
max_time=dialyzer.max_use_time or 0
if use_time > max_time:
dialyzer.write({
'state': 'expire',
})
raise Exception("%s is expired"%dialyzer.number)
use_time+=1
2015-01-15 06:44:58 +00:00
line["description"]=dialyzer.name or dialyzer.product_id.name or ""
2014-10-15 07:52:15 +00:00
line["use_time"]=use_time
2014-08-28 11:20:49 +00:00
line["max_use_time"]=dialyzer.max_use_time
line["dialyzer_type"]=dialyzer.dialyzer_type
2014-10-26 00:15:13 +00:00
data['dlz_id']=dialyzer.id
2014-08-28 11:20:49 +00:00
return data
2014-12-02 08:34:28 +00:00
def onchange_cycle(self,context={}):
data=context['data']
cycle_id=data['cycle_id']
cycle=get_model("clinic.cycle").browse(cycle_id)
date=data['time_start'][0:10]
data['time_start']='%s %s'%(date, cycle.time_start)
data['time_stop']='%s %s'%(date, cycle.time_stop)
2014-12-02 08:51:21 +00:00
fmt="%Y-%m-%d %H:%M"
diff=datetime.strptime(data['time_stop'],fmt)-datetime.strptime(data['time_start'],fmt)
total_time=round(diff.seconds/3600,2)
data['duration']=total_time
#XXX get nurse team
2014-12-02 08:34:28 +00:00
return data
2014-08-21 07:29:37 +00:00
2015-02-06 08:32:45 +00:00
def empty_line(self,lines=[]):
empty=True
for line in lines:
if line:
empty=False
break
return empty
2014-10-02 00:34:58 +00:00
def onchange_patient(self,context={}):
data=context['data']
patient_id=data['patient_id']
2014-11-30 13:05:14 +00:00
if patient_id:
patient=get_model('clinic.patient').browse(patient_id)
department=patient.department_id
2015-01-14 11:00:14 +00:00
branch=patient.branch_id
2014-11-30 13:05:14 +00:00
cycle=patient.cycle_id
2014-12-02 07:08:20 +00:00
partner=patient.type_id.contact_id
2015-01-14 03:55:08 +00:00
if partner:
data['fee_partner_id']=partner.id
else:
data['fee_partner_id']=None
2014-11-30 13:05:14 +00:00
data['department_id']=department.id
2015-01-14 11:00:14 +00:00
data['branch_id']=branch.id
2014-11-30 13:05:14 +00:00
data['cycle_id']=cycle.id
2014-12-19 16:57:34 +00:00
data['patient_type_id']=patient.type_id.id
data['type_code']=patient.type_id.code
2015-01-14 03:55:08 +00:00
if patient.type_id.hct_include:
data['hct_include']=True
2014-12-02 07:08:20 +00:00
else:
2015-01-14 03:55:08 +00:00
data['hct_include']=False
2014-11-01 03:48:22 +00:00
data['dialyzers']=[]
2014-12-09 07:29:30 +00:00
doctor=patient.doctor_id
data['staffs']=[] # XXX
data['staffs'].append({
'staff_id': doctor.id,
'type': 'doctor',
2015-04-29 01:36:05 +00:00
'priop': 'personal',
2014-12-09 07:29:30 +00:00
})
2015-02-06 08:32:45 +00:00
if data['patient_type_id']:
st=get_model("clinic.setting").browse(1)
data['lines']=[]
for pline in st.products:
if data['patient_type_id']==pline.patient_type_id.id:
data['lines'].append({
'product_categ_id': pline.product_categ_id.id,
'product_id': pline.product_id.id,
'description': pline.description or "",
'uom_id': pline.uom_id.id,
'qty': pline.qty or 0,
'price': pline.price or 0,
'amount': pline.amount or 0,
})
2014-10-02 00:34:58 +00:00
return data
2014-08-21 07:29:37 +00:00
2014-11-26 11:22:17 +00:00
def onchange_line(self,context={}):
data=context['data']
path=context['path']
line=get_data_path(data,path,parent=True)
qty=line['qty'] or 0
price=line['price'] or 0.0
line['amount']=qty*price
2014-12-14 11:15:14 +00:00
data=self.update_amount(context)
2014-12-21 10:11:22 +00:00
#bug show button
2014-11-26 11:22:17 +00:00
return data
2014-10-03 02:00:47 +00:00
def onchange_product(self,context={}):
data=context['data']
2014-11-26 11:22:17 +00:00
path=context['path']
2014-10-03 02:00:47 +00:00
line=get_data_path(data,path,parent=True)
product_id=line.get('product_id')
prod=get_model("product").browse(product_id)
2015-03-26 07:55:16 +00:00
if not prod:
return data
if prod.can_sell:
line['reimbursable']='no'
else:
line['reimbursable']='yes'
2014-10-03 02:00:47 +00:00
line['uom_id']=prod.uom_id.id
line['description']=prod.name
2014-12-20 18:55:26 +00:00
line['product_categ_id']=prod.categ_id.id
2014-11-26 11:22:17 +00:00
qty=1
price=prod.sale_price or 0.0
amt=qty*price
line['qty']=qty
line['price']=price
line['amount']=amt
2014-12-14 11:15:14 +00:00
data=self.update_amount(context)
2014-10-03 02:00:47 +00:00
return data
2014-12-04 14:08:29 +00:00
def onchange_pay(self,context={}):
data=context['data']
pay_amount=data['pay_amount'] or 0
amount=data['amount'] or 0
if pay_amount > amount:
data['pay_amount']=0
return data
2014-12-14 11:15:14 +00:00
def update_amount(self,context={}):
2014-12-04 14:08:29 +00:00
data=context['data']
due_amt=0.0
2014-12-20 18:55:26 +00:00
rmb_amt=0.0
2014-12-04 14:08:29 +00:00
for line in data['lines']:
2015-03-03 03:28:38 +00:00
amt=line.get('amount', 0.0)
2015-02-26 06:15:36 +00:00
reimbursable=line.get('reimbursable','no')
2014-12-20 18:55:26 +00:00
if reimbursable=='yes':
rmb_amt+=amt
else:
due_amt+=amt
data['rmb_amount']=rmb_amt
data['due_amount']=due_amt
data['total_amount']=due_amt+rmb_amt
2014-12-21 10:11:22 +00:00
data['req_fee']=0
if due_amt:
data['req_fee']=1
return data
2014-10-20 11:49:54 +00:00
def make_payment(self,ids,context={}):
obj=self.browse(ids)[0]
2014-12-21 10:11:22 +00:00
if not obj.total_amount:
2014-10-22 02:25:14 +00:00
return
2014-10-20 11:49:54 +00:00
remaining_amt=0.0
for line in obj.lines:
remaining_amt+=line.amount or 0.0
for line in obj.payment_lines:
remaining_amt-=line.amount or 0.0
2014-11-26 11:22:17 +00:00
partner=obj.patient_id.partner_id
if not partner:
2014-12-21 10:11:22 +00:00
raise Exception("Not partner")
2015-02-04 08:51:14 +00:00
st=get_model('clinic.setting').browse(1)
2014-12-21 10:11:22 +00:00
cash_account_id=st.cash_account_id.id
income_account_id=st.income_account_id.id
if not cash_account_id:
raise Exception("No Cash Account")
if not income_account_id:
raise Exception("No Income Account")
2014-10-22 08:55:57 +00:00
pay_amount=obj.pay_amount
2015-02-05 09:03:51 +00:00
bill_no=context.get("bill_no", "")
2014-10-22 08:55:57 +00:00
if context.get("amount",0):
pay_amount=context['amount'] or 0.0
2014-12-21 10:11:22 +00:00
company_id=get_active_company()
2014-10-20 11:49:54 +00:00
vals={
2014-11-26 11:22:17 +00:00
"partner_id": partner.id,
2014-10-20 11:49:54 +00:00
"company_id": company_id,
"type": "in",
"pay_type": "direct",
2014-11-26 11:22:17 +00:00
'date': time.strftime("%Y-%m-%d"),
2015-01-09 05:19:52 +00:00
"account_id": cash_account_id,
'related_id': "clinic.hd.case,%s"%obj.id,
2015-02-05 09:03:51 +00:00
'ref': bill_no or obj.number or "",
2015-01-09 05:19:52 +00:00
'direct_lines': [],
2014-10-20 11:49:54 +00:00
}
2015-02-04 14:10:41 +00:00
patient=obj.patient_id
ptype=patient.type_id
2015-02-06 08:32:45 +00:00
shop_type=st.shop_type_id
if not shop_type:
raise Exception("No Patient Type -> Clinic Settings-> RD Shop -> Patient Type")
ptype=shop_type
2015-02-04 14:10:41 +00:00
prod_acc=st.get_product_account
track_id=obj.branch_id.track_id.id
2015-02-04 14:10:41 +00:00
for line in obj.lines:
if line.reimbursable=='no':
if line.amount < 1:
continue
prod=line.product_id
acc=prod_acc(prod.id,ptype.id,'cash')
account_id=acc.get("ar_credit_id",None)
ar_debit_id=acc.get("ar_debit_id",None)
if not account_id:
raise Exception("No Income Credit Account for product [%s] %s"%(prod.code, prod.name))
if not ar_debit_id:
raise Exception("No Ar Debit Account for product [%s] %s"%(prod.code, prod.name))
desc=line.description or ""
if prod:
desc="[%s] %s"%(prod.code, line.description or "")
vals['direct_lines'].append(('create',{
"description": desc,
"qty": line.qty,
"unit_price": line.price or 0,
"amount": line.amount or 0,
'account_id': account_id,
'track_id': track_id,
2015-02-04 14:10:41 +00:00
}))
2015-03-18 14:40:58 +00:00
context={
'type': 'in',
'branch_id': obj.branch_id.id,
}
payment_id=get_model("account.payment").create(vals,context=context)
2014-10-20 11:49:54 +00:00
obj.write({
'payment_lines': [('create',{
'payment_id': payment_id,
2014-10-22 08:55:57 +00:00
'amount': pay_amount,
2014-10-20 11:49:54 +00:00
})],
})
2014-10-23 05:24:25 +00:00
payment=get_model('account.payment').browse(payment_id)
payment.post()
2015-02-04 14:10:41 +00:00
if payment.move_id:
for mline in payment.move_id.lines:
mline.write({
'partner_id': partner.id,
})
2014-10-20 11:49:54 +00:00
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Pay OK',
}
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]
2015-03-26 07:11:04 +00:00
if obj.sickbed_id:
obj.sickbed_id.write({
'available': True,
})
2015-03-13 11:42:57 +00:00
obj.write({"state":"cancelled"})
2014-10-03 02:00:47 +00:00
def make_invoices(self,ids,context={}):
2014-12-14 11:15:14 +00:00
setting=get_model("settings").browse(1,context)
2014-10-03 02:00:47 +00:00
currency_id=setting.currency_id.id
2014-12-14 11:15:14 +00:00
if not currency_id:
raise Exception("Currency not found in account settings")
2014-10-03 02:00:47 +00:00
company_id=get_active_company()
uom=get_model("uom").search_browse([['name','ilike','%Unit%']])
if not uom:
raise Exception("Unit not found in uom")
obj=self.browse(ids[0])
2014-12-05 02:31:48 +00:00
if obj.invoices:
for inv in obj.invoices:
inv.void()
2015-07-23 01:25:44 +00:00
due_date=obj.date[0:10]
2014-10-23 04:43:39 +00:00
# cash, credit
2014-12-21 10:11:22 +00:00
is_credit=context.get('is_credit') or False
2014-10-03 02:00:47 +00:00
context['type']='out'
context['inv_type']='invoice'
2015-01-08 08:07:33 +00:00
rmb_lines=[] #yes
normb_lines=[] #no
2015-01-09 05:19:52 +00:00
cst=get_model('clinic.setting').browse(1)
prod_acc=cst.get_product_account
track_id=obj.branch_id.track_id.id
2014-12-21 10:11:22 +00:00
for line in obj.lines:
if line.state!='draft':
continue
2015-01-29 03:12:17 +00:00
if line.amount < 1:
continue #XXX
2015-01-08 08:07:33 +00:00
prod=line.product_id
2015-02-03 07:57:06 +00:00
print("#1.find in line")
2015-01-09 05:19:52 +00:00
account_id=line.account_id.id
ar_debit_id=line.ar_debit_id.id
if not account_id or not ar_debit_id:
2015-02-03 07:57:06 +00:00
print("#2.find in ratchawat setting")
2015-02-04 05:13:10 +00:00
if line.reimbursable=='yes':
acc=prod_acc(prod.id,obj.patient_type_id.id)
else:
2015-02-06 08:32:45 +00:00
stype=cst.shop_type_id # Pay them self
if not stype:
raise Exception("No Patient Type : Clinic Setting -> RD Shop")
2015-02-04 14:10:41 +00:00
if is_credit:
2015-02-06 08:32:45 +00:00
acc=prod_acc(prod.id,stype.id,'credit')
2015-02-04 14:10:41 +00:00
else:
2015-02-06 08:32:45 +00:00
acc=prod_acc(prod.id,stype.id,'cash')
2015-02-03 07:57:06 +00:00
account_id=acc.get("ar_credit_id",None)
ar_debit_id=acc.get("ar_debit_id",None)
2015-01-09 05:19:52 +00:00
if not account_id:
raise Exception("No Income Credit Account for product [%s] %s"%(prod.code, prod.name))
if not ar_debit_id:
raise Exception("No Ar Debit Account for product [%s] %s"%(prod.code, prod.name))
2014-12-21 10:11:22 +00:00
if line.reimbursable=='yes':
2015-01-08 08:07:33 +00:00
rmb_lines.append(('create',{
"product_id": prod.id,
2015-01-09 05:19:52 +00:00
"description": line.description or "",
2014-12-21 10:11:22 +00:00
"qty": line.qty,
"uom_id": line.uom_id.id,
2015-01-09 05:19:52 +00:00
"unit_price": line.price or 0,
"amount": line.amount or 0,
2015-01-08 08:07:33 +00:00
'account_id': account_id,
'ar_debit_id': ar_debit_id,
'track_id': track_id,
2014-12-21 10:11:22 +00:00
}))
else:
2015-01-08 08:07:33 +00:00
normb_lines.append(('create',{
"product_id": prod.id,
2015-01-09 05:19:52 +00:00
"description": line.description or "",
2014-12-21 10:11:22 +00:00
"qty": line.qty,
"uom_id": line.uom_id.id,
2015-01-09 05:19:52 +00:00
"unit_price": line.price or 0,
"amount": line.amount or 0,
2015-01-08 08:07:33 +00:00
'account_id': account_id,
'ar_debit_id': ar_debit_id,
'track_id': track_id,
2015-01-08 08:07:33 +00:00
}))
2014-12-21 10:11:22 +00:00
patient=obj.patient_id
2015-03-04 07:19:53 +00:00
patient_partner=patient.partner_id
2014-12-21 10:11:22 +00:00
2015-01-08 08:07:33 +00:00
if rmb_lines:
2014-12-21 10:11:22 +00:00
ptype=patient.type_id
partner=ptype.contact_id
if not partner:
raise Exception("No contact for patient type %s"%obj.ptype.name)
2014-10-03 02:00:47 +00:00
vals={
"type": "out",
"inv_type": "invoice",
"tax_type": "tax_in",
2015-04-01 10:31:43 +00:00
'date': obj.date,
2014-10-03 02:00:47 +00:00
'due_date': due_date,
2015-01-20 13:58:38 +00:00
"ref": '%s (%s)'%(patient.name or '',patient.number or ''),
'department_id': obj.department_id.id,
2014-10-03 02:00:47 +00:00
"related_id": "clinic.hd.case,%s"%obj.id,
"currency_id": currency_id,
"company_id": company_id,
"lines": [],
"company_id": company_id,
2015-03-18 14:40:58 +00:00
'hdcase_credit': False,
2015-08-11 04:35:46 +00:00
'hdcase_reconcile': True,
2014-10-03 02:00:47 +00:00
}
vals["partner_id"]=partner.id
2015-01-08 08:07:33 +00:00
vals['lines']=rmb_lines
2015-03-04 07:19:53 +00:00
if patient_partner:
vals['patient_partner_id']=patient_partner.id,
2015-04-01 10:31:43 +00:00
#XXX
if obj.branch_id:
context['branch_id']=obj.branch_id.id
get_model("account.invoice").create(vals,context=context)
2014-11-28 04:54:21 +00:00
2015-01-08 08:07:33 +00:00
if normb_lines and is_credit:
2014-12-21 10:11:22 +00:00
partner=patient.partner_id
if not partner:
raise Exception("No contact for this patient %s"%obj.partner.name)
2015-08-11 05:30:58 +00:00
context['branch_id']=obj.branch_id.id
2015-04-01 10:31:43 +00:00
number=self._get_number_invoice_noclaim(context=context)
2014-12-21 10:11:22 +00:00
vals={
'number': number,
2014-12-21 10:11:22 +00:00
"type": "out",
"inv_type": "invoice",
"tax_type": "tax_in",
'due_date': due_date,
2015-08-13 06:27:46 +00:00
"ref": '%s (%s)'%(patient.name or '',patient.number or ''),
2014-12-21 10:11:22 +00:00
"related_id": "clinic.hd.case,%s"%obj.id,
"currency_id": currency_id,
"company_id": company_id,
"lines": [],
"company_id": company_id,
'partner_id':partner.id,
2015-03-18 14:40:58 +00:00
'hdcase_credit': True,
2015-08-11 04:35:46 +00:00
'hdcase_reconcile': True,
2014-12-21 10:11:22 +00:00
}
2015-01-08 08:07:33 +00:00
vals['lines']=normb_lines
2015-03-04 07:19:53 +00:00
if patient_partner:
vals['patient_partner_id']=patient_partner.id,
2014-12-21 10:11:22 +00:00
get_model("account.invoice").create(vals,context) # create alway
2014-10-22 08:55:57 +00:00
2014-12-21 10:11:22 +00:00
obj.make_pickings()
# prevent douplicate create invoice & picking
for line in obj.lines:
line.write({
'state': 'done',
2014-10-23 04:43:39 +00:00
})
2014-10-03 02:00:47 +00:00
2014-10-03 07:27:57 +00:00
def make_pickings(self,ids,context={}):
obj=self.browse(ids[0])
# no picking
if not obj.lines:
return
2014-12-19 18:43:56 +00:00
patient=obj.patient_id
partner=patient.partner_id
2014-10-03 07:27:57 +00:00
if not partner:
raise Exception("Contact not for this patient")
ship_address_id=None
for address in partner.addresses:
if address.type=="shipping":
ship_address_id=address.id
break
if not ship_address_id:
2014-12-19 18:43:56 +00:00
patient.simple_address()
#raise Exception("contact %s dont'have address with type shipping"%partner.name)
2015-01-11 08:10:38 +00:00
# default journal
cust_loc_id=None
wh_loc_id=None
# find location
# 1. from department -> branch -> stock journal -> from, to
department=obj.department_id
if department:
2015-01-13 08:58:47 +00:00
stock_journal=department.pick_out_journal_id
if stock_journal:
wh_loc_id=stock_journal.location_from_id.id
cust_loc_id=stock_journal.location_to_id.id
print("get location from stock journal %s "%(stock_journal.name))
2014-10-03 07:27:57 +00:00
pick_vals={
"type": "out",
2015-01-16 11:19:49 +00:00
'journal_id': stock_journal.id,
2014-10-03 07:27:57 +00:00
"ref": obj.number,
"related_id": "clinic.hd.case,%s"%obj.id,
"partner_id": obj.patient_id.partner_id.id,
"ship_address_id": ship_address_id,
"state": "draft",
"lines": [],
}
2015-01-11 08:10:38 +00:00
if not cust_loc_id:
res=get_model("stock.location").search([["type","=","customer"]])
if not res:
raise Exception("Customer location not found")
cust_loc_id=res[0]
2015-01-11 11:23:28 +00:00
#XXX
no_lines=context.get('no_line') or False
if no_lines:
return
prod_ids=context.get('prod_ids') or []
prod_exist_ids=[]
2014-10-03 07:27:57 +00:00
for line in obj.lines:
2014-12-21 10:11:22 +00:00
if line.state!='draft':
continue
2015-01-29 03:12:17 +00:00
if line.qty < 1:
continue
2014-10-03 07:27:57 +00:00
prod=line.product_id
2015-03-13 06:43:12 +00:00
if prod.type != 'stock':
continue
2015-03-13 00:01:23 +00:00
# check orginal product
prod_code=prod.code.split("-")[0]
2015-03-17 07:00:11 +00:00
if patient.type_id.main_product:
if len(prod_code)>1:
prods=get_model('product').search_browse(['code','=',prod_code])
if not prods:
raise Exception("Can not create good issue: product code %s is not found!"%prod_code)
prod=prods[0]
2015-01-11 11:23:28 +00:00
if prod_ids and prod.id not in prod_ids or prod.id in prod_exist_ids:
continue
prod_exist_ids.append(prod.id)
#XXX
dpt_prods=get_model('clinic.department.product').get_location(obj.department_id.id,prod.id)
if dpt_prods:
print("get location from menu department products")
wh_loc_id=dpt_prods.get('wh_loc_id')
cust_loc_id=dpt_prods.get('cust_loc_id')
#pick_vals['journal_id']=dpt_prods.get('journal_id')
2014-10-03 07:27:57 +00:00
if not wh_loc_id:
2015-01-11 08:10:38 +00:00
wh_loc_id=prod.location_id.id
if wh_loc_id:
2015-01-11 08:10:38 +00:00
res=get_model("stock.location").search([["type","=","internal"]])
if not res:
raise Exception("Warehouse not found")
wh_loc_id=res[0]
2014-10-03 07:27:57 +00:00
line_vals={
"product_id": prod.id,
2015-01-29 03:12:17 +00:00
"qty": line.qty,
2014-10-03 07:27:57 +00:00
"uom_id": prod.uom_id.id,
"location_from_id": wh_loc_id,
"location_to_id": cust_loc_id,
}
pick_vals["lines"].append(("create",line_vals))
if not pick_vals["lines"]:
return {
"flash": "Nothing left to deliver",
}
picking_obj=get_model("stock.picking")
2015-03-17 14:37:18 +00:00
context={
'pick_type': 'out',
'journal_id': pick_vals['journal_id'],
}
pick_id=picking_obj.create(pick_vals,context=context)
2014-10-03 07:27:57 +00:00
pick=picking_obj.browse(pick_id)
pick.set_done([pick_id])
2014-10-03 02:00:47 +00:00
def post_invoices(self,ids,context={}):
obj=self.browse(ids[0])
for inv in obj.invoices:
2014-12-21 13:29:25 +00:00
if inv.amount_total<1:
continue
2014-10-03 02:00:47 +00:00
inv.post()
print("Post!")
2014-10-02 19:12:52 +00:00
2014-10-15 07:52:15 +00:00
def do_treatment(self,ids,context={}):
2014-09-11 03:21:52 +00:00
obj=self.browse(ids)[0]
2014-11-30 05:54:57 +00:00
#TODO should find dlz when confirm visit
2014-10-15 07:52:15 +00:00
if not obj.dialyzers:
2014-11-25 01:41:49 +00:00
raise Exception("Please input dialyzer!")
2014-11-30 05:54:57 +00:00
vals={
'state': 'in_progress',
}
2014-12-19 18:43:56 +00:00
if obj.number=='/':
2015-03-17 15:51:56 +00:00
context['branch_id']=obj.branch_id.id
number=self._get_number(context=context)
2014-12-19 18:43:56 +00:00
vals['number']=number
2014-12-02 08:51:21 +00:00
# update start time
st=get_model("clinic.setting").browse(1)
if st.real_time:
timenow=time.strftime("%H:%M:%S")
date=obj.date
vals['time_start']='%s %s'%(date,timenow)
vals['time_stop']='%s %s'%(date,timenow)
2014-11-30 05:54:57 +00:00
obj.write(vals)
2014-09-11 03:21:52 +00:00
2014-10-05 05:47:19 +00:00
def discontinue(self,ids,context={}):
2014-09-11 03:21:52 +00:00
obj=self.browse(ids)[0]
2014-10-05 05:47:19 +00:00
# TODO pop to note
2014-11-29 14:56:15 +00:00
obj.write({"state":"cancelled"})
2014-10-15 07:52:15 +00:00
def update_usetime(self,ids,context={}):
for obj in self.browse(ids):
2015-01-15 06:32:52 +00:00
is_decrease=context.get('is_decrease')
2014-10-15 07:52:15 +00:00
for dlz_line in obj.dialyzers:
2015-05-04 10:35:11 +00:00
membrane_type=dlz_line.membrane_type or 'unsub'
dialyzer_type=dlz_line.dialyzer_type or 'low'
2015-01-15 06:32:52 +00:00
use_time=dlz_line.use_time or 0
2015-02-10 05:22:04 +00:00
max_use_time=dlz_line.max_use_time or 0
desc=dlz_line.description or ''
2015-01-15 06:32:52 +00:00
if is_decrease:
2015-01-15 06:56:50 +00:00
use_time-=1
2015-01-15 06:32:52 +00:00
print("decrease ok")
2015-02-10 05:22:04 +00:00
vals={
'membrane_type': membrane_type,
'dialyzer_type': dialyzer_type,
'use_time': use_time,
'max_use_time': max_use_time,
'note': desc,
}
if use_time==max_use_time:
vals.update({
2015-01-15 06:32:52 +00:00
'use_time': use_time,
2014-12-04 14:08:29 +00:00
'state': 'expire',
})
2015-02-10 05:22:04 +00:00
elif use_time > max_use_time:
2014-12-04 14:08:29 +00:00
raise Exception("Dialyzer is expired!")
2015-02-10 05:22:04 +00:00
else:
pass
dlz=dlz_line.dialyzer_id
dlz.write(vals)
2014-10-15 07:52:15 +00:00
return True
2014-10-26 08:48:51 +00:00
def create_cycle_item(self,ids,context={}):
for obj in self.browse(ids):
cycle_item=get_model("clinic.cycle.item")
2014-10-27 19:01:18 +00:00
datenow=obj.time_start[0:10]
2014-10-27 14:17:22 +00:00
if not datenow:
datenow=time.strftime('%Y-%m-%d')
2014-10-26 08:48:51 +00:00
cycle_id=obj.cycle_id.id
2015-01-15 06:32:52 +00:00
branch_id=obj.branch_id.id
department_id=obj.department_id.id
2015-01-15 06:32:52 +00:00
dom=[]
if datenow:
dom.append(['date','=',datenow])
if cycle_id:
dom.append(['cycle_id','=',cycle_id])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
2015-01-15 06:32:52 +00:00
cycle_item_ids=cycle_item.search(dom)
2014-10-26 08:48:51 +00:00
cycle_item_id=None
if cycle_item_ids:
cycle_item_id=cycle_item_ids[0]
else:
cycle_item_id=cycle_item.create({
2014-11-26 11:22:17 +00:00
'date': obj.date,
'cycle_id': cycle_id,
'branch_id': branch_id,
'department_id': department_id,
2014-10-26 08:48:51 +00:00
})
obj.write({
'cycle_item_id': cycle_item_id,
})
return True
2014-12-04 14:08:29 +00:00
def do_expense(self,ids,context={}):
2015-03-02 04:03:07 +00:00
# not longer use 2015-02-28
2014-12-04 14:08:29 +00:00
for obj in self.browse(ids):
# clear old expense
for exp in obj.expenes:
exp.delete()
exp_lines=[]
2014-12-14 11:15:14 +00:00
fee=0.0
mdc=0.0
srv=0.0
2014-12-21 10:11:22 +00:00
other=0.0
2014-12-14 11:15:14 +00:00
for line in obj.lines:
amt=line.amount or 0.0
2014-12-21 10:11:22 +00:00
if line.reimbursable=='no':
amt=0
categ=line.product_categ_id
if categ.code=='FEE':
2014-12-14 11:15:14 +00:00
fee+=amt
2014-12-21 10:11:22 +00:00
elif categ.code=='EPO':
2014-12-14 11:15:14 +00:00
mdc+=amt
2014-12-21 10:11:22 +00:00
elif categ.code=='SRV':
2014-12-14 11:15:14 +00:00
srv+=amt
2014-12-21 10:11:22 +00:00
else:
other+=amt
2014-12-14 11:15:14 +00:00
exp_lines.append(('create',{
'date': obj.date,
'patient_id': obj.patient_id.id,
'hd_case_id': obj.id,
'fee_amt': fee,
'mdc_amt': mdc,
'srv_amt': srv,
'state': 'waiting_matching',
}))
2014-12-04 14:08:29 +00:00
obj.write({
'expenes': exp_lines,
})
2014-10-04 18:33:18 +00:00
def complete(self,ids,context={}):
2014-10-02 19:12:52 +00:00
obj=self.browse(ids)[0]
2014-12-14 11:15:14 +00:00
obj.make_invoices(context=context)
obj.post_invoices(context=context)
2014-10-26 08:48:51 +00:00
obj.create_cycle_item()
2015-03-02 04:03:07 +00:00
#obj.do_expense(context=context)
2014-11-30 05:54:57 +00:00
vals={
"state":"waiting_payment", # for government
2014-11-30 05:54:57 +00:00
}
2014-12-02 08:51:21 +00:00
st=get_model("clinic.setting").browse(1)
if st.real_time:
timenow=time.strftime("%H:%M:%S")
date=obj.date
vals['time_stop']='%s %s'%(date,timenow)
2014-11-30 05:54:57 +00:00
obj.write(vals)
2014-10-27 19:01:18 +00:00
if context.get("called"):
return obj.id
2014-10-03 02:00:47 +00:00
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': obj.id,
},
2014-10-04 18:33:18 +00:00
'flash': '%s is completed'%obj.number,
2014-10-03 02:00:47 +00:00
}
2014-09-11 03:21:52 +00:00
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)
2014-10-20 09:08:03 +00:00
2014-10-20 09:03:17 +00:00
def onchange_hct(self,context={}):
data=context['data']
2014-10-22 02:25:14 +00:00
if not data.get("hct"):
data['hct']=0
hct=data["hct"]
2014-10-21 00:34:14 +00:00
msg=""
# XXX do not hard code
2015-01-15 05:15:46 +00:00
if(hct<=36):
2014-11-18 06:02:47 +00:00
msg="สามารถเบิกค่ายาสูงสุดไม่เกิน 1,125บาท ต่อ สัปดาห์"
2015-01-15 05:15:46 +00:00
elif(hct>36 and hct<=39):
2014-11-18 06:02:47 +00:00
msg="สามารถเบิกค่ายาสูงสุดไม่เกิน 750บาท ต่อ สัปดาห์"
elif(hct> 39):
msg="ไม่สามารถเบิกค่ายาฉีดได้ทุกตัว"
2014-10-21 00:34:14 +00:00
data['hct_msg']=msg
2014-10-20 09:03:17 +00:00
return data
2014-10-01 10:52:21 +00:00
2014-10-15 07:52:15 +00:00
def undo(self,ids,context={}):
obj=self.browse(ids)[0]
2015-01-15 06:32:52 +00:00
context['is_decrease']=True
obj.update_usetime(context=context)
2014-12-21 10:11:22 +00:00
for line in obj.lines:
line.write({
'state': 'draft',
})
2014-10-15 07:52:15 +00:00
for inv in obj.invoices:
inv.write({
'state': 'draft',
})
2015-02-13 07:46:39 +00:00
if inv.move_id:
inv.move_id.to_draft()
inv.move_id.delete()
2014-10-15 07:52:15 +00:00
inv.delete()
for pick in obj.pickings:
pick.write({
'state': 'draft',
})
pick.delete()
2014-10-21 00:34:14 +00:00
for payment in obj.payments:
payment.to_draft()
payment.delete()
for pm_line in obj.payment_lines:
pm_line.delete()
2014-10-26 08:48:51 +00:00
2014-12-04 14:08:29 +00:00
for exp in obj.expenes:
exp.delete()
2014-10-26 04:28:08 +00:00
state=context.get("state","in_progress") #force state
2014-10-15 07:52:15 +00:00
obj.write({
2014-10-26 04:28:08 +00:00
'state': state,
2014-10-15 07:52:15 +00:00
})
2015-03-17 04:35:48 +00:00
# update sickbed
2015-03-23 06:27:56 +00:00
if obj.sickbed_id:
obj.sickbed_id.write({
'available': False,
})
2014-10-26 04:28:08 +00:00
2014-10-15 07:52:15 +00:00
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': obj.id,
},
'flash': '%s has been undo'%obj.number,
}
2014-10-22 08:55:57 +00:00
def view_payment(self,ids,context={}):
print("clinic_view_payment")
2014-10-22 10:13:43 +00:00
return {
'next': {
'name': 'payment',
'mode': 'form',
'active_id': ids[0],
},
}
2014-10-23 04:43:39 +00:00
2014-12-05 02:31:48 +00:00
def request_fee(self,ids,context={}):
2014-10-23 04:43:39 +00:00
obj=self.browse(ids)[0]
2015-01-15 06:32:52 +00:00
#obj.update_usetime()
2014-12-05 02:31:48 +00:00
obj.complete()
# send some message to anyboby: patient
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': obj.id,
}
2014-12-05 02:31:48 +00:00
}
def pay(self,ids,context={}):
return {
'next': {
'name': 'clinic_payment',
'refer_id': ids[0], #XXX
}
}
def done(self,ids,context={}):
obj=self.browse(ids)[0]
2015-04-24 06:48:11 +00:00
count=0
for sline in obj.staffs:
if sline.staff_id:
count+=1
if not count:
raise Exception("Please define doctor for patient %s"%obj.patient_id.name)
2015-01-15 06:32:52 +00:00
obj.update_usetime()
#FIXME allow user to write sickbed status
user_id=get_active_user()
set_active_user(1)
2015-02-25 13:19:50 +00:00
nurse_id=None
for st in get_model("clinic.staff").search_browse([['user_id','=',user_id]]):
nurse_id=st.id
obj.write({
'state': 'completed',
'nurse_id': nurse_id,
})
2014-12-19 18:19:19 +00:00
obj.sickbed_id.write({
2015-03-17 04:35:48 +00:00
'available': True,
2014-12-19 18:19:19 +00:00
})
set_active_user(user_id)
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Finish treatment!',
}
2014-10-23 08:21:29 +00:00
def get_report_payment_data(self,context={}):
if not context.get('payment_id'):
return {}
2014-10-23 08:21:29 +00:00
payment_id=context.get("payment_id")
if not payment_id:
return {}
payment=get_model("account.payment").browse(int(payment_id))
comp_id=get_active_company()
comp=get_model('company').browse(comp_id)
2015-03-18 03:51:38 +00:00
hdcase=payment.related_id
if hdcase:
context['branch_id']=hdcase.branch_id.id
st=get_model('settings').browse(1,context=context)
2015-02-27 08:01:56 +00:00
cst=get_model('clinic.setting').browse(1)
cust=payment.partner_id
cust_name=cust.name or ''
cust_addr=''
if cust.addresses:
cust_addr=cust.addresses[0].address_text
2015-03-11 03:52:45 +00:00
if 'your' in cust_addr:
cust_addr=''
if cust.walkin_cust:
cust_name=payment.ref or ''
no=1
sub_total=0
amount_total=0
lines=[]
2015-07-01 01:13:25 +00:00
def get_prod(desc):
product=None
if desc:
i1=desc.index('[')
i2=desc.index(']')
code=desc[i1+1:i2]
for prod in get_model("product").search_browse([['code','=',code]]):
product=prod
return product
for line in payment.lines:
amt=line.amount or 0
2015-03-18 14:40:58 +00:00
desc=line.description or ''
uom_name=""
2015-07-01 01:13:25 +00:00
prod=get_prod(desc)
if prod:
uom_name=prod.uom_id.name
lines.append({
'no': no,
'product_name': '',
2015-03-18 14:40:58 +00:00
'description': desc,
'uom_name': uom_name,
'qty': line.qty or 0,
'price': line.unit_price or 0,
'amount': amt,
})
sub_total+=amt
no+=1
amount_total=sub_total
is_draft=payment.state=='draft' and True or False
is_cheque=False
pay_type=payment.pay_type or ''
2015-02-27 08:01:56 +00:00
user_id=get_active_user()
user=get_model("base.user").browse(user_id)
2015-03-18 03:51:38 +00:00
comp_name=comp.name or ""
if st.default_address_id.company:
comp_name=st.default_address_id.company or ""
2015-03-25 08:23:52 +00:00
add=st.default_address_id
2014-10-23 08:21:29 +00:00
data={
2015-03-18 03:51:38 +00:00
'comp_name': comp_name,
2015-03-25 08:23:52 +00:00
'add_address': add.address or '',
'add_address2': add.address2 or '',
'add_province_name': add.province_id.name or '',
'add_district_name': add.district_id.name or '',
2015-03-25 10:26:18 +00:00
'add_subdistrict_name': add.subdistrict_id.name or '',
2015-03-25 08:23:52 +00:00
'add_city': add.city or '',
'add_postal_code': add.postal_code or '',
'add_phone': add.phone or '',
'add_fax': add.fax or '',
'tax_no': st.tax_no or '',
'number': payment.number or '',
'ref': payment.ref,
'date': payment.date,
2015-03-13 07:43:57 +00:00
'datenow': payment.date or time.strftime("%d/%m/%Y"),
'dateprint': payment.date or time.strftime("%d/%m/%Y %H:%M:%S"),
'cust_name': cust_name,
'cust_addr': cust_addr,
2015-02-27 08:01:56 +00:00
'user_name': user.name or "",
'note': payment.memo or '',
'lines':lines,
'amount_subtotal': sub_total,
'amount_total': amount_total,
'total_text': utils.num2word(amount_total),
'is_cheque': is_cheque,
'is_draft': is_draft,
'pay_type': pay_type,
2015-03-13 07:43:57 +00:00
'state': payment.state or "",
2014-10-23 08:21:29 +00:00
}
if pay_type=='direct':
data['pay_type']='Cash'
else:
data['pay_type']='Credit'
if st.logo:
data['logo']=get_file_path(st.logo)
2015-02-27 08:01:56 +00:00
if cst.signature:
data['signature']=get_file_path(cst.signature)
2014-10-23 08:21:29 +00:00
return data
def get_payment_data(self,ids,context={}):
settings=get_model('settings').browse(1)
pages=[]
for obj in self.browse(ids):
2015-03-04 04:54:55 +00:00
if not obj.payments:
raise Exception("Receipt not found!")
for payment in obj.payments:
context['payment_id']=payment.id
data=self.get_report_payment_data(context=context)
2015-06-30 10:12:53 +00:00
limit_item=10
2015-03-13 07:43:57 +00:00
if data['state']=='draft':
limit_item=10
2015-03-11 03:52:45 +00:00
for i in range(len(data['lines']),limit_item):
2015-03-11 01:44:02 +00:00
data['lines'].append({
'no': '',
'product_name': '',
'description': '',
'uom_name': '',
'qty': None,
'price': None,
'amount': None,
})
pages.append(data)
if pages:
pages[-1]["is_last_page"]=True
return {
"pages": pages,
"logo": get_file_path(settings.logo),
}
2014-10-26 01:34:10 +00:00
def new_dialyzer(self,ids,context={}):
obj=self.browse(ids)[0]
2015-01-15 08:45:11 +00:00
is_wiz=context.get("is_wiz")
dlz_vals={}
if is_wiz:
pop_id=context.get('pop_id')
if pop_id:
pop=get_model("clinic.hd.case.popup.dlz").browse(pop_id)
prod=pop.product_id
dlz_vals={
'product_id': prod.id,
'name': prod.name or "",
'note': pop.note or '',
'use_time': 0,
'max_use_time': pop.max_use_time,
'dialyzer_type': pop.dialyzer_type,
'exp_date': pop.exp_date,
'department_id': obj.department_id.id,
'patient_id': obj.patient_id.id,
'visit_id': obj.visit_id.id,
2015-01-29 14:55:05 +00:00
"membrane_type": pop.membrane_type,
2015-01-15 08:45:11 +00:00
}
else:
2015-02-18 08:50:35 +00:00
dlz_vals=get_model("clinic.dialyzer").default_get(context=context)
2015-01-15 08:45:11 +00:00
dlz_vals['patient_id']=obj.patient_id.id
dlz_vals['company_id']=dlz_vals['company_id'][0]
product_name=dlz_vals['product_id'][1]
dlz_vals['product_id']=dlz_vals['product_id'][0]
2014-10-26 02:23:27 +00:00
dlz_id=get_model('clinic.dialyzer').create(dlz_vals)
2014-10-26 01:34:10 +00:00
dialyzer=get_model("clinic.dialyzer").browse(dlz_id)
2015-02-10 08:30:21 +00:00
dialyzer.validate()
2014-10-26 01:34:10 +00:00
vals={
'dlz_id': dlz_id,
'dialyzers': [],
}
vals['dialyzers'].append(('create',{
'dialyzer_id': dlz_id,
2015-01-15 06:44:58 +00:00
'description': dialyzer.name or product_name,
2014-10-26 01:34:10 +00:00
'use_time': 1,
'max_use_time': dialyzer.max_use_time,
'dialyzer_type': dialyzer.dialyzer_type,
2015-02-10 05:22:04 +00:00
'membrane_type': dialyzer.membrane_type,
2014-10-26 01:34:10 +00:00
}))
obj.write(vals)
2014-10-27 19:01:18 +00:00
if context.get('called'):
return obj.id
2014-10-26 01:34:10 +00:00
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Create new dialyzer successfully',
}
2014-10-26 04:28:08 +00:00
def to_draft(self,ids,context={}):
obj=self.browse(ids)[0]
context['state']='draft'
obj.undo(context=context)
2014-11-01 03:48:22 +00:00
def get_staff(self,ids,context={}):
2014-11-01 03:48:22 +00:00
res={}
for obj in self.browse(ids):
doctor=0
nurse=0
2014-11-21 16:11:57 +00:00
doctor_id=None
for ps in obj.staffs:
2014-11-21 16:11:57 +00:00
if ps.type=="doctor":
2015-04-29 01:36:05 +00:00
if ps.priop=='personal':
doctor_id=ps.staff_id.id
2014-11-01 03:48:22 +00:00
doctor+= 1
else:
nurse+=1
2015-05-11 05:23:42 +00:00
if not doctor_id:
for ps in obj.staffs:
if ps.type=="doctor":
doctor_id=ps.staff_id.id
2014-11-01 03:48:22 +00:00
res[obj.id]={
'total_doctor': doctor,
'total_nurse': nurse,
2014-11-21 16:11:57 +00:00
'doctor_id': doctor_id,
2014-11-01 03:48:22 +00:00
}
return res
2014-10-15 07:52:15 +00:00
2014-12-21 02:54:45 +00:00
def get_staff_line(self,vals,patient_id=None):
2014-11-26 11:22:17 +00:00
if not patient_id:
return vals
2014-12-04 08:37:54 +00:00
# staff
2014-11-26 11:22:17 +00:00
patient=get_model("clinic.patient").browse(patient_id)
2015-01-14 05:30:22 +00:00
if not vals.get('staffs'):
2014-12-04 08:37:54 +00:00
vals['staffs']=[]
2015-01-14 05:30:22 +00:00
doctor=patient.doctor_id
if doctor:
2014-11-26 11:22:17 +00:00
vals['staffs'].append(('create',{
'staff_id': doctor.id,
'type': 'doctor',
2015-04-29 01:36:05 +00:00
'priop': 'personal',
2014-11-26 11:22:17 +00:00
}))
2014-12-04 08:37:54 +00:00
# fee
2014-11-26 11:22:17 +00:00
st=get_model("clinic.setting").browse(1)
2014-12-19 16:57:34 +00:00
if st.auto_gen:
2014-12-21 13:29:25 +00:00
return vals
2014-11-26 11:22:17 +00:00
if not vals.get('lines'):
vals['lines']=[]
for st_prod in st.products:
2015-02-03 07:57:06 +00:00
ptype=st_prod.patient_type_id
prod=st_prod.product_id
prod_acc=st.get_product_account(prod.id,ptype.id) # get product account
if patient.type_id.id==ptype.id:
2015-01-30 11:15:13 +00:00
price=st_prod.price or 0
qty=st_prod.qty or 0
2014-11-27 15:14:31 +00:00
amt=st_prod.amount
categ=st_prod.product_categ_id
2015-02-03 07:57:06 +00:00
account_id=prod_acc.get("ar_credit_id",None)
ar_debit_id=prod_acc.get("ar_debit_id",None)
2014-11-27 15:14:31 +00:00
if not amt:
amt=qty*price
line_vals={
2014-12-21 02:54:45 +00:00
'product_categ_id': categ.id,
'uom_id': st_prod.uom_id.id,
2014-11-26 11:22:17 +00:00
'description': st_prod.description,
2014-11-27 15:14:31 +00:00
'price': price,
'qty': qty,
2014-12-21 02:54:45 +00:00
'reimbursable': st_prod.reimbursable,
2014-11-27 15:14:31 +00:00
'amount': amt,
2015-01-09 05:19:52 +00:00
'account_id': account_id,
'ar_debit_id': ar_debit_id,
}
if prod:
line_vals.update({
'product_id': prod.id,
})
#if not line_vals['account_id']:
#line_vals['account_id']=prod.sale_account_id.id
#if not line_vals['account_id']:
#raise Exception("Please contact accountant: product [%s] %s"%(prod.code, prod.name))
vals['lines'].append(('create',line_vals))
2014-12-02 11:41:05 +00:00
# XXX need to get default
2014-12-02 07:08:20 +00:00
partner=patient.type_id.contact_id
if partner:
vals['fee_partner_id']=partner.id
2014-12-02 11:41:05 +00:00
if not partner:
raise Exception("Not found contact %s at menu: Patiens -> Type"%patient.type_id.name)
2014-11-26 11:22:17 +00:00
return vals
2014-11-28 04:54:21 +00:00
2014-12-19 16:57:34 +00:00
def get_invoice_policy(self,vals={},patient_id=None):
2014-11-28 04:54:21 +00:00
if patient_id:
patient=get_model("clinic.patient").browse(patient_id)
st=get_model("clinic.setting").browse(1)
for pl in st.invoice_policies:
policy=pl.invoice_policy
2014-12-19 16:57:34 +00:00
patient_type=pl.patient_type_id
2014-11-28 04:54:21 +00:00
opt=pl.invoice_option
2014-12-19 16:57:34 +00:00
if patient.type_id.id==patient_type.id:
2014-11-28 04:54:21 +00:00
vals['invoice_policy']=policy
vals['invoice_option']=opt
break
return vals
2014-11-26 11:22:17 +00:00
2015-02-03 14:09:53 +00:00
def get_hct(self,vals,patient_id):
fmt="%Y-%m-%d"
datenow=datetime.strptime(vals['time_start'][0:10],fmt)
wd=datenow.weekday()
date_week=[datenow.strftime(fmt)]
count=1
res=''
for i in list(range(0,wd)):
if i < wd:
res=(datenow-timedelta(days=count)).strftime(fmt)
else:
res=(datenow+timedelta(days=count)).strftime(fmt)
date_week.append(res)
count+=1
count=1
for i in list(range(wd,6)):
if i < wd:
res=(datenow-timedelta(days=count)).strftime(fmt)
else:
res=(datenow+timedelta(days=count)).strftime(fmt)
date_week.append(res)
count+=1
print("day week", date_week)
# search hct from monday to sunday
dom=[]
dom.append(['patient_id','=',patient_id])
dom.append(['date', 'in',date_week])
# 1. get date between weekend
# 2. if date out of dat gen set 0 else copy previous hct
for hdcase in self.search_browse(dom):
vals['hct']=hdcase.hct or 0
#break
return vals
2014-11-26 11:22:17 +00:00
def create(self,vals,**kw):
patient_id=vals['patient_id']
2015-01-29 14:55:05 +00:00
if 'vascular_acc' in vals.keys():
patient=get_model("clinic.patient").browse(patient_id)
patient.write({
'vascular_acc': vals['vascular_acc']
})
2014-12-21 02:54:45 +00:00
vals=self.get_staff_line(vals,patient_id)
2015-02-03 14:09:53 +00:00
vals=self.get_hct(vals,patient_id)
2014-11-26 11:22:17 +00:00
new_id=super().create(vals,**kw)
2015-01-13 07:56:30 +00:00
self.function_store([new_id])
2014-11-26 11:22:17 +00:00
return new_id
2015-02-13 07:46:39 +00:00
def check_hct(self,obj):
if obj.hct_include and obj.state=='in_progress':
2015-02-13 07:46:39 +00:00
if not obj.hct:
raise Exception("Please define HCT")
else:
if len(str(obj.hct))<=1:
raise Exception("HCT should be more that 9")
2014-11-26 11:22:17 +00:00
def write(self,ids,vals,**kw):
2014-12-05 02:31:48 +00:00
obj=self.browse(ids)[0]
2015-01-29 14:55:05 +00:00
# update vascular access
if 'vascular_acc' in vals.keys():
patient_id=obj.patient_id.id
if 'patient_id' in vals.keys():
patient_id=vals['patient_id']
patient=get_model("clinic.patient").browse(patient_id)
patient.write({
'vascular_acc': vals['vascular_acc']
})
2015-01-09 05:19:52 +00:00
if 'sickbed_id' in vals.keys():
user_id=get_active_user()
set_active_user(1)
2015-01-09 05:19:52 +00:00
if vals['sickbed_id']!=obj.sickbed_id.id and obj.state!='draft':
if obj.sickbed_id:
obj.sickbed_id.write({
2015-03-17 04:35:48 +00:00
'available': True,
2015-01-09 05:19:52 +00:00
})
sb=get_model("clinic.sickbed").browse(vals['sickbed_id'])
sb.write({
'state': 'not_available',
})
set_active_user(user_id)
2015-03-23 06:58:30 +00:00
if 'lines' in vals.keys():
if not vals['lines']:
print("lines is empty will update it now...")
patient_id=obj.patient_id.id
vals=self.get_staff_line(vals,patient_id)
2015-01-13 07:56:30 +00:00
self.function_store(ids)
2014-12-21 02:54:45 +00:00
super().write(ids,vals,**kw)
2015-02-13 07:46:39 +00:00
obj=self.browse(ids)[0]
2015-04-23 09:30:20 +00:00
# prevent duplicate doctor
print('obj.state ', obj.state)
if obj.state in ('waiting_payment', 'paid'):
st={}
for lstaff in obj.staffs:
staff=lstaff.staff_id
if not st.get(staff.id):
st[staff.id]=1
else:
raise Exception("Douplicate %s"%staff.name)
2015-04-24 06:48:11 +00:00
if not st:
raise Exception("Please define doctor!")
2015-02-13 07:46:39 +00:00
self.check_hct(obj)
2014-11-26 11:22:17 +00:00
2014-11-30 05:54:57 +00:00
def approve(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({
'state': 'completed',
})
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': obj.id,
},
'flash': '%s has been approval'%obj.number,
}
2015-01-23 00:56:15 +00:00
def onchange_datestart(self,context={}):
data=context['data']
data['date']=data['time_start'][0:10]
data['time_stop']='%s %s'%(data['date'],data['time_stop'][11:])
return data
def onchange_cycle_item(self,context={}):
data=context['data']
item=get_model("clinic.cycle.item").browse(data['cycle_item_id'])
cycle=item.cycle_id
date=item.date
time_start='%s %s'%(date,cycle.time_start)
time_stop='%s %s'%(date,cycle.time_stop)
data['cycle_id']=cycle.id
data['date']=date
data['time_start']=time_start
data['time_stop']=time_stop
data['duration']=cycle.duration
return data
2015-01-29 16:38:22 +00:00
2015-03-17 04:35:48 +00:00
def onchange_weight(self,context={}):
data=context['data']
wt_stop=data['wt_stop'] or 0
wt_start=data['wt_start'] or 0
data['ultrafittration']=wt_stop-wt_start
return data
2015-01-29 16:38:22 +00:00
def new_shop(self,ids,context={}):
return {
'next': {
2015-02-04 08:51:14 +00:00
'hd_case_call': True,
2015-01-29 16:38:22 +00:00
'refer_id': ids[0],
'name': 'clinic_popup_shop',
}
}
2015-03-19 06:08:29 +00:00
def drop_dlz(self,ids,context={}):
obj=self.browse(ids)[0]
for dline in obj.dialyzers:
use_time=dline.use_time or 0
dlz=dline.dialyzer_id
if dlz.state=='drop':
raise Exception("%s is drop!"%dlz.number)
dlz.write({
'use_time': use_time,
})
dlz.drop(context=context)
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': obj.id,
},
'flash': '%s is droped'%dlz.number,
}
2015-04-24 06:48:11 +00:00
def onchange_staff(self,context={}):
data=context['data']
path=context['path']
line=get_data_path(data,path,parent=True)
if not line.get('priop'):
2015-04-29 01:36:05 +00:00
line['priop']='personal'
2015-04-24 06:48:11 +00:00
return data
2014-11-28 04:54:21 +00:00
2014-10-23 04:43:39 +00:00
HDCase.register()