clinic/netforce_clinic/models/report_payment_matching.py

96 lines
3.0 KiB
Python

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),
'state': fields.Selection([['draft','Draft'],['waiting_matching','Waiting Matching'],['match','Match'],['unmatch','Unmatch'],['approved','Approved']],'State'),
'patient_id': fields.Many2One("clinic.patient","Patient"),
'file': fields.File("File"),
'type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True),
}
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)
def _get_type_id(self,context={}):
st=get_model("clinic.setting").browse(1)
return st.patient_type_id.id
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': _get_date_from,
'date_to': _get_date_to,
'state': 'match',
'type_id': _get_type_id,
}
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',
}
def get_report_data(self,ids,context={}):
year, month=time.strftime("%Y-%m").split("-")
obj_id=None
if ids:
obj=self.browse(ids)[0]
obj_id=obj.id
lines=[]
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',
})
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()