clinic/netforce_clinic/models/report_payment_matching.py

129 lines
4.0 KiB
Python
Raw Normal View History

2014-12-09 02:40:53 +00:00
import time
from calendar import monthrange
from netforce.model import Model,fields,get_model
from netforce.access import get_active_company
from . import utils
2014-12-21 13:29:25 +00:00
STATES={
'draft': 'Draft',
'waiting_matching':'Waiting Matching',
'match':'Match',
'unmatch':'Unmatch',
'approved':'Approved',
}
2014-12-09 02:40:53 +00:00
class ReportPaymentMatching(Model):
_name="clinic.report.payment.matching"
_string="Report Payment Mathching"
_transient=True
_fields={
"date": fields.Date("Month", required=True),
"date_from": fields.Date("From", required=True),
"date_to": fields.Date("To", required=True),
2014-12-09 17:39:51 +00:00
'state': fields.Selection([['draft','Draft'],['waiting_matching','Waiting Matching'],['match','Match'],['unmatch','Unmatch'],['approved','Approved']],'State'),
'patient_id': fields.Many2One("clinic.patient","Patient"),
2014-12-16 09:53:36 +00:00
'file': fields.File("File"),
'type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True),
2014-12-09 02:40:53 +00:00
}
def _get_date_from(self,context={}):
year,month=time.strftime("%Y-%m").split("-")
return '%s-%s-01'%(year,month)
def _get_date_to(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-")
weekday, total_day=monthrange(int(year), int(month))
return "%s-%s-%s"%(year,month,total_day)
2014-12-16 09:53:36 +00:00
def _get_type_id(self,context={}):
st=get_model("clinic.setting").browse(1)
return st.patient_type_id.id
2014-12-09 02:40:53 +00:00
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': _get_date_from,
'date_to': _get_date_to,
2014-12-09 17:39:51 +00:00
'state': 'match',
2014-12-16 09:53:36 +00:00
'type_id': _get_type_id,
2014-12-09 02:40:53 +00:00
}
2014-12-16 09:53:36 +00:00
def match_invoice(self,ids,context={}):
2014-12-21 13:29:25 +00:00
if not ids:
print("no ids")
return
2014-12-16 09:53:36 +00:00
obj=self.browse(ids)[0]
if not obj.file:
raise Exception("File not found!")
2014-12-21 13:29:25 +00:00
dom=[]
dom.append(['state','=','waiting_matching'])
for exp in get_model("clinic.hd.case.expense").search_browse(dom):
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)
2014-12-16 09:53:36 +00:00
return {
'next': {
'name': 'clinic_report_payment_matching',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Match successfully',
}
2014-12-09 02:40:53 +00:00
2014-12-16 09:53:36 +00:00
def get_report_data(self,ids,context={}):
year, month=time.strftime("%Y-%m").split("-")
2014-12-09 02:40:53 +00:00
lines=[]
2014-12-21 13:29:25 +00:00
if not ids:
return
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):
2014-12-16 09:53:36 +00:00
patient=exp.patient_id
2014-12-21 13:29:25 +00:00
match='No'
exp_color=""
if exp.state=='match':
match='Yes'
else:
exp_color='#C0C0C0'
2014-12-16 09:53:36 +00:00
lines.append({
2014-12-21 13:29:25 +00:00
'exp_id': exp.id,
'patient_name': patient.name,
'patient_id': patient.id,
'hn': patient.hn,
'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,
2014-12-16 09:53:36 +00:00
})
2014-12-09 02:40:53 +00:00
data={
'lines': lines,
}
return data
def onchange_date(self,context={}):
data=context['data']
date=data['date']
year,month,day=date.split("-")
weekday, total_day=monthrange(int(year), int(month))
data['date_from']="%s-%s-01"%(year,month)
data['date_to']="%s-%s-%s"%(year,month,total_day)
return data
ReportPaymentMatching.register()