clinic/netforce_clinic/models/report_payment_matching.py

96 lines
3.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
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={}):
obj=self.browse(ids)[0]
if not obj.file:
raise Exception("File not found!")
for exp in get_model("clinic.hd.case.expense").search_browse([]):
exp.write({
'match_id': obj.id,
})
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("-")
obj_id=None
2014-12-09 02:40:53 +00:00
if ids:
obj=self.browse(ids)[0]
2014-12-16 09:53:36 +00:00
obj_id=obj.id
2014-12-09 02:40:53 +00:00
lines=[]
2014-12-16 09:53:36 +00:00
for exp in get_model("clinic.hd.case.expense").search_browse([]):
if exp.match_id.id!=obj_id:
continue
patient=exp.patient_id
lines.append({
'name': patient.name,
'fee': 'Yes',
'medicine': 'Yes',
'service': 'Yes',
'state': 'Match',
})
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()