conv_bal
watcha.h@almacom.co.th 2015-03-11 17:08:42 +07:00
parent 34f4f66312
commit f8e8f0f700
6 changed files with 94 additions and 30 deletions

View File

@ -43,7 +43,7 @@
<field name="patient_id" domain='[["type_id","=",type_id]]'/>
<field name="partner_id" domain='[["is_patient","=","true"]]'/>
<field name="hn"/>
<field name="card_no"/>
<!--<field name="card_no"/>-->
</list>
</field>
</tab>

View File

@ -153,6 +153,8 @@ class MatchingPayment(Model):
contact=patient_type.contact_id
if not contact:
raise Exception("contact not found")
st=get_model("clinic.setting").browse(1)
patient_hn=st.get_patient_hn()
matches1={}
matches2={}
matches3={}
@ -166,14 +168,18 @@ class MatchingPayment(Model):
print("len(invoices)", len(invoices))
for invoice in invoices:
pname,hn,card_no='', '', ''
pname2=pname
if invoice.related_id:
hdcase=invoice.related_id
patient=hdcase.patient_id
pname=patient.name_check or ""
#pname=patient.name_check or "" #XXX
pname='%s%s'%(patient.first_name or "",patient.last_name or "")
pname2='%s %s'%(patient.first_name or "",patient.last_name or "")
card_no=patient.card_no or ""
hn=patient.hn_no
elif invoice.ref:
pname=invoice.ref or ''
pname2=pname
pname=pname.replace(" ","") # remove space
for pt in get_model("clinic.patient").search_browse([['name_check','=',pname]]):
hn=pt.hn_no or ""
@ -201,8 +207,9 @@ class MatchingPayment(Model):
'fee': fee,
'epo': epo,
'srv': srv,
'name': pname2,
}
due_amount+=fee+epo+srv
due_amount+=fee+epo+srv #XXX
date=invoice.date
req_vals=[date,due_amount]
key1=':'.join([str(v) for v in [hn]+req_vals])
@ -282,7 +289,18 @@ class MatchingPayment(Model):
'state': 'match',
})
else:
pass
# from ratchawat account settting
phn=patient_hn.get(hn)
if phn:
key1=':'.join([str(v) for v in [phn['hn']]+req_vals])
ss="not found"
if matches1.get(key1):
ss="found"
record.update({
'invoice_id': matches1[key1]['invoice_id'],
'state': 'match',
})
print(ss, ' account mathing ', key1)
## unmatch
records.append(record)
elif obj.pcode=='UC':
@ -309,8 +327,9 @@ class MatchingPayment(Model):
hn=line['hn']
hn=hn.replace(" ", "")
key_uc=''
req_vals=[date,fee]
if date and time:
key_uc='%s:%s:%s'%(line['hn'],date,fee,)
key_uc=':'.join([str(v) for v in [line['hn']]+req_vals])
pname=''
pid=''
for pt in get_model("clinic.patient").search_browse([['hn_no','=',hn]]):
@ -333,8 +352,23 @@ class MatchingPayment(Model):
'state': 'match',
})
else:
pass
#print("not found")
hn=hn.replace("-", "")
hn=hn.replace("/", "")
phn=patient_hn.get(hn)
if phn:
# match with name
key3=':'.join([str(v) for v in [phn['name']]+req_vals])
ss="not found"
mvals=matches3.get(key3)
if mvals:
ss="found"
record.update({
'invoice_id': mvals['invoice_id'],
'name': mvals['name'],
'state': 'match',
})
print(ss, ' account mathing ', key_uc)
records.append(record)
if obj.hcode_id and not records:
raise Exception("Nothing to match! for %s"%(obj.hcode_id.name or ""))

View File

