auto remove visit(pending) and remove the rest visit before make apt

conv_bal
watcha.h 2015-02-22 16:04:35 +07:00
parent c1bb614d1e
commit d68842e5a5
3 changed files with 24 additions and 15 deletions

View File

@ -8,11 +8,10 @@
<field name="number"/> <field name="number"/>
<field name="type" required="1"/> <field name="type" required="1"/>
<field name="name"/> <field name="name"/>
<field name="name_eng"/>
<field name="nick_name"/>
<field name="partner_id" domain='[["is_staff","=","true"]]'/>
<field name="branch_id" required="1"/> <field name="branch_id" required="1"/>
<field name="nick_name"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' required="1"/> <field name="department_id" domain='[["branch_id","=",branch_id]]' required="1"/>
<field name="name_eng"/>
<field name="company_id" invisible="1"/> <field name="company_id" invisible="1"/>
<tabs> <tabs>
<tab string="General"> <tab string="General">
@ -46,6 +45,9 @@
<field name="ot_per_cycle"/> <field name="ot_per_cycle"/>
<!--<field name="check_max_cycle"/>--> <!--<field name="check_max_cycle"/>-->
</tab> </tab>
<tab string="Accounting">
<field name="partner_id" domain='[["is_staff","=","true"]]'/>
</tab>
<tab string="Note"> <tab string="Note">
<field name="note" nolabel="1"/> <field name="note" nolabel="1"/>
</tab> </tab>

View File

@ -146,6 +146,8 @@ class MakeAPT(Model):
for line in obj.lines: for line in obj.lines:
patient=line.patient_id patient=line.patient_id
if not patient:
continue
dpt=line.department_id or patient.department_id dpt=line.department_id or patient.department_id
days=[] days=[]
if line.mon_cycle_id: if line.mon_cycle_id:
@ -176,6 +178,15 @@ class MakeAPT(Model):
cycle=line.sun_cycle_id cycle=line.sun_cycle_id
days.append([7,cycle,dpt]) days.append([7,cycle,dpt])
# remove the rest
dom=[]
dom.append(['visit_date','>=', obj.date_from])
dom.append(['visit_date','<=', (datetime.strptime(obj.date_to,FMT_DATE)+timedelta(days=14)).strftime(FMT_DATE)])
dom.append(['patient_id', '=', patient.id])
dom.append(['state','=','pending'])
vids=visit_obj.search(dom)
visit_obj.delete(vids)
ntoday=1 ntoday=1
day_total=(date_to-date_from).days+ntoday day_total=(date_to-date_from).days+ntoday
for weekday, cycle, department in days: for weekday, cycle, department in days:
@ -207,19 +218,17 @@ class MakeAPT(Model):
'visit_date': visit_date, 'visit_date': visit_date,
'state': 'pending', 'state': 'pending',
} }
visit_vals.append(vals)
count+=7
dom=[] dom=[]
dom.append(['time_start','>=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 00:00:00')]) dom.append(['time_start','>=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 00:00:00')])
dom.append(['time_stop','<=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 23:59:59')]) dom.append(['time_stop','<=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 23:59:59')])
dom.append(['patient_id', '=', patient.id]) dom.append(['patient_id', '=', patient.id])
dom.append(['cycle_id', '=', cycle.id]) dom.append(['cycle_id', '=', cycle.id])
dom.append(['state','=','pending']) dom.append(['state','in',['confirmed']])
vids=visit_obj.search(dom) vids=visit_obj.search(dom)
visit_obj.delete(vids) if not vids:
visit_vals.append(vals)
count+=7
start_date=tmp start_date=tmp
user_id=get_active_user() user_id=get_active_user()
staff_ids=get_model("clinic.staff").search([['type','=','type'],['user_id','=',user_id]]) staff_ids=get_model("clinic.staff").search([['type','=','type'],['user_id','=',user_id]])
confirm_id=None confirm_id=None

View File

@ -68,7 +68,7 @@ class Patient(Model):
"weight": fields.Float("Weight (kg.)"), "weight": fields.Float("Weight (kg.)"),
"height": fields.Float("Height (cm.)"), "height": fields.Float("Height (cm.)"),
"card_type": fields.Selection([("identification","Identification"),("passport","Passport")],"Card Type"), "card_type": fields.Selection([("identification","Identification"),("passport","Passport")],"Card Type"),
'card_no' : fields.Char("ID Card"), 'card_no' : fields.Char("Card ID"),
'card_exp' : fields.Date("Card Exp."), 'card_exp' : fields.Date("Card Exp."),
"app_no": fields.Char("Application No."), "app_no": fields.Char("Application No."),
"salary": fields.Selection([["20000","5,001-20,000"],["50000","20,001-50,000"],["100000","50,001-100,000"],["100001","100,000+"]], "Salary"), "salary": fields.Selection([["20000","5,001-20,000"],["50000","20,001-50,000"],["100000","50,001-100,000"],["100001","100,000+"]], "Salary"),
@ -213,6 +213,7 @@ class Patient(Model):
if 'active' in vals.keys(): if 'active' in vals.keys():
if not vals['active']: if not vals['active']:
vals['resign_date']=time.strftime("%Y-%m-%d") vals['resign_date']=time.strftime("%Y-%m-%d")
vals['rm_remain_visit']=True
for obj in self.browse(ids): for obj in self.browse(ids):
if 'doctor_id' in vals.keys(): if 'doctor_id' in vals.keys():
@ -221,8 +222,6 @@ class Patient(Model):
'doctor_id': vals['doctor_id'], 'doctor_id': vals['doctor_id'],
}) })
print("update doctor %s to patient %s"%(vals['doctor_id'], obj.name)) print("update doctor %s to patient %s"%(vals['doctor_id'], obj.name))
#if not obj.addresses:
#raise Exception("Address not found - %s!"%obj.name)
partner_id=obj.partner_id partner_id=obj.partner_id
if not partner_id: if not partner_id:
for partner in get_model("partner").search_browse([['name', '=', obj.name]]): for partner in get_model("partner").search_browse([['name', '=', obj.name]]):
@ -237,7 +236,6 @@ class Patient(Model):
'is_patient': True, 'is_patient': True,
}) })
vals['partner_id']=partner_id vals['partner_id']=partner_id
if not isinstance(partner_id,int): if not isinstance(partner_id,int):
partner_id=partner_id.id partner_id=partner_id.id
if obj.addresses: if obj.addresses:
@ -256,8 +254,8 @@ class Patient(Model):
}) })
del vals['addresses'] del vals['addresses']
print("create address for %s"%obj.name, ' ', addr_vals) print("create address for %s"%obj.name, ' ', addr_vals)
if obj.rm_remain_visit: if obj.rm_remain_visit or vals.get('rm_remain_visit'):
visit_ids=get_model('clinic.visit').search([['patient_id','=',obj.id],['state','=','draft']]) visit_ids=get_model('clinic.visit').search([['patient_id','=',obj.id],['state','in',('draft','pending')]])
get_model('clinic.visit').delete(visit_ids) get_model('clinic.visit').delete(visit_ids)
print('remove visit auto %s'%visit_ids) print('remove visit auto %s'%visit_ids)
self.function_store(ids) self.function_store(ids)