matching payment

conv_bal
watcha.h 2015-02-20 17:59:49 +07:00
parent 73d6529f0c
commit 331121f367
8 changed files with 202 additions and 151 deletions

View File

@ -1,10 +1,12 @@
<action> <action>
<field name="string">Payment Matching</field> <field name="string">Payment Matching</field>
<!--<field name="view_cls">report</field> --> <field name="view_cls">multi_view</field>
<field name="view_cls">form_view</field>
<field name="view_xml">clinic_matching_payment</field>
<field name="model">clinic.matching.payment</field> <field name="model">clinic.matching.payment</field>
<!--<field name="report_template">matching_payment</field> -->
<!--<field name="report_template_xls">matching_payment</field> -->
<field name="menu">account_menu</field> <field name="menu">account_menu</field>
<field name="tabs">[
["All",[]],
["Draft",[["state","=","draft"]]],
["Approved",[["state","=","approved"]]]
]</field>
<field name="limit">10</field>
</action> </action>

View File

@ -5,7 +5,7 @@
<!--<item string="Labor Cost Entries" action="clinic_labor_cost_entry"/>--> <!--<item string="Labor Cost Entries" action="clinic_labor_cost_entry"/>-->
<item string="Payments Matching" action="clinic_matching_payment"/> <item string="Payments Matching" action="clinic_matching_payment"/>
<item string="HD Cases Matching" action="clinic_matching_hdcase_acc"/> <item string="HD Cases Matching" action="clinic_matching_hdcase_acc"/>
<item string="HD Case Expenses" action="clinic_hd_case_expense"/> <!--<item string="HD Case Expenses" action="clinic_hd_case_expense"/>-->
<divider/> <divider/>
<header string="REPORTS"/> <header string="REPORTS"/>
<item string="Labor Cost Summary" action="clinic_report_labor_cost_summary"/> <item string="Labor Cost Summary" action="clinic_report_labor_cost_summary"/>

View File

@ -1,4 +1,4 @@
<list model="clinic.dialyzer"> <list model="clinic.dialyzer" colors='{"#cfc":[["state","=","active"]],"#dbdbdb":[["state","=","drop"]]}'>
<top replace="1"></top> <top replace="1"></top>
<field name="date"/> <field name="date"/>
<field name="number"/> <field name="number"/>

View File

@ -1,31 +1,42 @@
<form model="clinic.matching.payment" title="Payment Matching"> <form model="clinic.matching.payment" attrs='{"readonly":[["state","=","approved"]]}'>
<head> <head>
<button string="Print" action="print" icon="print"/>
<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="Make Payment" method="do_import" type="default" confirm="Are you sure?"/> <item string="Make Payment" method="do_import" confirm="Are you sure?"/>
<item string="Clear Lines" method="clear_line" 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"/>
<field name="date_from" span="3"/> <field name="date_from" span="3"/>
<field name="date_to" span="3"/> <field name="date_to" span="3"/>
<field name="file" span="3"/> <field name="name" string="Description" span="3"/>
<newline/> <newline/>
<field name="patient_type_id" onchange="onchange_ptype" span="3"/> <field name="patient_type_id" onchange="onchange_ptype" span="3"/>
<field name="pcode" span="3"/> <field name="pcode" span="3"/>
<field name="hcode_id" span="3" attrs='{"required":[["pcode","=","SSO"]],"invisible":[["pcode","!=","SSO"]]}'/> <field name="hcode_id" span="3" attrs='{"required":[["pcode","=","SSO"]],"invisible":[["pcode","!=","SSO"]]}'/>
<field name="file" span="3"/>
<field name="lines" nolabel="1" count="0"> <field name="lines" nolabel="1" count="0">
<list> <list>
<field name="date"/> <field name="date"/>
<field name="hn"/> <field name="hn"/>
<field name="pid"/> <field name="pid"/>
<field name="name"/> <field name="name"/>
<field name="epo"/> <field name="epo" sum="1"/>
<field name="service"/> <field name="srv" sum="1"/>
<field name="fee"/> <field name="fee" sum="1"/>
<field name="invoice_id" domain='[["date","=",date],["state","=","waiting_payment"]]'/> <field name="amount" sum="1"/>
<field name="invoice_id" onchange="onchange_invoice" domain='[["date","=",date],["state","=","waiting_payment"]]'/>
<field name="state"/> <field name="state"/>
</list> </list>
</field> </field>
<group span="8" columns="1">
</group>
<group span="4" columns="1">
<field name="total"/>
<field name="match_total"/>
<field name="unmatch_total"/>
</group>
<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'/>
</foot> </foot>

