diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml b/netforce_clinic/layouts/clinic_hd_case_form.xml index 8b2eb7d..55cb4cc 100644 --- a/netforce_clinic/layouts/clinic_hd_case_form.xml +++ b/netforce_clinic/layouts/clinic_hd_case_form.xml @@ -9,7 +9,7 @@ - + @@ -35,7 +35,7 @@ - + diff --git a/netforce_clinic/models/account_invoice.py b/netforce_clinic/models/account_invoice.py index 23bf609..e5a087b 100644 --- a/netforce_clinic/models/account_invoice.py +++ b/netforce_clinic/models/account_invoice.py @@ -63,6 +63,7 @@ class AccountInvoice(Model): total_amt=0.0 total_base=0.0 total_tax=0.0 + hdcase=obj.related_id for line in obj.lines: cur_amt=get_model("currency").convert(line.amount,obj.currency_id.id,settings.currency_id.id,date=obj.date,rate_type=rate_type) total_amt+=cur_amt @@ -92,6 +93,8 @@ class AccountInvoice(Model): "partner_id": partner.id, } lines.append(line_vals) + if hdcase: + pass for comp_id,tax_vals in taxes.items(): comp=get_model("account.tax.component").browse(comp_id) acc_id=comp.account_id.id @@ -162,6 +165,7 @@ class AccountInvoice(Model): else: line["debit"]=0 line["credit"]=-amt + amt=0 for line in group_lines: amt-=line["debit"]-line["credit"] diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index 8d90ce2..d8ad886 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -1,6 +1,6 @@ import time -from datetime import datetime +from datetime import datetime, timedelta from netforce.model import Model, fields, get_model from netforce.utils import get_data_path, get_file_path from netforce.access import get_active_user,set_active_user @@ -91,7 +91,7 @@ class HDCase(Model): "vascular_acc": fields.Many2One("clinic.vascular.access","Vascular Ac."), "bid_flow_rate": fields.Integer("BFR (ml/min)"), "ultrafittration": fields.Float("Ultrafiltration (kg.)"), - "hct": fields.Integer("Hct",required=True), + "hct": fields.Integer("Hct"), "hct_msg" : fields.Char(""), 'hct_include': fields.Boolean("HCT Include", function="_get_store", function_multi=True,store=True), 'type_code': fields.Char("Product Code", function="_get_store", function_multi=True,store=True), @@ -153,15 +153,15 @@ class HDCase(Model): "time_stop": lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"), 'number': '/', "company_id": lambda *a: get_active_company(), - 'wt_start': 0.0, - 'wt_stop': 0.0, - 'bp_start': '0/0', - 'bp_stop': '0/0', - "bid_flow_rate": 0.0, - "ultrafittration": 0.0, + #'wt_start': 0.0, + #'wt_stop': 0.0, + #'bp_start': '0/0', + #'bp_stop': '0/0', + #"bid_flow_rate": 0.0, + #"ultrafittration": 0.0, 'hd_acc': 'o', 'hd_mode': 'chronic', - 'hct': 0, + #'hct': 0, 'hct_msg': "สามารถเบิกค่ายาสูงสุดไม่เกิน 1,125บาท ต่อ สัปดาห์", 'invoice_option': 'fee', 'invoice_policy': 'fee', @@ -1031,6 +1031,40 @@ class HDCase(Model): break return vals + def get_hct(self,vals,patient_id): + fmt="%Y-%m-%d" + datenow=datetime.strptime(vals['time_start'][0:10],fmt) + wd=datenow.weekday() + date_week=[datenow.strftime(fmt)] + count=1 + res='' + for i in list(range(0,wd)): + if i < wd: + res=(datenow-timedelta(days=count)).strftime(fmt) + else: + res=(datenow+timedelta(days=count)).strftime(fmt) + date_week.append(res) + count+=1 + count=1 + for i in list(range(wd,6)): + if i < wd: + res=(datenow-timedelta(days=count)).strftime(fmt) + else: + res=(datenow+timedelta(days=count)).strftime(fmt) + date_week.append(res) + count+=1 + print("day week", date_week) + # search hct from monday to sunday + dom=[] + dom.append(['patient_id','=',patient_id]) + dom.append(['date', 'in',date_week]) + # 1. get date between weekend + # 2. if date out of dat gen set 0 else copy previous hct + for hdcase in self.search_browse(dom): + vals['hct']=hdcase.hct or 0 + #break + return vals + def create(self,vals,**kw): patient_id=vals['patient_id'] if 'vascular_acc' in vals.keys(): @@ -1039,6 +1073,7 @@ class HDCase(Model): 'vascular_acc': vals['vascular_acc'] }) vals=self.get_staff_line(vals,patient_id) + vals=self.get_hct(vals,patient_id) new_id=super().create(vals,**kw) self.function_store([new_id]) return new_id diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index 29d2c40..5c6fe35 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -198,7 +198,14 @@ class Patient(Model): if 'active' in vals.keys(): if not vals['active']: vals['resign_date']=time.strftime("%Y-%m-%d") + for obj in self.browse(ids): + if 'doctor_id' in vals.keys(): + for vs in get_model("clinic.visit").search_browse([['state','in',['draft','pending']],['patient_id','=',obj.id]]): + vs.write({ + 'doctor_id': vals['doctor_id'], + }) + 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 diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py index ef6a8d1..22f07d7 100644 --- a/netforce_clinic/models/setting.py +++ b/netforce_clinic/models/setting.py @@ -102,17 +102,17 @@ class ClinicSetting(Model): return True def run_script(self,ids,context={}): - user_id=get_active_user + user_id=get_active_user() if user_id !=1: print("Only admin!!") return - count=1 - for hd_case in get_model("clinic.hd.case").search_browse([]): - hd_case.write({ - 'patient_type_id': hd_case.patient_id.type_id.id, - }) - print(count, " update ", hd_case.patient_id.type_id.id) - count+=1 + for vs in get_model("clinic.visit").search_browse([['state','in', ['draft','pending']],['doctor_id','=',None]]): + doctor=vs.patient_id.doctor_id + if doctor: + vs.write({ + 'doctor_id': doctor.id, + }) + print("update visit.date ", vs.visit_date) print("Done! ") def reset_last_import(self,ids,context={}):