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), } 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) _defaults={ 'date': lambda *a: time.strftime("%Y-%m-%d"), 'date_from': _get_date_from, 'date_to': _get_date_to, } def get_report_data(self,ids,context={}): year, month=time.strftime("%Y-%m").split("-") weekday, total_day=monthrange(int(year), int(month)) time_start='%s-%s-01'%(year,str(month).zfill(2)) time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day) defaults=context.get('defaults') if defaults: year,month,total_day=defaults['date'].split("-") weekday, total_day=monthrange(int(year), int(month)) time_start='%s-%s-01'%(year,str(month).zfill(2)) time_stop='%s-%s-%s'%(year,str(month).zfill(2),total_day) if ids: obj=self.browse(ids)[0] month=obj.date_from.split("-")[1] time_start=obj.date_from time_stop=obj.date_to dom=[] dom.append(['time_start','>=','%s 00:00:00'%time_start]) dom.append(['time_stop','<=','%s 23:59:59'%time_stop]) lines=[] company_id=get_active_company() company=get_model('company').browse(company_id) month_str=utils.MONTHS['th_TH'][int(month)] lines=sorted(lines, key=lambda x: x['prod_name']) year=int(year)+543 data={ 'company_name': company.name or "", 'parent_company_name': company.parent_id.name or "", 'lines': lines, 'month': month_str, 'year': year, } 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()