2014-09-11 03:21:52 +00:00
|
|
|
from netforce.model import Model, fields, get_model
|
2014-11-25 14:20:30 +00:00
|
|
|
from netforce.utils import get_file_path, get_data_path
|
2014-11-21 16:11:57 +00:00
|
|
|
from netforce.access import get_active_company
|
2015-01-08 08:07:33 +00:00
|
|
|
from netforce.database import get_connection
|
2014-09-11 03:21:52 +00:00
|
|
|
|
|
|
|
class ClinicSetting(Model):
|
|
|
|
_name="clinic.setting"
|
|
|
|
_string="Setting"
|
2014-12-03 11:40:37 +00:00
|
|
|
|
2014-09-11 03:21:52 +00:00
|
|
|
_fields={
|
2014-10-26 08:48:51 +00:00
|
|
|
"var_k": fields.Float("K"),
|
2014-10-27 14:17:22 +00:00
|
|
|
'file': fields.File("File"),
|
2014-11-21 02:39:26 +00:00
|
|
|
'levels': fields.One2Many("clinic.setting.level","setting_id","Levels"),
|
2014-11-26 11:22:17 +00:00
|
|
|
'products': fields.One2Many("clinic.setting.product","setting_id","Products"),
|
2014-11-27 15:14:31 +00:00
|
|
|
'invoice_policies': fields.One2Many("clinic.setting.policy","setting_id","Invoice Policies"),
|
2014-11-21 16:11:57 +00:00
|
|
|
'cost_per_case': fields.Float("Cost Per Case"),
|
|
|
|
'company_id': fields.Many2One("company", 'Company'),
|
2014-11-27 15:14:31 +00:00
|
|
|
'period_id': fields.Many2One("clinic.period","Period"),
|
2014-12-04 14:08:29 +00:00
|
|
|
'waiting_approval': fields.Boolean("Waiting Approval"), # HD Case
|
|
|
|
'real_time': fields.Boolean("Real Time"), # HD Case
|
|
|
|
'patient_type_id': fields.Many2One("clinic.patient.type","Default Type"), # Import payment
|
2014-12-21 18:00:54 +00:00
|
|
|
'imp_patient_type_id': fields.Many2One("clinic.patient.type","Import UC Type"), # Import payment
|
2014-12-04 14:08:29 +00:00
|
|
|
'find_dlz': fields.Boolean("Find Dialyzer After Confirm Visit"), # Visit
|
2014-12-14 11:15:14 +00:00
|
|
|
'stock_journal_id': fields.Many2One("stock.journal","Default Journal"),
|
2014-12-21 19:43:59 +00:00
|
|
|
'auto_gen': fields.Boolean("Auto Gen"), # HD Case
|
|
|
|
'schd_from': fields.Date("From"),
|
|
|
|
'schd_to': fields.Date("To"),
|
2014-09-11 03:21:52 +00:00
|
|
|
}
|
2014-10-27 19:01:18 +00:00
|
|
|
|
2014-11-21 16:11:57 +00:00
|
|
|
_defaults={
|
|
|
|
"company_id": lambda *a: get_active_company(),
|
|
|
|
}
|
|
|
|
|
2014-11-25 14:20:30 +00:00
|
|
|
def onchange_line(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
path=context['path']
|
|
|
|
line=get_data_path(data,path,parent=True)
|
|
|
|
var_a=line['var_a'] or ''
|
|
|
|
var_b=line['var_b'] or ''
|
|
|
|
op=line['op'] or ''
|
|
|
|
line['formular']='%sX%s%s'%(var_a,op,var_b)
|
|
|
|
return data
|
2014-09-11 03:21:52 +00:00
|
|
|
|
2014-11-26 11:22:17 +00:00
|
|
|
def onchange_product(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
path=context['path']
|
|
|
|
line=get_data_path(data,path,parent=True)
|
|
|
|
product_id=line['product_id']
|
|
|
|
if product_id:
|
|
|
|
prod=get_model("product").browse(product_id)
|
|
|
|
uom=prod.uom_id
|
|
|
|
if not uom:
|
|
|
|
uom=get_model("uom").browse(1)
|
|
|
|
if not uom:
|
|
|
|
raise Exception("Not found uom 'Unit'")
|
|
|
|
line['uom_id']=uom.id
|
|
|
|
line['description']=prod.name
|
2014-11-27 15:14:31 +00:00
|
|
|
price=prod.sale_price or 0.0
|
|
|
|
line['price']=price
|
2014-12-21 02:54:45 +00:00
|
|
|
categ=prod.categ_id
|
|
|
|
if categ:
|
|
|
|
line['product_categ_id']=categ.id
|
2014-12-02 07:08:20 +00:00
|
|
|
qty=1
|
2014-11-27 15:14:31 +00:00
|
|
|
amt=qty*price
|
2014-11-26 11:22:17 +00:00
|
|
|
line['amount']=amt
|
|
|
|
return data
|
|
|
|
|
2014-11-27 15:14:31 +00:00
|
|
|
def onchange_setting_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
|
|
|
|
amt=qty*price
|
|
|
|
line['amount']=amt
|
|
|
|
return data
|
2014-12-26 02:37:59 +00:00
|
|
|
|
2014-12-21 19:43:59 +00:00
|
|
|
def schd_confirm(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
if not obj.schd_from:
|
|
|
|
raise Exception("No date from")
|
|
|
|
if not obj.schd_to:
|
|
|
|
raise Exception("No date to")
|
|
|
|
dom=[]
|
|
|
|
dom.append(['date', '>=', obj.schd_from])
|
|
|
|
dom.append(['date', '<=', obj.schd_to])
|
|
|
|
for schd in get_model('clinic.schedule').search_browse(dom):
|
|
|
|
schd.confirm()
|
|
|
|
return True
|
2014-12-21 17:24:08 +00:00
|
|
|
|
2014-12-26 02:37:59 +00:00
|
|
|
def run_script(self,ids,context={}):
|
2015-01-14 17:49:17 +00:00
|
|
|
dts={}
|
|
|
|
for pt in get_model('clinic.patient').search_browse([]):
|
|
|
|
doctor=pt.doctor_id
|
|
|
|
if not dts.get(doctor.id):
|
|
|
|
dts[doctor.id]=[]
|
|
|
|
dts[doctor.id].append(pt.id)
|
|
|
|
x=0
|
|
|
|
y=0
|
|
|
|
c=1
|
|
|
|
for doctor_id, pt_ids in dts.items():
|
|
|
|
st=set()
|
|
|
|
b_ids=[pt.branch_id.id for pt in get_model('clinic.patient').browse(pt_ids)]
|
|
|
|
for b_id in b_ids:
|
|
|
|
st.update({b_id})
|
|
|
|
if len(st)>1:
|
|
|
|
if doctor_id:
|
|
|
|
doctor=get_model('clinic.staff').browse(doctor_id)
|
|
|
|
doctor.write({
|
|
|
|
'branch_id': 5,
|
|
|
|
})
|
|
|
|
print('%s %s'%(doctor_id, st))
|
|
|
|
# update doctor to ratchawat branch
|
|
|
|
x+=1
|
|
|
|
else:
|
|
|
|
y+=1
|
|
|
|
c+=1
|
|
|
|
print("RD ", x)
|
|
|
|
print("Other", y)
|
2014-11-27 15:14:31 +00:00
|
|
|
|
2015-01-08 08:07:33 +00:00
|
|
|
def reset_last_import(self,ids,context={}):
|
|
|
|
res=get_model("clinic.report.payment.matching").search_read([],['date'],order="date desc")
|
|
|
|
if res:
|
|
|
|
db=get_connection()
|
|
|
|
res1=res[0]
|
|
|
|
date1='%s 00:00:00'%res1['date']
|
|
|
|
date2='%s 23:59:59'%res1['date']
|
|
|
|
exp_ids=[x['id'] for x in db.query("select id from clinic_hd_case_expense where write_time>=%s and write_time<=%s",date1,date2)]
|
|
|
|
for exp in get_model("clinic.hd.case.expense").browse(exp_ids):
|
|
|
|
exp.write({
|
|
|
|
'state': 'waiting_matching',
|
|
|
|
'ok': False,
|
|
|
|
})
|
|
|
|
for inv in exp.invoices:
|
|
|
|
payment=inv.payment_id
|
|
|
|
if payment:
|
|
|
|
if payment.state !='draft':
|
|
|
|
payment.to_draft()
|
|
|
|
print("to draft payment ", payment.id)
|
|
|
|
print("Done")
|
|
|
|
|
2014-09-11 03:21:52 +00:00
|
|
|
ClinicSetting.register()
|