fix import payment

conv_bal
watcha.h 2015-02-19 15:15:41 +07:00
parent 4ac1060064
commit 82aa96abb9
7 changed files with 129 additions and 192 deletions

View File

@ -4,7 +4,6 @@
<field name="cycle_id"/> <field name="cycle_id"/>
<field name="patient_id"/> <field name="patient_id"/>
<field name="patient_type_id"/> <field name="patient_type_id"/>
<field name="sickbed_id"/>
<field name="department_id"/> <field name="department_id"/>
<field name="doctor_id"/> <field name="doctor_id"/>
<field name="state"/> <field name="state"/>

View File

@ -2,7 +2,7 @@
<head> <head>
<button string="Options" dropdown="1"> <button string="Options" dropdown="1">
<item string="Update Identification" method="update_id"/> <item string="Update Identification" method="update_id"/>
<item string="Import Payment" method="do_import" type="default"/> <item string="Make Payment" method="do_import" type="default" confirm="Are you sure?"/>
</button> </button>
</head> </head>
<field name="date" onchange="onchange_date" mode="month" span="3"/> <field name="date" onchange="onchange_date" mode="month" span="3"/>
@ -22,12 +22,11 @@
<field name="epo"/> <field name="epo"/>
<field name="service"/> <field name="service"/>
<field name="fee"/> <field name="fee"/>
<field name="expense_id" onchange="onchange_line" domain='[["date","=",date],["patient_id.name","=",name]]'/> <field name="invoice_id" domain='[["date","=",date],["state","=","waiting_payment"]]'/>
<field name="state"/> <field name="state"/>
</list> </list>
</field> </field>
<foot replace="1"> <foot replace="1">
<button string="Match" method="do_match" type="success" icon='ok'/> <button string="Match" method="do_match" type="success" icon='ok'/>
<!--<button string="Import Payment" method="do_import" type="default" icon='arrow-right'/>-->
</foot> </foot>
</form> </form>

View File

