diff --git a/netforce_clinic/actions/clinic_hd_case.xml b/netforce_clinic/actions/clinic_hd_case.xml
index e6f021c..43c34eb 100644
--- a/netforce_clinic/actions/clinic_hd_case.xml
+++ b/netforce_clinic/actions/clinic_hd_case.xml
@@ -2,7 +2,7 @@
Treatments
multi_view
clinic.hd.case
- [["All",[]],["Draft",[["state","=","draft"]]],["In Progress",[["state","=","in_progress"]]],["Completed",[["state","=","completed"]]],["In Completed",[["state","=","in_completed"]]]]
+ [["All",[]],["Draft",[["state","=","draft"]]],["In Progress",[["state","=","in_progress"]]],["Waiting Payment",[["state","=","waiting_payment"]]],["Completed",[["state","=","completed"]]],["In Completed",[["state","=","in_completed"]]]]
list,form
clinic_menu
diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml b/netforce_clinic/layouts/clinic_hd_case_form.xml
index 758fa25..03239c5 100644
--- a/netforce_clinic/layouts/clinic_hd_case_form.xml
+++ b/netforce_clinic/layouts/clinic_hd_case_form.xml
@@ -58,11 +58,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -96,13 +96,30 @@
-
-
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/netforce_clinic/layouts/clinic_payment_form.xml b/netforce_clinic/layouts/clinic_payment_form.xml
index 850141c..b357b57 100644
--- a/netforce_clinic/layouts/clinic_payment_form.xml
+++ b/netforce_clinic/layouts/clinic_payment_form.xml
@@ -1,10 +1,14 @@
diff --git a/netforce_clinic/layouts/clinic_report_hd_dialy.xml b/netforce_clinic/layouts/clinic_report_hd_dialy.xml
deleted file mode 100644
index b2eeb23..0000000
--- a/netforce_clinic/layouts/clinic_report_hd_dialy.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py
index 3a89dc2..7d9b480 100644
--- a/netforce_clinic/models/hd_case.py
+++ b/netforce_clinic/models/hd_case.py
@@ -6,7 +6,7 @@ from netforce.utils import get_data_path
from netforce.access import get_active_user,set_active_user
from netforce.access import get_active_company
-class HDcase(Model):
+class HDCase(Model):
_name="clinic.hd.case"
_string="Treatment"
_audit_log=True
@@ -50,7 +50,7 @@ class HDcase(Model):
"hct_msg" : fields.Char("HCT message"),
"check_goverment_pay" : fields.Boolean("The Government Pay"),
"check_personal_pay" : fields.Boolean("Pay yourself"),
- "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"),("waiting_payment","Waiting Payment"),("discountinued","Discountinued"),("in_completed","In completed")],"Status",required=True),
"dialyzers": fields.One2Many("clinic.dialyzer.line","hd_case_id","Dialyzers"),
"lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"),
"comments": fields.One2Many("message","related_id","Comments"),
@@ -64,9 +64,9 @@ class HDcase(Model):
"payment_lines": fields.One2Many("clinic.payment","hd_case_id","Payment Lines"),
'visit_id': fields.Many2One("clinic.visit", "Visit"),
'duration': fields.Integer("Duration (hrs)",function="get_hrs"),
- "fee_type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)"),("personal","Personal"),("others","Others")],"Fee Type"),
'fee_partner_id': fields.Many2One("partner","Contact Fee"),
"fee_amount": fields.Float("Fee",function="get_total",readonly=True,function_multi=True),
+ 'fee_paid': fields.Boolean("Fee Paid"),
'note': fields.Text("Note"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
'pay_amount': fields.Float("Amount",function="get_pay_amount"),
@@ -106,10 +106,10 @@ class HDcase(Model):
"company_id": lambda *a: get_active_company(),
'hct': 0,
'hct_msg': "Reimbursement of medicines : 1,125/Week",
+ 'fee_paid': False,
}
_order="date desc,number desc"
-
def onchange_dialyzer(self,context={}):
data=context["data"]
path=context["path"]
@@ -175,8 +175,6 @@ class HDcase(Model):
price=line.get('price') or 0
qty=line.get('qty') or 0
amt=qty * price
- #product_id=line.get("product_id")
- #if product_id:
line['amount']=amt
if line['type']=='fee':
fee_amt+=amt
@@ -188,9 +186,9 @@ class HDcase(Model):
for line in data['payment_lines']:
total-=line['amount'] or 0.0
data['amount']=total
- if not data['pay_date']:
+ if not data.get('pay_date'):
data['pay_date']=time.strftime("%Y-%m-%d")
- if not data['pay_account_id']:
+ if not data.get('pay_account_id'):
patient_id=data['patient_id']
if patient_id:
patient=get_model("clinic.patient").browse(patient_id)
@@ -297,7 +295,8 @@ class HDcase(Model):
raise Exception("Unit not found in uom")
obj=self.browse(ids[0])
due_date=obj.date[0:10]
-
+ # cash, credit
+ make_invoice=context.get('make_invoice',True)
context['type']='out'
context['inv_type']='invoice'
fee_lines=[]
@@ -337,12 +336,12 @@ class HDcase(Model):
else:
vals['lines'].append(('create',inv_line))
- if obj.amount: ## not pay yet
+ if obj.amount and make_invoice: ## not pay yet
inv_id=get_model("account.invoice").create(vals,context)
# create picking
obj.make_pickings()
-
- if fee_lines:
+
+ if fee_lines and not obj.fee_paid:
vals={
"type": "out",
"inv_type": "invoice",
@@ -356,8 +355,6 @@ class HDcase(Model):
"company_id": company_id,
}
vals["partner_id"]=obj.fee_partner_id.id
- #XXX
-
account_id=account_receivable_id
patient_type=obj.patient_id.type
if patient_type=='mg':
@@ -371,6 +368,9 @@ class HDcase(Model):
fee_line['account_id']=account_id
vals['lines'].append(('create',fee_line))
inv_id=get_model("account.invoice").create(vals,context)
+ obj.write({
+ 'fee_paid': True,
+ })
def make_pickings(self,ids,context={}):
obj=self.browse(ids[0])
@@ -514,16 +514,6 @@ class HDcase(Model):
if obj.state != 'draft':
raise Exception("Can not delete HD Case %s because state is not draft"%obj.number)
super().delete(ids)
-
- def onchange_fee_type(self,context={}):
- data=context['data']
- fee_type=data.get("fee_type","")
- if fee_type in ("mg","sc","nhso"):
- data['fee']=1500
- else:
- data['fee']=0.0
- return data
-
def onchange_hct(self,context={}):
data=context['data']
@@ -560,6 +550,7 @@ class HDcase(Model):
obj.write({
'state': 'in_progress',
+ 'fee_paid': False,
})
return {
'next': {
@@ -579,5 +570,11 @@ class HDcase(Model):
'active_id': ids[0],
},
}
+
+ def done(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ obj.write({
+ 'state': 'waiting_payment',
+ })
-HDcase.register()
+HDCase.register()
diff --git a/netforce_clinic/models/hd_case_discont.py b/netforce_clinic/models/hd_case_discont.py
index b746913..1e05c27 100644
--- a/netforce_clinic/models/hd_case_discont.py
+++ b/netforce_clinic/models/hd_case_discont.py
@@ -24,7 +24,7 @@ class HDCaseDiscont(Model):
hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
hd_case.write({
'note': obj.note,
- 'state': 'uncompleted',
+ 'state': 'in_completed',
})
return {
'next': {
diff --git a/netforce_clinic/models/hd_case_payment.py b/netforce_clinic/models/hd_case_payment.py
index f63457a..809a0bb 100644
--- a/netforce_clinic/models/hd_case_payment.py
+++ b/netforce_clinic/models/hd_case_payment.py
@@ -6,7 +6,10 @@ class HDCasePayment(Model):
_fields={
"hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"),
- "pay_amount": fields.Float("Amount"),
+ "pay_amount": fields.Float("Due Amount"),
+ "fee": fields.Float("Fee"),
+ "to_pay": fields.Float("To Pay"),
+ "complete": fields.Boolean("Complete"),
}
def _get_hd_case_id(self,context={}):
@@ -20,34 +23,71 @@ class HDCasePayment(Model):
hd_case=get_model("clinic.hd.case").browse(hd_case_id)
return hd_case.amount
+ def _get_fee(self,context={}):
+ hd_case_id=context.get("refer_id")
+ hd_case=get_model("clinic.hd.case").browse(hd_case_id)
+ return hd_case.fee_amount
+
+ def _get_topay(self,context={}):
+ hd_case_id=context.get("refer_id")
+ hd_case=get_model("clinic.hd.case").browse(hd_case_id)
+ return hd_case.amount
+
_defaults={
'hd_case_id': _get_hd_case_id,
'pay_amount': _get_pay_amount,
+ 'fee': _get_fee,
+ 'to_pay': _get_topay,
+ 'complete': True,
}
def cash(self,ids,context):
obj=self.browse(ids)[0]
- hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
- context['amount']=obj.pay_amount or 0.0
- print(">><< ", obj.pay_amount)
- hd_case.make_payment(context=context)
- obj.write({
- 'pay_amount': hd_case.amount,
- })
- print(":: ", context['amount']-obj.pay_amount)
- if not obj.pay_amount:
- return {
- 'next': {
- 'name': 'clinic_hd_case',
- 'mode': 'form',
- 'active_id': hd_case.id,
- },
- 'flash': 'Paid',
- }
+ if obj.pay_amount:
+ hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
+ context['amount']=obj.pay_amount or 0.0
+ context['make_invoice']=False
+ hd_case.make_invoices(context=context) #XXX
+ hd_case.make_payment(context=context)
+ if obj.complete:
+ hd_case.write({
+ 'state': 'completed',
+ })
+ obj.write({
+ 'pay_amount': hd_case.amount,
+ })
+ return {
+ 'next': {
+ 'name': 'clinic_hd_case',
+ 'mode': 'form',
+ 'active_id': hd_case.id,
+ },
+ 'flash': 'Paid',
+ }
def credit(self,ids,context):
obj=self.browse(ids)[0]
hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
+ hd_case.make_invoices()
+ if obj.complete:
+ hd_case.write({
+ 'state': 'completed',
+ })
+ return {
+ 'next': {
+ 'name': 'clinic_hd_case',
+ 'mode': 'form',
+ 'active_id': hd_case.id,
+ },
+ 'flash': 'Paid',
+ }
+
+ def onchange_amount(self,context={}):
+ data=context['data']
+ pay_amount=data['pay_amount'] or 0.0
+ data['pay_amount']=pay_amount
+ data['to_pay']=pay_amount
+ return data
HDCasePayment.register()