import payment

conv_bal
watcha.h 2014-12-03 09:16:05 +07:00
parent a4bf713e3e
commit f8e99319b4
6 changed files with 168 additions and 18 deletions

View File

@ -66,6 +66,6 @@
<item string="Import Patient" action="import_clinic_patient"/>
<item string="Import Visit" action="import_clinic_visit"/>
<item string="Import HD Case" action="import_clinic_hd_case"/>
<item string="Clinic Payment" action="import_clinic_payment"/>
<item string="Import Payment" action="import_clinic_payment"/>
</item>
</menu>

View File

@ -2,25 +2,59 @@
<head>
<field name="state"/>
<button string="Options" dropdown="1">
<item string="View Journal Entry"/>
<item string="Create Journal Entry" states="draft"/>
<item string="View Journal Entry" states="confirmed"/>
</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"/>
<!--<field name="date_from" span="3"/>-->
<!--<field name="date_to" span="3"/>-->
<separator string="Summary"/>
<tabs>
<tab string="Information">
<field name="total_row" span="4" readonly="1"/>
<field name="remain_row" span="4" readonly="1"/>
<field name="total_row" span="3" readonly="1"/>
<field name="remain_row" span="3" readonly="1"/>
<field name="match_qty" span="3" readonly="1"/>
<field name="unmatch_qty" span="3" readonly="1"/>
<newline/>
<field name="done_qty" span="4" readonly="1"/>
<field name="fail_qty" span="4" readonly="1"/>
<field name="done_qty" span="3" readonly="1"/>
<field name="fail_qty" span="3" readonly="1"/>
<field name="est_time" span="3" readonly="1"/>
</tab>
<tab string="Invoice">
<tab string="Match">
<field name="match_lines" nolabel="1">
<list>
<field name="date"/>
<field name="invoice_id"/>
<field name="patient_id"/>
<field name="hd_case_id"/>
</list>
<form>
<field name="date"/>
<field name="invoice_id"/>
<field name="patient_id"/>
<field name="hd_case_id"/>
</form>
</field>
</tab>
<tab string="Payment">
<tab string="Unmatch">
<field name="unmatch_lines" nolabel="1">
<list>
<field name="date"/>
<field name="invoice_id"/>
<field name="patient_id"/>
<field name="hd_case_id"/>
</list>
<form>
<field name="date"/>
<field name="invoice_id"/>
<field name="patient_id"/>
<field name="hd_case_id"/>
</form>
</field>
</tab>
<tab string="Message">
<field name="msg" span="6" nolabel="1" width="1000" height="180"/>

View File

@ -65,6 +65,7 @@ from . import branch
from . import period
from . import period_line
from . import import_payment
from . import import_payment_line
from . import import_product
from . import import_patient
from . import import_visit

View File