View File

@ -0,0 +1,6 @@
<list model="clinic.matching.payment">
<field name="name"/>
<field name="patient_type_id"/>
<field name="pcode"/>
<field name="hcode_id"/>
</list>

View File

@ -38,6 +38,7 @@ class HDCasePopupDlz(Model):
def onchange_product(self,context={}): def onchange_product(self,context={}):
data=context['data'] data=context['data']
product_id=data['product_id'] product_id=data['product_id']
data['membrane_type']=None
for dlz in get_model("clinic.dialyzer").search_browse([]): for dlz in get_model("clinic.dialyzer").search_browse([]):
prod=dlz.product_id prod=dlz.product_id
if prod.id==product_id: if prod.id==product_id:

View File

@ -12,7 +12,24 @@ class MatchingPayment(Model):
_name="clinic.matching.payment" _name="clinic.matching.payment"
_transient=True _transient=True
def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
match_total=0
for line in obj.lines:
state=line.state or ''
if state=='match':
match_total+=1
res[obj.id]={
'total': len(obj.lines),
'match_total': match_total,
'unmatch_total': len(obj.lines)-match_total,
}
return res
_fields={ _fields={
'name': fields.Char("Name"),
"date": fields.Date("Month"), "date": fields.Date("Month"),
"date_from": fields.Date("From", required=True), "date_from": fields.Date("From", required=True),
"date_to": fields.Date("To", required=True), "date_to": fields.Date("To", required=True),
@ -20,10 +37,12 @@ class MatchingPayment(Model):
'patient_type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True), 'patient_type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True),
'pcode': fields.Char("Code",required=True), 'pcode': fields.Char("Code",required=True),
'hcode_id': fields.Many2One("clinic.hospital","HCode"), 'hcode_id': fields.Many2One("clinic.hospital","HCode"),
'expenes': fields.Many2Many("clinic.hd.case.expense","Expenses"),
'lines': fields.One2Many("clinic.matching.payment.line","match_id", "Lines"), 'lines': fields.One2Many("clinic.matching.payment.line","match_id", "Lines"),
'note': fields.Text("Note"), 'note': fields.Text("Note"),
'exp_id': fields.Many2One("clinic.hd.case.expense","Expenses"), 'match_total': fields.Integer("Match",function="_get_all",function_multi=True),
'unmatch_total': fields.Integer("Unmatch",function="_get_all",function_multi=True),
'total': fields.Integer("Total",function="_get_all",function_multi=True),
'state': fields.Selection([['draft','Draft'],['approved','Approved']],'State'),
} }
def _get_ptype(self,context={}): def _get_ptype(self,context={}):
@ -47,13 +66,19 @@ class MatchingPayment(Model):
weekday, total_day=monthrange(int(year), int(month)) weekday, total_day=monthrange(int(year), int(month))
return "%s-%s-%s"%(year,month,total_day) return "%s-%s-%s"%(year,month,total_day)
def _get_name(self,ids,context={}):
return time.strftime("%Y/%m")
_defaults={ _defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"), 'date': lambda *a: time.strftime("%Y-%m-%d"),
'name': _get_name,
'date_from': _get_date_from, 'date_from': _get_date_from,
'date_to': _get_date_to, 'date_to': _get_date_to,
'patient_type_id': _get_ptype, 'patient_type_id': _get_ptype,
'pcode': _get_pcode, 'pcode': _get_pcode,
'state': 'draft',
} }
_order="date desc"
def get_line(self,ids,context={}): def get_line(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
@ -89,6 +114,7 @@ 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()
print("len.lines ", len(lines))
patient_type=obj.patient_type_id patient_type=obj.patient_type_id
if not patient_type: if not patient_type:
raise Exception("not found patient type") raise Exception("not found patient type")
@ -98,52 +124,72 @@ class MatchingPayment(Model):
matches1={} matches1={}
matches2={} matches2={}
matches3={} matches3={}
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(['partner_id',"=",contact.id]) dom.append(['partner_id',"=",contact.id])
dom.append(['state','=', 'waiting_payment']) dom.append(['state','=', 'waiting_payment'])
for inv in get_model('account.invoice').search_browse(dom): invoices=get_model('account.invoice').search_browse(dom)
pname=inv.ref or '' print("len(invoices)", len(invoices))
pname=pname.replace(" ","") for invoice in invoices:
##XXX ธงชัย วิศาลโภคะ (1045-12-1-53) pname,hn,card_no='', '', ''
#pname_alpha=''.join([pn for pn in pname if pn.isalpha()]) if invoice.related_id:
#hn=''.join([str(pn) for pn in pname if pn.isdigit()]) hdcase=invoice.related_id
#print(hn, pname_alpha) patient=hdcase.patient_id
hn="" pname=patient.name_check or ""
card_no=patient.card_no or ""
hn=patient.hn_no
elif invoice.ref:
pname=invoice.ref or ''
pname=pname.replace(" ","") # remove space
else:
pass
fee,epo,srv=0, 0, 0
due_amount=0
for inv_line in invoice.lines:
amount=inv_line.amount or 0
prod=inv_line.product_id
categ_code=''
categ=prod.categ_id
if categ:
categ_code=categ.code
if categ_code=='FEE':
fee+=amount
elif categ_code=='SRV':
srv+=amount
elif categ_code=='EPO':
epo+=amount
else:
due_amount+=amount
vals={ vals={
'invoice_id': inv.id, 'invoice_id': invoice.id,
'fee': fee,
'epo': epo,
'srv': srv,
} }
date=inv.date due_amount+=fee+epo+srv
key1='%s:%s'%( date=invoice.date
pname, req_vals=[date,due_amount]
date, key1=':'.join([str(v) for v in [hn]+req_vals])
) key2=':'.join([str(v) for v in [card_no]+req_vals])
key3=':'.join([str(v) for v in [pname]+req_vals]) # name no space
key_uc=':'.join([str(v) for v in [hn,date,due_amount]])
# becareful!!!
if not matches1.get(key1): if not matches1.get(key1):
matches1[key1]=vals matches1[key1]=vals
for pt in get_model("clinic.patient").search_browse([['name_check','=',pname]]): if not matches2.get(key2):
hn=pt.hn_no or hn or '' matches2[key2]=vals
key2='%s:%s'%( if not matches3.get(key3):
hn, matches3[key3]=vals
date, if not matches_uc.get(key_uc):
) matches_uc[key_uc]=vals
if not matches2.get(key2):
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
records=[] records=[]
if obj.pcode=='SSO': if obj.pcode=='SSO':
no=1
for line in lines: for line in lines:
hcode=line.get('hcode18') hcode=line.get('hcode18')
if not hcode: if not hcode:
@ -151,79 +197,60 @@ class MatchingPayment(Model):
hcode=int(hcode) hcode=int(hcode)
hcode=str(hcode) hcode=str(hcode)
if nf_hcode==hcode: if nf_hcode==hcode:
lsrv_amt=line.get('epoadm29') or 0 epo=line.get('epoadm29') or 0
lfee_amt=line.get('amount23') or 0 fee=line.get('amount23') or 0
lmdc_amt=line.get('allow37') or 0 srv=line.get('allow37') or 0
dttran=line.get("dttran") date_treatment=line.get("dttran")
name=line.get("name14") name=line.get("name14")
name2=name name_nospace=name.replace(" ","")
name=name.replace(" ","") card_no=int(line.get('pid'))
pid=int(line.get('pid')) date=date_treatment[0:10]
date=dttran[0:10] time=date_treatment[11:] #XXX
time=dttran[11:] #XXX
if not time: if not time:
print("wrong format") print("wrong format")
continue continue
due_amount=fee+epo+srv
req_vals=[date,due_amount]
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()])
#if hn=='10288153': key1=':'.join([str(v) for v in [hn]+req_vals])
#import pdb; pdb.set_trace() key2=':'.join([str(v) for v in [card_no]+req_vals])
#1. name, 2. hn, 3. id_card key3=':'.join([str(v) for v in [name_nospace]+req_vals])
key1='%s:%s'%(
name,
date,
)
key2='%s:%s'%(
hn,
date,
)
key3='%s:%s'%(
pid,
date,
)
record={ record={
'date':date, 'date':date,
'patient_name': name2, 'patient_name': name,
'pid': pid, 'pid': card_no,
'hn': hn, 'hn': hn,
'fee_amt': lfee_amt, 'fee': fee,
'srv_amt': lsrv_amt, 'srv': srv,
'mdc_amt': lmdc_amt, 'epo': epo,
'invoice_id': None, 'invoice_id': None,
'state': 'unmatch',
} }
#import pdb; pdb.set_trace() #if hn=='100794':
print(key1, ' - ' , key2, ' - ', key3) #import pdb; pdb.set_trace()
if not matches1.get(key1): if matches1.get(key1):
if not matches2.get(key2): print("found ", key1)
if not matches3.get(key3):
print("not found")
pass
else:
print("found 3.")
# found 3.
found=matches3[key3]
record.update({
'invoice_id': found['invoice_id'],
'state': 'match',
})
else:
# found 2.
print("found 2.")
found=matches2[key2]
record.update({
'invoice_id': found['invoice_id'],
'state': 'match',
})
else:
# found 1.
found=matches1[key1]
print("found 1.")
record.update({ record.update({
'invoice_id': found['invoice_id'], 'invoice_id': matches1[key1]['invoice_id'],
'state': 'match', 'state': 'match',
}) })
elif matches2.get(key2):
print("found ", key2)
record.update({
'invoice_id': matches2[key2]['invoice_id'],
'state': 'match',
})
elif matches3.get(key3):
print("found ", key3)
record.update({
'invoice_id': matches3[key3]['invoice_id'],
'state': 'match',
})
else:
pass
## unmatch
records.append(record) records.append(record)
no+=1
elif obj.pcode=='UC': elif obj.pcode=='UC':
records=[] records=[]
for line in lines: for line in lines:
@ -242,55 +269,43 @@ class MatchingPayment(Model):
#'rid': '2190', #'rid': '2190',
#'station': '01'} #'station': '01'}
date,time=(line['dttran'] or "").split("T") date,time=(line['dttran'] or "").split("T")
amt=line['amount'] or "0" fee=0
amt=float(amt) if line.get('amount'):
fee=float(line['amount'])
hn=line['hn'] hn=line['hn']
hn=hn.replace(" ", "") hn=hn.replace(" ", "")
key_uc=''
if date and time: if date and time:
key2='%s:%s'%( key_uc='%s:%s:%s'%(line['hn'],date,fee,)
line['hn'], pname=''
date,
#amt,
)
name=''
pid='' pid=''
key1=''
key3=''
for pt in get_model("clinic.patient").search_browse([['hn_no','=',hn]]): for pt in get_model("clinic.patient").search_browse([['hn_no','=',hn]]):
name=pt.name_check or "" pname=pt.name or ""
key1='%s:%s'%(name,date) pid=pt.card_no or ""
pid=pt.card_no or ''
key3='%s:%s'%(pid,date)
name1=pt.name or ""
record={ record={
'date':date, 'date':date,
'name': name1, 'name': pname,
'pid': pid, 'pid': pid,
'hn': hn, 'hn': hn,
'fee_amt': amt, 'fee': fee,
'srv_amt': 0, 'srv': 0,
'mdc_amt': 0, 'epo': 0,
'invoice_id': None, 'invoice_id': None,
'state': 'unmatch',
} }
if matches1.get(key1): if matches_uc.get(key_uc):
vals=matches1[key1]
record.update({ record.update({
'invoice_id':vals['invoice_id'], 'invoice_id': matches1[key_uc]['invoice_id'],
}) 'state': 'match',
elif matches2.get(key2):
vals=matches2[key2]
record.update({
'invoice_id':vals['invoice_id'],
})
elif matches3.get(key3):
vals=matches3[key3]
record.update({
'invoice_id':vals['invoice_id'],
}) })
else: else:
pass pass
#print("not found") #print("not found")
records.append(record) records.append(record)
if obj.hcode_id and not records:
raise Exception("Nothing to match! for %s"%(obj.hcode_id.name or ""))
if not records:
raise Exception("Nothing to match! Please verify your file and your filter condition.")
return records return records
def onchange_date(self,context={}): def onchange_date(self,context={}):
@ -300,6 +315,7 @@ class MatchingPayment(Model):
weekday, total_day=monthrange(int(year), int(month)) weekday, total_day=monthrange(int(year), int(month))
data['date_from']="%s-%s-01"%(year,month) data['date_from']="%s-%s-01"%(year,month)
data['date_to']="%s-%s-%s"%(year,month,total_day) data['date_to']="%s-%s-%s"%(year,month,total_day)
data['name']='%s/%s'%(year,month)
return data return data
def onchange_ptype(self,context={}): def onchange_ptype(self,context={}):
@ -359,19 +375,22 @@ class MatchingPayment(Model):
lines=[] lines=[]
if obj.pcode=='SSO': if obj.pcode=='SSO':
for record in records: for record in records:
state=record['state'] or ''
vals={ vals={
'date': record['date'], 'date': record['date'],
'hn': record['hn'], 'hn': record['hn'],
'pid': record['pid'], 'pid': record['pid'],
'name': record['patient_name'], 'name': record['patient_name'],
'epo': record['mdc_amt'], 'epo': record['epo'],
'service': record['srv_amt'], 'srv': record['srv'],
'fee': record['fee_amt'], 'fee': record['fee'],
'invoice_id': record['invoice_id'], 'invoice_id': record['invoice_id'],
'state': state,
} }
lines.append(('create', vals)) lines.append(('create', vals))
elif obj.pcode=='UC': elif obj.pcode=='UC':
for record in records: for record in records:
state=record['state'] or ''
vals={ vals={
'date': record['date'], 'date': record['date'],
'hn': record['hn'], 'hn': record['hn'],
@ -379,6 +398,7 @@ class MatchingPayment(Model):
'name': record['name'], 'name': record['name'],
'fee': record['fee_amt'], 'fee': record['fee_amt'],
'invoice_id': record['invoice_id'], 'invoice_id': record['invoice_id'],
'state': state,
} }
lines.append(('create', vals)) lines.append(('create', vals))
for line in obj.lines: for line in obj.lines:
@ -588,15 +608,20 @@ class MatchingPayment(Model):
'flash': flash, 'flash': flash,
} }
def onchange_line(self,context={}): def onchange_invoice(self,context={}):
data=context['data'] data=context['data']
path=context['path'] path=context['path']
line=get_data_path(data,path,parent=True) line=get_data_path(data,path,parent=True)
if line.get("expense_id"): if line.get("invoice_id"):
line['state']='match' line['state']='match'
else: else:
print("else ") line['state']=''
line['state']=None
return data return data
def clear_line(self,ids,context={}):
obj=self.browse(ids)[0]
line_ids=[line.id for line in obj.lines]
get_model("clinic.matching.payment.line").delete(line_ids)
print("Cleared %s"%(line_ids))
MatchingPayment.register() MatchingPayment.register()

View File

@ -4,19 +4,25 @@ class MatchingPaymentLine(Model):
_name="clinic.matching.payment.line" _name="clinic.matching.payment.line"
_transient=True _transient=True
def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
res[obj.id]={
'amount': (obj.fee or 0)+(obj.epo or 0)+(obj.srv or 0),
}
return res
_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"),
'invoice_id': fields.Many2One("account.invoice","Invoice (Waiting Payment)"), 'invoice_id': fields.Many2One("account.invoice","Invoice (Waiting Payment)"),
#"date": fields.Date("Date"),
"date": fields.Char("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"),
'epo': fields.Float("EPO"), 'epo': fields.Float("EPO"),
'service': fields.Float("Service"), 'srv': fields.Float("Service"),
"fee": fields.Float("Fee"), "fee": fields.Float("Fee"),
'state': fields.Selection([['match','Match'],['not_math','Not Match']],'State'), 'amount': fields.Float("Amount",function="_get_all",function_multi=True),
'state': fields.Selection([['match','Match'],['unmatch','Not Match']],'State'),
} }