import payment

conv_bal
watcha.h 2014-10-28 02:01:18 +07:00
parent 7ceeb51d2b
commit d2e0bd55c2
17 changed files with 247 additions and 83 deletions

View File

@ -1,7 +1,7 @@
<action> <action>
<field name="string">Social Security</field> <field name="string">Social Security</field>
<field name="view_cls">multi_view</field> <field name="view_cls">multi_view</field>
<field name="tabs">[["All",[]],["Success",[["type","=","success"]]],["Fail",[["type","=","fail"]]]]</field> <field name="tabs">[["All",[]],["Match",[["type","=","match"]]],["Not Match",[["type","=","not_match"]]]]</field>
<field name="model">clinic.data.sc</field> <field name="model">clinic.data.sc</field>
<field name="menu">account_menu</field> <field name="menu">account_menu</field>
</action> </action>

View File

@ -11,4 +11,5 @@
<field name="st"/> <field name="st"/>
<field name="allow37"/> <field name="allow37"/>
<field name="type"/> <field name="type"/>
<field name="hd_case_id"/>
</form> </form>

View File

@ -1,4 +1,4 @@
<list model="clinic.data.sc" colors='{"red":[["type","=","fail"]]}'> <list model="clinic.data.sc" colors='{"red":[["type","=","not_match"]]}'>
<field name="hn"/> <field name="hn"/>
<field name="name14"/> <field name="name14"/>
<field name="hcode18"/> <field name="hcode18"/>
@ -11,4 +11,5 @@
<field name="st"/> <field name="st"/>
<field name="allow37"/> <field name="allow37"/>
<field name="type"/> <field name="type"/>
<field name="hd_case_id"/>
</list> </list>

View File

@ -1,6 +0,0 @@
<form model="clinic.input.data">
<field name="doc_date"/>
<field name="name"/>
<field name="hn"/>
<field name="amount"/>
</form>

View File

@ -3,7 +3,8 @@
<field name="type"/> <field name="type"/>
<button string="Options" dropdown="1"> <button string="Options" dropdown="1">
<item string="Generate Visit" action="clinic_gen_visit"/> <item string="Generate Visit" action="clinic_gen_visit"/>
<item string="Generate Dialyzer" action="clinic_gen_dialyzer"/> <item string="New Dialyzer" method="new_dialyzer"/>
<item string="Simple Address" method="simple_address"/>
</button> </button>
</head> </head>
<field name="number"/> <field name="number"/>

View File

@ -3,12 +3,15 @@
<tab string="Testing"> <tab string="Testing">
<field name="file"/> <field name="file"/>
<newline/> <newline/>
<button string="Read Case" method="read_hd_case"/>
<button string="Post" method="done_hd_case"/>
</tab> </tab>
<tab string="General"> <tab string="General">
<separator string="Labor Cost"/> <separator string="Labor Cost"/>
<field name="var_k"/> <field name="var_k"/>
</tab> </tab>
</tabs> </tabs>
<foot>
<button string="Make Visit" method="make_visit"/>
<button string="Make HD Case" method="make_done"/>
<button string="Complete HD Case" method="make_complete"/>
</foot>
</form> </form>

View File

@ -12,5 +12,8 @@
</group> </group>
<foot replace="1"> <foot replace="1">
<button string="Import Data" method="import_sc" type="primary" icon="arrow-right"/> <button string="Import Data" method="import_sc" type="primary" icon="arrow-right"/>
<!--<button string="Match Invoice" method="match_invoice_sc" icon="retweet" type="default"/>-->
<button string="Pay Invoice" method="post_sc" icon="ok" type="success"/>
<button string="Clear" method="clear_sc" type="danger" icon="remove"/>
</foot> </foot>
</form> </form>

View File

@ -25,7 +25,6 @@ from . import hd_case_payment
from . import dialyzer from . import dialyzer
from . import dialyzer_line from . import dialyzer_line
from . import import_payment from . import import_payment
from . import file_sheet
from . import cycle from . import cycle
from . import cycle_item from . import cycle_item
from . import cycle_item_line from . import cycle_item_line
@ -34,7 +33,7 @@ from . import gen_visit_line
from . import report_hd_detail from . import report_hd_detail
from . import report_hd_summary from . import report_hd_summary
from . import report_hd_medical from . import report_hd_medical
from . import input_data from . import report_hd_payment
from . import fin_setting from . import fin_setting
from . import import_data_mg from . import import_data_mg
from . import import_data_nhso from . import import_data_nhso
@ -43,5 +42,4 @@ from . import translate
from . import payment from . import payment
from . import account_payment from . import account_payment
from . import account_invoice from . import account_invoice
from . import report_hd_payment
from . import personal_categ from . import personal_categ