@ -122,11 +122,15 @@ class MatchingHDCase(Model):
categ=prod.categ_id categ=prod.categ_id
if categ and line.reimbursable=='yes': if categ and line.reimbursable=='yes':
if categ.code=='EPO': if categ.code=='EPO':
prod_line.append((prod.name or "").upper()) #prod_line.append((prod.name or "").upper())
prod_name=(prod.name or "").split("-")
if len(prod_name) > 1:
prod_name=prod_name[0]
prod_line.append(prod_name)
elif categ.code=='FEE': elif categ.code=='FEE':
fee_amt=line.amount or 0 fee_amt=line.amount or 0
prod_name=','.join(prod_line) prod_name='-'.join(prod_line)
key1='%s-%s-%s-%s-%s'%(date,hn,hct,prod_name,fee_amt) key1='%s-%s-%s-%s'%(date,hn,prod_name,fee_amt)
hdcases[key1]={ hdcases[key1]={
'id': hdcase.id, 'id': hdcase.id,
'number': hdcase.number or '', 'number': hdcase.number or '',
@ -164,8 +168,9 @@ class MatchingHDCase(Model):
prod_name=vals[10] or '' prod_name=vals[10] or ''
prod_name=prod_name.replace(" ", "") prod_name=prod_name.replace(" ", "")
prod_id=products.get(prod_name.upper(),None) prod_id=products.get(prod_name.upper(),None)
key1='%s-%s-%s-%s-%s'%(date,hn,hct,prod_name.upper(),fee_amt) key1='%s-%s-%s-%s'%(date,hn,prod_name.upper(),fee_amt)
hdcase=hdcases.get(key1) hdcase=hdcases.get(key1)
unit_amt=float(vals[11])
line_vals={ line_vals={
'hn': hn, 'hn': hn,
'date': date, 'date': date,
@ -173,7 +178,7 @@ class MatchingHDCase(Model):
'patient_id': pt_id, 'patient_id': pt_id,
'patient_type': pt_type, 'patient_type': pt_type,
'hct': hct, 'hct': hct,
'prod_name': prod_name, 'prod_name': (prod_name or "").title(),
'prod_id': prod_id, 'prod_id': prod_id,
'fee_amt': fee_amt, 'fee_amt': fee_amt,
'note': '', 'note': '',
@ -182,25 +187,30 @@ class MatchingHDCase(Model):
'nf_hct': '', 'nf_hct': '',
'nf_epo': '', 'nf_epo': '',
'nf_fee': '', 'nf_fee': '',
'unit_amt': unit_amt,
} }
if hdcase: if hdcase:
line_vals['is_match']=True line_vals['is_match']=True
line_vals['hd_case_id']=hdcase['id'] line_vals['hd_case_id']=hdcase['id']
line_vals['hd_case_number']=hdcase['number'] line_vals['hd_case_number']=hdcase['number']
else: else:
key2='%s-%s'%(date,hn) line_vals['is_match']=False
hdcase2=hdcases2.get(key2)
if hdcase2: key2='%s-%s'%(date,hn)
line_vals['is_match']=False hdcase2=hdcases2.get(key2)
line_vals['hd_case_id']=hdcase2['id'] #print("hdcase2 ", hdcase2)
line_vals['hd_case_number']=hdcase2['number'] if hdcase2:
line_vals['note']='' #line_vals['is_match']=False
nf_date,nf_hn,nf_hct,nf_epo,nf_fee=hdcase2['note'].split(",") line_vals['hd_case_id']=hdcase2['id']
line_vals['nf_date']=nf_date line_vals['hd_case_number']=hdcase2['number']
line_vals['nf_hn']=nf_hn line_vals['note']=''
line_vals['nf_hct']=nf_hct nf_date,nf_hn,nf_hct,nf_epo,nf_fee=hdcase2['note'].split(",")
line_vals['nf_epo']=nf_epo line_vals['nf_date']=nf_date
line_vals['nf_fee']=round(float((nf_fee or "0")),2) line_vals['nf_hn']=nf_hn
line_vals['nf_hct']=nf_hct
nf_epo=(nf_epo or "").replace("-",",")
line_vals['nf_epo']=nf_epo.title()
line_vals['nf_fee']=round(float((nf_fee or "0")),2)
lines.append(line_vals) lines.append(line_vals)
no=1 no=1
lines2=[] lines2=[]

View File

@ -64,7 +64,11 @@ class MatchingPayment(Model):
hcode=obj.hcode_id.code or "" hcode=obj.hcode_id.code or ""
if not hcode: if not hcode:
raise Exception("Wrong HCode") raise Exception("Wrong HCode")
n,sf=fname.split(".") try:
n,sf=fname.split(".")
except Exception as e:
print("ERROR: wrong file ", e)
if sf not in ('xls','xlsx'): if sf not in ('xls','xlsx'):
raise Exception("File should be xls or xlsx") raise Exception("File should be xls or xlsx")
fpath=get_file_path(fname) fpath=get_file_path(fname)
@ -85,72 +89,50 @@ class MatchingPayment(Model):
def match(self,ids,context={}): def match(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
lines=obj.get_line() lines=obj.get_line()
patient_type=obj.patient_type_id
if not patient_type:
raise Exception("not found patient type")
contact=patient_type.contact_id
if not contact:
raise Exception("contact not found")
matches1={} matches1={}
matches2={} matches2={}
matches3={} matches3={}
matches4={}
matches_uc={}
dom=[] dom=[]
dom.append(['date',">=",obj.date_from]) dom.append(['date',">=",obj.date_from])
dom.append(['date',"<=",obj.date_to]) dom.append(['date',"<=",obj.date_to])
dom.append(['patient_id.type_id',"=",obj.patient_type_id.id]) dom.append(['partner_id',"=",contact.id])
dom.append(['state','!=', 'completed']) dom.append(['state','=', 'waiting_payment'])
for exp in get_model('clinic.hd.case.expense').search_browse(dom): for inv in get_model('account.invoice').search_browse(dom):
patient=exp.patient_id pname=inv.ref or ''
hn=patient.hn_no pname=pname.replace(" ","")
pid=patient.card_no
pid=pid and pid or ""
name=patient.name or ''
name_check=name.replace(" ","")
date=exp.date or ""
lfee_amt=exp.fee_amt or 0
lmdc_amt=exp.mdc_amt or 0
lsrv_amt=exp.srv_amt or 0
#hn
key1='%s:%s:%s:%s:%s'%(
hn,
date,
lfee_amt,
lsrv_amt,
lmdc_amt,
)
# id card
key2='%s:%s:%s:%s:%s'%(
pid,
date,
lfee_amt,
lsrv_amt,
lmdc_amt,
)
key3='%s:%s:%s:%s:%s'%(
name_check,
date,
lfee_amt,
lsrv_amt,
lmdc_amt,
)
key4='%s:%s'%(name_check,date)
key_uc='%s:%s:%s'%(hn,date,lfee_amt)
vals={ vals={
'pid': pid, 'invoice_id': inv.id,
'name': name,
'date': date,
'fee_amt': lfee_amt,
'service_amt': lsrv_amt,
'epo_amt': lmdc_amt,
'hn': hn,
'expense_id': exp.id,
} }
date=inv.date
key1='%s:%s'%(
pname,
date,
)
if not matches1.get(key1): if not matches1.get(key1):
matches1[key1]=vals matches1[key1]=vals
if not matches2.get(key2): for pt in get_model("clinic.patient").search_browse([['name_check','=',pname]]):
matches2[key2]=vals hn=pt.hn_no or ''
if not matches3.get(key3): key2='%s:%s'%(
matches3[key3]=vals hn,
if not matches4.get(key3): date,
matches4[key4]=vals )
if not matches_uc.get(key_uc): if not matches2.get(key2):
matches4[key_uc]=vals matches2[key2]=vals
id_card=pt.card_no or ""
key3='%s:%s'%(
id_card,
date,
)
if not matches3.get(key3):
matches2[key3]=vals
nf_hcode='' nf_hcode=''
if obj.hcode_id: if obj.hcode_id:
nf_hcode=obj.hcode_id.code nf_hcode=obj.hcode_id.code
@ -171,7 +153,7 @@ class MatchingPayment(Model):
name=line.get("name14") name=line.get("name14")
name2=name name2=name
name=name.replace(" ","") name=name.replace(" ","")
pid=line.get('pid') pid=int(line.get('pid'))
date=dttran[0:10] date=dttran[0:10]
time=dttran[11:] #XXX time=dttran[11:] #XXX
if not time: if not time:
@ -179,38 +161,23 @@ class MatchingPayment(Model):
continue continue
hn=line.get('hn') hn=line.get('hn')
hn=''.join([x for x in hn if x.isdigit()]) hn=''.join([x for x in hn if x.isdigit()])
key1='%s:%s:%s:%s:%s'%(
hn, #if hn=='10288153':
date, #import pdb; pdb.set_trace()
lfee_amt, #1. name, 2. hn, 3. id_card
lsrv_amt, key1='%s:%s'%(
lmdc_amt,
)
key2='%s:%s:%s:%s:%s'%(
pid,
date,
lfee_amt,
lsrv_amt,
lmdc_amt,
)
key3='%s:%s:%s:%s:%s'%(
name, name,
date, date,
lfee_amt,
lsrv_amt,
lmdc_amt,
) )
key4='%s:%s'%(name,date) key2='%s:%s'%(
#vals={ hn,
#'pid': pid, date,
#'name': name, )
#'date': date, key3='%s:%s'%(
#'fee_amt': lfee_amt, pid,
#'service_amt': lsrv_amt, date,
#'epo_amt': lmdc_amt, )
#}
record={ record={
'no': no,
'date':date, 'date':date,
'patient_name': name2, 'patient_name': name2,
'pid': pid, 'pid': pid,
@ -218,58 +185,37 @@ class MatchingPayment(Model):
'fee_amt': lfee_amt, 'fee_amt': lfee_amt,
'srv_amt': lsrv_amt, 'srv_amt': lsrv_amt,
'mdc_amt': lmdc_amt, 'mdc_amt': lmdc_amt,
'note': '', 'invoice_id': None,
'nf_patient': '',
'nf_pid': '',
'nf_hn': '',
'nf_fee_amt': 0,
'nf_srv_amt': 0,
'nf_mdc_amt': 0,
'expense_id': None,
'expense_number': '',
'found': False,
} }
#import pdb; pdb.set_trace()
print(key1, ' - ' , key2, ' - ', key3)
if not matches1.get(key1): if not matches1.get(key1):
if not matches2.get(key2): if not matches2.get(key2):
if not matches4.get(key3): if not matches3.get(key3):
notes=matches4.get(key4)
if notes:
print("not found") print("not found")
record.update({
'nf_date': notes['date'],
'nf_hn': notes['hn'],
'nf_pid': notes['pid'],
'nf_patient_name': notes['name'],
'nf_fee_amt': notes['fee_amt'],
'nf_srv_amt': notes['srv_amt'],
'nf_mdc_amt': notes['mdc_amt'],
'expense_id': notes['expense_id'],
'expense_number': notes['expense_number'],
})
else:
print(">> ", notes)
else: else:
print("found 3.") print("found 3.")
# found 3. # found 3.
found=matches3[key3] found=matches3[key3]
record.update({ record.update({
'expense_id': found['expense_id'], 'invoice_id': found['invoice_id'],
'state': 'match',
}) })
else: else:
# found 2. # found 2.
print("found 2.") print("found 2.")
found=matches2[key2] found=matches2[key2]
record.update({ record.update({
'expense_id': found['expense_id'], 'invoice_id': found['invoice_id'],
'state': 'match',
}) })
else: else:
# found 1. # found 1.
found=matches1[key1] found=matches1[key1]
print("found 1.") print("found 1.")
record.update({ record.update({
'expense_id': found['expense_id'], 'invoice_id': found['invoice_id'],
'expense_number': found['expense_number'], 'state': 'match',
'found': True,
}) })
records.append(record) records.append(record)
no+=1 no+=1
@ -296,10 +242,10 @@ class MatchingPayment(Model):
hn=line['hn'] hn=line['hn']
hn=hn.replace(" ", "") hn=hn.replace(" ", "")
if date and time: if date and time:
key1='%s:%s:%s'%( key2='%s:%s:%s'%(
line['hn'], line['hn'],
date, date,
amt, #amt,
) )
name='' name=''
pid='' pid=''
@ -308,32 +254,20 @@ class MatchingPayment(Model):
pid=pt.card_no or '' pid=pt.card_no or ''
record={ record={
'date':date, 'date':date,
'name': name, 'patient_name': name2,
'pid': pid, 'pid': pid,
'hn': hn, 'hn': hn,
'fee_amt': amt, 'fee_amt': lfee_amt,
'srv_amt': 0, 'srv_amt': lsrv_amt,
'mdc_amt': 0, 'mdc_amt': lmdc_amt,
'note': '', 'invoice_id': None,
'nf_patient': '',
'nf_pid': '',
'nf_hn': '',
'nf_fee_amt': 0,
'nf_srv_amt': 0,
'nf_mdc_amt': 0,
'expense_id': None,
'expense_number': '',
'found': False,
} }
if matches_uc.get(key1): if matches2.get(key2):
vals=matches_uc[key1] vals=matches2[key2]
record.update({ record.update({
'found': True, 'invoice_id':vals['invoice_id'],
'expense_id':vals['expense_id'],
'fee_amt': vals['fee'] or 0,
}) })
records.append(record) records.append(record)
return records return records
def onchange_date(self,context={}): def onchange_date(self,context={}):
@ -372,32 +306,18 @@ class MatchingPayment(Model):
} }
for line in obj.lines: for line in obj.lines:
exp=line.expense_id inv=line.invoice_id
if exp: if inv:
exp.write({ vals['invoice_lines'].append(('create',{
'state': 'match', 'invoice_id': inv.id,
}) 'amount': inv.amount_due or 0,
line.delete() }))
dom=[] if inv.related_id:
dom.append(['state','=','match']) hdcase=inv.related_id
for exp in get_model("clinic.hd.case.expense").search_browse(dom):
if exp.state=='match':
for inv in exp.hd_case_id.invoices:
if inv.partner_id.id==partner.id:
vals['invoice_lines'].append(('create',{
'invoice_id': inv.id,
'amount': inv.amount_due or 0,
}))
#should not match again
exp.write({
'state': 'completed',
})
hdcase=exp.hd_case_id
if hdcase: if hdcase:
hdcase.write({ hdcase.write({
'state': 'paid', 'state': 'paid',
}) })
if not vals['invoice_lines']: if not vals['invoice_lines']:
raise Exception("Nothing to import") raise Exception("Nothing to import")
payment_id=get_model("account.payment").create(vals,context={"type":"in"}) payment_id=get_model("account.payment").create(vals,context={"type":"in"})
@ -424,7 +344,7 @@ class MatchingPayment(Model):
'epo': record['mdc_amt'], 'epo': record['mdc_amt'],
'service': record['srv_amt'], 'service': record['srv_amt'],
'fee': record['fee_amt'], 'fee': record['fee_amt'],
'expense_id': record['expense_id'], 'invoice_id': record['invoice_id'],
} }
lines.append(('create', vals)) lines.append(('create', vals))
elif obj.pcode=='UC': elif obj.pcode=='UC':
@ -435,7 +355,7 @@ class MatchingPayment(Model):
'pid': record['pid'], 'pid': record['pid'],
'name': record['name'], 'name': record['name'],
'fee': record['fee_amt'], 'fee': record['fee_amt'],
'expense_id': record['expense_id'], 'invoice_id': record['invoice_id'],
} }
lines.append(('create', vals)) lines.append(('create', vals))
for line in obj.lines: for line in obj.lines:
@ -656,5 +576,4 @@ class MatchingPayment(Model):
line['state']=None line['state']=None
return data return data
MatchingPayment.register() MatchingPayment.register()