@ -1,4 +1,6 @@
import time
from datetime import datetime, timedelta
from calendar import monthrange
from netforce.model import Model, fields, get_model
from netforce.utils import get_file_path
@ -16,17 +18,24 @@ class ImportPayment(Model):
_fields={
'name': fields.Char("Name",function="_get_name"),
'type_id': fields.Many2One("clinic.patient.type","Patient Type"),
'date': fields.Date("Date"),
'file': fields.File("File"),
'type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True),
'hcode_id': fields.Many2One("clinic.hospital", "Hospital",required=True),
'date': fields.Date("Date"),
'date_from': fields.Date("From"),
'date_to': fields.Date("To"),
'file': fields.File("File"),
'max_row': fields.Integer("Max Row"),
'remain_row': fields.Integer("Pending"),
'total_row': fields.Integer("Total Payment"),
'est_time': fields.Float("Estimate Time",scale=4),
'msg': fields.Text("Message"),
'done_qty': fields.Integer("Success"),
'fail_qty': fields.Integer("Fail"),
'state': fields.Selection([['draft','Draft'],['fail','Fail'],['success','Success']],'State'),
'match_qty': fields.Integer("Match"),
'unmatch_qty': fields.Integer("UnMatch"),
'state': fields.Selection([['draft','Draft'],['confirmed','Confirmed'],['fail','Fail'],['success','Success']],'State'),
'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"]]),
}
def get_hcode_id(self,context={}):
@ -36,33 +45,79 @@ class ImportPayment(Model):
hp_id=hp_ids[0]
return hp_id
def _get_date_from(self,context={}):
datenow=time.strftime("%Y-%m-%d")
year,month,day=datenow.split("-")
return '%s-%s-01'%(year,month)
def _get_date_to(self,context={}):
datenow=datetime.now().strftime("%Y-%m-%d")
year,month,day=datenow.split("-")
weekday, total_day=monthrange(int(year), int(month))
return '%s-%s-%s'%(year,month,total_day)
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': _get_date_from,
'date_to': _get_date_to,
'hcode_id': get_hcode_id,
'max_row': 50,
'state': 'draft',
}
def import_payment(self,ids,context={}):
fmt='%Y-%m-%d %H:%M:%S'
start_time=time.strftime(fmt)
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
lines=utils.read_excel(fpath,show_datetime=True)
lines=utils.read_excel(fpath,show_datetime=False)
if not lines:
raise Exception("Wrong File")
msg=""
max_row=obj.max_row
count=0
nofound=0
did=0
blank=0
fail_qty=0
done_qty=0
match_qty=0
unmatch_qty=0
msg+=""*10; msg+="hcode,hn,name\n"
dom=[]
dom.append(['state','=','waiting_payment'])
invoices={}
for inv in get_model("account.invoice").search_browse(dom):
hd_case=inv.related_id
patient=hd_case.patient_id
key=(inv.date,patient.id)
invoices[key]={
'id': inv.id,
'amount_due': inv.amount_due,
'hd_case_id': hd_case.id,
}
patients={}
for pt in get_model("clinic.patient").search_read([[]],['hn','hn_num']):
key=pt['hn_num']
patients[key]={
'id': pt['id'],
}
def get_hn_num(hn=""):
return ''.join(h for h in hn if h.isdigit())
mlines=[]
umlines=[]
for line in lines:
name=line.get("name14")
hn=line.get('hn',"")
hn_num=get_hn_num(hn)
hct=line.get("hct","")
inv_date=line.get("dttran")
hcode=line.get('hcode18','0')
if not hcode:
hcode='0'
@ -77,16 +132,54 @@ class ImportPayment(Model):
else:
blank+=1
continue
if patients.get(hn_num):
patient_id=patients[hn_num]['id']
key=(inv_date,patient_id)
if invoices.get(key):
inv=invoices[key]
mlines.append(('create',{
'date': inv_date,
'invoice_id': inv['id'],
'hd_case_id': inv['hd_case_id'],
'patient_id': patient_id,
'state': 'match',
}))
match_qty+=1
else:
umlines.append(('create',{
'date': inv_date,
'patient_id': patient_id,
}))
unmatch_qty+=1
for mline in obj.match_lines:
mline.delete()
for umline in obj.unmatch_lines:
umline.delete()
stop_time=time.strftime(fmt)
est_time=datetime.strptime(stop_time,fmt)-datetime.strptime(start_time,fmt)
remain_row=len(lines)-blank-did-count
if remain_row <= 0:
msg="Nothing to import"
obj.write({
'total_row': len(lines),
'remain_row': remain_row,
'remain_row': remain_row-match_qty,
'msg': msg,
'done_qty': done_qty,
'done_qty': match_qty,
'fail_qty': fail_qty,
'match_qty': match_qty,
'unmatch_qty': unmatch_qty,
'est_time': est_time.seconds/3600,
'match_lines': mlines,
'unmatch_lines': umlines,
})
print("Done!")
ImportPayment.register()

View File

@ -0,0 +1,21 @@
from netforce.model import Model, fields
class PaymentLine(Model):
_name="import.clinic.payment.line"
_string="Race"
_fields={
'import_payment_id': fields.Many2One("import.clinic.payment","Payment",required=True,on_delete="cascade"),
'date': fields.Date("Date"),
'invoice_id': fields.Many2One("account.invoice","Invoice"),
'patient_id': fields.Many2One("clinic.patient","Patient"),
'hd_case_id': fields.Many2One("clinic.hd.case","HDCase"),
'state': fields.Selection([['match','Match'],['unmatch','Unmatch']],"State"),
'amount': fields.Float("Amount"),
}
_defaults={
'state': 'unmatch',
}
PaymentLine.register()

View File

@ -1,7 +1,8 @@
- missing
- import schedule -> wait K. Ekk
- missing hd case in staff (nurse, doctor)
- special nurse
- report for show max cycle and got cycle
===============