fix import payment
parent
4ac1060064
commit
82aa96abb9
|
@ -4,7 +4,6 @@
|
|||
<field name="cycle_id"/>
|
||||
<field name="patient_id"/>
|
||||
<field name="patient_type_id"/>
|
||||
<field name="sickbed_id"/>
|
||||
<field name="department_id"/>
|
||||
<field name="doctor_id"/>
|
||||
<field name="state"/>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<head>
|
||||
<button string="Options" dropdown="1">
|
||||
<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>
|
||||
</head>
|
||||
<field name="date" onchange="onchange_date" mode="month" span="3"/>
|
||||
|
@ -22,12 +22,11 @@
|
|||
<field name="epo"/>
|
||||
<field name="service"/>
|
||||
<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"/>
|
||||
</list>
|
||||
</field>
|
||||
<foot replace="1">
|
||||
<button string="Match" method="do_match" type="success" icon='ok'/>
|
||||
<!--<button string="Import Payment" method="do_import" type="default" icon='arrow-right'/>-->
|
||||
</foot>
|
||||
</form>
|
||||
|
|
|
@ -122,11 +122,15 @@ class MatchingHDCase(Model):
|
|||
categ=prod.categ_id
|
||||
if categ and line.reimbursable=='yes':
|
||||
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':
|
||||
fee_amt=line.amount or 0
|
||||
prod_name=','.join(prod_line)
|
||||
key1='%s-%s-%s-%s-%s'%(date,hn,hct,prod_name,fee_amt)
|
||||
prod_name='-'.join(prod_line)
|
||||
key1='%s-%s-%s-%s'%(date,hn,prod_name,fee_amt)
|
||||
hdcases[key1]={
|
||||
'id': hdcase.id,
|
||||
'number': hdcase.number or '',
|
||||
|
@ -164,8 +168,9 @@ class MatchingHDCase(Model):
|
|||
prod_name=vals[10] or ''
|
||||
prod_name=prod_name.replace(" ", "")
|
||||
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)
|
||||
unit_amt=float(vals[11])
|
||||
line_vals={
|
||||
'hn': hn,
|
||||
'date': date,
|
||||
|
@ -173,7 +178,7 @@ class MatchingHDCase(Model):
|
|||
'patient_id': pt_id,
|
||||
'patient_type': pt_type,
|
||||
'hct': hct,
|
||||
'prod_name': prod_name,
|
||||
'prod_name': (prod_name or "").title(),
|
||||
'prod_id': prod_id,
|
||||
'fee_amt': fee_amt,
|
||||
'note': '',
|
||||
|
@ -182,25 +187,30 @@ class MatchingHDCase(Model):
|
|||
'nf_hct': '',
|
||||
'nf_epo': '',
|
||||
'nf_fee': '',
|
||||
'unit_amt': unit_amt,
|
||||
}
|
||||
if hdcase:
|
||||
line_vals['is_match']=True
|
||||
line_vals['hd_case_id']=hdcase['id']
|
||||
line_vals['hd_case_number']=hdcase['number']
|
||||
else:
|
||||
key2='%s-%s'%(date,hn)
|
||||
hdcase2=hdcases2.get(key2)
|
||||
if hdcase2:
|
||||
line_vals['is_match']=False
|
||||
line_vals['hd_case_id']=hdcase2['id']
|
||||
line_vals['hd_case_number']=hdcase2['number']
|
||||
line_vals['note']=''
|
||||
nf_date,nf_hn,nf_hct,nf_epo,nf_fee=hdcase2['note'].split(",")
|
||||
line_vals['nf_date']=nf_date
|
||||
line_vals['nf_hn']=nf_hn
|
||||
line_vals['nf_hct']=nf_hct
|
||||
line_vals['nf_epo']=nf_epo
|
||||
line_vals['nf_fee']=round(float((nf_fee or "0")),2)
|
||||
line_vals['is_match']=False
|
||||
|
||||
key2='%s-%s'%(date,hn)
|
||||
hdcase2=hdcases2.get(key2)
|
||||
#print("hdcase2 ", hdcase2)
|
||||
if hdcase2:
|
||||
#line_vals['is_match']=False
|
||||
line_vals['hd_case_id']=hdcase2['id']
|
||||
line_vals['hd_case_number']=hdcase2['number']
|
||||
line_vals['note']=''
|
||||
nf_date,nf_hn,nf_hct,nf_epo,nf_fee=hdcase2['note'].split(",")
|
||||
line_vals['nf_date']=nf_date
|
||||
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)
|
||||
no=1
|
||||
lines2=[]
|
||||
|
|
|
@ -64,7 +64,11 @@ class MatchingPayment(Model):
|
|||
hcode=obj.hcode_id.code or ""
|
||||
if not 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'):
|
||||
raise Exception("File should be xls or xlsx")
|
||||
fpath=get_file_path(fname)
|
||||
|
@ -85,72 +89,50 @@ class MatchingPayment(Model):
|
|||
def match(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
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={}
|
||||
matches2={}
|
||||
matches3={}
|
||||
matches4={}
|
||||
matches_uc={}
|
||||
dom=[]
|
||||
dom.append(['date',">=",obj.date_from])
|
||||
dom.append(['date',"<=",obj.date_to])
|
||||
dom.append(['patient_id.type_id',"=",obj.patient_type_id.id])
|
||||
dom.append(['state','!=', 'completed'])
|
||||
for exp in get_model('clinic.hd.case.expense').search_browse(dom):
|
||||
patient=exp.patient_id
|
||||
hn=patient.hn_no
|
||||
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)
|
||||
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(" ","")
|
||||
vals={
|
||||
'pid': pid,
|
||||
'name': name,
|
||||
'date': date,
|
||||
'fee_amt': lfee_amt,
|
||||
'service_amt': lsrv_amt,
|
||||
'epo_amt': lmdc_amt,
|
||||
'hn': hn,
|
||||
'expense_id': exp.id,
|
||||
'invoice_id': inv.id,
|
||||
}
|
||||
date=inv.date
|
||||
key1='%s:%s'%(
|
||||
pname,
|
||||
date,
|
||||
)
|
||||
if not matches1.get(key1):
|
||||
matches1[key1]=vals
|
||||
if not matches2.get(key2):
|
||||
matches2[key2]=vals
|
||||
if not matches3.get(key3):
|
||||
matches3[key3]=vals
|
||||
if not matches4.get(key3):
|
||||
matches4[key4]=vals
|
||||
if not matches_uc.get(key_uc):
|
||||
matches4[key_uc]=vals
|
||||
for pt in get_model("clinic.patient").search_browse([['name_check','=',pname]]):
|
||||
hn=pt.hn_no 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
|
||||
|
||||
nf_hcode=''
|
||||
if obj.hcode_id:
|
||||
nf_hcode=obj.hcode_id.code
|
||||
|
@ -171,7 +153,7 @@ class MatchingPayment(Model):
|
|||
name=line.get("name14")
|
||||
name2=name
|
||||
name=name.replace(" ","")
|
||||
pid=line.get('pid')
|
||||
pid=int(line.get('pid'))
|
||||
date=dttran[0:10]
|
||||
time=dttran[11:] #XXX
|
||||
if not time:
|
||||
|
@ -179,38 +161,23 @@ class MatchingPayment(Model):
|
|||
continue
|
||||
hn=line.get('hn')
|
||||
hn=''.join([x for x in hn if x.isdigit()])
|
||||
key1='%s:%s:%s:%s:%s'%(
|
||||
hn,
|
||||
date,
|
||||
lfee_amt,
|
||||
lsrv_amt,
|
||||
lmdc_amt,
|
||||
)
|
||||
key2='%s:%s:%s:%s:%s'%(
|
||||
pid,
|
||||
date,
|
||||
lfee_amt,
|
||||
lsrv_amt,
|
||||
lmdc_amt,
|
||||
)
|
||||
key3='%s:%s:%s:%s:%s'%(
|
||||
|
||||
#if hn=='10288153':
|
||||
#import pdb; pdb.set_trace()
|
||||
#1. name, 2. hn, 3. id_card
|
||||
key1='%s:%s'%(
|
||||
name,
|
||||
date,
|
||||
lfee_amt,
|
||||
lsrv_amt,
|
||||
lmdc_amt,
|
||||
)
|
||||
key4='%s:%s'%(name,date)
|
||||
#vals={
|
||||
#'pid': pid,
|
||||
#'name': name,
|
||||
#'date': date,
|
||||
#'fee_amt': lfee_amt,
|
||||
#'service_amt': lsrv_amt,
|
||||
#'epo_amt': lmdc_amt,
|
||||
#}
|
||||
key2='%s:%s'%(
|
||||
hn,
|
||||
date,
|
||||
)
|
||||
key3='%s:%s'%(
|
||||
pid,
|
||||
date,
|
||||
)
|
||||
record={
|
||||
'no': no,
|
||||
'date':date,
|
||||
'patient_name': name2,
|
||||
'pid': pid,
|
||||
|
@ -218,58 +185,37 @@ class MatchingPayment(Model):
|
|||
'fee_amt': lfee_amt,
|
||||
'srv_amt': lsrv_amt,
|
||||
'mdc_amt': lmdc_amt,
|
||||
'note': '',
|
||||
'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,
|
||||
'invoice_id': None,
|
||||
}
|
||||
#import pdb; pdb.set_trace()
|
||||
print(key1, ' - ' , key2, ' - ', key3)
|
||||
if not matches1.get(key1):
|
||||
if not matches2.get(key2):
|
||||
if not matches4.get(key3):
|
||||
notes=matches4.get(key4)
|
||||
if notes:
|
||||
if not matches3.get(key3):
|
||||
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:
|
||||
print("found 3.")
|
||||
# found 3.
|
||||
found=matches3[key3]
|
||||
record.update({
|
||||
'expense_id': found['expense_id'],
|
||||
'invoice_id': found['invoice_id'],
|
||||
'state': 'match',
|
||||
})
|
||||
else:
|
||||
# found 2.
|
||||
print("found 2.")
|
||||
found=matches2[key2]
|
||||
record.update({
|
||||
'expense_id': found['expense_id'],
|
||||
'invoice_id': found['invoice_id'],
|
||||
'state': 'match',
|
||||
})
|
||||
else:
|
||||
# found 1.
|
||||
found=matches1[key1]
|
||||
print("found 1.")
|
||||
record.update({
|
||||
'expense_id': found['expense_id'],
|
||||
'expense_number': found['expense_number'],
|
||||
'found': True,
|
||||
'invoice_id': found['invoice_id'],
|
||||
'state': 'match',
|
||||
})
|
||||
records.append(record)
|
||||
no+=1
|
||||
|
@ -296,10 +242,10 @@ class MatchingPayment(Model):
|
|||
hn=line['hn']
|
||||
hn=hn.replace(" ", "")
|
||||
if date and time:
|
||||
key1='%s:%s:%s'%(
|
||||
key2='%s:%s:%s'%(
|
||||
line['hn'],
|
||||
date,
|
||||
amt,
|
||||
#amt,
|
||||
)
|
||||
name=''
|
||||
pid=''
|
||||
|
@ -308,32 +254,20 @@ class MatchingPayment(Model):
|
|||
pid=pt.card_no or ''
|
||||
record={
|
||||
'date':date,
|
||||
'name': name,
|
||||
'patient_name': name2,
|
||||
'pid': pid,
|
||||
'hn': hn,
|
||||
'fee_amt': amt,
|
||||
'srv_amt': 0,
|
||||
'mdc_amt': 0,
|
||||
'note': '',
|
||||
'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,
|
||||
'fee_amt': lfee_amt,
|
||||
'srv_amt': lsrv_amt,
|
||||
'mdc_amt': lmdc_amt,
|
||||
'invoice_id': None,
|
||||
}
|
||||
if matches_uc.get(key1):
|
||||
vals=matches_uc[key1]
|
||||
if matches2.get(key2):
|
||||
vals=matches2[key2]
|
||||
record.update({
|
||||
'found': True,
|
||||
'expense_id':vals['expense_id'],
|
||||
'fee_amt': vals['fee'] or 0,
|
||||
'invoice_id':vals['invoice_id'],
|
||||
})
|
||||
records.append(record)
|
||||
|
||||
return records
|
||||
|
||||
def onchange_date(self,context={}):
|
||||
|
@ -372,32 +306,18 @@ class MatchingPayment(Model):
|
|||
}
|
||||
|
||||
for line in obj.lines:
|
||||
exp=line.expense_id
|
||||
if exp:
|
||||
exp.write({
|
||||
'state': 'match',
|
||||
})
|
||||
line.delete()
|
||||
dom=[]
|
||||
dom.append(['state','=','match'])
|
||||
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
|
||||
inv=line.invoice_id
|
||||
if inv:
|
||||
vals['invoice_lines'].append(('create',{
|
||||
'invoice_id': inv.id,
|
||||
'amount': inv.amount_due or 0,
|
||||
}))
|
||||
if inv.related_id:
|
||||
hdcase=inv.related_id
|
||||
if hdcase:
|
||||
hdcase.write({
|
||||
'state': 'paid',
|
||||
})
|
||||
|
||||
if not vals['invoice_lines']:
|
||||
raise Exception("Nothing to import")
|
||||
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
|
||||
|
@ -424,7 +344,7 @@ class MatchingPayment(Model):
|
|||
'epo': record['mdc_amt'],
|
||||
'service': record['srv_amt'],
|
||||
'fee': record['fee_amt'],
|
||||
'expense_id': record['expense_id'],
|
||||
'invoice_id': record['invoice_id'],
|
||||
}
|
||||
lines.append(('create', vals))
|
||||
elif obj.pcode=='UC':
|
||||
|
@ -435,7 +355,7 @@ class MatchingPayment(Model):
|
|||
'pid': record['pid'],
|
||||
'name': record['name'],
|
||||
'fee': record['fee_amt'],
|
||||
'expense_id': record['expense_id'],
|
||||
'invoice_id': record['invoice_id'],
|
||||
}
|
||||
lines.append(('create', vals))
|
||||
for line in obj.lines:
|
||||
|
@ -656,5 +576,4 @@ class MatchingPayment(Model):
|
|||
line['state']=None
|
||||
return data
|
||||
|
||||
|
||||
MatchingPayment.register()
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from netforce.model import Model, fields, get_model
|
||||
|
||||
|
||||
class MatchingPaymentLine(Model):
|
||||
_name="clinic.matching.payment.line"
|
||||
_transient=True
|
||||
|
@ -8,7 +7,9 @@ class MatchingPaymentLine(Model):
|
|||
_fields={
|
||||
'match_id': fields.Many2One("clinic.matching.payment","Match",required=True,on_delete="cascade"),
|
||||
'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"),
|
||||
'pid': fields.Char("PID"),
|
||||
"name": fields.Char("Name"),
|
||||
|
|
|
@ -62,12 +62,13 @@ class ReportLaborCostSummary(Model):
|
|||
date_from=obj.date_from
|
||||
date_to=obj.date_to
|
||||
staff_id=obj.staff_id.id
|
||||
staff_type=obj.type
|
||||
staff_type=obj.staff_type
|
||||
level_id=obj.level_id.id
|
||||
categ_id=obj.categ_id.id
|
||||
only_value=obj.only_value
|
||||
dom.append(['date','>=',date_from])
|
||||
dom.append(['date','<=',date_to])
|
||||
print("staff_type ", staff_type)
|
||||
if staff_id:
|
||||
dom.append(['staff_id','=',staff_id])
|
||||
if staff_type:
|
||||
|
@ -86,17 +87,23 @@ class ReportLaborCostSummary(Model):
|
|||
categ_name=''
|
||||
categ_id=None
|
||||
categ=staff.categ_id
|
||||
level_name=''
|
||||
#XXX fix
|
||||
if not staff:
|
||||
continue
|
||||
if level_id and staff.level_id.id!=level_id:
|
||||
continue
|
||||
if categ:
|
||||
categ_id=categ.id
|
||||
categ_name=categ.name or ""
|
||||
if staff.level_id:
|
||||
level_name=staff.level_id.name or ""
|
||||
if not staffs.get(staff.name):
|
||||
staffs[staff.name]={
|
||||
'number': staff.number or '',
|
||||
'staff_id': staff.id,
|
||||
'staff_type': staff.type,
|
||||
'staff_level': staff.level_id.name,
|
||||
'staff_level': level_name,
|
||||
'categ_name': categ_name,
|
||||
'categ_id': categ_id,
|
||||
dpt.name: {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<table class="table table-condensed table-striped">
|
||||
<thead>
|
||||
<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>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -16,6 +16,7 @@
|
|||
<th>Type</th>
|
||||
<th>HCT</th>
|
||||
<th>EPO</th>
|
||||
<th>Unit</th>
|
||||
<th>Fee</th>
|
||||
<th>Match</th>
|
||||
<th>Date</th>
|
||||
|
@ -44,6 +45,7 @@
|
|||
{{else}}
|
||||
<td>{{prod_name}}</td>
|
||||
{{/if}}
|
||||
<td>{{unit_amt}}</td>
|
||||
<td>{{currency fee_amt zero=""}}</td>
|
||||
{{#if is_match}}
|
||||
<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>
|
||||
</td>
|
||||
{{/if}}
|
||||
<td>{{nf_date}}</td>
|
||||
<td style="width:10%;">{{nf_date}}</td>
|
||||
<td>{{nf_hn}}</td>
|
||||
<td>{{nf_hct}}</td>
|
||||
<td>{{nf_epo}}</td>
|
||||
|
|
Loading…
Reference in New Issue