From d5f07de974e9e13891174642b0d6575e3a6f720c Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Mon, 5 Jun 2017 00:47:34 +0700 Subject: [PATCH] refactor --- netforce_clinic/models/patient_move.py | 53 +++++++++---------- .../models/report_hdcase_summary.py | 6 +-- netforce_clinic/todo.txt | 7 +++ 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/netforce_clinic/models/patient_move.py b/netforce_clinic/models/patient_move.py index 84722a3..4bfab2f 100644 --- a/netforce_clinic/models/patient_move.py +++ b/netforce_clinic/models/patient_move.py @@ -9,20 +9,10 @@ from . import utils class PatientMove(Model): _name="clinic.patient.move" - - def get_all(self, ids, context={}): - res={} - for obj in self.browse(ids): - res[obj.id]={ - 'date_move': obj.date.split(" ")[0], - } - return res - _fields={ 'patient_id': fields.Many2One('clinic.patient','Patient',search=True), - 'date': fields.DateTime("Date", required=True,search=True), - 'date_move': fields.Date("Date Move", function="get_all", function_multi=True, store=True), + 'date': fields.Date("Date", required=True,search=True), 'location_from_id': fields.Many2One("clinic.department","Location From",search=True), 'location_to_id': fields.Many2One("clinic.department","Location To",search=True), "state": fields.Selection([['normal','Normal'],['new','New'],['dispose','Dispose']], "State"), @@ -37,14 +27,15 @@ class PatientMove(Model): def get_data(self, date, department_id, context={}): if not date: raise Exception("Missing date!") + y,m,d=date.split("-") y=int(y) m=int(m) weekday, day_month=monthrange(y, m) cond1=[ - ['date','>=','%s-%s-01 00:00:00'%(y,str(m).zfill(2))], - ['date','<=','%s-%s-%s 23:59:59'%(y,str(m).zfill(2),day_month)], + ['date','>=','%s-%s-01'%(y,str(m).zfill(2))], + ['date','<=','%s-%s-%s'%(y,str(m).zfill(2),day_month)], ['location_to_id','=', department_id], ] cond=cond1+[['state','=','normal']] @@ -99,21 +90,34 @@ class PatientMove(Model): } return res - def auto_get_data(self, context={}): + def auto_get_data(self, date, department_id, context={}): user_id=get_active_user() set_active_user(1) + datenow=time.strftime("%Y-%m-%d") - date=context.get("date") if not date: raise Exception("Missing date!") + if not department_id: + raise Exception("Missing department!") + y,m,d=date.split("-") weekday, day_month=monthrange(int(y), int(m)) cond=[ - ['date','>=','%s-%s-01 00:00:00'%(y,m)], - ['date','<=','%s-%s-%s 23:59:59'%(y,m,day_month)], + ['date','>=','%s-%s-01'%(y,m)], + ['date','<=','%s-%s-%s'%(y,m,day_month)], + ['location_to_id','=',department_id], ] res=self.search(cond) + #XXX reset data + if res and date > datenow: + ids=self.search(cond) + print("reset data...") + print(ids) + self.delete(ids) + res=None + + # copy data from previous month if not res: y=int(y) @@ -124,8 +128,9 @@ class PatientMove(Model): weekday, day_month=monthrange(int(y), int(m)) cond=[ - ['date','>=','%s-%s-01 00:00:00'%(y,m)], - ['date','<=','%s-%s-%s 23:59:59'%(y,m,day_month)], + ['date','>=','%s-%s-01'%(y,m)], + ['date','<=','%s-%s-%s'%(y,m,day_month)], + ['location_to_id','=',department_id], ] res=self.search_browse(cond) for obj in res: @@ -166,14 +171,4 @@ class PatientMove(Model): set_active_user(user_id) - def create(self, vals, **kw): - new_id=super().create(vals,**kw) - self.function_store([new_id]) - return new_id - - def write(self, ids, vals, **kw): - super().write(ids, vals, **kw) - self.function_store(ids) - - PatientMove.register() diff --git a/netforce_clinic/models/report_hdcase_summary.py b/netforce_clinic/models/report_hdcase_summary.py index 3b989b8..6a2b1f1 100644 --- a/netforce_clinic/models/report_hdcase_summary.py +++ b/netforce_clinic/models/report_hdcase_summary.py @@ -30,12 +30,8 @@ class ReportHDCaseSummaryV2(Model): def get_report_data(self, ids, context={}): defaults=self.default_get(context=context) - month=defaults.get("month") - - y,m,d=month.split("-") - branch_id=defaults.get("branch_id") department_id=defaults.get("department_id") @@ -47,7 +43,7 @@ class ReportHDCaseSummaryV2(Model): y,m,d=month.split("-") #auto gen at the fist time of that month - get_model("clinic.patient.move").auto_get_data(context={'date': month}) + get_model("clinic.patient.move").auto_get_data(date=month, department_id=department_id) crr_month=m weekday, total_day=monthrange(int(y), int(m)) diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt index 5dd8b32..fc9be68 100644 --- a/netforce_clinic/todo.txt +++ b/netforce_clinic/todo.txt @@ -1,3 +1,10 @@ +move +new +dispose + +============== + + redesign print payment & invoice from hdcase - print payment - direct payment