129 lines
4.9 KiB
Python
129 lines
4.9 KiB
Python
from netforce.model import Model, fields, get_model
|
|
|
|
class HDCasePopupDlz(Model):
|
|
_name="clinic.hd.case.popup.dlz"
|
|
_transient=True
|
|
|
|
_fields={
|
|
"hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"),
|
|
'product_id': fields.Many2One("product", "Product",required=False),
|
|
'new_product': fields.Char("New Product"),
|
|
"dialyzer_type": fields.Selection([("low","low flux"),("high","high flux"),("dbl","dbl hifulx")],"Dialyzer Type"),
|
|
"max_use_time": fields.Integer("Max Use Time"),
|
|
"exp_date": fields.Date("Expiry Date"),
|
|
"note": fields.Text("Note"),
|
|
"membrane_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Membrane Type"),
|
|
'drop_old': fields.Boolean("Drop Old Dialyzer"),
|
|
}
|
|
|
|
def __get_hd_case_id(self,context={}):
|
|
hd_case_id=context.get("refer_id")
|
|
print("clinic.hd.case.popup.dlz default")
|
|
if not hd_case_id:
|
|
return None
|
|
return int(hd_case_id)
|
|
|
|
def default_get(self,field_names=None,context={},**kw):
|
|
defaults=context.get("defaults",{})
|
|
hdcase_id=defaults.get('hd_case_id')
|
|
dialyzer_type=defaults.get('dialyzer_type', "low")
|
|
membrane_type=defaults.get('membrane_type', "unsub")
|
|
product_id=defaults.get('product_id', None)
|
|
max_use_time=defaults.get('max_use_time', 10)
|
|
if not hdcase_id:
|
|
hdcase_id=context.get("refer_id")
|
|
if hdcase_id:
|
|
hdcase_id=int(hdcase_id)
|
|
hdcase=get_model('clinic.hd.case').browse(hdcase_id)
|
|
for line in hdcase.dialyzers:
|
|
dlz=line.dialyzer_id
|
|
product_id=dlz.product_id.id
|
|
dialyzer_type=dlz.dialyzer_type or "low"
|
|
membrane_type=dlz.membrane_type or "unsub"
|
|
max_use_time=dlz.max_use_time or 10
|
|
res={
|
|
'hd_case_id': hdcase_id,
|
|
'dialyzer_type': dialyzer_type,
|
|
'membrane_type': membrane_type,
|
|
'max_use_time': max_use_time,
|
|
'product_id': product_id,
|
|
'drop_old': True,
|
|
}
|
|
print('dlz.res', res)
|
|
return res
|
|
|
|
def new_dlz(self,ids,context={}):
|
|
obj=self.browse(ids)[0]
|
|
hd_case=obj.hd_case_id
|
|
res={}
|
|
if hd_case:
|
|
context['is_wiz']=True
|
|
context['pop_id']=obj.id
|
|
context['drop_old']=obj.drop_old
|
|
if obj.new_product:
|
|
name=obj.new_product
|
|
uom_id=None
|
|
for r_id in get_model("uom").search([['name','=','Unit']]):
|
|
uom_id=r_id
|
|
if not uom_id:
|
|
raise Exception("Missing UoM <Unit>!")
|
|
categ_id=None
|
|
for r_id in get_model("product.categ").search([['code','=','DLZ']]):
|
|
categ_id=r_id
|
|
if not categ_id:
|
|
raise Exception("Missing Product category code DLZ!")
|
|
new_prod_id=get_model("product").create({
|
|
'type': 'stock',
|
|
'code': name.upper(),
|
|
'name': name,
|
|
'description': name,
|
|
"uom_id": uom_id,
|
|
'categ_id': categ_id,
|
|
'can_sell': True,
|
|
'can_purchase': True,
|
|
})
|
|
obj.write({
|
|
'product_id': new_prod_id,
|
|
})
|
|
if not obj.product_id:
|
|
raise Exception("Missing product!")
|
|
res=hd_case.new_dialyzer(context=context)
|
|
return res
|
|
|
|
def onchange_product(self,context={}):
|
|
data=context['data']
|
|
hdcase_id=data['hd_case_id']
|
|
patient=None
|
|
if hdcase_id:
|
|
hdcase=get_model('clinic.hd.case').browse(hdcase_id)
|
|
patient=hdcase.patient_id
|
|
product_id=data['product_id']
|
|
data['membrane_type']=None
|
|
data['dialyzer_type']=None
|
|
data['max_use_time']=10
|
|
dom=[]
|
|
if patient:
|
|
dom.append(['patient_id','=',patient.id])
|
|
count=0
|
|
for dlz in get_model("clinic.dialyzer").search_browse(dom):
|
|
prod=dlz.product_id
|
|
if prod.id==product_id:
|
|
count+=1
|
|
data['membrane_type']=dlz.membrane_type
|
|
data['dialyzer_type']=dlz.dialyzer_type or "low"
|
|
data['max_use_time']=dlz.max_use_time or 10
|
|
break
|
|
# search from another patient
|
|
if not count:
|
|
dom=[]
|
|
for dlz in get_model("clinic.dialyzer").search_browse(dom):
|
|
prod=dlz.product_id
|
|
if prod.id==product_id:
|
|
data['membrane_type']=dlz.membrane_type
|
|
data['dialyzer_type']=dlz.dialyzer_type or "low"
|
|
data['max_use_time']=dlz.max_use_time or 10
|
|
break
|
|
return data
|
|
|
|
HDCasePopupDlz.register()
|