View File

@ -126,6 +126,7 @@ class CycleItem(Model):
'amount': qty*rate, 'amount': qty*rate,
})) }))
print("qty * rate ", qty, ' ', rate) print("qty * rate ", qty, ' ', rate)
# x=(pt*k+n2*100+n3*250-n4*25-n5*25+n6*75)/(n1+n2+n3+0.5*(n4+n5+n6))
obj.write(vals) obj.write(vals)
@ -197,7 +198,7 @@ class CycleItem(Model):
'amount': line.amount, 'amount': line.amount,
})) }))
payment_id=get_model("account.payment").create(vals,context={"type":"in"}) payment_id=get_model("account.payment").create(vals,context={"type":"out"})
#get_model("account.payment").browse(payment_id).post() #get_model("account.payment").browse(payment_id).post()
obj.write({ obj.write({
'state': 'done', 'state': 'done',

View File

@ -1,14 +0,0 @@
from netforce.model import Model, fields
class FileSheet(Model):
_name="clinic.file.sheet"
_string="File Sheet"
_fields={
'name': fields.Char("Name"),
'index': fields.Integer("Index"),
"select": fields.Selection([("yes","Yes"),("no","No")],"Select"),
'imp_id': fields.Many2One("clinic.import.payment","Import Payment"),
}
FileSheet.register()

View File

@ -465,7 +465,7 @@ class HDCase(Model):
def create_cycle_item(self,ids,context={}): def create_cycle_item(self,ids,context={}):
for obj in self.browse(ids): for obj in self.browse(ids):
cycle_item=get_model("clinic.cycle.item") cycle_item=get_model("clinic.cycle.item")
datenow=obj.start_time[0:10] datenow=obj.time_start[0:10]
if not datenow: if not datenow:
datenow=time.strftime('%Y-%m-%d') datenow=time.strftime('%Y-%m-%d')
cycle_id=obj.cycle_id.id cycle_id=obj.cycle_id.id
@ -491,6 +491,8 @@ class HDCase(Model):
obj.write({ obj.write({
"state":"completed", "state":"completed",
}) })
if context.get("called"):
return obj.id
return { return {
'next': { 'next': {
'name': 'clinic_hd_case', 'name': 'clinic_hd_case',
@ -651,7 +653,6 @@ class HDCase(Model):
dlz_vals['company_id']=dlz_vals['company_id'][0] dlz_vals['company_id']=dlz_vals['company_id'][0]
product_name=dlz_vals['product_id'][1] product_name=dlz_vals['product_id'][1]
dlz_vals['product_id']=dlz_vals['product_id'][0] dlz_vals['product_id']=dlz_vals['product_id'][0]
dlz_id=get_model('clinic.dialyzer').create(dlz_vals) dlz_id=get_model('clinic.dialyzer').create(dlz_vals)
dialyzer=get_model("clinic.dialyzer").browse(dlz_id) dialyzer=get_model("clinic.dialyzer").browse(dlz_id)
dialyzer.confirm() dialyzer.confirm()
@ -671,6 +672,8 @@ class HDCase(Model):
'state': dialyzer.state, 'state': dialyzer.state,
})) }))
obj.write(vals) obj.write(vals)
if context.get('called'):
return obj.id
return { return {
'next': { 'next': {
'name': 'clinic_hd_case', 'name': 'clinic_hd_case',

View File

@ -15,8 +15,11 @@ class ImportDataSC(Model):
'st': fields.Char('st'), 'st': fields.Char('st'),
'allow37': fields.Char('allow37'), 'allow37': fields.Char('allow37'),
'dttran': fields.Date("dttran"), 'dttran': fields.Date("dttran"),
'type': fields.Selection([['success','Succes'],['fail','Fail']],'Type', search=True), 'type': fields.Selection([['match','Match'],['not_match','Not Match']],'Type', search=True),
'hd_case_id': fields.Many2One("clinic.hd.case","HD Case"),
#'invoice_id': fields.Many2One("clinic.hd.case","HD Case"),
} }
_order="type"
ImportDataSC.register() ImportDataSC.register()

View File

@ -129,6 +129,15 @@ class ImportPayment(Model):
old_patient=[x['hn'] for x in patient.search_read([],['hn']) if x['hn']] old_patient=[x['hn'] for x in patient.search_read([],['hn']) if x['hn']]
fail_qty=0 fail_qty=0
success_qty=0 success_qty=0
hd_cases=get_model("clinic.hd.case").search_browse([['state','=','completed']])
def get_hdcase(hn,date):
for hd_case in hd_cases:
hd_date=hd_case.time_start[0:10]
if hn==hd_case.patient_id.hn and date==hd_date: #XXX
return hd_case.id
for line in lines: for line in lines:
hn=line.get('hn') hn=line.get('hn')
if not hn: if not hn:
@ -144,11 +153,18 @@ class ImportPayment(Model):
st.update({hn: line.get('name14')}) st.update({hn: line.get('name14')})
print("create %s ok"%hn) print("create %s ok"%hn)
hcode=int((line.get('hcode18') or "0")) # XXX hcode=int((line.get('hcode18') or "0")) # XXX
type=hcode==23869 and 'success' or 'fail' type='match'
if type=='success': if hcode!=(int(obj.hcode)):
continue
dttran=line.get("dttran","")
hd_case_id=get_hdcase(hn,dttran)
if hd_case_id:
success_qty+=1 success_qty+=1
else: else:
fail_qty+=1 fail_qty+=1
type='not_match'
vals={ vals={
'hn': hn, 'hn': hn,
'name14': line.get('name14'), 'name14': line.get('name14'),
@ -162,6 +178,7 @@ class ImportPayment(Model):
'allow37': line.get('allow37'), 'allow37': line.get('allow37'),
'dttran': line.get("dttran"), 'dttran': line.get("dttran"),
'type': type, 'type': type,
'hd_case_id': hd_case_id,
} }
data_sc.create(vals) data_sc.create(vals)
msg='' msg=''
@ -182,5 +199,63 @@ class ImportPayment(Model):
def test_sc(self,ids,context={}): def test_sc(self,ids,context={}):
pass pass
def clear_sc(self,ids,context={}):
sc_ids=get_model("clinic.data.sc").search([])
get_model("clinic.data.sc").delete(sc_ids)
obj=self.browse(ids)[0]
obj.write({
'result': 'Clear OK',
})
def match_invoice_sc(self,ids,context={}):
obj=self.browse(ids)[0]
for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
for invoice in sc.hd_case_id.invoices:
print(invoice.number)
obj.write({
'result': 'Match OK',
})
def post_sc(self,ids,context={}):
settings=get_model("settings").browse(1)
account_id=settings.ap_sc_id.id
if not account_id:
raise Exception("No Account payment for Social Security")
obj=self.browse(ids)[0]
vals={
'partner_id': '',
"company_id": get_active_company(),
"type": "in",
"pay_type": "invoice",
"date": obj.date or time.strftime("%Y-%m-%d"),
"account_id": account_id,
'invoice_lines': [],
}
invoice_ids=[]
partner_id=None
for sc in get_model("clinic.data.sc").search_browse([['type','=','match']]):
if not partner_id:
partner_id=sc.hd_case_id.fee_partner_id.id
for invoice in sc.hd_case_id.invoices:
invoice_ids.append(invoice.id)
vals['invoice_lines'].append(('create',{
'invoice_id': invoice.id,
'amount': invoice.amount_due or 0.0,
}))
sc.delete() #XXX
vals['partner_id']=partner_id
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
#get_model("account.payment").browse(payment_id).post()
return {
'next': {
'name': 'payment',
'mode': 'form',
'active_id': payment_id,
},
'flash': 'Paid',
}
ImportPayment.register() ImportPayment.register()

View File

@ -1,18 +0,0 @@
from netforce.model import Model, fields, get_model
class InputData(Model):
_name="clinic.input.data"
_transient=True
_fields={
'date': fields.Date("Date"),
'name': fields.Char("Patient Name"),
'hn': fields.Char("HN"),
'amount': fields.Char("Amount"),
'hct': fields.Char("HCT"),
'medical_type': fields.Char("Medical Type"),
'medical_cost': fields.Char("Medical Cost"),
'other_cost': fields.Char("Other Cost"),
}
InputData.register()

View File

@ -247,5 +247,49 @@ class Patient(Model):
ids3=self.search(dom) ids3=self.search(dom)
ids=list(set(ids1+ids2+ids3)) ids=list(set(ids1+ids2+ids3))
return self.name_get(ids,context=context) return self.name_get(ids,context=context)
def simple_address(self,ids,context={}):
print("call simple address ")
for obj in self.browse(ids):
if not obj.addresses:
addr_id=get_model("address").create({
'patient_id': obj.id,
'partner_id': obj.partner_id.id,
'type': 'shipping',
'address': 'xxxx',
'address2': 'xxxx',
'city': 'BKK',
'country_id': 1,
'postal_code': '12000',
})
if context.get('called'):
return obj.id
return {
'next': {
'name': 'clinic_patient',
'mode': 'form',
'active_id': obj.id,
},'flash': 'Simple Address OK',
}
def new_dialyzer(self,ids,context={}):
dlz_id=None
for obj in self.browse(ids):
dlz_vals=get_model("clinic.dialyzer").default_get()
dlz_vals['patient_id']=obj.id
dlz_vals['company_id']=dlz_vals['company_id'][0]
dlz_vals['product_id']=dlz_vals['product_id'][0]
dlz_id=get_model('clinic.dialyzer').create(dlz_vals)
dialyzer=get_model("clinic.dialyzer").browse(dlz_id)
dialyzer.confirm()
if context.get('called'):
return dlz_id
return {
'next': {
'name': 'clinic_patient',
'mode': 'form',
'active_id': obj.id,
},'flash': 'New Dialyzer successfully',
}
Patient.register() Patient.register()

View File

@ -15,6 +15,7 @@ class ClinicSetting(Model):
"var_k": fields.Float("K"), "var_k": fields.Float("K"),
'file': fields.File("File"), 'file': fields.File("File"),
} }
def read_excel(self,fpath=None): def read_excel(self,fpath=None):
data={} data={}
if fpath: if fpath:
@ -42,7 +43,7 @@ class ClinicSetting(Model):
data.append(d) data.append(d)
return data return data
def read_cash(self,ids,context={}): def make_visit(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
fname=obj.file fname=obj.file
fpath=get_file_path(fname) fpath=get_file_path(fname)
@ -52,32 +53,18 @@ class ClinicSetting(Model):
medicals=[] medicals=[]
patients=[] patients=[]
for line in lines: for line in lines:
medical=line['medical'] or "" medical=line.get('medical') or line.get('eponame') or ""
if not medical in medicals: if not medical in medicals:
medicals.append(medical) medicals.append(medical)
patient=line['hn'] or "" patient=line.get('hn','')
name14=line['name14'] or "" name14=line.get('name14') or ""
value=(patient,name14) value=(patient,name14)
if not value in patients: if not value in patients:
patients.append(value) patients.append(value)
#vals={
#'hn': hn,
#'name14': line.get('name14'),
#'hcode18': hcode,
#'amount23': line.get('amount23'),
#"cur": line.get('cur'),
#'epoadm29': line.get('epoadm29'),
#'eponame': line.get('eponame'),
#'ln': line.get('ln'),
#'st': line.get('st'),
#'allow37': line.get('allow37'),
#'dttran': line.get("dttran"),
#'type': type,
#}
products=[p['name'] for p in get_model("product").search_read([],['name'])] products=[p['name'] for p in get_model("product").search_read([],['name'])]
print('generate product') print('generate product')
print("="*50) print("="*50)
seq=1 seq=6
for md in medicals: for md in medicals:
md=md.replace(" ","") md=md.replace(" ","")
if not md: if not md:
@ -122,20 +109,13 @@ class ClinicSetting(Model):
return pt return pt
return None return None
def get_visit(date,cycle_name=None,state=None): def get_visit(date,state=None):
for visit in visits: for visit in visits:
if date==visit['time_start'][0:10]: if date==visit['time_start'][0:10]:
if state: if state:
print(state, " ", visit['state'])
if visit['state']==state: if visit['state']==state:
if cycle_name:
if cycle_name==visit['cycle_id'][1]:
return visit
else:
return None
return visit return visit
else: else:
print("else ")
return None return None
return visit return visit
print("="*50) print("="*50)
@ -165,22 +145,25 @@ class ClinicSetting(Model):
print("create visit %s ", visit_id) print("create visit %s ", visit_id)
print("="*50) print("="*50)
print("visit with state is draft") print("visit with state is draft")
return #XXXX
count=0 count=0
for line in lines: for line in lines:
date=line['dttran'] date=line['dttran']
# prevent timeout # prevent timeout
if count > 10: if count > 10:
break break
#print(date)
visit=get_visit(date=date,state='draft') visit=get_visit(date=date,state='draft')
print(date, ' ', visit)
if visit: if visit:
visit_id=visit['id'] visit_id=visit['id']
context['called']=True context['called']=True
hd_case_id=get_model("clinic.visit").browse(visit_id).confirm(context=context) hd_case_id=get_model("clinic.visit").browse(visit_id).confirm(context=context)
#allow37=line['allow37'] #allow37=line['allow37']
hct=line['hct'] hct=line.get('hct')
medical=line['medical'] medical=line.get('medical') or line.get("eponame") or ""
medical_cost=line['medical_cost'] medical_cost=line.get('medical_cost') or line.get('allow37') or 0.0
inject_service=line['inject_service'] inject_service=line.get('inject_service') or line.get("epoadm29") or ""
vals={ vals={
'hct': hct and hct or 0, 'hct': hct and hct or 0,
'lines': [], 'lines': [],
@ -215,5 +198,78 @@ class ClinicSetting(Model):
print("="*50) print("="*50)
print("Done") print("Done")
return return
def make_done(self,ids,context={}):
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
lines=self.read_excel(fpath)
if not lines:
raise Exception("Wrong File")
def get_line(hn,date):
for line in lines:
if hn==line['hn'] and date==line['dttran']:
return line
count=0
for visit in get_model("clinic.visit").search_browse([['state','=','draft']]):
if count > 200:
break
count+=1
context['called']=True
hd_case_id=visit.confirm(context=context)
hn=visit.patient_id.hn
date_visit=visit.time_start[0:10]
line=get_line(hn,date_visit)
if line:
hct=line.get('hct')
medical=line.get('medical') or line.get('eponame') or ""
medical_cost=line.get('medical_cost') or line.get("allow37") or ""
inject_service=line.get('inject_service') or line.get("EPOadm29") or ""
vals={
'hct': hct and hct or 0,
'lines': [],
}
if medical:
prods=get_model("product").search_browse([['name','=',medical]])
if prods:
prod=prods[0]
vals['lines'].append(('create',{
'type': 'fee',
'product_id': prod.id,
'description': prod.name,
'uom_id': prod.uom_id.id,
'qty': 1,
'price': medical_cost,
'amount': medical_cost,
}))
if inject_service:
prod=get_model("product").browse(55)
vals['lines'].append(('create',{
'type': 'other',
'product_id': 55, #XXX
'description': prod.name,
'uom_id': prod.uom_id.id,
'qty': 1,
'price': medical_cost,
'amount': medical_cost,
}))
hd_case=get_model("clinic.hd.case").browse(hd_case_id)
hd_case.write(vals)
print("#%s make hd_case %s ok "%(count,hd_case.number))
def make_complete(self,ids,context={}):
context['called']=True
count=0
for hd_case in get_model('clinic.hd.case').search_browse(['state','=','draft']):
if count > 100:
break
if not hd_case.dialyzers:
patient=hd_case.patient_id
if not patient.addresses:
patient.simple_address()
hd_case.new_dialyzer(context=context)
hd_case.complete()
print("%s is completed"%hd_case.number)
count+=1
ClinicSetting.register() ClinicSetting.register()

View File

@ -130,6 +130,19 @@ class Visit(Model):
'amount': product.sale_price or 0.0, 'amount': product.sale_price or 0.0,
'uom_id': product.uom_id.id, 'uom_id': product.uom_id.id,
})) }))
if obj.patient_id.type=='sc':
products=get_model("product").search_browse([['code','=','S0001']]) #XXX
for product in products:
vals['lines'].append(('create',{
'type': 'fee',
'product_id': product.id,
'description': product.name or "",
'qty': 1,
'price': product.sale_price or 0.0,
'amount': product.sale_price or 0.0,
'uom_id': product.uom_id.id,
}))
patient_type={ patient_type={
"mg":"Medical Government", "mg":"Medical Government",