from netforce.model import Model, fields, get_model from netforce.utils import get_file_path, get_data_path from netforce.access import get_active_company from netforce.database import get_connection class ClinicSetting(Model): _name="clinic.setting" _string="Setting" _fields={ "var_k": fields.Float("K"), 'file': fields.File("File"), 'levels': fields.One2Many("clinic.setting.level","setting_id","Levels"), 'products': fields.One2Many("clinic.setting.product","setting_id","Products"), 'invoice_policies': fields.One2Many("clinic.setting.policy","setting_id","Invoice Policies"), 'cost_per_case': fields.Float("Cost Per Case"), 'company_id': fields.Many2One("company", 'Company'), 'period_id': fields.Many2One("clinic.period","Period"), 'waiting_approval': fields.Boolean("Waiting Approval"), # HD Case 'real_time': fields.Boolean("Real Time"), # HD Case 'patient_type_id': fields.Many2One("clinic.patient.type","Default Type"), # Import payment 'imp_patient_type_id': fields.Many2One("clinic.patient.type","Import UC Type"), # Import payment 'find_dlz': fields.Boolean("Find Dialyzer After Confirm Visit"), # Visit 'stock_journal_id': fields.Many2One("stock.journal","Default Journal"), 'auto_gen': fields.Boolean("Auto Gen"), # HD Case 'schd_from': fields.Date("From"), 'schd_to': fields.Date("To"), 'department_id': fields.Many2One("clinic.department","Department"), 'branch_id': fields.Many2One("clinic.branch","Branch"), } _defaults={ "company_id": lambda *a: get_active_company(), } def onchange_line(self,context={}): data=context['data'] path=context['path'] line=get_data_path(data,path,parent=True) var_a=line['var_a'] or '' var_b=line['var_b'] or '' op=line['op'] or '' line['formular']='%sX%s%s'%(var_a,op,var_b) return data def onchange_product(self,context={}): data=context['data'] path=context['path'] line=get_data_path(data,path,parent=True) product_id=line['product_id'] if product_id: prod=get_model("product").browse(product_id) uom=prod.uom_id if not uom: uom=get_model("uom").browse(1) if not uom: raise Exception("Not found uom 'Unit'") line['uom_id']=uom.id line['description']=prod.name price=prod.sale_price or 0.0 line['price']=price categ=prod.categ_id if categ: line['product_categ_id']=categ.id qty=1 amt=qty*price line['amount']=amt return data def onchange_setting_line(self,context={}): data=context['data'] path=context['path'] line=get_data_path(data,path,parent=True) qty=line['qty'] or 0 price=line['price'] or 0 amt=qty*price line['amount']=amt return data def schd_confirm(self,ids,context={}): obj=self.browse(ids)[0] if not obj.schd_from: raise Exception("No date from") if not obj.schd_to: raise Exception("No date to") dom=[] dom.append(['date', '>=', obj.schd_from]) dom.append(['date', '<=', obj.schd_to]) for schd in get_model('clinic.schedule').search_browse(dom): schd.confirm() return True def run_script(self,ids,context={}): db=get_connection() db.execute(""" update clinic_branch set active=True; update clinic_department set active=True; """) print("Done!") return obj=self.browse(ids)[0] ################ update sickbed ############# #sickbed: update department for sb in get_model('clinic.sickbed').search_browse([]): hdcs=sorted(sb.hd_cases, key=lambda a: a.id) if hdcs: hdc=hdcs[0] #patient=hdc.patient_id sb.write({ 'department_id': hdc.department_id.id, }) #print("Done!") #return ############################################# ############### cycle item for lc in get_model('clinic.labor.cost').search_browse([]): lc.delete() db=get_connection() res=db.query(""" select cycle_item_id, nurse_id, level_id from clinic_cycle_item_nurse """) for rs in res: item_id=rs['cycle_item_id'] nid=rs['nurse_id'] lid=rs['level_id'] if item_id: item=get_model('clinic.cycle.item').browse(item_id) item.write({ 'lines': [('create',{'nurse_id': nid, 'level_id': lid})], }) print('update ', item.name) item.validate() if item.department_id: print("update department for nurse", nid) get_model("clinic.staff").browse(nid).write({ 'department_id': item.department_id.id, }) #return ############################################# print("Done!") def reset_last_import(self,ids,context={}): res=get_model("clinic.report.payment.matching").search_read([],['date'],order="date desc") if res: db=get_connection() res1=res[0] date1='%s 00:00:00'%res1['date'] date2='%s 23:59:59'%res1['date'] exp_ids=[x['id'] for x in db.query("select id from clinic_hd_case_expense where write_time>=%s and write_time<=%s",date1,date2)] for exp in get_model("clinic.hd.case.expense").browse(exp_ids): exp.write({ 'state': 'waiting_matching', 'ok': False, }) for inv in exp.invoices: payment=inv.payment_id if payment: if payment.state !='draft': payment.to_draft() print("to draft payment ", payment.id) print("Done") ClinicSetting.register()