206 lines
8.6 KiB
Python
206 lines
8.6 KiB
Python
from netforce.model import Model, fields, get_model
|
|
from netforce.utils import get_data_path
|
|
import time
|
|
from netforce.access import get_active_user,set_active_user
|
|
from netforce.access import get_active_company
|
|
|
|
class HDcase(Model):
|
|
_name="clinic.hd.case"
|
|
_string="HD Case Treatment"
|
|
_audit_log=True
|
|
_name_field="number"
|
|
_multi_company=True
|
|
_fields={
|
|
"number": fields.Char("Number",required=True,search=True),
|
|
"patient_id": fields.Many2One("clinic.patient","Patients",required=True,search=True),
|
|
"doctor_id": fields.Many2One("clinic.doctor","Doctor",search=True),
|
|
"nurse_id": fields.Many2One("clinic.nurse","Nurse",search=True),
|
|
"date_start": fields.DateTime("Date start",required=True,search=True),
|
|
"date_stop": fields.DateTime("Date stop",required=True,search=True),
|
|
"department": fields.Char("Department",required=False,search=True),
|
|
"wh_start": fields.Float("Wt.Kg start",required=True,search=True),
|
|
"wh_stop": fields.Float("Wt.Kg stop",required=True,search=True),
|
|
"bp_start": fields.Integer("BP mmHG start",required=True,search=True),
|
|
"per_bp_start": fields.Integer("/Per start",required=True,search=True),
|
|
"bp_stop": fields.Integer("BP mmHG stop",required=True,search=True),
|
|
"per_bp_stop": fields.Integer("/Per stop",required=True,search=True),
|
|
"hct": fields.Integer("HCT %",required=True,search=True),
|
|
"state": fields.Selection([("draft","Draft"),("approved","Approved"),("confirmed","Confirmed"),("validate","Validate"),("canceled","Canceled"),("payment","Payment")],"Status",required=True),
|
|
"lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Details"),
|
|
"lines_detail": fields.One2Many("clinic.hd.case.line.detail","hd_case_id","Detail"),
|
|
"comments": fields.One2Many("message","related_id","Comments"),
|
|
"company_id": fields.Many2One("company","Company"),
|
|
"fee": fields.Float("Fee",required=True),
|
|
"amount": fields.Float("Amount",function="get_total",readonly=True,function_multi=True),
|
|
"total": fields.Float("Total",function="get_total",readonly=True,function_multi=True),
|
|
"reconcile_id": fields.Many2One("account.reconcile","Reconcile Id",readonly=True),
|
|
}
|
|
|
|
def _get_number(self,context={}):
|
|
while 1:
|
|
num=get_model("sequence").get_number("sale_order")
|
|
if not num:
|
|
return None
|
|
res=self.search([["number","=",num]])
|
|
if not res:
|
|
return num
|
|
get_model("sequence").increment("sale_order")
|
|
|
|
def onchange_dialyzer(self,context={}):
|
|
data=context["data"]
|
|
path=context["path"]
|
|
line=get_data_path(data,path,parent=True)
|
|
dialyzer_id=line.get("dialzer_id")
|
|
if not dialyzer_id:
|
|
return {}
|
|
dialyzer=get_model("clinic.dialyzer").browse(dialyzer_id)
|
|
line["detail"]=dialyzer.detail
|
|
line["use_time"]=dialyzer.use_time
|
|
line["max_use_time"]=dialyzer.max_use_time
|
|
line["member_type"]=dialyzer.member_type
|
|
line["dialyzer_type"]=dialyzer.dialyzer_type
|
|
line["bid_flow_rate"]=dialyzer.bid_flow_rate
|
|
line["ultrafittration"]=dialyzer.ultrafittration
|
|
line["state"]=dialyzer.state
|
|
return data
|
|
|
|
_defaults={
|
|
"state": "draft",
|
|
"date_start": lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
|
"date_stop": lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
|
|
"number": _get_number,
|
|
"company_id": lambda *a: get_active_company(),
|
|
"fee": 1500,
|
|
}
|
|
_order="date_start desc,number desc"
|
|
|
|
|
|
|
|
def canceled(self,ids,context={}):
|
|
obj=self.browse(ids)[0]
|
|
obj.write({"state":"canceled"})
|
|
|
|
def confirmed(self,ids,context={}):
|
|
obj=self.browse(ids)[0]
|
|
obj.write({"state":"confirmed"})
|
|
|
|
def payment(self,ids,context={}):
|
|
obj=self.browse(ids)[0]
|
|
obj.write({"state":"payment"})
|
|
|
|
def approved(self,ids,context={}):
|
|
for obj in self.browse(ids):
|
|
user_id=get_active_user()
|
|
try:
|
|
set_active_user(1)
|
|
settings=get_model("clinic.setting").browse(1)
|
|
reconcile_id=get_model("account.reconcile").create({})
|
|
if obj.patient_id.type == 'mg':
|
|
vals={
|
|
"narration": obj.number,
|
|
"lines": [
|
|
("create",{
|
|
"description": obj.number,
|
|
"account_id": settings.ar_mg_id.id,
|
|
"debit": obj.amount,
|
|
"credit": 0,
|
|
"partner_id": settings.mg_partner_id.id,
|
|
"due_date": obj.date,
|
|
"reconcile_id":reconcile_id,
|
|
}),
|
|
("create",{
|
|
"description": obj.number,
|
|
"account_id": settings.ap_mg_id.id,
|
|
"debit": 0,
|
|
"credit": obj.amount,
|
|
}),
|
|
],
|
|
"state": "posted",
|
|
"date_posted": obj.date,
|
|
"date": obj.date,
|
|
}
|
|
get_model("account.move").create(vals)
|
|
elif obj.patient_id.type == 'sc':
|
|
vals={
|
|
"narration": obj.number,
|
|
"lines": [
|
|
("create",{
|
|
"description": obj.number,
|
|
"account_id": settings.ar_sc_id.id,
|
|
"debit": obj.amount,
|
|
"credit": 0,
|
|
"partner_id": settings.sc_partner_id.id,
|
|
"due_date": obj.date,
|
|
"reconcile_id":reconcile_id,
|
|
}),
|
|
("create",{
|
|
"description": obj.number,
|
|
"account_id": settings.ap_sc_id.id,
|
|
"debit": 0,
|
|
"credit": obj.amount,
|
|
}),
|
|
],
|
|
"state": "posted",
|
|
"date_posted": obj.date,
|
|
"date": obj.date,
|
|
}
|
|
get_model("account.move").create(vals)
|
|
elif obj.patient_id.type == 'nhso':
|
|
vals={
|
|
"narration": obj.number,
|
|
"lines": [
|
|
("create",{
|
|
"description": obj.number,
|
|
"account_id": settings.ar_nhso_id.id,
|
|
"debit": obj.amount,
|
|
"credit": 0,
|
|
"partner_id": settings.nhso_partner_id.id,
|
|
"due_date": obj.date,
|
|
"reconcile_id":reconcile_id,
|
|
}),
|
|
("create",{
|
|
"description": obj.number,
|
|
"account_id": settings.ap_nhso_id.id,
|
|
"debit": 0,
|
|
"credit": obj.amount,
|
|
}),
|
|
],
|
|
"state": "posted",
|
|
"date_posted": obj.date,
|
|
"date": obj.date,
|
|
}
|
|
get_model("account.move").create(vals)
|
|
finally:
|
|
set_active_user(user_id)
|
|
obj.write({"state":"approved","reconcile_id":reconcile_id})
|
|
|
|
def journal_report(self,ids,context={}):
|
|
obj=self.browse(ids[0])
|
|
move_id = get_model("account.move").search([["narration","=",obj.number]])
|
|
if not move_id:
|
|
raise Exception("Order is not post or nove have jounal entry.")
|
|
return {
|
|
"next": {
|
|
"name": "journal_entry",
|
|
"mode":"form",
|
|
"active_id":move_id[0],
|
|
}
|
|
}
|
|
|
|
def get_total(self,ids,context={}):
|
|
vals={}
|
|
for obj in self.browse(ids):
|
|
total=0
|
|
amt=0
|
|
fee=obj.fee
|
|
for line in obj.lines_detail:
|
|
total+=line.total
|
|
amt=total+fee
|
|
vals[obj.id]={
|
|
"total": total,
|
|
"amount": amt,
|
|
}
|
|
return vals
|
|
|
|
HDcase.register()
|