View File

@ -1,6 +1,5 @@
from netforce.model import Model, fields, get_model from netforce.model import Model, fields, get_model
class MatchingPaymentLine(Model): class MatchingPaymentLine(Model):
_name="clinic.matching.payment.line" _name="clinic.matching.payment.line"
_transient=True _transient=True
@ -8,7 +7,9 @@ class MatchingPaymentLine(Model):
_fields={ _fields={
'match_id': fields.Many2One("clinic.matching.payment","Match",required=True,on_delete="cascade"), 'match_id': fields.Many2One("clinic.matching.payment","Match",required=True,on_delete="cascade"),
'expense_id': fields.Many2One("clinic.hd.case.expense","Expense"), 'expense_id': fields.Many2One("clinic.hd.case.expense","Expense"),
"date": fields.Date("Date"), 'invoice_id': fields.Many2One("account.invoice","Invoice (Waiting Payment)"),
#"date": fields.Date("Date"),
"date": fields.Char("Date"),
"hn": fields.Char("HN"), "hn": fields.Char("HN"),
'pid': fields.Char("PID"), 'pid': fields.Char("PID"),
"name": fields.Char("Name"), "name": fields.Char("Name"),

View File

@ -62,12 +62,13 @@ class ReportLaborCostSummary(Model):
date_from=obj.date_from date_from=obj.date_from
date_to=obj.date_to date_to=obj.date_to
staff_id=obj.staff_id.id staff_id=obj.staff_id.id
staff_type=obj.type staff_type=obj.staff_type
level_id=obj.level_id.id level_id=obj.level_id.id
categ_id=obj.categ_id.id categ_id=obj.categ_id.id
only_value=obj.only_value only_value=obj.only_value
dom.append(['date','>=',date_from]) dom.append(['date','>=',date_from])
dom.append(['date','<=',date_to]) dom.append(['date','<=',date_to])
print("staff_type ", staff_type)
if staff_id: if staff_id:
dom.append(['staff_id','=',staff_id]) dom.append(['staff_id','=',staff_id])
if staff_type: if staff_type:
@ -86,17 +87,23 @@ class ReportLaborCostSummary(Model):
categ_name='' categ_name=''
categ_id=None categ_id=None
categ=staff.categ_id categ=staff.categ_id
level_name=''
#XXX fix
if not staff:
continue
if level_id and staff.level_id.id!=level_id: if level_id and staff.level_id.id!=level_id:
continue continue
if categ: if categ:
categ_id=categ.id categ_id=categ.id
categ_name=categ.name or "" categ_name=categ.name or ""
if staff.level_id:
level_name=staff.level_id.name or ""
if not staffs.get(staff.name): if not staffs.get(staff.name):
staffs[staff.name]={ staffs[staff.name]={
'number': staff.number or '', 'number': staff.number or '',
'staff_id': staff.id, 'staff_id': staff.id,
'staff_type': staff.type, 'staff_type': staff.type,
'staff_level': staff.level_id.name, 'staff_level': level_name,
'categ_name': categ_name, 'categ_name': categ_name,
'categ_id': categ_id, 'categ_id': categ_id,
dpt.name: { dpt.name: {

View File

@ -5,7 +5,7 @@
<table class="table table-condensed table-striped"> <table class="table table-condensed table-striped">
<thead> <thead>
<tr> <tr>
<th colspan="9" style="text-align:center;background-color:#f9e37d;">Import File</th> <th colspan="10" style="text-align:center;background-color:#f9e37d;">Import File</th>
<th colspan="5" style="text-align:center;background-color:#2d6ed2;color:white">Netforce</th> <th colspan="5" style="text-align:center;background-color:#2d6ed2;color:white">Netforce</th>
</tr> </tr>
<tr> <tr>
@ -16,6 +16,7 @@
<th>Type</th> <th>Type</th>
<th>HCT</th> <th>HCT</th>
<th>EPO</th> <th>EPO</th>
<th>Unit</th>
<th>Fee</th> <th>Fee</th>
<th>Match</th> <th>Match</th>
<th>Date</th> <th>Date</th>
@ -44,6 +45,7 @@
{{else}} {{else}}
<td>{{prod_name}}</td> <td>{{prod_name}}</td>
{{/if}} {{/if}}
<td>{{unit_amt}}</td>
<td>{{currency fee_amt zero=""}}</td> <td>{{currency fee_amt zero=""}}</td>
{{#if is_match}} {{#if is_match}}
<td style="background-color:#4daa35;width:8%;"> <td style="background-color:#4daa35;width:8%;">
@ -54,7 +56,7 @@
<a style="color:white" href="/ui#name=clinic_hd_case&mode=form&active_id={{hd_case_id}}">{{hd_case_number}}</a> <a style="color:white" href="/ui#name=clinic_hd_case&mode=form&active_id={{hd_case_id}}">{{hd_case_number}}</a>
</td> </td>
{{/if}} {{/if}}
<td>{{nf_date}}</td> <td style="width:10%;">{{nf_date}}</td>
<td>{{nf_hn}}</td> <td>{{nf_hn}}</td>
<td>{{nf_hct}}</td> <td>{{nf_hct}}</td>
<td>{{nf_epo}}</td> <td>{{nf_epo}}</td>