conv_bal
watcha.h@almacom.co.th 2014-12-21 20:29:25 +07:00
parent dbe2a6d0fd
commit 0b8e46e5b1
10 changed files with 302 additions and 33 deletions

View File

@ -80,5 +80,6 @@
</tab> </tab>
</tabs> </tabs>
<foot> <foot>
<button string="Update Date" type="default" method="update_date"/>
</foot> </foot>
</form> </form>

View File

@ -1,2 +1,3 @@
from . import clinic_setting from . import clinic_setting
from . import import_data #from . import import_pks
from . import import_uc

View File

@ -5,7 +5,7 @@ from netforce.access import get_active_user, set_active_user, set_active_company
from . import utils from . import utils
class Migration(migration.Migration): class Migration(migration.Migration):
_name="import.clinic.hd.case" _name="import.pks"
_version="2.10" _version="2.10"
def import_visit(self,lines): def import_visit(self,lines):
@ -62,6 +62,9 @@ class Migration(migration.Migration):
visits.update({ visits.update({
visit_id: { visit_id: {
'hct': line.get('hct'), 'hct': line.get('hct'),
'epoadm29':line.get("epoadm29"), # SRV
'amount23':line.get("amount23"), # FEE
'allow37':line.get("allow37"), # EPO
} }
}) })
else: else:
@ -77,12 +80,38 @@ class Migration(migration.Migration):
visit_ids=visits.keys() visit_ids=visits.keys()
for visit in get_model('clinic.visit').browse(visit_ids): for visit in get_model('clinic.visit').browse(visit_ids):
if visit!='confirmed': if visit!='confirmed':
visit.confirm() hd_case_id=visit.confirm()['next']['active_id']
hd_case=visit.hd_cases[0] hd_case=get_model("clinic.hd.case").browse(hd_case_id)
# lines # lines
hd_case.write({ vals={
'hct': visits[visit.id]['hct'] or 0, 'hct': visits[visit.id]['hct'] or 0,
}) 'lines': [],
}
for st_prod in st.products:
if st_prod.patient_type_id.id==3:
prod=st_prod.product_id
price=st_prod.price
qty=st_prod.qty
categ=st_prod.product_categ_id
if categ.code=='FEE':
amt=visits[visit.id]['amount23'] or 0
elif categ.code=='SRV':
amt=visits[visit.id]['epoadm29'] or 0
elif categ.code=='EPO':
amt=visits[visit.id]['allow37'] or 0
else:
amt=0
vals['lines'].append(('create',{
'product_id': prod.id,
'uom_id': st_prod.uom_id.id,
'product_categ_id': categ.id,
'description': st_prod.description,
'price': price,
'qty': qty,
'reimbursable': st_prod.reimbursable,
'amount': amt,
}))
hd_case.write(vals)
hd_case_ids.append(hd_case.id) hd_case_ids.append(hd_case.id)
st.write({ st.write({
'auto_gen': False, 'auto_gen': False,
@ -109,6 +138,7 @@ class Migration(migration.Migration):
print('hd case ', len(hd_case_ids)) print('hd case ', len(hd_case_ids))
hd_case_ids=self.hdc_done(hd_case_ids) hd_case_ids=self.hdc_done(hd_case_ids)
print('Done ', len(hd_case_ids)) print('Done ', len(hd_case_ids))
set_active_company(1)
return True return True
Migration.register() Migration.register()

View File

@ -0,0 +1,141 @@
from netforce.model import get_model
from netforce import migration
from netforce.utils import get_file_path
from netforce.access import get_active_user, set_active_user, set_active_company, get_active_company
from . import utils
class Migration(migration.Migration):
_name="import.uc"
_version="2.11"
def import_visit(self,lines):
visits={}
cycles=[(c['id'],'%s:00'%c['time_start'],'%s:00'%c['time_stop']) for c in get_model("clinic.cycle").search_read([[]],['time_start','time_stop'])]
patients=get_model("clinic.patient").search_browse([])
for line in lines:
dttran=line.get("dttran")
hn=line.get("hn")
if hn:
hn=''.join(x for x in hn if x.isdigit)
pid=None
for pt in patients:
if pt['hn_num']==hn:
pid=pt.id
break
if not pid:
print('continue ', pid)
continue
if dttran:
date,time=dttran.split("T")
if not time:
continue
cycle_id=None
patient=get_model("clinic.patient").browse(pid)
doctor=patient.doctor_id
department=patient.department_id
vals={
'patient_id': patient.id,
'doctor_id': doctor.id,
'department_id': department.id,
'state': 'pending',
}
for cycle in cycles:
time_start=cycle[1]
time_stop=cycle[2]
if time >= time_start:
cycle_id=cycle[0]
vals['cycle_id']=cycle_id
vals['time_start']='%s %s'%(date,time_start)
vals['time_stop']='%s %s'%(date,time_stop)
if not cycle_id:
raise Exception("not found cycle on this time %s %s %s"%(dttran, time_start,time_stop))
visit_ids=get_model("clinic.visit").search([['visit_date','=',date],['patient_id','=',pid]])
visit_id=None
if not visit_ids:
vals['visit_date']=date
visit_id=get_model('clinic.visit').create(vals)
else:
visit_id=visit_ids[0]
if visit_id:
visits.update({
visit_id: {
'hct': line.get('hct'),
}
})
pass
return visits
def confirm_visit(self,visits):
st=get_model("clinic.setting").browse(1)
st.write({
'auto_gen': True,
})
hd_case_ids=[]
visit_ids=visits.keys()
for visit in get_model('clinic.visit').browse(visit_ids):
if visit!='confirmed':
hd_case_id=visit.confirm()['next']['active_id']
hd_case=get_model("clinic.hd.case").browse(hd_case_id)
# lines
vals={
'hct': visits[visit.id]['hct'] or 0,
'lines': [],
}
for st_prod in st.products:
if st_prod.patient_type_id.id==3:
prod=st_prod.product_id
price=st_prod.price
qty=st_prod.qty
categ=st_prod.product_categ_id
if categ.code=='FEE':
amt=visits[visit.id]['amount23'] or 0
elif categ.code=='SRV':
amt=visits[visit.id]['epoadm29'] or 0
elif categ.code=='EPO':
amt=visits[visit.id]['allow37'] or 0
else:
amt=0
vals['lines'].append(('create',{
'product_id': prod.id,
'uom_id': st_prod.uom_id.id,
'product_categ_id': categ.id,
'description': st_prod.description,
'price': price,
'qty': qty,
'reimbursable': st_prod.reimbursable,
'amount': amt,
}))
hd_case.write(vals)
hd_case_ids.append(hd_case.id)
st.write({
'auto_gen': False,
})
return hd_case_ids
def hdc_done(self,hd_case_ids):
done_ids=[]
for hd_case in get_model("clinic.hd.case").browse(hd_case_ids):
if hd_case.state=='waiting_treatment':
hd_case.complete()
done_ids.append(hd_case.id)
return done_ids
def migrate(self):
#fname='22283_EURSTM_201406.xml'
fname='22283_UOCDSTM_20140902.xml'
fpath=get_file_path(fname)
node='HDBills'
lines=utils.read_xml(fpath,node=node)
set_active_company(1)
visits=self.import_visit(lines)
print("visit ", len(visits))
#hd_case_ids=self.confirm_visit(visits)
#print('hd case ', len(hd_case_ids))
#hd_case_ids=self.hdc_done(hd_case_ids)
#print('Done ', len(hd_case_ids))
return True
Migration.register()

View File

@ -361,6 +361,7 @@ class HDCase(Model):
context['inv_type']='invoice' context['inv_type']='invoice'
lines1=[] #yes lines1=[] #yes
lines2=[] #no lines2=[] #no
for line in obj.lines: for line in obj.lines:
if line.state!='draft': if line.state!='draft':
continue continue
@ -403,6 +404,7 @@ class HDCase(Model):
account_mdc_id=partner.account_mdc_id.id account_mdc_id=partner.account_mdc_id.id
account_fee_id=partner.account_fee_id.id account_fee_id=partner.account_fee_id.id
account_service_id=partner.account_service_id.id account_service_id=partner.account_service_id.id
print('>>>> ', partner.id, account_service_id, account_mdc_id, account_fee_id, ' <<<')
vals={ vals={
"type": "out", "type": "out",
"inv_type": "invoice", "inv_type": "invoice",
@ -531,6 +533,9 @@ class HDCase(Model):
def post_invoices(self,ids,context={}): def post_invoices(self,ids,context={}):
obj=self.browse(ids[0]) obj=self.browse(ids[0])
for inv in obj.invoices: for inv in obj.invoices:
#XXX
if inv.amount_total<1:
continue
inv.post() inv.post()
print("Post!") print("Post!")
@ -890,8 +895,7 @@ class HDCase(Model):
# fee # fee
st=get_model("clinic.setting").browse(1) st=get_model("clinic.setting").browse(1)
if st.auto_gen: if st.auto_gen:
return return vals
if not vals.get('lines'): if not vals.get('lines'):
vals['lines']=[] vals['lines']=[]
for st_prod in st.products: for st_prod in st.products:
@ -946,7 +950,13 @@ class HDCase(Model):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
vals['req_fee']=0 vals['req_fee']=0
if 'lines' in vals.keys(): if 'lines' in vals.keys():
for mode, line_ids, line_vals in vals['lines']: #for mode, line_ids, line_vals in vals['lines']:
for line in vals['lines']:
mode=line[0]
if mode=='create':
line_vals=line[1]
else:
line_vals=line[2]
if line_vals['reimbursable']=='no': if line_vals['reimbursable']=='no':
vals['req_fee']=1 # to show button pay vals['req_fee']=1 # to show button pay
else: else:

View File

@ -37,6 +37,7 @@ class HDCaseExpense(Model):
'pt_conflict': fields.Boolean("Patient Conclict",function="_get_patient_conflict"), 'pt_conflict': fields.Boolean("Patient Conclict",function="_get_patient_conflict"),
'company_id': fields.Many2One("company","Company"), 'company_id': fields.Many2One("company","Company"),
'match_id': fields.Many2One("clinic.report.payment.matching","Match"), 'match_id': fields.Many2One("clinic.report.payment.matching","Match"),
'invno': fields.Char("Invoice No"),
} }
_defaults={ _defaults={

View File

@ -5,6 +5,14 @@ from netforce.model import Model,fields,get_model
from netforce.access import get_active_company from netforce.access import get_active_company
from . import utils from . import utils
STATES={
'draft': 'Draft',
'waiting_matching':'Waiting Matching',
'match':'Match',
'unmatch':'Unmatch',
'approved':'Approved',
}
class ReportPaymentMatching(Model): class ReportPaymentMatching(Model):
_name="clinic.report.payment.matching" _name="clinic.report.payment.matching"
_string="Report Payment Mathching" _string="Report Payment Mathching"
@ -42,14 +50,27 @@ class ReportPaymentMatching(Model):
} }
def match_invoice(self,ids,context={}): def match_invoice(self,ids,context={}):
if not ids:
print("no ids")
return
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
if not obj.file: if not obj.file:
raise Exception("File not found!") raise Exception("File not found!")
dom=[]
for exp in get_model("clinic.hd.case.expense").search_browse([]): dom.append(['state','=','waiting_matching'])
exp.write({ for exp in get_model("clinic.hd.case.expense").search_browse(dom):
'match_id': obj.id, ptype=exp.patient_id.type_id
}) if ptype.id==obj.type_id.id:
exp.write({
'match_id': obj.id,
})
else:
exp.write({
'match_id': None,
})
# TODO
# udpate check state , write ref (invno)
return { return {
'next': { 'next': {
'name': 'clinic_report_payment_matching', 'name': 'clinic_report_payment_matching',
@ -61,21 +82,33 @@ class ReportPaymentMatching(Model):
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
year, month=time.strftime("%Y-%m").split("-") year, month=time.strftime("%Y-%m").split("-")
obj_id=None
if ids:
obj=self.browse(ids)[0]
obj_id=obj.id
lines=[] lines=[]
for exp in get_model("clinic.hd.case.expense").search_browse([]): if not ids:
if exp.match_id.id!=obj_id: return
continue obj=self.browse(ids)[0]
dom=[]
dom.append(['state','=','waiting_matching'])
dom.append(['match_id','=',obj.id])
for exp in get_model("clinic.hd.case.expense").search_browse(dom):
patient=exp.patient_id patient=exp.patient_id
match='No'
exp_color=""
if exp.state=='match':
match='Yes'
else:
exp_color='#C0C0C0'
lines.append({ lines.append({
'name': patient.name, 'exp_id': exp.id,
'fee': 'Yes', 'patient_name': patient.name,
'medicine': 'Yes', 'patient_id': patient.id,
'service': 'Yes', 'hn': patient.hn,
'state': 'Match', 'fee_amt': exp.fee_amt or 0,
'mdc_amt': exp.mdc_amt or 0,
'srv_amt': exp.srv_amt or 0,
#'state': STATES[exp.state],
'match': match,
'invno': exp.invno,
'exp_color': exp_color,
}) })
data={ data={

View File

@ -71,5 +71,50 @@ class ClinicSetting(Model):
amt=qty*price amt=qty*price
line['amount']=amt line['amount']=amt
return data return data
def update_date(self,ids,context={}):
pass
#for hd_case in get_model("clinic.hd.case").search_browse([]):
#if hd_case.state!='waiting_treatment':
#continue
#for line in hd_case.lines:
#categ=line.product_categ_id
#if categ:
#if categ.code=='SRV':
#line.delete()
#for vs in get_model("clinic.visit").search_browse([]):
#if vs.state=='pending':
#vs.confirm()
#print(vs.number)
#obj=self.browse(ids)[0]
#for hd_case in get_model("clinic.hd.case").search_browse([]):
#number='/'
#if hd_case.number=='/':
#number=get_model("clinic.hd.case")._get_number()
#if hd_case.state=='waiting_treatment':
#hd_case.complete()
#date,time=hd_case.time_start.split(" ")
#hd_case.write({
#'date': date,
#'number': number,
#})
#for inv in hd_case.invoices:
#inv.write({
#'date': date,
#'due_date': date,
#})
#for pick in hd_case.pickings:
#pick.write({
#'date': date,
#})
#for exp in get_model('clinic.hd.case.expense').search_browse([]):
#exp.write({
#'date': exp.hd_case_id.date,
#})
#print('done')
ClinicSetting.register() ClinicSetting.register()

View File

@ -394,6 +394,7 @@ class Visit(Model):
vals['sequence']='%s-%s'%(vals['time_start'][0:10],cycle.sequence) #date-sequence vals['sequence']='%s-%s'%(vals['time_start'][0:10],cycle.sequence) #date-sequence
vals['visit_date']=vals['time_start'][0:10] vals['visit_date']=vals['time_start'][0:10]
new_id=super().create(vals,**kw) new_id=super().create(vals,**kw)
print('create visit ', new_id)
return new_id return new_id
def cancel(self,ids,context={}): def cancel(self,ids,context={}):

View File

@ -4,20 +4,26 @@
{{#if lines}} {{#if lines}}
<table class="table table-condensed table-striped"> <table class="table table-condensed table-striped">
<thead> <thead>
<th>HN</th>
<th>Patient</th> <th>Patient</th>
<th>Fee(1,500)</th> <th>Invoice No</th>
<th>Fee</th>
<th>Medicine</th> <th>Medicine</th>
<th>Service</th> <th>Service</th>
<th>Status</th> <th>Match</th>
<th></th>
</thead> </thead>
<tbody> <tbody>
{{#each lines}} {{#each lines}}
<tr> <tr>
<td>{{name}}</td> <td style="background-color:{{exp_color}}"><a href="/ui#name=clinic_patient&active_id={{patient_id}}&mode=form">{{hn}}</a></td>
<td>{{fee}}</td> <td style="background-color:{{exp_color}}"><a href="/ui#name=clinic_patient&active_id={{patient_id}}&mode=form">{{patient_name}}</a></td>
<td>{{medicine}}</td> <td style="background-color:{{exp_color}}">{{invno}}</td>
<td>{{service}}</td> <td style="background-color:{{exp_color}}">{{fee_amt}}</td>
<td>{{state}}</td> <td style="background-color:{{exp_color}}">{{mdc_amt}}</td>
<td style="background-color:{{exp_color}}">{{srv_amt}}</td>
<td style="background-color:{{exp_color}}">{{match}}</td>
<td style="background-color:{{exp_color}}"><a href="/ui#name=clinic_hd_case_expense&active_id={{exp_id}}&mode=form">Edit</a></td>
</tr> </tr>
{{/each}} {{/each}}
</tbody> </tbody>