2014-10-02 19:12:52 +00:00
|
|
|
import time
|
|
|
|
|
2014-10-20 09:03:17 +00:00
|
|
|
from datetime import datetime
|
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
|
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-11-26 11:22:17 +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
|
|
|
|
|
|
|
def _get_total(self,ids,context={}):
|
|
|
|
vals={}
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
total=0
|
|
|
|
due_amt=0
|
|
|
|
fee_amt=0
|
|
|
|
mdc_amt=0
|
|
|
|
for line in obj.lines:
|
|
|
|
if line.type=='fee':
|
|
|
|
fee_amt+=line.amount or 0.0
|
|
|
|
elif line.type=='medicine':
|
|
|
|
mdc_amt+=line.amount or 0.0
|
|
|
|
total+=line.amount or 0.0
|
|
|
|
|
|
|
|
# TODO need to check with invoice policy
|
|
|
|
# government pay for :
|
|
|
|
# - fee -> create invoice with fee type on state waiting to payment
|
|
|
|
# - fee & medicine -> create 2 invoice for fee and medicine type
|
|
|
|
if obj.invoice_policy=='fee':
|
|
|
|
due_amt=total-fee_amt
|
|
|
|
elif obj.invoice_policy=='fee_mdc':
|
|
|
|
due_amt=total-(fee_amt+mdc_amt)
|
|
|
|
else:
|
|
|
|
due_amt=total
|
|
|
|
|
|
|
|
for line in obj.payment_lines:
|
|
|
|
due_amt-=line.amount or 0.0
|
|
|
|
vals[obj.id]={
|
|
|
|
"total": total,
|
|
|
|
"amount": due_amt,
|
|
|
|
'fee_amount': fee_amt,
|
|
|
|
'mdc_amount': mdc_amt,
|
|
|
|
}
|
|
|
|
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-02 07:08:20 +00:00
|
|
|
res[obj.id]=patient.type_id.name
|
2014-11-29 14:56:15 +00:00
|
|
|
return res
|
|
|
|
|
2014-08-21 07:29:37 +00:00
|
|
|
_fields={
|
|
|
|
"number": fields.Char("Number",required=True,search=True),
|
2014-11-29 14:56:15 +00:00
|
|
|
"ref": fields.Char("Ref",search=True),
|
|
|
|
"time_start": fields.DateTime("Start Time",required=True,search=True),
|
|
|
|
"time_stop": fields.DateTime("Finish Time",required=True,search=True),
|
2014-11-21 16:11:57 +00:00
|
|
|
"date": fields.Date("Date",required=True,search=True),
|
2014-10-02 00:34:58 +00:00
|
|
|
"patient_id": fields.Many2One("clinic.patient","Patient",required=True,search=True),
|
2014-12-02 07:08:20 +00:00
|
|
|
"patient_type": fields.Char("Service Type",function="_get_patient_type"),
|
|
|
|
"vascular_acc": fields.Many2One("clinic.vascular.access","Vascular Ac."),
|
2014-11-25 11:39:53 +00:00
|
|
|
"nurse_id": fields.Many2One("clinic.staff","Approve By", domain=[['type','=','nurse']]),
|
2014-12-02 07:08:20 +00:00
|
|
|
"staff_id": fields.Many2One("clinic.staff", "Staff"),
|
2014-10-02 00:34:58 +00:00
|
|
|
"department_id": fields.Many2One("clinic.department", "Department",search=True),
|
2014-11-29 14:56:15 +00:00
|
|
|
"wt_kg": fields.Float("Wt.kg."),
|
|
|
|
"bp": fields.Integer("BP"),
|
|
|
|
"mm_hg": fields.Integer("mmHG"),
|
2014-12-02 07:08:20 +00:00
|
|
|
"hct": fields.Integer("Hct%(<40)",required=True),
|
2014-11-29 14:56:15 +00:00
|
|
|
"hct_msg" : fields.Char(""),
|
2014-10-08 04:36:22 +00:00
|
|
|
"check_goverment_pay" : fields.Boolean("The Government Pay"),
|
|
|
|
"check_personal_pay" : fields.Boolean("Pay yourself"),
|
2014-11-29 14:56:15 +00:00
|
|
|
"state": fields.Selection([("draft","Draft"),('waiting_treatment','Waiting Treatment'),("in_progress","In Progress"),('waiting_approval','Waiting Approval'),("completed","Completed"),("waiting_payment","Waiting Payment"),("discountinued","Discountinued"),("cancelled","Cancelled")],"Status",required=True),
|
2014-11-21 17:31:10 +00:00
|
|
|
"dialyzers": fields.One2Many("clinic.hd.case.dialyzer","hd_case_id","Dialyzers"),
|
2014-10-02 19:12:52 +00:00
|
|
|
"lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"),
|
2014-11-25 11:39:53 +00:00
|
|
|
"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-09-11 03:21:52 +00:00
|
|
|
"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-20 11:49:54 +00:00
|
|
|
"payment_lines": fields.One2Many("clinic.payment","hd_case_id","Payment Lines"),
|
2014-10-02 02:02:22 +00:00
|
|
|
'visit_id': fields.Many2One("clinic.visit", "Visit"),
|
2014-11-30 13:05:14 +00:00
|
|
|
'duration': fields.Integer("Duration(Hours)",function="_get_duration"),
|
2014-11-28 04:54:21 +00:00
|
|
|
"total": fields.Float("Total",function="_get_total",readonly=True,function_multi=True),
|
|
|
|
"fee_amount": fields.Float("Fee",function="_get_total",readonly=True,function_multi=True),
|
|
|
|
"mdc_amount": fields.Float("Medicine",function="_get_total",readonly=True,function_multi=True),
|
|
|
|
"amount": fields.Float("Due Amount",function="_get_total",readonly=True,function_multi=True),
|
2014-10-06 00:48:42 +00:00
|
|
|
'fee_partner_id': fields.Many2One("partner","Contact Fee"),
|
2014-10-23 04:43:39 +00:00
|
|
|
'fee_paid': fields.Boolean("Fee Paid"),
|
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"),
|
2014-11-30 06:30:09 +00:00
|
|
|
'cycle_item_id': fields.Many2One("clinic.cycle.item","Nurse Schedule"), # 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
|
2014-11-25 11:39:53 +00:00
|
|
|
"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:"),
|
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
|
|
|
_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-10-02 00:34:58 +00:00
|
|
|
"number": _get_number,
|
|
|
|
"company_id": lambda *a: get_active_company(),
|
2014-11-29 14:56:15 +00:00
|
|
|
'wt_kg': 0.0,
|
|
|
|
'bp': 0,
|
|
|
|
'mm_hg': 0,
|
2014-10-21 00:34:14 +00:00
|
|
|
'hct': 0,
|
2014-11-18 06:02:47 +00:00
|
|
|
'hct_msg': "สามารถเบิกค่ายาสูงสุดไม่เกิน 1,125บาท ต่อ สัปดาห์",
|
2014-10-23 04:43:39 +00:00
|
|
|
'fee_paid': False,
|
2014-11-28 04:54:21 +00:00
|
|
|
'invoice_option': 'fee',
|
|
|
|
'invoice_policy': 'fee',
|
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
|
2014-10-26 02:23:27 +00:00
|
|
|
line["description"]=dialyzer.description 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["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
|
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)
|
|
|
|
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']
|
2014-11-30 13:05:14 +00:00
|
|
|
if patient_id:
|
|
|
|
patient=get_model('clinic.patient').browse(patient_id)
|
|
|
|
department=patient.department_id
|
|
|
|
cycle=patient.cycle_id
|
2014-12-02 07:08:20 +00:00
|
|
|
partner=patient.type_id.contact_id
|
2014-11-30 13:05:14 +00:00
|
|
|
data['department_id']=department.id
|
|
|
|
data['cycle_id']=cycle.id
|
2014-12-02 07:08:20 +00:00
|
|
|
if partner:
|
|
|
|
data['fee_partner_id']=partner.id
|
|
|
|
else:
|
|
|
|
data['fee_partner_id']=None
|
|
|
|
data['patient_type']=patient.type_id.name or ""
|
2014-11-01 03:48:22 +00:00
|
|
|
data['dialyzers']=[]
|
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
|
|
|
|
self.update_amount(data)
|
|
|
|
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)
|
|
|
|
line['uom_id']=prod.uom_id.id
|
|
|
|
line['description']=prod.name
|
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
|
|
|
|
self.update_amount(data)
|
2014-10-03 02:00:47 +00:00
|
|
|
return data
|
|
|
|
|
2014-11-26 11:22:17 +00:00
|
|
|
def update_amount(self,data):
|
|
|
|
total_amt=0.0
|
2014-10-22 08:55:57 +00:00
|
|
|
fee_amt=0.0
|
2014-10-03 02:00:47 +00:00
|
|
|
for line in data['lines']:
|
|
|
|
price=line.get('price') or 0
|
|
|
|
qty=line.get('qty') or 0
|
2014-11-26 11:22:17 +00:00
|
|
|
amt=qty*price
|
2014-10-22 08:55:57 +00:00
|
|
|
if line['type']=='fee':
|
|
|
|
fee_amt+=amt
|
|
|
|
else:
|
2014-11-26 11:22:17 +00:00
|
|
|
total_amt+=amt
|
|
|
|
data['total']=total_amt+fee_amt
|
2014-10-22 08:55:57 +00:00
|
|
|
data['fee_amount']=fee_amt
|
2014-10-20 11:49:54 +00:00
|
|
|
for line in data['payment_lines']:
|
2014-11-26 11:22:17 +00:00
|
|
|
total_amt-=line['amount'] or 0.0
|
|
|
|
data['amount']=total_amt
|
2014-10-13 08:10:20 +00:00
|
|
|
return data
|
|
|
|
|
2014-10-20 11:49:54 +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
|
|
|
|
|
|
|
|
def make_payment(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
2014-10-22 02:25:14 +00:00
|
|
|
if not obj.total:
|
|
|
|
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-10-20 11:49:54 +00:00
|
|
|
raise Exception("No contact on this patient")
|
|
|
|
company_id=get_active_company()
|
2014-11-26 11:22:17 +00:00
|
|
|
account_receivable_id=partner.account_receivable_id
|
|
|
|
if not account_receivable_id:
|
|
|
|
st=get_model('settings').browse(1)
|
|
|
|
account_receivable_id=st.account_receivable_id
|
|
|
|
if not account_receivable_id:
|
|
|
|
raise Exception("Not found account recieveable in account setting")
|
|
|
|
account_id=account_receivable_id.id
|
2014-10-22 02:25:14 +00:00
|
|
|
if not account_id:
|
|
|
|
raise Exception("No Account for payment")
|
2014-10-22 08:55:57 +00:00
|
|
|
pay_amount=obj.pay_amount
|
2014-11-26 11:22:17 +00:00
|
|
|
|
2014-10-22 08:55:57 +00:00
|
|
|
if context.get("amount",0):
|
|
|
|
pay_amount=context['amount'] or 0.0
|
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"),
|
2014-10-20 11:49:54 +00:00
|
|
|
"account_id": account_id,
|
|
|
|
'related_id': "clinic.hd.case,%s"%obj.id,
|
|
|
|
'direct_lines': [],
|
|
|
|
}
|
|
|
|
vals['direct_lines'].append(('create',{
|
|
|
|
'description': 'Payment; %s'%obj.number,
|
|
|
|
'account_id': account_id,
|
|
|
|
'qty': 1,
|
2014-10-22 08:55:57 +00:00
|
|
|
'unit_price': pay_amount,
|
|
|
|
'amount': pay_amount,
|
2014-10-20 11:49:54 +00:00
|
|
|
}))
|
|
|
|
|
|
|
|
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
|
|
|
|
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()
|
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]
|
2014-10-13 08:10:20 +00:00
|
|
|
obj.write({" state":"cancelled"})
|
2014-10-03 02:00:47 +00:00
|
|
|
|
|
|
|
def make_invoices(self,ids,context={}):
|
|
|
|
setting=get_model("settings").browse(1)
|
|
|
|
currency_id=setting.currency_id.id
|
|
|
|
account_receivable_id=setting.account_receivable_id.id
|
|
|
|
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-11-28 04:54:21 +00:00
|
|
|
due_date=obj.date[0:10] # XXX
|
2014-10-23 04:43:39 +00:00
|
|
|
# cash, credit
|
|
|
|
make_invoice=context.get('make_invoice',True)
|
2014-10-03 02:00:47 +00:00
|
|
|
context['type']='out'
|
|
|
|
context['inv_type']='invoice'
|
2014-10-22 10:13:43 +00:00
|
|
|
fee_lines=[]
|
2014-11-28 04:54:21 +00:00
|
|
|
mdc_lines=[]
|
2014-10-22 10:13:43 +00:00
|
|
|
if obj.lines:
|
2014-10-03 02:00:47 +00:00
|
|
|
vals={
|
|
|
|
"type": "out",
|
|
|
|
"inv_type": "invoice",
|
|
|
|
"tax_type": "tax_in",
|
|
|
|
'due_date': due_date,
|
|
|
|
"ref": obj.number,
|
|
|
|
"related_id": "clinic.hd.case,%s"%obj.id,
|
|
|
|
"currency_id": currency_id,
|
|
|
|
"company_id": company_id,
|
|
|
|
"lines": [],
|
|
|
|
"company_id": company_id,
|
|
|
|
}
|
|
|
|
partner=obj.patient_id.partner_id
|
|
|
|
if not partner:
|
|
|
|
raise Exception("No contact for patient %s"%obj.patient_id.name)
|
|
|
|
vals["partner_id"]=partner.id
|
2014-11-28 04:54:21 +00:00
|
|
|
|
2014-10-03 02:00:47 +00:00
|
|
|
for line in obj.lines:
|
2014-10-22 08:55:57 +00:00
|
|
|
if line.product_id:
|
|
|
|
account_id=line.product_id.sale_account_id.id or account_receivable_id
|
|
|
|
else:
|
|
|
|
account_id=account_receivable_id
|
|
|
|
inv_line={
|
2014-10-03 02:00:47 +00:00
|
|
|
"product_id": line.product_id.id,
|
|
|
|
"description": line.description,
|
|
|
|
"qty": line.qty,
|
|
|
|
"uom_id": line.uom_id.id,
|
|
|
|
"unit_price": line.price,
|
|
|
|
"amount": line.amount,
|
2014-10-06 00:48:42 +00:00
|
|
|
'account_id': account_id,
|
2014-10-03 02:00:47 +00:00
|
|
|
}
|
2014-11-28 04:54:21 +00:00
|
|
|
|
|
|
|
if obj.invoice_policy=='fee':
|
|
|
|
if line.type=='fee':
|
|
|
|
fee_lines.append(inv_line)
|
|
|
|
else:
|
|
|
|
vals['lines'].append(('create',inv_line))
|
|
|
|
elif obj.invoice_policy=='fee_mdc':
|
|
|
|
if line.type=='fee':
|
|
|
|
fee_lines.append(inv_line)
|
|
|
|
elif line.type=='medicine':
|
|
|
|
mdc_lines.append(inv_line)
|
|
|
|
else:
|
|
|
|
vals['lines'].append(('create',inv_line))
|
2014-10-22 08:55:57 +00:00
|
|
|
else:
|
|
|
|
vals['lines'].append(('create',inv_line))
|
|
|
|
|
2014-10-23 04:43:39 +00:00
|
|
|
if obj.amount and make_invoice: ## not pay yet
|
2014-11-28 04:54:21 +00:00
|
|
|
get_model("account.invoice").create(vals,context)
|
|
|
|
# check if type of product is stockable then create picking
|
2014-10-03 07:27:57 +00:00
|
|
|
obj.make_pickings()
|
2014-10-23 04:43:39 +00:00
|
|
|
|
2014-11-28 04:54:21 +00:00
|
|
|
vals={
|
|
|
|
"type": "out",
|
|
|
|
"inv_type": "invoice",
|
|
|
|
"tax_type": "tax_in",
|
|
|
|
'due_date': due_date,
|
|
|
|
"ref": obj.number,
|
|
|
|
"related_id": "clinic.hd.case,%s"%obj.id,
|
|
|
|
"currency_id": currency_id,
|
|
|
|
"company_id": company_id,
|
|
|
|
"lines": [],
|
|
|
|
"company_id": company_id,
|
|
|
|
}
|
|
|
|
|
|
|
|
if obj.invoice_option=='fee_mdc_plus':
|
|
|
|
fee_lines+=mdc_lines
|
|
|
|
mdc_lines=[]
|
|
|
|
|
|
|
|
if mdc_lines:
|
|
|
|
inv_vals=vals.copy()
|
|
|
|
inv_vals["partner_id"]=obj.fee_partner_id.id
|
|
|
|
account_id=account_receivable_id
|
|
|
|
patient_type=obj.patient_id.type
|
|
|
|
if patient_type=='sc':
|
|
|
|
account_id=setting.ar_sc_id.id
|
|
|
|
elif patient_type=='uc':
|
|
|
|
account_id=setting.ar_uc_id.id
|
|
|
|
for mdc_line in mdc_lines:
|
|
|
|
mdc_line['account_id']=account_id
|
|
|
|
inv_vals['lines'].append(('create',mdc_line))
|
|
|
|
get_model("account.invoice").create(inv_vals,context)
|
|
|
|
|
2014-10-23 04:43:39 +00:00
|
|
|
if fee_lines and not obj.fee_paid:
|
2014-11-28 04:54:21 +00:00
|
|
|
inv_vals=vals.copy()
|
|
|
|
inv_vals["partner_id"]=obj.fee_partner_id.id
|
2014-10-22 08:55:57 +00:00
|
|
|
account_id=account_receivable_id
|
|
|
|
patient_type=obj.patient_id.type
|
2014-11-28 04:54:21 +00:00
|
|
|
if patient_type=='sc':
|
2014-10-22 08:55:57 +00:00
|
|
|
account_id=setting.ar_sc_id.id
|
2014-11-25 10:26:10 +00:00
|
|
|
elif patient_type=='uc':
|
2014-11-28 04:54:21 +00:00
|
|
|
account_id=setting.ar_uc_id.id
|
2014-10-22 08:55:57 +00:00
|
|
|
|
|
|
|
for fee_line in fee_lines:
|
|
|
|
fee_line['account_id']=account_id
|
2014-11-28 04:54:21 +00:00
|
|
|
inv_vals['lines'].append(('create',fee_line))
|
|
|
|
get_model("account.invoice").create(inv_vals,context)
|
2014-10-23 04:43:39 +00:00
|
|
|
obj.write({
|
|
|
|
'fee_paid': True,
|
|
|
|
})
|
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
|
|
|
|
|
|
|
|
partner=obj.patient_id.partner_id
|
|
|
|
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:
|
|
|
|
raise Exception("contact %s dont'have address with type shipping"%partner.name)
|
|
|
|
pick_vals={
|
|
|
|
"type": "out",
|
|
|
|
"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": [],
|
|
|
|
}
|
|
|
|
res=get_model("stock.location").search([["type","=","customer"]])
|
|
|
|
if not res:
|
|
|
|
raise Exception("Customer location not found")
|
|
|
|
cust_loc_id=res[0]
|
|
|
|
|
|
|
|
|
|
|
|
for line in obj.lines:
|
|
|
|
prod=line.product_id
|
2014-10-15 11:44:33 +00:00
|
|
|
|
2014-10-03 07:27:57 +00:00
|
|
|
if prod.type != 'stock':
|
2014-10-15 11:44:33 +00:00
|
|
|
print("continue ")
|
2014-10-03 07:27:57 +00:00
|
|
|
continue
|
|
|
|
wh_loc_id=prod.location_id.id
|
|
|
|
if not wh_loc_id:
|
|
|
|
res=get_model("stock.location").search([["type","=","internal"]])
|
|
|
|
if not res:
|
|
|
|
raise Exception("Warehouse not found")
|
|
|
|
wh_loc_id=res[0]
|
|
|
|
line_vals={
|
|
|
|
"product_id": prod.id,
|
|
|
|
"qty": 1,
|
|
|
|
"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")
|
|
|
|
pick_id=picking_obj.create(pick_vals,context={"pick_type": "out"})
|
|
|
|
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:
|
|
|
|
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
|
|
|
# update start time
|
|
|
|
timenow=time.strftime("%H:%M:%S")
|
|
|
|
date=obj.date
|
|
|
|
vals={
|
|
|
|
'time_start': '%s %s'%(date,timenow),
|
|
|
|
'time_stop': '%s %s'%(date,timenow),
|
|
|
|
'state': 'in_progress',
|
|
|
|
}
|
|
|
|
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):
|
|
|
|
for dlz_line in obj.dialyzers:
|
|
|
|
dlz=dlz_line.dialyzer_id
|
2014-10-23 05:24:25 +00:00
|
|
|
#XXX
|
|
|
|
if dlz_line.use_time > dlz.use_time:
|
|
|
|
dlz.write({
|
|
|
|
'use_time': dlz_line.use_time,
|
|
|
|
})
|
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
|
|
|
|
cycle_item_ids=cycle_item.search([['date','=',datenow],['cycle_id','=',cycle_id]])
|
|
|
|
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,
|
2014-10-26 08:48:51 +00:00
|
|
|
'cycle_id': obj.cycle_id.id,
|
|
|
|
})
|
|
|
|
obj.write({
|
|
|
|
'cycle_item_id': cycle_item_id,
|
|
|
|
})
|
|
|
|
return True
|
|
|
|
|
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-10-03 02:00:47 +00:00
|
|
|
obj.make_invoices()
|
|
|
|
obj.post_invoices()
|
2014-10-15 07:52:15 +00:00
|
|
|
obj.update_usetime()
|
2014-10-26 08:48:51 +00:00
|
|
|
obj.create_cycle_item()
|
2014-11-30 05:54:57 +00:00
|
|
|
timenow=time.strftime("%H:%M:%S")
|
|
|
|
date=obj.date
|
|
|
|
vals={
|
2014-10-04 18:33:18 +00:00
|
|
|
"state":"completed",
|
2014-12-02 07:08:20 +00:00
|
|
|
#'time_stop': '%s %s'%(date,timenow),
|
2014-11-30 05:54:57 +00:00
|
|
|
}
|
|
|
|
st=get_model("clinic.setting").browse(1)
|
|
|
|
if st.waiting_approval:
|
|
|
|
vals['state']='waiting_approval'
|
|
|
|
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=""
|
2014-11-18 06:02:47 +00:00
|
|
|
if(hct<36):
|
|
|
|
msg="สามารถเบิกค่ายาสูงสุดไม่เกิน 1,125บาท ต่อ สัปดาห์"
|
|
|
|
elif(hct>=36 and hct<=39):
|
|
|
|
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]
|
|
|
|
for inv in obj.invoices:
|
|
|
|
inv.write({
|
|
|
|
'state': 'draft',
|
|
|
|
})
|
|
|
|
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-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-23 04:43:39 +00:00
|
|
|
'fee_paid': False,
|
2014-10-15 07:52:15 +00:00
|
|
|
})
|
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
|
|
|
|
|
|
|
def done(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
2014-10-23 05:24:25 +00:00
|
|
|
obj.update_usetime()
|
2014-10-24 04:24:33 +00:00
|
|
|
state='waiting_payment'
|
|
|
|
if not obj.amount:
|
|
|
|
obj.complete()
|
|
|
|
else:
|
|
|
|
obj.write({
|
|
|
|
'state': state,
|
|
|
|
})
|
2014-10-23 08:21:29 +00:00
|
|
|
|
|
|
|
def get_report_payment_data(self,context={}):
|
|
|
|
settings=get_model("settings").browse(1)
|
|
|
|
refer_id=context.get("refer_id")
|
|
|
|
payment_id=context.get("payment_id")
|
|
|
|
data={
|
|
|
|
'settings_address_text': settings.default_address_id and settings.default_address_id.get_address_text()[settings.default_address_id.id] or "",
|
|
|
|
'logo': get_file_path(settings.logo) or "",
|
|
|
|
}
|
|
|
|
if refer_id:
|
|
|
|
pass
|
|
|
|
if payment_id:
|
|
|
|
#context['refer_id']=payment_id
|
|
|
|
#data=get_model("account.payment").get_report_data(context=context)
|
|
|
|
payment=get_model("account.payment").browse(int(payment_id))
|
|
|
|
partner_address_id=payment.partner_id.default_address_id
|
|
|
|
data['number']=payment.number
|
|
|
|
data['ref']=payment.related_id.number
|
|
|
|
data['date']=payment.date
|
|
|
|
data['partner_name']=payment.partner_id.name or 0
|
|
|
|
data['partner_address_text']=partner_address_id and partner_address_id.get_address_text()[partner_address_id.id] or "",
|
|
|
|
lines=[]
|
|
|
|
for line in payment.direct_lines:
|
|
|
|
lines.append({
|
|
|
|
'description': line.description or '',
|
|
|
|
'qty': line.qty,
|
|
|
|
'unit_price': line.unit_price or 0.0,
|
|
|
|
'amount': line.amount or 0.0,
|
|
|
|
})
|
|
|
|
data['lines']=lines
|
|
|
|
data['amount_subtotal']=payment.amount_subtotal or 0.0
|
|
|
|
data['amount_tax']=payment.amount_tax or 0.0
|
|
|
|
data['amount_total']=payment.amount_total or 0.0
|
|
|
|
|
|
|
|
return data
|
2014-10-26 01:34:10 +00:00
|
|
|
|
|
|
|
def new_dialyzer(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
2014-10-26 02:23:27 +00:00
|
|
|
dlz_vals=get_model("clinic.dialyzer").default_get()
|
|
|
|
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]
|
|
|
|
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)
|
|
|
|
dialyzer.confirm()
|
|
|
|
vals={
|
|
|
|
'dlz_id': dlz_id,
|
|
|
|
'dialyzers': [],
|
|
|
|
}
|
|
|
|
vals['dialyzers'].append(('create',{
|
|
|
|
'dialyzer_id': dlz_id,
|
2014-10-26 02:23:27 +00:00
|
|
|
'description': dialyzer.description or product_name,
|
2014-10-26 01:34:10 +00:00
|
|
|
'use_time': 1,
|
|
|
|
'max_use_time': dialyzer.max_use_time,
|
|
|
|
'member_type': dialyzer.member_type,
|
|
|
|
'dialyzer_type': dialyzer.dialyzer_type,
|
|
|
|
'bid_flow_rate': dialyzer.bid_flow_rate,
|
|
|
|
'ultrafittration': dialyzer.ultrafittration,
|
|
|
|
'state': dialyzer.state,
|
|
|
|
}))
|
|
|
|
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
|
|
|
|
2014-11-25 11:39:53 +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
|
2014-11-25 11:39:53 +00:00
|
|
|
for ps in obj.staffs:
|
2014-11-21 16:11:57 +00:00
|
|
|
if ps.type=="doctor":
|
|
|
|
if ps.priop=='owner':
|
2014-11-25 11:39:53 +00:00
|
|
|
doctor_id=ps.staff_id.id
|
2014-11-01 03:48:22 +00:00
|
|
|
doctor+= 1
|
|
|
|
else:
|
|
|
|
nurse+=1
|
|
|
|
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-11-26 11:22:17 +00:00
|
|
|
def get_staff_line(self,vals,patient_id=None):
|
|
|
|
if not patient_id:
|
|
|
|
return vals
|
|
|
|
patient=get_model("clinic.patient").browse(patient_id)
|
|
|
|
doctor=patient.doctor_id
|
|
|
|
if doctor:
|
|
|
|
if not vals.get('staffs'):
|
|
|
|
vals['staffs']=[]
|
|
|
|
vals['staffs'].append(('create',{
|
|
|
|
'staff_id': doctor.id,
|
|
|
|
'type': 'doctor',
|
|
|
|
'priop': 'owner',
|
|
|
|
}))
|
|
|
|
|
|
|
|
st=get_model("clinic.setting").browse(1)
|
|
|
|
if not vals.get('lines'):
|
|
|
|
vals['lines']=[]
|
|
|
|
for st_prod in st.products:
|
2014-12-02 08:34:28 +00:00
|
|
|
if patient.type_id.id==st_prod.patient_type_id.id:
|
2014-11-26 11:22:17 +00:00
|
|
|
prod=st_prod.product_id
|
2014-11-27 15:14:31 +00:00
|
|
|
price=st_prod.price
|
|
|
|
qty=st_prod.qty
|
|
|
|
amt=st_prod.amount
|
|
|
|
if not amt:
|
|
|
|
amt=qty*price
|
2014-11-26 11:22:17 +00:00
|
|
|
vals['lines'].append(('create',{
|
|
|
|
'product_id': prod.id,
|
|
|
|
'uom_id': st_prod.uom_id.id,
|
|
|
|
'type': st_prod.type,
|
|
|
|
'description': st_prod.description,
|
2014-11-27 15:14:31 +00:00
|
|
|
'price': price,
|
|
|
|
'qty': qty,
|
|
|
|
'amount': amt,
|
2014-11-26 11:22:17 +00:00
|
|
|
}))
|
2014-12-02 07:08:20 +00:00
|
|
|
partner=patient.type_id.contact_id
|
|
|
|
if partner:
|
|
|
|
vals['fee_partner_id']=partner.id
|
2014-11-26 11:22:17 +00:00
|
|
|
return vals
|
2014-11-28 04:54:21 +00:00
|
|
|
|
|
|
|
def get_invoice_policy(self,vals,patient_id=None):
|
|
|
|
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
|
|
|
|
patient_type=pl.patient_type
|
|
|
|
opt=pl.invoice_option
|
|
|
|
if patient.type==patient_type:
|
|
|
|
vals['invoice_policy']=policy
|
|
|
|
vals['invoice_option']=opt
|
|
|
|
break
|
|
|
|
return vals
|
2014-11-26 11:22:17 +00:00
|
|
|
|
|
|
|
def create(self,vals,**kw):
|
|
|
|
patient_id=vals['patient_id']
|
|
|
|
vals=self.get_staff_line(vals,patient_id)
|
2014-11-28 04:54:21 +00:00
|
|
|
vals=self.get_invoice_policy(vals,patient_id)
|
2014-11-26 11:22:17 +00:00
|
|
|
new_id=super().create(vals,**kw)
|
|
|
|
return new_id
|
|
|
|
|
|
|
|
def write(self,ids,vals,**kw):
|
|
|
|
patient_id=vals.get('patient_id')
|
2014-12-02 07:08:20 +00:00
|
|
|
# XXX import problem
|
|
|
|
#vals=self.get_staff_line(vals,patient_id)
|
2014-11-28 04:54:21 +00:00
|
|
|
vals=self.get_invoice_policy(vals,patient_id)
|
2014-12-02 07:08:20 +00:00
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
for st in obj.staffs:
|
|
|
|
if st.type=='doctor':
|
|
|
|
doctor=st.staff_id
|
|
|
|
vals['staff_id']=doctor.id
|
2014-11-26 11:22:17 +00:00
|
|
|
super().write(ids,vals,**kw)
|
|
|
|
|
2014-11-28 04:54:21 +00:00
|
|
|
def onchange_type(self,context={}):
|
|
|
|
data=self.onchange_policy(context)
|
|
|
|
return data
|
|
|
|
|
|
|
|
def onchange_policy(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
inv_pol=data['invoice_policy']
|
|
|
|
total=0.0
|
|
|
|
fee=0.0
|
|
|
|
mdc=0.0
|
|
|
|
due_amt=0.0
|
|
|
|
for line in data['lines']:
|
|
|
|
amt=line['amount'] or 0.0
|
|
|
|
total+=amt
|
|
|
|
ltype=line['type']
|
|
|
|
if ltype=='fee':
|
|
|
|
fee+=amt
|
|
|
|
elif ltype=='medicine':
|
|
|
|
mdc+=amt
|
|
|
|
elif ltype=='others':
|
|
|
|
pass
|
|
|
|
if inv_pol=='fee':
|
|
|
|
due_amt=total-fee
|
|
|
|
data['invoice_option']=''
|
|
|
|
elif inv_pol=='fee_mdc':
|
|
|
|
due_amt=total-fee-mdc
|
|
|
|
data['invoice_option']='fee_mdc_split'
|
|
|
|
else:
|
|
|
|
due_amt=total
|
|
|
|
data['total']=total
|
|
|
|
data['fee_amount']=fee
|
|
|
|
data['mdc_amount']=mdc
|
|
|
|
data['amount']=due_amt
|
|
|
|
return data
|
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,
|
|
|
|
}
|
|
|
|
|
2014-11-28 04:54:21 +00:00
|
|
|
|
2014-10-23 04:43:39 +00:00
|
|
|
HDCase.register()
|