clinic/netforce_clinic/models/old/import_payment.py

162 lines
4.9 KiB
Python
Raw Normal View History

2014-12-03 00:05:18 +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
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()