diff --git a/netforce_clinic/actions/clinic_payment.xml b/netforce_clinic/actions/clinic_payment.xml
deleted file mode 100644
index 2207289..0000000
--- a/netforce_clinic/actions/clinic_payment.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
- Payment
- form_popup
- clinic.payment
- _popup
-
diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml b/netforce_clinic/layouts/clinic_hd_case_form.xml
index 0bc1f6f..0190878 100644
--- a/netforce_clinic/layouts/clinic_hd_case_form.xml
+++ b/netforce_clinic/layouts/clinic_hd_case_form.xml
@@ -10,7 +10,7 @@
-
+
@@ -28,7 +28,6 @@
-
@@ -77,12 +76,30 @@
-
+
+
+
+
+
+
+
+
+ {{#each context.data}}
+
+ {{/each}}
+
+
-
diff --git a/netforce_clinic/layouts/clinic_payment_form.xml b/netforce_clinic/layouts/clinic_payment_form.xml
deleted file mode 100644
index 7ce4b08..0000000
--- a/netforce_clinic/layouts/clinic_payment_form.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 565a8f0..20a9074 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -32,5 +32,4 @@ from . import gen_visit_line
from . import report_hd_dialy
from . import report_hd_monthly
from . import payment
-from . import payment_line
from . import input_data
diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py
index 7c0ee1b..6ea3e4f 100644
--- a/netforce_clinic/models/hd_case.py
+++ b/netforce_clinic/models/hd_case.py
@@ -56,6 +56,7 @@ class HDcase(Model):
"invoices": fields.One2Many("account.invoice","related_id","Invoices"),
"pickings": fields.One2Many("stock.picking","related_id","Pickings"),
"payments": fields.One2Many("account.payment","related_id","Payments"),
+ "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"),
@@ -64,7 +65,9 @@ class HDcase(Model):
"fee_total": fields.Float("Total",function="get_gmtotal",readonly=True,function_multi=True),
'note': fields.Text("Note"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
- 'pop_txt': fields.Char("POP TEXT", readonly=True),
+ 'pay_amount': fields.Float("Amount"),
+ 'pay_date': fields.Date("Pay Date"),
+ 'pay_account_id': fields.Many2One("account.account","Account"),
}
def _get_number(self,context={}):
@@ -98,7 +101,6 @@ class HDcase(Model):
"number": _get_number,
"company_id": lambda *a: get_active_company(),
"fee": 1500,
- 'show_pop': False,
}
_order="date desc,number desc"
@@ -171,15 +173,86 @@ class HDcase(Model):
line['amount']=amt
total+=amt
data['total']=total
+ for line in data['payment_lines']:
+ total-=line['amount'] or 0.0
+ data['amount']=total
+ if not data['pay_date']:
+ data['pay_date']=time.strftime("%Y-%m-%d")
+ if not data['pay_account_id']:
+ patient_id=data['patient_id']
+ if patient_id:
+ patient=get_model("clinic.patient").browse(patient_id)
+ partner=patient.partner_id
+ if partner:
+ account_id=partner.account_payable_id
+ if not account_id:
+ settings=get_model("settings").browse(1)
+ account_id=settings.account_receivable_id
+ data['pay_account_id']=account_id.id
+ pay_amount=total
+ data['pay_amount']=pay_amount
return data
+ def onchange_pay(self,context={}):
+ data=context['data']
+ pay_amount=data['pay_amount'] or 0
+ amount=data['amount'] or 0
+ if pay_amount > amount:
+ data['pay_amount']=0
+ return data
+
+ def make_payment(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ remaining_amt=0.0
+ for line in obj.lines:
+ remaining_amt+=line.amount or 0.0
+ for line in obj.payment_lines:
+ remaining_amt-=line.amount or 0.0
+ partner_id=obj.patient_id.partner_id.id
+ if not partner_id:
+ raise Exception("No contact on this patient")
+ company_id=get_active_company()
+ account_id=obj.pay_account_id.id
+ vals={
+ "partner_id": partner_id,
+ "company_id": company_id,
+ "type": "in",
+ "pay_type": "direct",
+ "date": obj.pay_date,
+ "account_id": account_id,
+ 'related_id': "clinic.hd.case,%s"%obj.id,
+ 'direct_lines': [],
+ }
+ vals['direct_lines'].append(('create',{
+ 'description': 'Payment; %s'%obj.number,
+ 'account_id': account_id,
+ 'qty': 1,
+ 'unit_price': obj.pay_amount,
+ 'amount': obj.pay_amount,
+ }))
+
+ payment_id=get_model("account.payment").create(vals,context={"type":"in"})
+ obj.write({
+ 'pay_amount': remaining_amt-obj.pay_amount,
+ 'payment_lines': [('create',{
+ 'payment_id': payment_id,
+ 'amount': obj.pay_amount,
+ })],
+ })
+ return {
+ 'next': {
+ 'name': 'clinic_hd_case',
+ 'mode': 'form',
+ 'active_id': obj.id,
+ },
+ 'flash': 'Pay OK',
+ }
+
def onchange_hct(self,context={}):
data=context['data']
hct=data['hct']
if(hct<=39):
- data['pop_txt']='xxxxxxxxxxxxxxxxx'
- else:
- data['pop_txt']=''
+ pass
return data
def cancelled(self,ids,context={}):
@@ -217,9 +290,6 @@ class HDcase(Model):
data['fee_amount']=total
return data
- def make_payment(self,ids,context={}):
- pass
-
def make_invoices(self,ids,context={}):
setting=get_model("settings").browse(1)
currency_id=setting.currency_id.id
@@ -423,11 +493,11 @@ class HDcase(Model):
for obj in self.browse(ids):
total=0
amt=0
- fee=obj.fee or 0
for line in obj.lines:
- total+=line.amount or 0
- fee=0 # XXX
- amt=total+fee
+ total+=line.amount or 0.0
+ amt=total
+ for line in obj.payment_lines:
+ amt-=line.amount or 0.0
vals[obj.id]={
"total": total,
"amount": amt,
@@ -489,5 +559,6 @@ class HDcase(Model):
},
'flash': '%s has been undo'%obj.number,
}
+
HDcase.register()
diff --git a/netforce_clinic/models/payment.py b/netforce_clinic/models/payment.py
index 86f156a..bba4efb 100644
--- a/netforce_clinic/models/payment.py
+++ b/netforce_clinic/models/payment.py
@@ -1,65 +1,15 @@
-#from netforce.access import get_active_user
-from netforce.model import Model, fields, get_model
+from netforce.model import Model, fields
class Payment(Model):
_name="clinic.payment"
_transient=True
-
- def _get_all(self,ids,context={}):
- res={}
- for obj in self.browse(ids):
- total=0.0
- for line in obj.lines:
- total+=line.amount or 0.0
- res[obj.id]={
- 'total': total
- }
- return res
_fields={
- 'partner_id': fields.Many2One("partner","Partner"),
- 'lines': fields.One2Many("clinic.payment.line","payment_id", "Lines"),
- 'total': fields.Float("Total", function="_get_all",function_multi=True),
- "state": fields.Selection([["draft","Draft"],['paid','Paid'],["cancelled","Cancelled"]],"Status",required=True),
+ 'hd_case_id': fields.Many2One("clinic.hd.case","HD Case",on_delete="cascade"),
+ 'payment_id': fields.Many2One("account.payment","Payment",on_delete="cascade"),
+ 'account_id': fields.Many2One("account.account","Account"),
+ 'amount': fields.Float("Amount"),
}
-
- def _get_partner_id(self,context={}):
- refer_id=context.get("refer_id") # hd_case_id
- hd_case=get_model('clinic.hd.case').browse(refer_id)
- partner_id=hd_case.patient_id.partner_id.id or None
- return partner_id
-
- def _get_lines(self,context={}):
- refer_id=context.get("refer_id") # hd_case_id
- hd_case=get_model('clinic.hd.case').browse(refer_id)
- lines=[]
- for line in hd_case.lines:
- vals={
- 'description': line.description or '',
- 'qty': line.qty or 0,
- 'price': line.price,
- 'amount': line.amount,
- }
- lines.append(vals)
- return lines
-
- def _get_total(self,context={}):
- refer_id=context.get("refer_id")
- hd_case=get_model('clinic.hd.case').browse(refer_id)
- total=0.0
- for line in hd_case.lines:
- total+=line.amount
- print("total ", total)
- return total
-
- _defaults={
- 'partner_id': _get_partner_id,
- 'lines': _get_lines,
- 'total': _get_total,
- }
-
- def paid(self,context={}):
- pass
-
Payment.register()
+
diff --git a/netforce_clinic/models/payment_line.py b/netforce_clinic/models/payment_line.py
deleted file mode 100644
index d2b9829..0000000
--- a/netforce_clinic/models/payment_line.py
+++ /dev/null
@@ -1,17 +0,0 @@
-from netforce.model import Model, fields, get_model
-
-class PaymentLine(Model):
- _name="clinic.payment.line"
- _transient=True
-
- _fields={
- 'payment_id': fields.Many2One("clinic.payment","Payment"),
- 'description': fields.Char("Description"),
- 'qty': fields.Integer("Qty"),
- 'price': fields.Float("Unit Price"),
- 'account_id': fields.Many2One("account.account","Account"),
- 'amount': fields.Float("Amount"),
- }
-
-PaymentLine.register()
-