@ -205,14 +205,15 @@ class Patient(Model):
obj=self.browse(obj_id)
partner_id=obj.partner_id
if not partner_id:
for partner in get_model("partner").search_browse([['name', '=', obj.name]]):
partner_name='%s %s'%(obj.first_name or "",obj.last_name or "") # XXX
for partner in get_model("partner").search_browse([['name', '=', partner_name]]):
if partner.name==obj.name:
partner_id=partner.id
break
if not partner_id:
partner_id=get_model("partner").create({
'name': obj.name,
'last_name': obj.name,
'first_name': obj.first_name or "",
'last_name': obj.last_name or "",
'type': 'person',
'is_patient': True,
})
@ -299,18 +300,28 @@ class Patient(Model):
# create partner if not found
partner_id=obj.partner_id
if not partner_id:
for partner in get_model("partner").search_browse([['name', '=', obj.name]]):
partner_name='%s %s'%(obj.first_name or "", obj.last_name or "") # XXX
for partner in get_model("partner").search_browse([['name', '=', partner_name]]):
if partner.name==obj.name:
partner_id=partner.id
break
if not partner_id:
partner_id=get_model("partner").create({
'name': obj.name,
'last_name': obj.name,
'first_name': obj.first_name or "",
'last_name': obj.last_name or "",
'type': 'person',
'is_patient': True,
})
vals['partner_id']=partner_id
#add to account setting
get_model("clinic.setting.account.patient").create({
'setting_id': 1,
'type_id': obj.type_id.id,
'patient_id': obj.id,
'partner_id': partner_id,
'hn': obj.hn_no,
})
if not isinstance(partner_id,int):
partner_id=partner_id.id
if obj.addresses:
@ -341,7 +352,9 @@ class Patient(Model):
for obj in self.browse(ids):
print(obj.name or "")
obj.partner_id.write({
'last_name': obj.name,
'type': 'person',
'first_name': obj.first_name or "",
'last_name': obj.last_name or "",
})
def name_get(self,ids,context={}):

View File

@ -136,19 +136,19 @@ class ClinicSetting(Model):
if user_id !=1:
print("Only admin!!")
return
obj=self.browse(ids)[0]
lines=[]
for pt in get_model("clinic.patient").search_browse([]):
lines.append(('create',{
'patient_id': pt.id,
'partner_id': pt.partner_id.id,
'type_id': pt.type_id.id,
'hn': pt.hn_no,
'card_no': pt.card_no,
}))
obj.write({
'account_patients': lines,
})
pt.partner_id.write({
'type': 'person',
'first_name': pt.first_name or "",
'last_name': pt.last_name or "",
})
for st in get_model("clinic.staff").search_browse([]):
st.partner_id.write({
'type': 'person',
'first_name': st.first_name or "",
'last_name': st.last_name or "",
})
print('Done!')
return
@ -809,4 +809,19 @@ class ClinicSetting(Model):
break
return res
def get_patient_hn(self,ids,context={}):
obj=self.browse(ids)[0]
res={}
for line in obj.account_patients:
pt=line.patient_id
hn=line.hn
if hn not in res.keys():
res[hn]={
'hn': pt.hn,
'pid': pt.id,
'card_no': pt.card_no,
'name': "%s%s"%(pt.first_name or "", pt.last_name or ""),
}
return res
ClinicSetting.register()

View File

@ -2,7 +2,7 @@ from netforce.model import Model, fields
class SettingAccountPatient(Model):
_name="clinic.setting.account.patient"
_string="Setting Account Patient"
_string="Account Patient"
_fields={
"setting_id": fields.Many2One("clinic.setting","Setting",required=True,on_delete="cascade"),

View File

@ -256,15 +256,16 @@ class Staff(Model):
vals['name']='%s%s %s'%(title_name,vals['first_name'],vals['last_name'])
else:
vals['name']='%s %s'%(vals['first_name'],vals['last_name'])
partner_name='%s %s'%(vals['first_name'],vals['last_name']) #XXX
employee_id=vals.get('employee_id')
name=vals['name']
emp_id=self.check_emp(name,employee_id)
if emp_id:
vals['employee_id']=emp_id
partner_id=get_model("clinic.staff").check_contact(name)
partner_id=get_model("clinic.staff").check_contact(partner_name)
address_id=None
if not partner_id:
vals['partner_id'],address_id=self.create_contact(vals['number'],name)
vals['partner_id'],address_id=self.create_contact(vals['number'],partner_name)
new_id=super().create(vals,**kw)
self.function_store([new_id])
for obj in self.browse([new_id]):
@ -284,10 +285,11 @@ class Staff(Model):
emp_id=self.check_emp(name,obj.employee_id.id)
if emp_id:
vals['employee_id']=emp_id
partner_id=get_model("clinic.staff").check_contact(name)
partner_name='%s %s'%(obj.first_name or "",obj.last_name or "")
partner_id=get_model("clinic.staff").check_contact(partner_name)
address_id=None
if not partner_id:
vals['partner_id'],address_id=self.create_contact(name,name) #XXX
vals['partner_id'],address_id=self.create_contact(partner_name,partner_name) #XXX
super().write(ids,vals,**kw)
self.function_store(ids)
if address_id: