matchin payment for SSO

fix_acc
watcha.h 2015-08-24 16:45:12 +07:00
parent 429dcac788
commit e69cf8a48f
4 changed files with 203 additions and 37 deletions

View File

@ -10,9 +10,12 @@
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
</group>
<separator string="Document Mathing"/>
<field name="file_id" span="2"/>
<field name="view_type" span="2"/>
<field name="patient_type_id" onchange="onchange_ptype" span="2"/>
<field name="pcode" span="2"/>
<field name="hcode_id" span="2" attrs='{"required":[["pcode","=","SSO"]],"invisible":[["pcode","!=","SSO"]]}'/>
<button string="Copy Invoice To Payment" icon="arrow-right"/>
<group form_layout="stacked" attrs='{"invisible":[["view_type","=","invoice"]]}'>
<field name="file_id" span="2"/>
<field name="patient_type_id" onchange="onchange_ptype" span="2" attrs='{"required":[["view_type","=","matching"]]}'/>
<field name="pcode" span="2" attrs='{"required":[["view_type","=","matching"]]}'/>
<field name="hcode_id" span="2" attrs='{"required":[["pcode","=","SSO"]],"invisible":[["pcode","!=","SSO"]]}'/>
</group>
</form>

View File

@ -4,10 +4,22 @@ from netforce.model import Model, fields, get_model
class AccountInvoice(Model):
_inherit="account.invoice"
def _get_patient(self,ids,context={}):
res={}
for obj in self.browse(ids):
pt_id=None
if obj.patient_partner_id:
for pt in get_model('clinic.patient').search_browse([['partner_id','=',obj.patient_partner_id.id]]):
pt_id=pt.id
res[obj.id]=pt_id
return res
_fields={
'clinic_expense_id': fields.Many2One("clinic.hd.case.expense","Expense"),
'department_id': fields.Many2One("clinic.department","Department",search=True),
'patient_partner_id': fields.Many2One("partner","Patient",search=True),
'patient_partner_id': fields.Many2One("partner","Partner Patient",search=True),
'patient_id': fields.Many2One("clinic.patient","Patient",function="_get_patient", store=True,search=True),
}
def _get_number(self,context={}):
@ -280,4 +292,5 @@ class AccountInvoice(Model):
t1=time.time()
dt=(t1-t0)*1000
print("invoice.post <<< %d ms"%dt)
AccountInvoice.register()

View File

@ -22,7 +22,7 @@ class PaymentMatching(Model):
'department_id': fields.Many2One("clinic.department","Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"),
"inv_state": fields.Selection([("draft","Draft"),("waiting_approval","Waiting Approval"),("waiting_payment","Waiting Payment"),("paid","Paid"),("voided","Voided")],"Status"),
"view_type": fields.Selection([("invoice","Invoice"),("file","File")],"View Type"),
"view_type": fields.Selection([("invoice","Invoice"),("matching","Matching")],"View Type"),
'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"),
@ -129,27 +129,106 @@ class PaymentMatching(Model):
inv_state=obj.inv_state
view_type=obj.view_type
lines=[]
dom=[
['date','>=',date_from],
['date','<=',date_to],
['state','=',inv_state],
]
if branch_id and not department_id:
dom.append(['department_id.branch_id','=',branch_id])
elif department_id:
dom.append(['department_id','=',department_id])
if view_type=='invoice':
field_names=['date','number','amount_due']
invoices=[]
total_match_invoice=0
total_epo=0
total_srv=0
total_fee=0
total_amount=0
def get_invoices():
invoices=[]
dom=[
['date','>=',date_from],
['date','<=',date_to],
['state','=',inv_state],
]
if branch_id and not department_id:
dom.append(['department_id.branch_id','=',branch_id])
elif department_id:
dom.append(['department_id','=',department_id])
field_names=['date','number','amount_due','patient_id']
for inv in get_model('account.invoice').search_read(dom,field_names):
vals={}
vals={
'id': inv['id'],
'patient_id': None,
'patient_name': '',
'patient_hn': '',
}
for field_name in field_names:
vals[field_name]=inv[field_name],
lines.append(vals)
if field_name=='patient_id' and inv['patient_id']:
patient=get_model('clinic.patient').browse(inv['patient_id'][0])
vals['patient_id']=patient.id
vals['patient_name']=patient.name
vals['patient_nospace_name']=patient.name_check
vals['patient_cid']=patient.card_no
vals['patient_hn']=patient.hn
else:
vals[field_name]=inv[field_name]
vals[field_name]=inv[field_name]
invoices.append(vals)
return invoices
if view_type=='invoice':
lines=get_invoices()
else:
if obj:
invoices=get_invoices()
rlines=obj.get_line()
no=1
for rline in rlines:
date_treatment=rline.get("dttran")
date=date_treatment[0:10]
time=date_treatment[11:]
if not time:
continue
epo=rline.get('epoadm29') or 0
fee=rline.get('amount23') or 0
srv=rline.get('allow37') or 0
name=rline.get("name14")
name_nospace=name.replace(" ","")
pid=rline.get('pid')
hn=rline.get('hn')
hn=''.join([x for x in hn if x.isdigit()])
total_fee+=fee
total_epo+=epo
total_srv+=srv
amount=fee+epo+srv
total_amount+=amount
line_vals={
'no': no,
'date':date,
'patient_name': name,
'pid': pid,
'hn': hn,
'fee': fee,
'srv': srv,
'epo': epo,
'amount': amount,
}
for item_amt in ['fee','srv','epo']:
for inv in invoices:
if inv['patient_id']:
# check card no first then HN finally patient name
if pid==inv['patient_cid'] or hn==inv['patient_hn'] or name_nospace==inv['patient_nospace_name']:
inv_amt=inv['amount_due']
inv_date=inv['date']
if inv_date==date and inv_amt==line_vals[item_amt]:
line_vals['inv_%s'%(item_amt)]=inv['number']
line_vals['inv_%s_id'%(item_amt)]=inv['id']
total_match_invoice+=1
break
lines.append(line_vals)
no+=1
data={
'lines': lines,
'date_from': date_from,
'date_to': date_to,
'total_inv': len(lines),
'total_qty': len(lines),
'total_fee': total_fee,
'total_epo': total_epo,
'total_srv': total_srv,
'total_match_invoice': total_match_invoice,
'total_invoice': len(invoices),
'total_amount': total_amount,
'view_type': view_type,
}
return data

