conv_bal
watcha.h 2014-12-03 18:40:37 +07:00
parent 7a384046fe
commit a07f6025c2
6 changed files with 188 additions and 47 deletions

View File

@ -64,6 +64,9 @@
<separator string="Doctor"/> <separator string="Doctor"/>
<field name="cost_per_case"/> <field name="cost_per_case"/>
</tab> </tab>
<tab string="Importing">
<field name="patient_type_id"/>
</tab>
</tabs> </tabs>
<foot> <foot>
</foot> </foot>

View File

@ -1,7 +1,18 @@
<form title="Import Patient"> <form title="Import Patient">
<group form_layout="stacked"> <group form_layout="stacked">
<field name="file" span="3"/> <field name="file" span="3"/>
<field name="hcode" span="3"/> <field name="hcode_id" span="3"/>
<field name="patient_type_id" span="3"/>
<separator string="Summary"/>
<tabs>
<tab string="General">
<field name="done_qty" readonly="1"/>
<field name="fail_qty" readonly="1"/>
</tab>
<tab string="Message">
<field name="msg" nolabel="1"/>
</tab>
</tabs>
</group> </group>
<foot replace="1"> <foot replace="1">
<button string="Import" method="import_patient" type="primary" icon="arrow-right"/> <button string="Import" method="import_patient" type="primary" icon="arrow-right"/>

View File

@ -19,10 +19,10 @@
<!--<field name="remain_row" span="3" readonly="1"/>--> <!--<field name="remain_row" span="3" readonly="1"/>-->
<field name="match_qty" span="3" readonly="1"/> <field name="match_qty" span="3" readonly="1"/>
<field name="unmatch_qty" span="3" readonly="1"/> <field name="unmatch_qty" span="3" readonly="1"/>
<newline/>
<field name="done_qty" span="3" readonly="1"/>
<field name="fail_qty" span="3" readonly="1"/> <field name="fail_qty" span="3" readonly="1"/>
<field name="est_time" span="3" readonly="1"/> <newline/>
<!--<field name="done_qty" span="3" readonly="1"/>-->
<field name="est_time" span="4" readonly="1"/>
</tab> </tab>
<tab string="Match"> <tab string="Match">
<field name="match_lines" nolabel="1"> <field name="match_lines" nolabel="1">
@ -66,8 +66,9 @@
<tab string="Accounting"> <tab string="Accounting">
<group form_layout="stacked"> <group form_layout="stacked">
<field name="payment_id" span="3" readonly="1"/> <field name="payment_id" span="3" readonly="1"/>
<field name="partner_id" span="3"/> <button string="Approve" method="approve" icon="ok" span="3" confirm="Are you sure?"/>
<button string="Approve" method="approve" icon="ok" span="3"/> <newline/>
<field name="partner_id" span="3" readonly="1"/>
</group> </group>
</tab> </tab>
</tabs> </tabs>

View File

