matching payment
parent
c6e5111a2d
commit
a4bf713e3e
|
@ -0,0 +1,6 @@
|
||||||
|
<action>
|
||||||
|
<field name="string">Hospital</field>
|
||||||
|
<field name="view_cls">multi_view</field>
|
||||||
|
<field name="model">clinic.hospital</field>
|
||||||
|
<field name="menu">clinic_menu</field>
|
||||||
|
</action>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<action>
|
||||||
|
<field name="string">Import Payment</field>
|
||||||
|
<field name="view_cls">multi_view</field>
|
||||||
|
<field name="model">import.clinic.payment</field>
|
||||||
|
<field name="menu">clinic_menu</field>
|
||||||
|
</action>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<form model="clinic.hospital">
|
||||||
|
<field name="code"/>
|
||||||
|
<field name="name"/>
|
||||||
|
</form>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<list model="clinic.hospital">
|
||||||
|
<field name="code"/>
|
||||||
|
<field name="name"/>
|
||||||
|
</list>
|
|
@ -55,6 +55,7 @@
|
||||||
<item string="Settings">
|
<item string="Settings">
|
||||||
<item string="Branch" action="clinic_branch"/>
|
<item string="Branch" action="clinic_branch"/>
|
||||||
<item string="Departments" action="clinic_department"/>
|
<item string="Departments" action="clinic_department"/>
|
||||||
|
<item string="Hospital" action="clinic_hospital"/>
|
||||||
<item string="Nationalities" action="clinic_nation"/>
|
<item string="Nationalities" action="clinic_nation"/>
|
||||||
<!--<item string="Period" action="clinic_period"/>-->
|
<!--<item string="Period" action="clinic_period"/>-->
|
||||||
<item string="Valcular Access" action="clinic_vascular_access"/>
|
<item string="Valcular Access" action="clinic_vascular_access"/>
|
||||||
|
@ -65,5 +66,6 @@
|
||||||
<item string="Import Patient" action="import_clinic_patient"/>
|
<item string="Import Patient" action="import_clinic_patient"/>
|
||||||
<item string="Import Visit" action="import_clinic_visit"/>
|
<item string="Import Visit" action="import_clinic_visit"/>
|
||||||
<item string="Import HD Case" action="import_clinic_hd_case"/>
|
<item string="Import HD Case" action="import_clinic_hd_case"/>
|
||||||
|
<item string="Clinic Payment" action="import_clinic_payment"/>
|
||||||
</item>
|
</item>
|
||||||
</menu>
|
</menu>
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
<form title="HD Case">
|
<form title="HD Case">
|
||||||
<field name="file" span="3"/>
|
<field name="file" span="3"/>
|
||||||
<field name="date" span="3" mode="month"/>
|
<field name="hcode_id" span="4"/>
|
||||||
<field name="hcode" span="3"/>
|
|
||||||
<field name="max_row" span="3"/>
|
<field name="max_row" span="3"/>
|
||||||
<separator string="Summary"/>
|
<separator string="Summary"/>
|
||||||
<field name="total_row" span="4" readonly="1"/>
|
<tabs>
|
||||||
<field name="remain_row" span="4" readonly="1"/>
|
<tab string="Information">
|
||||||
|
<field name="total_row" span="4" readonly="1"/>
|
||||||
|
<field name="remain_row" span="4" readonly="1"/>
|
||||||
|
<newline/>
|
||||||
|
<field name="done_qty" span="4" readonly="1"/>
|
||||||
|
<field name="fail_qty" span="4" readonly="1"/>
|
||||||
|
</tab>
|
||||||
|
<tab string="Message">
|
||||||
|
<field name="msg" span="6" nolabel="1" width="700" height="180"/>
|
||||||
|
</tab>
|
||||||
|
</tabs>
|
||||||
<foot replace="1">
|
<foot replace="1">
|
||||||
<button string="Import" method="import_hd_case" type="primary" icon="arrow-right"/>
|
<button string="Import" method="import_hd_case" type="primary" icon="arrow-right"/>
|
||||||
</foot>
|
</foot>
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
<form model="import.clinic.payment">
|
||||||
|
<head>
|
||||||
|
<field name="state"/>
|
||||||
|
<button string="Options" dropdown="1">
|
||||||
|
<item string="View Journal Entry"/>
|
||||||
|
</button>
|
||||||
|
</head>
|
||||||
|
<field name="file" span="3"/>
|
||||||
|
<field name="hcode_id" span="3"/>
|
||||||
|
<field name="type_id" span="3"/>
|
||||||
|
<field name="date" span="3" readonly="1"/>
|
||||||
|
<separator string="Summary"/>
|
||||||
|
<tabs>
|
||||||
|
<tab string="Information">
|
||||||
|
<field name="total_row" span="4" readonly="1"/>
|
||||||
|
<field name="remain_row" span="4" readonly="1"/>
|
||||||
|
<newline/>
|
||||||
|
<field name="done_qty" span="4" readonly="1"/>
|
||||||
|
<field name="fail_qty" span="4" readonly="1"/>
|
||||||
|
</tab>
|
||||||
|
<tab string="Invoice">
|
||||||
|
</tab>
|
||||||
|
<tab string="Payment">
|
||||||
|
</tab>
|
||||||
|
<tab string="Message">
|
||||||
|
<field name="msg" span="6" nolabel="1" width="1000" height="180"/>
|
||||||
|
</tab>
|
||||||
|
</tabs>
|
||||||
|
<foot replace="1">
|
||||||
|
<button string="Import" method="import_payment" type="primary" icon="arrow-right"/>
|
||||||
|
</foot>
|
||||||
|
</form>
|
|
@ -0,0 +1,5 @@
|
||||||
|
<list model="import.clinic.payment" colors='{"#cfc":[["state","=","success"]],"red":[["state","=","fail"]]}'>
|
||||||
|
<field name="date"/>
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="state"/>
|
||||||
|
</list>
|
|
@ -72,3 +72,4 @@ from . import import_hd_case
|
||||||
from . import import_data_uc
|
from . import import_data_uc
|
||||||
from . import import_data_sc
|
from . import import_data_sc
|
||||||
from . import vascular_access
|
from . import vascular_access
|
||||||
|
from . import hospital
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
from netforce.model import Model, fields
|
||||||
|
|
||||||
|
class Hospital(Model):
|
||||||
|
_name="clinic.hospital"
|
||||||
|
_string="Hospital"
|
||||||
|
_key=['code','name']
|
||||||
|
|
||||||
|
_fields={
|
||||||
|
"code": fields.Char("Code",required=True,search=True),
|
||||||
|
"name": fields.Char("Name",required=True,search=True),
|
||||||
|
}
|
||||||
|
|
||||||
|
def name_get(self,ids,context={}):
|
||||||
|
vals=[]
|
||||||
|
for obj in self.browse(ids):
|
||||||
|
name="[%s] %s"%(obj.code,obj.name)
|
||||||
|
vals.append((obj.id,name))
|
||||||
|
return vals
|
||||||
|
|
||||||
|
def name_search(self,name,domain=None,context={},**kw):
|
||||||
|
dom=[["code","ilike","%"+name+"%"]]
|
||||||
|
if domain:
|
||||||
|
dom=[dom,domain]
|
||||||
|
ids1=self.search(dom)
|
||||||
|
dom=[["name","ilike","%"+name+"%"]]
|
||||||
|
if domain:
|
||||||
|
dom=[dom,domain]
|
||||||
|
ids2=self.search(dom)
|
||||||
|
ids=list(set(ids1+ids2))
|
||||||
|
return self.name_get(ids,context=context)
|
||||||
|
|
||||||
|
Hospital.register()
|
|
@ -1,9 +1,7 @@
|
||||||
import time
|
import time
|
||||||
from calendar import monthrange
|
|
||||||
|
|
||||||
from netforce.model import Model, fields, get_model
|
from netforce.model import Model, fields, get_model
|
||||||
from netforce.utils import get_file_path
|
from netforce.utils import get_file_path
|
||||||
from netforce.database import get_connection
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
class ImportHDCase(Model):
|
class ImportHDCase(Model):
|
||||||
|
@ -13,20 +11,25 @@ class ImportHDCase(Model):
|
||||||
_fields={
|
_fields={
|
||||||
'date': fields.Date("Date"),
|
'date': fields.Date("Date"),
|
||||||
'file': fields.File("File"),
|
'file': fields.File("File"),
|
||||||
'hcode': fields.Char("Hospital Code"),
|
'hcode_id': fields.Many2One("clinic.hospital", "Hospital",required=True),
|
||||||
'max_row': fields.Integer("Max Row"),
|
'max_row': fields.Integer("Max Row"),
|
||||||
'remain_row': fields.Integer("Remain Row"),
|
'remain_row': fields.Integer("Import Pending"),
|
||||||
'total_row': fields.Integer("Totol Row"),
|
'total_row': fields.Integer("Total Case"),
|
||||||
|
'msg': fields.Text("Message"),
|
||||||
|
'done_qty': fields.Integer("Success"),
|
||||||
|
'fail_qty': fields.Integer("Fail"),
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_hcode(self,context={}):
|
def get_hcode_id(self,context={}):
|
||||||
settings=get_model("settings").browse(1)
|
hp_ids=get_model("clinic.hospital").search([])
|
||||||
hcode=settings.hospital_code or ""
|
hp_id=None
|
||||||
return hcode
|
if hp_ids:
|
||||||
|
hp_id=hp_ids[0]
|
||||||
|
return hp_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,
|
||||||
'max_row': 50,
|
'max_row': 50,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,15 +61,14 @@ class ImportHDCase(Model):
|
||||||
if st_policy=='sc':
|
if st_policy=='sc':
|
||||||
policy=st_policy.invoice_policy
|
policy=st_policy.invoice_policy
|
||||||
option=st_policy.invoice_option
|
option=st_policy.invoice_option
|
||||||
|
msg=""
|
||||||
# make hd case
|
|
||||||
# 1. create hd case
|
|
||||||
# - add all expense, set policy
|
|
||||||
# 2. find visit
|
|
||||||
# 3. update visit (state: 'confirmed', hd_cases)
|
|
||||||
print('total line ', len(lines))
|
|
||||||
max_row=obj.max_row
|
max_row=obj.max_row
|
||||||
count=0
|
count=0
|
||||||
|
nofound=0
|
||||||
|
did=0
|
||||||
|
blank=0
|
||||||
|
fail_qty=0
|
||||||
|
done_qty=0
|
||||||
for line in lines:
|
for line in lines:
|
||||||
name=line.get("name14")
|
name=line.get("name14")
|
||||||
hn=line.get('hn',"")
|
hn=line.get('hn',"")
|
||||||
|
@ -76,11 +78,17 @@ class ImportHDCase(Model):
|
||||||
hcode='0'
|
hcode='0'
|
||||||
hcode=int(hcode)
|
hcode=int(hcode)
|
||||||
hcode=str(hcode)
|
hcode=str(hcode)
|
||||||
if not obj.hcode==hcode:
|
if not obj.hcode_id.code==hcode:
|
||||||
|
if hcode:
|
||||||
|
nofound+=1
|
||||||
|
if hcode!='0':
|
||||||
|
msg+="not found %s, %s, %s \n"%(hcode,hn,name)
|
||||||
|
fail_qty+=1
|
||||||
|
else:
|
||||||
|
blank+=1
|
||||||
continue
|
continue
|
||||||
dttran=line.get("dttran","")
|
dttran=line.get("dttran","")
|
||||||
date=dttran[0:10]
|
date=dttran[0:10]
|
||||||
#time_stop=dttran[11:] # finish hd case
|
|
||||||
pt_ids=get_model("clinic.patient").search([['name','=',name]])
|
pt_ids=get_model("clinic.patient").search([['name','=',name]])
|
||||||
if not pt_ids:
|
if not pt_ids:
|
||||||
pt_ids=get_model("clinic.patient").search([['hn','=',hn]])
|
pt_ids=get_model("clinic.patient").search([['hn','=',hn]])
|
||||||
|
@ -111,7 +119,7 @@ class ImportHDCase(Model):
|
||||||
visits=visit_obj.search_browse([['visit_date','=',date],['patient_id','=',patient_id],['state','=','draft']])
|
visits=visit_obj.search_browse([['visit_date','=',date],['patient_id','=',patient_id],['state','=','draft']])
|
||||||
if visits:
|
if visits:
|
||||||
count+=1
|
count+=1
|
||||||
print("confirming")
|
done_qty+=1
|
||||||
hlines+=st_lines
|
hlines+=st_lines
|
||||||
visit=visits[0]
|
visit=visits[0]
|
||||||
cycle=visit.cycle_id
|
cycle=visit.cycle_id
|
||||||
|
@ -136,16 +144,21 @@ class ImportHDCase(Model):
|
||||||
inv.write({
|
inv.write({
|
||||||
'date': inv.due_date,
|
'date': inv.due_date,
|
||||||
})
|
})
|
||||||
print("confirm visit ", visit.number)
|
msg+="confirm visit %s\n"%(visit.visit_date)
|
||||||
else:
|
else:
|
||||||
print("not found visit for %s on %s"%(name,date))
|
did+=1
|
||||||
|
#print("not found visit for %s on %s"%(name,date))
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
#print("XXXX ", name)
|
remain_row=len(lines)-blank-did-count
|
||||||
|
if remain_row <= 0:
|
||||||
|
msg="Nothing to import"
|
||||||
obj.write({
|
obj.write({
|
||||||
'total_row': len(lines),
|
'total_row': len(lines),
|
||||||
'remain_row': len(lines)-count,
|
'remain_row': remain_row,
|
||||||
|
'msg': msg,
|
||||||
|
'done_qty': done_qty,
|
||||||
|
'fail_qty': fail_qty,
|
||||||
})
|
})
|
||||||
print("Done!")
|
print("Done!")
|
||||||
|
|
||||||
|
|
|
@ -1,161 +1,92 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from netforce.model import Model, fields, get_model
|
from netforce.model import Model, fields, get_model
|
||||||
from netforce.access import get_active_company
|
|
||||||
from netforce.utils import get_file_path
|
from netforce.utils import get_file_path
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
class ImportPayment(Model):
|
class ImportPayment(Model):
|
||||||
_name="clinic.import.payment"
|
_name="import.clinic.payment"
|
||||||
_transient=True
|
_string="Clinic Payment"
|
||||||
|
|
||||||
|
def _get_name(self,ids,context={}):
|
||||||
|
res={}
|
||||||
|
for obj in self.browse(ids):
|
||||||
|
res[obj.id]=obj.type_id.name
|
||||||
|
return res
|
||||||
|
|
||||||
_fields={
|
_fields={
|
||||||
'date': fields.DateTime("Date"),
|
'name': fields.Char("Name",function="_get_name"),
|
||||||
|
'type_id': fields.Many2One("clinic.patient.type","Patient Type"),
|
||||||
|
'date': fields.Date("Date"),
|
||||||
'file': fields.File("File"),
|
'file': fields.File("File"),
|
||||||
'result': fields.Text("Success"),
|
'hcode_id': fields.Many2One("clinic.hospital", "Hospital",required=True),
|
||||||
'hcode': fields.Char("Hospital Code"),
|
'max_row': fields.Integer("Max Row"),
|
||||||
|
'remain_row': fields.Integer("Pending"),
|
||||||
|
'total_row': fields.Integer("Total Payment"),
|
||||||
|
'msg': fields.Text("Message"),
|
||||||
|
'done_qty': fields.Integer("Success"),
|
||||||
|
'fail_qty': fields.Integer("Fail"),
|
||||||
|
'state': fields.Selection([['draft','Draft'],['fail','Fail'],['success','Success']],'State'),
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_hcode(self,context={}):
|
def get_hcode_id(self,context={}):
|
||||||
settings=get_model("settings").browse(1)
|
hp_ids=get_model("clinic.hospital").search([])
|
||||||
hcode=settings.hospital_code or ""
|
hp_id=None
|
||||||
return hcode
|
if hp_ids:
|
||||||
|
hp_id=hp_ids[0]
|
||||||
|
return hp_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,
|
||||||
|
'max_row': 50,
|
||||||
|
'state': 'draft',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def import_uc(self,ids,context={}):
|
def import_payment(self,ids,context={}):
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
fname=obj.file
|
fname=obj.file
|
||||||
fpath=get_file_path(fname)
|
fpath=get_file_path(fname)
|
||||||
if not fpath:
|
lines=utils.read_excel(fpath,show_datetime=True)
|
||||||
raise Exception("Please select file")
|
|
||||||
lines=utils.read_xml(fpath,node='HDBills')
|
|
||||||
if not lines:
|
|
||||||
raise Exception("Wrong file")
|
|
||||||
data_uc=get_model("clinic.data.uc")
|
|
||||||
uc_ids=data_uc.search([])
|
|
||||||
data_uc.delete(uc_ids)
|
|
||||||
result=""
|
|
||||||
result+="Match: %s"%(50)
|
|
||||||
result+="\n"
|
|
||||||
result+="*"*50
|
|
||||||
for line in lines:
|
|
||||||
# TODO need to check match or not
|
|
||||||
data_uc.create(line)
|
|
||||||
line['type']='success'
|
|
||||||
print(line)
|
|
||||||
result+="\n"
|
|
||||||
result+="Not Match: %s"%(40)
|
|
||||||
result+="\n"
|
|
||||||
result+="*"*50
|
|
||||||
obj.write({
|
|
||||||
'result': result,
|
|
||||||
})
|
|
||||||
|
|
||||||
def import_sc(self,ids,context={}):
|
|
||||||
obj=self.browse(ids)[0]
|
|
||||||
fname=obj.file
|
|
||||||
fpath=get_file_path(fname)
|
|
||||||
lines=utils.read_excel(fpath)
|
|
||||||
if not lines:
|
if not lines:
|
||||||
raise Exception("Wrong File")
|
raise Exception("Wrong File")
|
||||||
|
msg=""
|
||||||
patients={}
|
max_row=obj.max_row
|
||||||
for pt in get_model("clinic.patient").search_read([[]],['hn_num','name']):
|
count=0
|
||||||
hn=pt['hn_num']
|
nofound=0
|
||||||
if not hn:
|
did=0
|
||||||
continue
|
blank=0
|
||||||
patients[hn]={
|
fail_qty=0
|
||||||
'id': pt['id'],
|
done_qty=0
|
||||||
'name': pt['name'],
|
msg+=""*10; msg+="hcode,hn,name\n"
|
||||||
}
|
|
||||||
|
|
||||||
def get_hn_nu(hn=""):
|
|
||||||
return ''.join(x for x in hn if x.isdigit())
|
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
name=line.get("name14")
|
||||||
|
hn=line.get('hn',"")
|
||||||
|
hct=line.get("hct","")
|
||||||
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:
|
if not obj.hcode_id.code==hcode:
|
||||||
invno=line.get("invno","")
|
if hcode:
|
||||||
name=line.get("name14")
|
nofound+=1
|
||||||
hn=line.get('hn',"")
|
if hcode!='0':
|
||||||
hn_num=get_hn_nu(hn)
|
msg+="not found %s, %s, %s \n"%(hcode,hn,name)
|
||||||
hct=line.get("HCT","")
|
fail_qty+=1
|
||||||
amount=line.get("amount23",0)
|
|
||||||
dttran=line.get("dttran","")
|
|
||||||
|
|
||||||
vals=patients.get(hn_num)
|
|
||||||
if vals:
|
|
||||||
#print(vals)
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
print('not found ', hn, hn_num, name)
|
blank+=1
|
||||||
#print(dttran, invno, hcode, hn, name, hct, amount)
|
continue
|
||||||
|
remain_row=len(lines)-blank-did-count
|
||||||
def clear_sc(self,ids,context={}):
|
if remain_row <= 0:
|
||||||
sc_ids=get_model("clinic.data.sc").search([])
|
msg="Nothing to import"
|
||||||
get_model("clinic.data.sc").delete(sc_ids)
|
|
||||||
obj=self.browse(ids)[0]
|
|
||||||
obj.write({
|
obj.write({
|
||||||
'result': 'Clear OK',
|
'total_row': len(lines),
|
||||||
|
'remain_row': remain_row,
|
||||||
|
'msg': msg,
|
||||||
|
'done_qty': done_qty,
|
||||||
|
'fail_qty': fail_qty,
|
||||||
})
|
})
|
||||||
|
print("Done!")
|
||||||
def match_invoice_sc(self,ids,context={}):
|
|
||||||
obj=self.browse(ids)[0]
|
|
||||||
for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
|
|
||||||
for invoice in sc.hd_case_id.invoices:
|
|
||||||
print(invoice.number)
|
|
||||||
|
|
||||||
obj.write({
|
|
||||||
'result': 'Match OK',
|
|
||||||
})
|
|
||||||
|
|
||||||
def approve_sc(self,ids,context={}):
|
|
||||||
settings=get_model("settings").browse(1)
|
|
||||||
account_id=settings.ap_sc_id.id
|
|
||||||
if not account_id:
|
|
||||||
raise Exception("No Account payment for Social Security")
|
|
||||||
obj=self.browse(ids)[0]
|
|
||||||
vals={
|
|
||||||
'partner_id': '',
|
|
||||||
"company_id": get_active_company(),
|
|
||||||
"type": "in",
|
|
||||||
"pay_type": "invoice",
|
|
||||||
"date": obj.date or time.strftime("%Y-%m-%d"),
|
|
||||||
"account_id": account_id,
|
|
||||||
'invoice_lines': [],
|
|
||||||
}
|
|
||||||
invoice_ids=[]
|
|
||||||
partner_id=None
|
|
||||||
for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
|
|
||||||
if not partner_id:
|
|
||||||
partner_id=sc.hd_case_id.fee_partner_id.id
|
|
||||||
for invoice in sc.hd_case_id.invoices:
|
|
||||||
invoice_ids.append(invoice.id)
|
|
||||||
vals['invoice_lines'].append(('create',{
|
|
||||||
'invoice_id': invoice.id,
|
|
||||||
'amount': invoice.amount_due or 0.0,
|
|
||||||
}))
|
|
||||||
sc.delete() #XXX
|
|
||||||
vals['partner_id']=partner_id
|
|
||||||
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
|
|
||||||
#get_model("account.payment").browse(payment_id).post()
|
|
||||||
return {
|
|
||||||
'next': {
|
|
||||||
'name': 'payment',
|
|
||||||
'mode': 'form',
|
|
||||||
'active_id': payment_id,
|
|
||||||
},
|
|
||||||
'flash': 'Paid',
|
|
||||||
}
|
|
||||||
|
|
||||||
ImportPayment.register()
|
ImportPayment.register()
|
||||||
|
|
|
@ -0,0 +1,161 @@
|
||||||
|
import time
|
||||||
|
|
||||||
|
from netforce.model import Model, fields, get_model
|
||||||
|
from netforce.access import get_active_company
|
||||||
|
from netforce.utils import get_file_path
|
||||||
|
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
class ImportPayment(Model):
|
||||||
|
_name="clinic.import.payment"
|
||||||
|
_transient=True
|
||||||
|
|
||||||
|
_fields={
|
||||||
|
'date': fields.DateTime("Date"),
|
||||||
|
'file': fields.File("File"),
|
||||||
|
'result': fields.Text("Success"),
|
||||||
|
'hcode': fields.Char("Hospital Code"),
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_hcode(self,context={}):
|
||||||
|
settings=get_model("settings").browse(1)
|
||||||
|
hcode=settings.hospital_code or ""
|
||||||
|
return hcode
|
||||||
|
|
||||||
|
_defaults={
|
||||||
|
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
'hcode': get_hcode,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def import_uc(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
fname=obj.file
|
||||||
|
fpath=get_file_path(fname)
|
||||||
|
if not fpath:
|
||||||
|
raise Exception("Please select file")
|
||||||
|
lines=utils.read_xml(fpath,node='HDBills')
|
||||||
|
if not lines:
|
||||||
|
raise Exception("Wrong file")
|
||||||
|
data_uc=get_model("clinic.data.uc")
|
||||||
|
uc_ids=data_uc.search([])
|
||||||
|
data_uc.delete(uc_ids)
|
||||||
|
result=""
|
||||||
|
result+="Match: %s"%(50)
|
||||||
|
result+="\n"
|
||||||
|
result+="*"*50
|
||||||
|
for line in lines:
|
||||||
|
# TODO need to check match or not
|
||||||
|
data_uc.create(line)
|
||||||
|
line['type']='success'
|
||||||
|
print(line)
|
||||||
|
result+="\n"
|
||||||
|
result+="Not Match: %s"%(40)
|
||||||
|
result+="\n"
|
||||||
|
result+="*"*50
|
||||||
|
obj.write({
|
||||||
|
'result': result,
|
||||||
|
})
|
||||||
|
|
||||||
|
def import_sc(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
fname=obj.file
|
||||||
|
fpath=get_file_path(fname)
|
||||||
|
lines=utils.read_excel(fpath)
|
||||||
|
if not lines:
|
||||||
|
raise Exception("Wrong File")
|
||||||
|
|
||||||
|
patients={}
|
||||||
|
for pt in get_model("clinic.patient").search_read([[]],['hn_num','name']):
|
||||||
|
hn=pt['hn_num']
|
||||||
|
if not hn:
|
||||||
|
continue
|
||||||
|
patients[hn]={
|
||||||
|
'id': pt['id'],
|
||||||
|
'name': pt['name'],
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_hn_nu(hn=""):
|
||||||
|
return ''.join(x for x in hn if x.isdigit())
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
hcode=line.get('hcode18','0')
|
||||||
|
if not hcode:
|
||||||
|
hcode='0'
|
||||||
|
hcode=int(hcode)
|
||||||
|
hcode=str(hcode)
|
||||||
|
if obj.hcode==hcode:
|
||||||
|
invno=line.get("invno","")
|
||||||
|
name=line.get("name14")
|
||||||
|
hn=line.get('hn',"")
|
||||||
|
hn_num=get_hn_nu(hn)
|
||||||
|
hct=line.get("HCT","")
|
||||||
|
amount=line.get("amount23",0)
|
||||||
|
dttran=line.get("dttran","")
|
||||||
|
|
||||||
|
vals=patients.get(hn_num)
|
||||||
|
if vals:
|
||||||
|
#print(vals)
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print('not found ', hn, hn_num, name)
|
||||||
|
#print(dttran, invno, hcode, hn, name, hct, amount)
|
||||||
|
|
||||||
|
def clear_sc(self,ids,context={}):
|
||||||
|
sc_ids=get_model("clinic.data.sc").search([])
|
||||||
|
get_model("clinic.data.sc").delete(sc_ids)
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
obj.write({
|
||||||
|
'result': 'Clear OK',
|
||||||
|
})
|
||||||
|
|
||||||
|
def match_invoice_sc(self,ids,context={}):
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
|
||||||
|
for invoice in sc.hd_case_id.invoices:
|
||||||
|
print(invoice.number)
|
||||||
|
|
||||||
|
obj.write({
|
||||||
|
'result': 'Match OK',
|
||||||
|
})
|
||||||
|
|
||||||
|
def approve_sc(self,ids,context={}):
|
||||||
|
settings=get_model("settings").browse(1)
|
||||||
|
account_id=settings.ap_sc_id.id
|
||||||
|
if not account_id:
|
||||||
|
raise Exception("No Account payment for Social Security")
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
vals={
|
||||||
|
'partner_id': '',
|
||||||
|
"company_id": get_active_company(),
|
||||||
|
"type": "in",
|
||||||
|
"pay_type": "invoice",
|
||||||
|
"date": obj.date or time.strftime("%Y-%m-%d"),
|
||||||
|
"account_id": account_id,
|
||||||
|
'invoice_lines': [],
|
||||||
|
}
|
||||||
|
invoice_ids=[]
|
||||||
|
partner_id=None
|
||||||
|
for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
|
||||||
|
if not partner_id:
|
||||||
|
partner_id=sc.hd_case_id.fee_partner_id.id
|
||||||
|
for invoice in sc.hd_case_id.invoices:
|
||||||
|
invoice_ids.append(invoice.id)
|
||||||
|
vals['invoice_lines'].append(('create',{
|
||||||
|
'invoice_id': invoice.id,
|
||||||
|
'amount': invoice.amount_due or 0.0,
|
||||||
|
}))
|
||||||
|
sc.delete() #XXX
|
||||||
|
vals['partner_id']=partner_id
|
||||||
|
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
|
||||||
|
#get_model("account.payment").browse(payment_id).post()
|
||||||
|
return {
|
||||||
|
'next': {
|
||||||
|
'name': 'payment',
|
||||||
|
'mode': 'form',
|
||||||
|
'active_id': payment_id,
|
||||||
|
},
|
||||||
|
'flash': 'Paid',
|
||||||
|
}
|
||||||
|
|
||||||
|
ImportPayment.register()
|
Loading…
Reference in New Issue