View File

@ -1,21 +1,20 @@
<!--
<center>
<h3>Payment Matching</h3>
<h4>From {{date_from}} To {{date_to}}</h4>
</center>
-->
<div class="row">
<div class="col-sm-6">
</div>
<div class="col-sm-6">
<h4>
<span class="pull-right label label-default">TOTAL: {{currency total_inv}}</span>
</h4>
</div>
<div class="row" style="margin-top:10px;">
<table class="table table-bordered">
<thead>
<th style="text-align:center">Total Invoice</th>
<th style="text-align:center">Match</th>
</thead>
<tbody>
<tr>
<td style="text-align:center">{{currency total_invoice}}</td>
<td style="text-align:center">{{currency total_match_invoice}}</td>
</tr>
</tbody>
</table>
</div>
<table class="table table-hover">
{{#ifeq view_type 'invoice'}}
<thead>
<thead class="scroll-header">
<th>Invoice Date</th>
<th>Number</th>
</thead>
@ -33,6 +32,78 @@
<tfoot>
</tfoot>
{{else}}
TODO
<thead class="scroll-header">
<th>No.</th>
<th>Date</th>
<th>PID</th>
<th>HN</th>
<th>Patient</th>
<th style="text-align:right">Fee</th>
<th>Inv Fee</th>
<th style="text-align:right">EPO</th>
<th>Inv EPO</th>
<th style="text-align:right">Service</th>
<th>Inv Service</th>
<th style="text-align:right">Amount</th>
</thead>
<tbody>
{{#if lines}}
{{#each lines}}
<tr>
<td>{{no}}</td>
<td style="width:8%">{{date}}</td>
<td>{{pid}}</td>
<td>{{hn}}</td>
<td>{{patient_name}}</td>
<td style="text-align:right">{{currency fee}}</td>
<td>
<a style="text-decoration:None" href="ui#form_view_xml=cust_invoice_form&active_id={{inv_fee_id}}&name=cust_invoice&mode=form" target="_blank">
{{#if inv_fee_id}}
<span class="label label-info">
{{inv_fee}}
</span>
{{/if}}
</a>
</td>
<td style="text-align:right">{{currency epo}}</td>
<td>
<a style="text-decoration:None" href="ui#form_view_xml=cust_invoice_form&active_id={{inv_epo_id}}&name=cust_invoice&mode=form" target="_blank">
{{#if inv_epo_id}}
<span class="label label-info">
{{inv_epo}}
</span>
{{/if}}
</a>
</td>
<td style="text-align:right">{{currency srv}}</td>
<td>
<a href="ui#form_view_xml=cust_invoice_form&active_id={{inv_srv_id}}&name=cust_invoice&mode=form" target="_blank">
{{#if inv_srv_id}}
<span class="label label-info">
{{inv_srv}}
</span>
{{/if}}
</a>
</td>
<td style="text-align:right">{{currency amount}}</td>
</tr>
{{/each}}
{{else}}
{{/if}}
</tbody>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th style="text-align:right;">{{currency total_fee}}</th>
<th></th>
<th style="text-align:right;">{{currency total_epo}}</th>
<th></th>
<th style="text-align:right">{{currency total_srv}}</th>
<th></th>
<th style="text-align:right">{{currency total_amount}}</th>
<tfoot>
</tfoot>
{{/ifeq}}
</table>