matching payment
parent
73d6529f0c
commit
331121f367
|
@ -1,10 +1,12 @@
|
|||
<action>
|
||||
<field name="string">Payment Matching</field>
|
||||
<!--<field name="view_cls">report</field> -->
|
||||
<field name="view_cls">form_view</field>
|
||||
<field name="view_xml">clinic_matching_payment</field>
|
||||
<field name="view_cls">multi_view</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="tabs">[
|
||||
["All",[]],
|
||||
["Draft",[["state","=","draft"]]],
|
||||
["Approved",[["state","=","approved"]]]
|
||||
]</field>
|
||||
<field name="limit">10</field>
|
||||
</action>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<!--<item string="Labor Cost Entries" action="clinic_labor_cost_entry"/>-->
|
||||
<item string="Payments Matching" action="clinic_matching_payment"/>
|
||||
<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/>
|
||||
<header string="REPORTS"/>
|
||||
<item string="Labor Cost Summary" action="clinic_report_labor_cost_summary"/>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<list model="clinic.dialyzer">
|
||||
<list model="clinic.dialyzer" colors='{"#cfc":[["state","=","active"]],"#dbdbdb":[["state","=","drop"]]}'>
|
||||
<top replace="1"></top>
|
||||
<field name="date"/>
|
||||
<field name="number"/>
|
||||
|
|
|
@ -1,31 +1,42 @@
|
|||
<form model="clinic.matching.payment" title="Payment Matching">
|
||||
<form model="clinic.matching.payment" attrs='{"readonly":[["state","=","approved"]]}'>
|
||||
<head>
|
||||
<button string="Print" action="print" icon="print"/>
|
||||
<button string="Options" dropdown="1">
|
||||
<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>
|
||||
</head>
|
||||
<field name="date" onchange="onchange_date" mode="month" span="3"/>
|
||||
<field name="date_from" span="3"/>
|
||||
<field name="date_to" span="3"/>
|
||||
<field name="file" span="3"/>
|
||||
<field name="name" string="Description" span="3"/>
|
||||
<newline/>
|
||||
<field name="patient_type_id" onchange="onchange_ptype" span="3"/>
|
||||
<field name="pcode" span="3"/>
|
||||
<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">
|
||||
<list>
|
||||
<field name="date"/>
|
||||
<field name="hn"/>
|
||||
<field name="pid"/>
|
||||
<field name="name"/>
|
||||
<field name="epo"/>
|
||||
<field name="service"/>
|
||||
<field name="fee"/>
|
||||
<field name="invoice_id" domain='[["date","=",date],["state","=","waiting_payment"]]'/>
|
||||
<field name="epo" sum="1"/>
|
||||
<field name="srv" sum="1"/>
|
||||
<field name="fee" sum="1"/>
|
||||
<field name="amount" sum="1"/>
|
||||
<field name="invoice_id" onchange="onchange_invoice" domain='[["date","=",date],["state","=","waiting_payment"]]'/>
|
||||
<field name="state"/>
|
||||
</list>
|
||||
</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">
|
||||
<button string="Match" method="do_match" type="success" icon='ok'/>
|
||||
</foot>
|
|
@ -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>
|
|
@ -38,6 +38,7 @@ class HDCasePopupDlz(Model):
|
|||
def onchange_product(self,context={}):
|
||||
data=context['data']
|
||||
product_id=data['product_id']
|
||||
data['membrane_type']=None
|
||||
for dlz in get_model("clinic.dialyzer").search_browse([]):
|
||||
prod=dlz.product_id
|
||||
if prod.id==product_id:
|
||||
|
|
|
@ -12,7 +12,24 @@ class MatchingPayment(Model):
|
|||
_name="clinic.matching.payment"
|
||||
_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={
|
||||
'name': fields.Char("Name"),
|
||||
"date": fields.Date("Month"),
|
||||
"date_from": fields.Date("From", 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),
|
||||
'pcode': fields.Char("Code",required=True),
|
||||
'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"),
|
||||
'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={}):
|
||||
|
@ -47,13 +66,19 @@ class MatchingPayment(Model):
|
|||
weekday, total_day=monthrange(int(year), int(month))
|
||||
return "%s-%s-%s"%(year,month,total_day)
|
||||
|
||||
def _get_name(self,ids,context={}):
|
||||
return time.strftime("%Y/%m")
|
||||
|
||||
_defaults={
|
||||
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
||||
'name': _get_name,
|
||||
'date_from': _get_date_from,
|
||||
'date_to': _get_date_to,
|
||||
'patient_type_id': _get_ptype,
|
||||
'pcode': _get_pcode,
|
||||
'state': 'draft',
|
||||
}
|
||||
_order="date desc"
|
||||
|
||||
def get_line(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
|
@ -89,6 +114,7 @@ class MatchingPayment(Model):
|
|||
def match(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
lines=obj.get_line()
|
||||
print("len.lines ", len(lines))
|
||||
patient_type=obj.patient_type_id
|
||||
if not patient_type:
|
||||
raise Exception("not found patient type")
|
||||
|
@ -98,52 +124,72 @@ class MatchingPayment(Model):
|
|||
matches1={}
|
||||
matches2={}
|
||||
matches3={}
|
||||
matches_uc={}
|
||||
dom=[]
|
||||
dom.append(['date',">=",obj.date_from])
|
||||
dom.append(['date',"<=",obj.date_to])
|
||||
dom.append(['partner_id',"=",contact.id])
|
||||
dom.append(['state','=', 'waiting_payment'])
|
||||
for inv in get_model('account.invoice').search_browse(dom):
|
||||
pname=inv.ref or ''
|
||||
pname=pname.replace(" ","")
|
||||
##XXX ธงชัย วิศาลโภคะ (1045-12-1-53)
|
||||
#pname_alpha=''.join([pn for pn in pname if pn.isalpha()])
|
||||
#hn=''.join([str(pn) for pn in pname if pn.isdigit()])
|
||||
#print(hn, pname_alpha)
|
||||
hn=""
|
||||
invoices=get_model('account.invoice').search_browse(dom)
|
||||
print("len(invoices)", len(invoices))
|
||||
for invoice in invoices:
|
||||
pname,hn,card_no='', '', ''
|
||||
if invoice.related_id:
|
||||
hdcase=invoice.related_id
|
||||
patient=hdcase.patient_id
|
||||
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={
|
||||
'invoice_id': inv.id,
|
||||
'invoice_id': invoice.id,
|
||||
'fee': fee,
|
||||
'epo': epo,
|
||||
'srv': srv,
|
||||
}
|
||||
date=inv.date
|
||||
key1='%s:%s'%(
|
||||
pname,
|
||||
date,
|
||||
)
|
||||
due_amount+=fee+epo+srv
|
||||
date=invoice.date
|
||||
req_vals=[date,due_amount]
|
||||
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):
|
||||
matches1[key1]=vals
|
||||
for pt in get_model("clinic.patient").search_browse([['name_check','=',pname]]):
|
||||
hn=pt.hn_no or hn or ''
|
||||
key2='%s:%s'%(
|
||||
hn,
|
||||
date,
|
||||
)
|
||||
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
|
||||
|
||||
if not matches2.get(key2):
|
||||
matches2[key2]=vals
|
||||
if not matches3.get(key3):
|
||||
matches3[key3]=vals
|
||||
if not matches_uc.get(key_uc):
|
||||
matches_uc[key_uc]=vals
|
||||
nf_hcode=''
|
||||
if obj.hcode_id:
|
||||
nf_hcode=obj.hcode_id.code
|
||||
records=[]
|
||||
if obj.pcode=='SSO':
|
||||
no=1
|
||||
for line in lines:
|
||||
hcode=line.get('hcode18')
|
||||
if not hcode:
|
||||
|
@ -151,79 +197,60 @@ class MatchingPayment(Model):
|
|||
hcode=int(hcode)
|
||||
hcode=str(hcode)
|
||||
if nf_hcode==hcode:
|
||||
lsrv_amt=line.get('epoadm29') or 0
|
||||
lfee_amt=line.get('amount23') or 0
|
||||
lmdc_amt=line.get('allow37') or 0
|
||||
dttran=line.get("dttran")
|
||||
epo=line.get('epoadm29') or 0
|
||||
fee=line.get('amount23') or 0
|
||||
srv=line.get('allow37') or 0
|
||||
date_treatment=line.get("dttran")
|
||||
name=line.get("name14")
|
||||
name2=name
|
||||
name=name.replace(" ","")
|
||||
pid=int(line.get('pid'))
|
||||
date=dttran[0:10]
|
||||
time=dttran[11:] #XXX
|
||||
name_nospace=name.replace(" ","")
|
||||
card_no=int(line.get('pid'))
|
||||
date=date_treatment[0:10]
|
||||
time=date_treatment[11:] #XXX
|
||||
if not time:
|
||||
print("wrong format")
|
||||
continue
|
||||
due_amount=fee+epo+srv
|
||||
req_vals=[date,due_amount]
|
||||
hn=line.get('hn')
|
||||
hn=''.join([x for x in hn if x.isdigit()])
|
||||
#if hn=='10288153':
|
||||
#import pdb; pdb.set_trace()
|
||||
#1. name, 2. hn, 3. id_card
|
||||
key1='%s:%s'%(
|
||||
name,
|
||||
date,
|
||||
)
|
||||
key2='%s:%s'%(
|
||||
hn,
|
||||
date,
|
||||
)
|
||||
key3='%s:%s'%(
|
||||
pid,
|
||||
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 [name_nospace]+req_vals])
|
||||
record={
|
||||
'date':date,
|
||||
'patient_name': name2,
|
||||
'pid': pid,
|
||||
'patient_name': name,
|
||||
'pid': card_no,
|
||||
'hn': hn,
|
||||
'fee_amt': lfee_amt,
|
||||
'srv_amt': lsrv_amt,
|
||||
'mdc_amt': lmdc_amt,
|
||||
'fee': fee,
|
||||
'srv': srv,
|
||||
'epo': epo,
|
||||
'invoice_id': None,
|
||||
'state': 'unmatch',
|
||||
}
|
||||
#import pdb; pdb.set_trace()
|
||||
print(key1, ' - ' , key2, ' - ', key3)
|
||||
if not matches1.get(key1):
|
||||
if not matches2.get(key2):
|
||||
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.")
|
||||
#if hn=='100794':
|
||||
#import pdb; pdb.set_trace()
|
||||
if matches1.get(key1):
|
||||
print("found ", key1)
|
||||
record.update({
|
||||
'invoice_id': found['invoice_id'],
|
||||
'invoice_id': matches1[key1]['invoice_id'],
|
||||
'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)
|
||||
no+=1
|
||||
elif obj.pcode=='UC':
|
||||
records=[]
|
||||
for line in lines:
|
||||
|
@ -242,55 +269,43 @@ class MatchingPayment(Model):
|
|||
#'rid': '2190',
|
||||
#'station': '01'}
|
||||
date,time=(line['dttran'] or "").split("T")
|
||||
amt=line['amount'] or "0"
|
||||
amt=float(amt)
|
||||
fee=0
|
||||
if line.get('amount'):
|
||||
fee=float(line['amount'])
|
||||
hn=line['hn']
|
||||
hn=hn.replace(" ", "")
|
||||
key_uc=''
|
||||
if date and time:
|
||||
key2='%s:%s'%(
|
||||
line['hn'],
|
||||
date,
|
||||
#amt,
|
||||
)
|
||||
name=''
|
||||
key_uc='%s:%s:%s'%(line['hn'],date,fee,)
|
||||
pname=''
|
||||
pid=''
|
||||
key1=''
|
||||
key3=''
|
||||
for pt in get_model("clinic.patient").search_browse([['hn_no','=',hn]]):
|
||||
name=pt.name_check or ""
|
||||
key1='%s:%s'%(name,date)
|
||||
pid=pt.card_no or ''
|
||||
key3='%s:%s'%(pid,date)
|
||||
name1=pt.name or ""
|
||||
pname=pt.name or ""
|
||||
pid=pt.card_no or ""
|
||||
record={
|
||||
'date':date,
|
||||
'name': name1,
|
||||
'name': pname,
|
||||
'pid': pid,
|
||||
'hn': hn,
|
||||
'fee_amt': amt,
|
||||
'srv_amt': 0,
|
||||
'mdc_amt': 0,
|
||||
'fee': fee,
|
||||
'srv': 0,
|
||||
'epo': 0,
|
||||
'invoice_id': None,
|
||||
'state': 'unmatch',
|
||||
}
|
||||
if matches1.get(key1):
|
||||
vals=matches1[key1]
|
||||
if matches_uc.get(key_uc):
|
||||
record.update({
|
||||
'invoice_id':vals['invoice_id'],
|
||||
})
|
||||
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'],
|
||||
'invoice_id': matches1[key_uc]['invoice_id'],
|
||||
'state': 'match',
|
||||
})
|
||||
else:
|
||||
pass
|
||||
#print("not found")
|
||||
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
|
||||
|
||||
def onchange_date(self,context={}):
|
||||
|
@ -300,6 +315,7 @@ class MatchingPayment(Model):
|
|||
weekday, total_day=monthrange(int(year), int(month))
|
||||
data['date_from']="%s-%s-01"%(year,month)
|
||||
data['date_to']="%s-%s-%s"%(year,month,total_day)
|
||||
data['name']='%s/%s'%(year,month)
|
||||
return data
|
||||
|
||||
def onchange_ptype(self,context={}):
|
||||
|
@ -359,19 +375,22 @@ class MatchingPayment(Model):
|
|||
lines=[]
|
||||
if obj.pcode=='SSO':
|
||||
for record in records:
|
||||
state=record['state'] or ''
|
||||
vals={
|
||||
'date': record['date'],
|
||||
'hn': record['hn'],
|
||||
'pid': record['pid'],
|
||||
'name': record['patient_name'],
|
||||
'epo': record['mdc_amt'],
|
||||
'service': record['srv_amt'],
|
||||
'fee': record['fee_amt'],
|
||||
'epo': record['epo'],
|
||||
'srv': record['srv'],
|
||||
'fee': record['fee'],
|
||||
'invoice_id': record['invoice_id'],
|
||||
'state': state,
|
||||
}
|
||||
lines.append(('create', vals))
|
||||
elif obj.pcode=='UC':
|
||||
for record in records:
|
||||
state=record['state'] or ''
|
||||
vals={
|
||||
'date': record['date'],
|
||||
'hn': record['hn'],
|
||||
|
@ -379,6 +398,7 @@ class MatchingPayment(Model):
|
|||
'name': record['name'],
|
||||
'fee': record['fee_amt'],
|
||||
'invoice_id': record['invoice_id'],
|
||||
'state': state,
|
||||
}
|
||||
lines.append(('create', vals))
|
||||
for line in obj.lines:
|
||||
|
@ -588,15 +608,20 @@ class MatchingPayment(Model):
|
|||
'flash': flash,
|
||||
}
|
||||
|
||||
def onchange_line(self,context={}):
|
||||
def onchange_invoice(self,context={}):
|
||||
data=context['data']
|
||||
path=context['path']
|
||||
line=get_data_path(data,path,parent=True)
|
||||
if line.get("expense_id"):
|
||||
if line.get("invoice_id"):
|
||||
line['state']='match'
|
||||
else:
|
||||
print("else ")
|
||||
line['state']=None
|
||||
line['state']=''
|
||||
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()
|
||||
|
|
|
@ -4,19 +4,25 @@ class MatchingPaymentLine(Model):
|
|||
_name="clinic.matching.payment.line"
|
||||
_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={
|
||||
'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)"),
|
||||
#"date": fields.Date("Date"),
|
||||
"date": fields.Char("Date"),
|
||||
"hn": fields.Char("HN"),
|
||||
'pid': fields.Char("PID"),
|
||||
"name": fields.Char("Name"),
|
||||
'epo': fields.Float("EPO"),
|
||||
'service': fields.Float("Service"),
|
||||
'srv': fields.Float("Service"),
|
||||
"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'),
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue