onchage dialyzer

conv_bal
watcha.h 2014-10-15 14:52:15 +07:00
parent dee373fb31
commit f4881e778a
7 changed files with 68 additions and 38 deletions

View File

@ -2,7 +2,7 @@
<field name="string">Treatments</field> <field name="string">Treatments</field>
<field name="view_cls">multi_view</field> <field name="view_cls">multi_view</field>
<field name="model">clinic.hd.case</field> <field name="model">clinic.hd.case</field>
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["In Progress",[["state","=","in_progress"]]],["Completed",[["state","=","completed"]]],["Uncompleted",[["state","=","uncompleted"]]]]</field> <field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["In Progress",[["state","=","in_progress"]]],["Completed",[["state","=","completed"]]],["In Completed",[["state","=","in_completed"]]]]</field>
<field name="modes">list,form</field> <field name="modes">list,form</field>
<field name="menu">clinic_menu</field> <field name="menu">clinic_menu</field>
</action> </action>

View File

@ -23,8 +23,8 @@
</group> </group>
<foot> <foot>
<button string="Confirm" type="success" states="new" method="confirm"/> <button string="Confirm" type="success" states="new" method="confirm"/>
<button string="Drop" type="danger" states="active" method="drop"/> <button string="Drop" type="danger" icon="remove" states="active" method="drop"/>
<button string="Renew" type="primary" states="active" method="renew"/> <button string="Renew" type="primary" icon="refresh" states="active" method="renew"/>
</foot> </foot>
<related> <related>
<field name="pickings" click_action="view_picking"/> <field name="pickings" click_action="view_picking"/>

View File

@ -27,10 +27,10 @@
<field name="per_bp_start"/> <field name="per_bp_start"/>
<field name="bp_stop"/> <field name="bp_stop"/>
<field name="per_bp_stop"/> <field name="per_bp_stop"/>
<field name="hct"/> <field name="hct" onchange="onchange_hct"/>
<field name="dialyzers" nolabel="1"> <field name="dialyzers" nolabel="1">
<list> <list>
<field name="dialyzer_id" domain="[['patient_id','=',parent.patient_id]]" onchange="onchange_dialyzer"/> <field name="dialyzer_id" domain="[['patient_id','=',parent.patient_id],['state','=','active']]" onchange="onchange_dialyzer"/>
<field name="description"/> <field name="description"/>
<field name="use_time"/> <field name="use_time"/>
<field name="max_use_time"/> <field name="max_use_time"/>
@ -89,9 +89,10 @@
</tab> </tab>
</tabs> </tabs>
<foot> <foot>
<button string="Confirm" type="success" method="confirm" states="draft"/> <button string="Do Treatment" type="success" icon="arrow-right" method="do_treatment" states="draft"/>
<button string="Complete" type="success" method="complete" states="in_progress"/> <button string="Complete" type="success" icon="ok" method="complete" states="in_progress"/>
<button string="Discontinue" type="danger" action="clinic_hd_case_distcont" states="in_progress"/> <button string="Discontinue" type="danger" icon="remove" action="clinic_hd_case_distcont" states="in_progress"/>
<button string="Undo" type="default" icon="refresh" method="undo" states="completed"/>
</foot> </foot>
<related> <related>
<field name="invoices" click_action="view_invoice"/> <field name="invoices" click_action="view_invoice"/>

View File

@ -152,6 +152,7 @@ class Dialyzer(Model):
for obj in self.browse(ids): for obj in self.browse(ids):
if obj.state != 'new': if obj.state != 'new':
raise Exception("Can not delete Dializer %s because state is not 'new'"%obj.number) raise Exception("Can not delete Dializer %s because state is not 'new'"%obj.number)
super().delete(ids)
def cancel(self,ids,context={}): def cancel(self,ids,context={}):
obj=self.browse(ids[0]) obj=self.browse(ids[0])

View File

