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 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 } _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 update_date(self,ids,context={}): for inv in get_model("account.invoice").search_browse([]): amount_total=0 for line in inv.lines: amount_total+=line.amount inv.write({ 'amount_total': amount_total, 'amount_due': amount_total, }) print("Done!") #for hd_case in get_model("clinic.hd.case").search_browse([]): #if hd_case.state!='waiting_treatment': #continue #for line in hd_case.lines: #categ=line.product_categ_id #if categ: #if categ.code=='SRV': #line.delete() #for vs in get_model("clinic.visit").search_browse([]): #if vs.state=='pending': #vs.confirm() #print(vs.number) #obj=self.browse(ids)[0] #for hd_case in get_model("clinic.hd.case").search_browse([]): #number='/' #if hd_case.number=='/': #number=get_model("clinic.hd.case")._get_number() #if hd_case.state=='waiting_treatment': #hd_case.complete() #date,time=hd_case.time_start.split(" ") #hd_case.write({ #'date': date, #'number': number, #}) #for inv in hd_case.invoices: #inv.write({ #'date': date, #'due_date': date, #}) #for pick in hd_case.pickings: #pick.write({ #'date': date, #}) #for exp in get_model('clinic.hd.case.expense').search_browse([]): #exp.write({ #'date': exp.hd_case_id.date, #}) #print('done') ClinicSetting.register()