clinic/netforce_clinic/models/import_payment.py

162 lines
4.9 KiB
Python
Raw Normal View History

2014-10-04 15:51:54 +00:00
import time
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
from netforce.utils import get_file_path
2014-12-02 11:41:05 +00:00
from . import utils
2014-11-30 13:05:14 +00:00
2014-10-04 15:51:54 +00:00
class ImportPayment(Model):
_name="clinic.import.payment"
2014-10-22 03:45:23 +00:00
_transient=True
2014-10-27 14:17:22 +00:00
2014-10-04 15:51:54 +00:00
_fields={
2014-10-22 03:45:23 +00:00
'date': fields.DateTime("Date"),
2014-10-05 17:00:16 +00:00
'file': fields.File("File"),
2014-10-24 08:08:56 +00:00
'result': fields.Text("Success"),
2014-10-27 14:17:22 +00:00
'hcode': fields.Char("Hospital Code"),
2014-10-04 15:51:54 +00:00
}
2014-10-22 03:45:23 +00:00
2014-10-27 14:17:22 +00:00
def get_hcode(self,context={}):
settings=get_model("settings").browse(1)
hcode=settings.hospital_code or ""
return hcode
2014-10-04 15:51:54 +00:00
_defaults={
2014-10-22 03:45:23 +00:00
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
2014-10-27 14:17:22 +00:00
'hcode': get_hcode,
2014-10-04 15:51:54 +00:00
}
2014-10-05 17:00:16 +00:00
2014-10-24 04:24:33 +00:00
2014-11-25 10:26:10 +00:00
def import_uc(self,ids,context={}):
2014-10-05 17:00:16 +00:00
obj=self.browse(ids)[0]
2014-10-22 03:45:23 +00:00
fname=obj.file
fpath=get_file_path(fname)
2014-10-24 04:24:33 +00:00
if not fpath:
raise Exception("Please select file")
2014-12-02 11:41:05 +00:00
lines=utils.read_xml(fpath,node='HDBills')
2014-10-24 04:24:33 +00:00
if not lines:
raise Exception("Wrong file")
2014-11-25 10:26:10 +00:00
data_uc=get_model("clinic.data.uc")
uc_ids=data_uc.search([])
data_uc.delete(uc_ids)
2014-10-24 08:08:56 +00:00
result=""
result+="Match: %s"%(50)
result+="\n"
result+="*"*50
2014-10-24 04:24:33 +00:00
for line in lines:
2014-10-24 08:08:56 +00:00
# TODO need to check match or not
2014-11-25 10:26:10 +00:00
data_uc.create(line)
2014-10-24 08:08:56 +00:00
line['type']='success'
2014-10-24 04:24:33 +00:00
print(line)
2014-10-24 08:08:56 +00:00
result+="\n"
result+="Not Match: %s"%(40)
result+="\n"
result+="*"*50
obj.write({
'result': result,
})
2014-10-05 17:00:16 +00:00
2014-10-22 03:45:23 +00:00
def import_sc(self,ids,context={}):
2014-10-05 17:00:16 +00:00
obj=self.browse(ids)[0]
2014-10-22 03:45:23 +00:00
fname=obj.file
fpath=get_file_path(fname)
2014-12-02 11:41:05 +00:00
lines=utils.read_excel(fpath)
2014-10-24 08:08:56 +00:00
if not lines:
raise Exception("Wrong File")
2014-12-02 11:41:05 +00:00
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())
2014-11-30 13:05:14 +00:00
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',"")
2014-12-02 11:41:05 +00:00
hn_num=get_hn_nu(hn)
2014-11-30 13:05:14 +00:00
hct=line.get("HCT","")
amount=line.get("amount23",0)
dttran=line.get("dttran","")
2014-12-02 11:41:05 +00:00
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)
2014-10-27 19:01:18 +00:00
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',
})
2014-10-28 13:39:29 +00:00
def approve_sc(self,ids,context={}):
2014-10-27 19:01:18 +00:00
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',
}
2014-10-04 15:51:54 +00:00
ImportPayment.register()