@ -1,5 +1,5 @@
import time import time
from datetime import datetime, timedelta from datetime import datetime
from netforce.model import Model, fields, get_model from netforce.model import Model, fields, get_model
from netforce.utils import get_data_path from netforce.utils import get_data_path
@ -43,9 +43,8 @@ class HDcase(Model):
"hct": fields.Integer("HCT %", required=True), "hct": fields.Integer("HCT %", required=True),
"check_goverment_pay" : fields.Boolean("The Government Pay"), "check_goverment_pay" : fields.Boolean("The Government Pay"),
"check_personal_pay" : fields.Boolean("Pay yourself"), "check_personal_pay" : fields.Boolean("Pay yourself"),
"state": fields.Selection([("draft","Draft"),("confirmed","Confirmed"),("approved","Approved"),("cancelled","Cancelled"),("paid","Paid")],"Status",required=True), "hct": fields.Integer("HCT %(>39)"),
"hct": fields.Integer("HCT %"), "state": fields.Selection([("draft","Draft"),("in_progress","In Progress"),("completed","Completed"),("discountinued","Discountinued"),("in_completed","In completed")],"Status",required=True),
"state": fields.Selection([("draft","Draft"),("in_progress","In Progress"),("completed","Completed"),("discountinued","Discountinued"),("uncompleted","Uncompleted")],"Status",required=True),
"dialyzers": fields.One2Many("clinic.dialyzer.line","hd_case_id","Dialyzers"), "dialyzers": fields.One2Many("clinic.dialyzer.line","hd_case_id","Dialyzers"),
"lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"), "lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"),
"gm_lines": fields.One2Many("clinic.hd.case.gm.line","hd_case_id","GM Lines"), "gm_lines": fields.One2Many("clinic.hd.case.gm.line","hd_case_id","GM Lines"),
@ -109,8 +108,16 @@ class HDcase(Model):
if not dialyzer_id: if not dialyzer_id:
return {} return {}
dialyzer=get_model("clinic.dialyzer").browse(dialyzer_id) dialyzer=get_model("clinic.dialyzer").browse(dialyzer_id)
use_time=dialyzer.use_time or 0
max_time=dialyzer.max_use_time or 0
if use_time > max_time:
dialyzer.write({
'state': 'expire',
})
raise Exception("%s is expired"%dialyzer.number)
use_time+=1
line["description"]=dialyzer.description or "" line["description"]=dialyzer.description or ""
line["use_time"]=dialyzer.use_time line["use_time"]=use_time
line["max_use_time"]=dialyzer.max_use_time line["max_use_time"]=dialyzer.max_use_time
line["member_type"]=dialyzer.member_type line["member_type"]=dialyzer.member_type
line["dialyzer_type"]=dialyzer.dialyzer_type line["dialyzer_type"]=dialyzer.dialyzer_type
@ -165,11 +172,11 @@ class HDcase(Model):
return data return data
def onchange_hct(self,context={}): def onchange_hct(self,context={}):
data=context['hct'] data=context['data']
hct=data['hct'] hct=data['hct']
if(hct<=39): if(hct<=39):
raise Exception("Unit not found in uom") data['hct']=0
return data
def cancelled(self,ids,context={}): def cancelled(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
@ -209,7 +216,6 @@ class HDcase(Model):
def make_payment(self,ids,context={}): def make_payment(self,ids,context={}):
pass pass
def make_invoices(self,ids,context={}): def make_invoices(self,ids,context={}):
setting=get_model("settings").browse(1) setting=get_model("settings").browse(1)
currency_id=setting.currency_id.id currency_id=setting.currency_id.id
@ -356,21 +362,31 @@ class HDcase(Model):
inv.post() inv.post()
print("Post!") print("Post!")
def confirm(self,ids,context={}): def do_treatment(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
if not obj.dialyzers:
raise Exception("Can not do treatment without dialyzer!")
obj.write({"state":"in_progress"}) obj.write({"state":"in_progress"})
def discontinue(self,ids,context={}): def discontinue(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
# TODO pop to note # TODO pop to note
obj.write({"state":"uncompleted"}) obj.write({"state":"in_completed"})
def update_usetime(self,ids,context={}):
for obj in self.browse(ids):
for dlz_line in obj.dialyzers:
dlz=dlz_line.dialyzer_id
dlz.write({
'use_time': dlz_line.use_time,
})
return True
def complete(self,ids,context={}): def complete(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
if not obj.dialyzers:
raise Exception("Please enter dialyzer!")
obj.make_invoices() obj.make_invoices()
obj.post_invoices() obj.post_invoices()
obj.update_usetime()
obj.write({ obj.write({
"state":"completed", "state":"completed",
}) })
@ -443,4 +459,29 @@ class HDcase(Model):
data['fee']=0.0 data['fee']=0.0
return data return data
def undo(self,ids,context={}):
obj=self.browse(ids)[0]
for inv in obj.invoices:
inv.write({
'state': 'draft',
})
inv.delete()
for pick in obj.pickings:
pick.write({
'state': 'draft',
})
pick.delete()
obj.write({
'state': 'draft',
})
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': obj.id,
},
'flash': '%s has been undo'%obj.number,
}
HDcase.register() HDcase.register()

View File

@ -53,21 +53,7 @@ class ImportPayment(Model):
} }
def load_data(self,ids,context): def load_data(self,ids,context):
records=[1,2,] pass
del records[0]
fmt1="%y-%m-%d"
fmt2="%Y-%m-%d"
for record in records:
row=record.split(",")
doc_date=row[0]
if doc_date:
#'%m/%d/%y
pt="(\d+)/(\d+)/(\d+)"
res=re.search(pt,doc_date)
if res:
doc_date="%s-%s-%s" % (res.group(3),res.group(1),res.group(2))
newdate=datetime.strptime(doc_date,fmt1)
print(newdate.strftime(fmt2))
def load_sheet(self,ids,context={}): def load_sheet(self,ids,context={}):
obj=self.browse(ids[0]) obj=self.browse(ids[0])

View File

@ -112,8 +112,9 @@ class Visit(Model):
'lines':[], 'lines':[],
'gm_lines':[], 'gm_lines':[],
'dialyzers': [], 'dialyzers': [],
'state': 'in_progress', 'state': 'draft',
} }
products=get_model("product").search_browse([['code','=','FEE']]) products=get_model("product").search_browse([['code','=','FEE']])
for product in products: for product in products:
vals['gm_lines'].append(('create',{ vals['gm_lines'].append(('create',{