@ -12,7 +12,11 @@ class ImportPatient(Model):
'date': fields.DateTime("Date"), 'date': fields.DateTime("Date"),
'file': fields.File("File"), 'file': fields.File("File"),
'result': fields.Text("Success"), 'result': fields.Text("Success"),
'hcode': fields.Char("Hospital Code"), 'hcode_id': fields.Many2One("clinic.hospital", "Hospital",required=True),
'patient_type_id': fields.Many2One('clinic.patient.type','Type',required=True),
'msg': fields.Text("Message"),
'done_qty': fields.Integer("Success"),
'fail_qty': fields.Integer("Fail"),
} }
def get_hcode(self,context={}): def get_hcode(self,context={}):
@ -20,35 +24,109 @@ class ImportPatient(Model):
hcode=settings.hospital_code or "" hcode=settings.hospital_code or ""
return hcode return hcode
def get_hcode_id(self,context={}):
hp_ids=get_model("clinic.hospital").search([])
hp_id=None
if hp_ids:
hp_id=hp_ids[0]
return hp_id
def _get_patient_type(self,context={}):
st=get_model('clinic.setting').browse(1)
ptype=st.patient_type_id
ptype_id=None
if ptype:
ptype_id=ptype.id
return ptype_id
_defaults={ _defaults={
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"), 'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
'hcode': get_hcode, 'hcode_id': get_hcode_id,
'patient_type_id': _get_patient_type,
} }
def import_patient(self,ids,context={}): def import_patient(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
ptype=obj.patient_type_id
res={}
if ptype.code=='PKS':
res=self.import_patient_pks(ids,context)
elif ptype.code=='UC':
res=self.import_patient_uc(ids,context)
else:
raise Exception('No script to import patient with type %s'%ptype.name)
return res
def import_patient_uc(self,ids,context):
obj=self.browse(ids)[0]
#ptype=obj.patient_type_id
fname=obj.file
fpath=get_file_path(fname)
lines=utils.read_xml(fpath,node='HDBills')
if not lines:
raise Exception("Wrong File")
for line in lines:
print(line)
return {
'next': {
'name': 'import_clinic_patient',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Import successfully',
}
def import_patient_pks(self,ids,context):
obj=self.browse(ids)[0]
ptype=obj.patient_type_id
fname=obj.file fname=obj.file
fpath=get_file_path(fname) fpath=get_file_path(fname)
lines=utils.read_excel(fpath,show_datetime=True) lines=utils.read_excel(fpath,show_datetime=True)
if not lines: if not lines:
raise Exception("Wrong File") raise Exception("Wrong File")
msg=""
msg+="hcode,hn,name,note\n"
done_qty=0
fail_qty=0
for line in lines: for line in lines:
hcode=line.get('hcode18','0') hcode=line.get('hcode18','0')
if not hcode: if not hcode:
hcode='0' hcode='0'
hcode=int(hcode) hcode=int(hcode)
hcode=str(hcode) hcode=str(hcode)
if obj.hcode==hcode: hn=line.get('hn',"")
name=line.get("name14") patient_name=line.get("name14")
hn=line.get('hn',"") if obj.hcode_id.code==hcode:
patient_ids=get_model("clinic.patient").search([['name','=',name]]) patient_ids=get_model("clinic.patient").search([['name','=',patient_name]])
if not patient_ids: if not patient_ids:
done_qty+=1
vals={ vals={
'name': name, 'name': patient_name,
'hn': hn, 'hn': hn,
'type': 'sc', 'type_id': ptype.id,
} }
patient_id=get_model('clinic.patient').create(vals) patient_id=get_model('clinic.patient').create(vals)
msg+="%s,%s,%s,%s\n"%(hcode,hn,patient_name,"Created")
print("create patient ", patient_id) print("create patient ", patient_id)
else:
if hcode!='0':
msg+="%s,%s,%s,%s\n"%(hcode,hn,patient_name,"Wrong Code hospital")
fail_qty+=1
obj.write({
'fail_qty': fail_qty,
'done_qty': done_qty,
'msg': msg,
})
return {
'next': {
'name': 'import_clinic_patient',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Import successfully',
}
ImportPatient.register() ImportPatient.register()

View File

@ -18,6 +18,18 @@ class ImportPayment(Model):
res[obj.id]=obj.type_id.name res[obj.id]=obj.type_id.name
return res return res
def _get_partner(self,ids,context={}):
res={}
for obj in self.browse(ids):
ptype=obj.type_id
contact_id=None
if ptype:
contact=ptype.contact_id
if contact:
contact_id=contact.id
res[obj.id]=contact_id
return res
_fields={ _fields={
'name': fields.Char("Name",function="_get_name"), 'name': fields.Char("Name",function="_get_name"),
'type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True), 'type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True),
@ -28,19 +40,19 @@ class ImportPayment(Model):
'file': fields.File("File"), 'file': fields.File("File"),
'max_row': fields.Integer("Max Row"), 'max_row': fields.Integer("Max Row"),
'remain_row': fields.Integer("Pending"), 'remain_row': fields.Integer("Pending"),
'total_row': fields.Integer("Total Record"), 'total_row': fields.Integer("Total"),
'est_time': fields.Float("Estimate Time",scale=4), 'est_time': fields.Float("Estimate Time",scale=4),
'msg': fields.Text("Message"), 'msg': fields.Text("Message"),
'done_qty': fields.Integer("Success"), 'done_qty': fields.Integer("Success"),
'fail_qty': fields.Integer("Fail"), 'fail_qty': fields.Integer("Other"),
'match_qty': fields.Integer("Match"), 'match_qty': fields.Integer("Match"),
'unmatch_qty': fields.Integer("UnMatch"), 'unmatch_qty': fields.Integer("UnMatch"),
'state': fields.Selection([['draft','Draft'],['confirmed','Confirmed'],['fail','Fail'],['success','Success']],'State'), 'state': fields.Selection([['draft','Draft'],['confirmed','Confirmed'],['approved','Approved'],['fail','Fail'],['success','Success']],'State'),
'match_lines': fields.One2Many("import.clinic.payment.line","import_payment_id","Match",domain=[["state","=","match"]]), 'match_lines': fields.One2Many("import.clinic.payment.line","import_payment_id","Match",domain=[["state","=","match"]]),
'unmatch_lines': fields.One2Many("import.clinic.payment.line","import_payment_id","UnMatch",domain=[["state","=","unmatch"]]), 'unmatch_lines': fields.One2Many("import.clinic.payment.line","import_payment_id","UnMatch",domain=[["state","=","unmatch"]]),
'payment_id': fields.Many2One("account.payment","Payment"), 'payment_id': fields.Many2One("account.payment","Payment"),
'company_id': fields.Many2One("company","Company"), 'company_id': fields.Many2One("company","Company"),
'partner_id': fields.Many2One("partner","Partner"), 'partner_id': fields.Many2One("partner","Fee Contact",function="_get_partner"),
} }
def get_hcode_id(self,context={}): def get_hcode_id(self,context={}):
@ -61,6 +73,13 @@ class ImportPayment(Model):
weekday, total_day=monthrange(int(year), int(month)) weekday, total_day=monthrange(int(year), int(month))
return '%s-%s-%s'%(year,month,total_day) return '%s-%s-%s'%(year,month,total_day)
def _get_patient_type(self,context={}):
st=get_model('clinic.setting').browse(1)
ptype=st.patient_type_id
ptype_id=None
if ptype:
ptype_id=ptype.id
return ptype_id
_defaults={ _defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"), 'date': lambda *a: time.strftime("%Y-%m-%d"),
@ -68,6 +87,7 @@ class ImportPayment(Model):
'date_to': _get_date_to, 'date_to': _get_date_to,
'hcode_id': get_hcode_id, 'hcode_id': get_hcode_id,
'company_id': lambda *a: get_active_company(), 'company_id': lambda *a: get_active_company(),
'type_id': _get_patient_type,
'max_row': 50, 'max_row': 50,
'state': 'draft', 'state': 'draft',
} }
@ -86,16 +106,13 @@ class ImportPayment(Model):
if not lines: if not lines:
raise Exception("Wrong File") raise Exception("Wrong File")
msg="" msg=""
count=0
nofound=0 nofound=0
did=0
blank=0 blank=0
fail_qty=0 fail_qty=0
done_qty=0
match_qty=0 match_qty=0
unmatch_qty=0 unmatch_qty=0
msg+=""*10; msg+="hcode,hn,name\n" msg+=""*10; msg+="hcode,hn,name,note\n"
print("getting invoice") print("getting invoice")
dom=[] dom=[]
@ -136,7 +153,7 @@ class ImportPayment(Model):
mlines=[] mlines=[]
umlines=[] umlines=[]
for line in lines: for line in lines:
name=line.get("name14") patient_name=line.get("name14")
hn=line.get('hn',"") hn=line.get('hn',"")
hn_num=get_hn_num(hn) hn_num=get_hn_num(hn)
hct=line.get("hct","") hct=line.get("hct","")
@ -151,8 +168,10 @@ class ImportPayment(Model):
if hcode: if hcode:
nofound+=1 nofound+=1
if hcode!='0': if hcode!='0':
msg+="not found %s, %s, %s \n"%(hcode,hn,name) msg+="%s, %s, %s, Wrong hospital code \n"%(hcode,hn,patient_name)
fail_qty+=1 fail_qty+=1
else:
blank+=1
else: else:
blank+=1 blank+=1
continue continue
@ -176,13 +195,16 @@ class ImportPayment(Model):
vals={ vals={
'date': inv_date, 'date': inv_date,
'patient_id': patient_id, 'patient_id': patient_id,
'amount': amount,
} }
if hd_case: if hd_case:
vals['hd_case_id']=hd_case['id'] vals['hd_case_id']=hd_case['id']
umlines.append(('create',vals)) umlines.append(('create',vals))
unmatch_qty+=1 unmatch_qty+=1
else:
msg+="%s,%s,%s,Not found invoice on %s\n"%(hcode,hn,patient_name,inv_date)
nofound+=1
unmatch_qty+=nofound #XXX
for mline in obj.match_lines: for mline in obj.match_lines:
mline.delete() mline.delete()
for umline in obj.unmatch_lines: for umline in obj.unmatch_lines:
@ -191,9 +213,8 @@ class ImportPayment(Model):
stop_time=time.strftime(fmt) stop_time=time.strftime(fmt)
est_time=datetime.strptime(stop_time,fmt)-datetime.strptime(start_time,fmt) est_time=datetime.strptime(stop_time,fmt)-datetime.strptime(start_time,fmt)
remain_row=len(lines)-blank-did-count total_row=len(lines)
if remain_row <= 0: remain_row=total_row-blank-match_qty-unmatch_qty
msg="Nothing to import"
obj.write({ obj.write({
'total_row': len(lines), 'total_row': len(lines),
'remain_row': remain_row-match_qty, 'remain_row': remain_row-match_qty,
@ -201,7 +222,7 @@ class ImportPayment(Model):
'done_qty': match_qty+unmatch_qty, 'done_qty': match_qty+unmatch_qty,
'fail_qty': fail_qty, 'fail_qty': fail_qty,
'match_qty': match_qty, 'match_qty': match_qty,
'unmatch_qty': unmatch_qty, 'unmatch_qty': unmatch_qty-fail_qty,
'est_time': est_time.seconds/3600, 'est_time': est_time.seconds/3600,
'match_lines': mlines, 'match_lines': mlines,
'unmatch_lines': umlines, 'unmatch_lines': umlines,
@ -210,7 +231,7 @@ class ImportPayment(Model):
def approve(self,ids,context={}): def approve(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
partner=obj.patient_id.partner_id partner=obj.partner_id
if not partner: if not partner:
raise Exception("No contact on this patient") raise Exception("No contact on this patient")
company_id=get_active_company() company_id=get_active_company()
@ -220,30 +241,54 @@ class ImportPayment(Model):
account_receivable_id=st.account_receivable_id account_receivable_id=st.account_receivable_id
if not account_receivable_id: if not account_receivable_id:
raise Exception("Not found account recieveable in account setting") raise Exception("Not found account recieveable in account setting")
account_id=account_receivable_id.id account_id=account_receivable_id.id
if not account_id: datenow=time.strftime("%Y-%m-%d")
raise Exception("No Account for payment")
vals={ vals={
"partner_id": partner.id, "partner_id": partner.id,
"company_id": company_id, "company_id": company_id,
"type": "in", "type": "in",
"pay_type": "invoice", "pay_type": "invoice",
'date': time.strftime("%Y-%m-%d"), 'date': datenow,
"account_id": account_id, "account_id": account_id,
'related_id': "clinic.hd.case,%s"%obj.id, 'related_id': "import.clinic.payment,%s"%obj.id,
'invoice_lines': [], 'invoice_lines': [],
} }
vals['invoice_lines'].append(('create',{ for mline in obj.match_lines:
'type': 'invoice', inv=mline.invoice_id
'description': 'Payment; %s'%obj.number, if inv:
'account_id': account_id, amt=inv.amount_due or 0.0
'qty': 1, vals['invoice_lines'].append(('create',{
'unit_price': pay_amount, 'type': 'invoice',
'amount': pay_amount, 'account_id': account_id,
})) 'invoice_id': inv.id,
'amount': amt,
}))
for umline in obj.unmatch_lines:
inv=mline.invoice_id
if inv:
amt=inv.amount_due or 0.0
vals['invoice_lines'].append(('create',{
'type': 'invoice',
'account_id': account_id,
'invoice_id': inv.id,
'amount': amt,
}))
payment=obj.payment_id
if payment:
for inv_line in payment.invoice_lines:
inv_line.delete()
payment.write(vals)
else:
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
vals['payment_id']=payment_id
obj.write({
'payment_id': payment_id,
'state': 'approved',
})
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
#payment=get_model('account.payment').browse(payment_id) #payment=get_model('account.payment').browse(payment_id)
#payment.post() #payment.post()
return { return {
@ -252,7 +297,7 @@ class ImportPayment(Model):
'mode': 'form', 'mode': 'form',
'active_id': obj.id, 'active_id': obj.id,
}, },
'flash': 'Done!', 'flash': '%s has been paid'%obj.type_id.name,
} }
ImportPayment.register() ImportPayment.register()

View File

@ -5,6 +5,8 @@ from netforce.access import get_active_company
class ClinicSetting(Model): class ClinicSetting(Model):
_name="clinic.setting" _name="clinic.setting"
_string="Setting" _string="Setting"
_fields={ _fields={
"var_k": fields.Float("K"), "var_k": fields.Float("K"),
'file': fields.File("File"), 'file': fields.File("File"),
@ -16,6 +18,7 @@ class ClinicSetting(Model):
'period_id': fields.Many2One("clinic.period","Period"), 'period_id': fields.Many2One("clinic.period","Period"),
'waiting_approval': fields.Boolean("Waiting Approval"), 'waiting_approval': fields.Boolean("Waiting Approval"),
'real_time': fields.Boolean("Real Time"), 'real_time': fields.Boolean("Real Time"),
'patient_type_id': fields.Many2One("clinic.patient.type","Default Type"),
} }
_defaults={ _defaults={