diff --git a/netforce_clinic/actions/clinic_payment.xml b/netforce_clinic/actions/clinic_payment.xml
new file mode 100644
index 0000000..906209e
--- /dev/null
+++ b/netforce_clinic/actions/clinic_payment.xml
@@ -0,0 +1,6 @@
+
+ Payment
+ form_popup
+ clinic.hd.case.payment
+ _popup
+
diff --git a/netforce_clinic/actions/clinic_view_payment.xml b/netforce_clinic/actions/clinic_view_payment.xml
new file mode 100644
index 0000000..e55255c
--- /dev/null
+++ b/netforce_clinic/actions/clinic_view_payment.xml
@@ -0,0 +1,5 @@
+
+ method
+ clinic.hd.case
+ view_payment
+
diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml b/netforce_clinic/layouts/clinic_hd_case_form.xml
index 661b104..758fa25 100644
--- a/netforce_clinic/layouts/clinic_hd_case_form.xml
+++ b/netforce_clinic/layouts/clinic_hd_case_form.xml
@@ -2,6 +2,7 @@
@@ -44,32 +45,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -83,10 +62,11 @@
-
+
+
{{#each context.data}}
@@ -104,12 +84,19 @@
-
-
+
+
+
+
+
+
+
+
+
-
+
@@ -117,7 +104,7 @@
-
+
diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml.old b/netforce_clinic/layouts/clinic_hd_case_form.xml.old
new file mode 100644
index 0000000..970965a
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_hd_case_form.xml.old
@@ -0,0 +1,132 @@
+
diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml
index 391ea12..a8a10b1 100644
--- a/netforce_clinic/layouts/clinic_patient_form.xml
+++ b/netforce_clinic/layouts/clinic_patient_form.xml
@@ -3,6 +3,7 @@
diff --git a/netforce_clinic/layouts/clinic_payment_form.xml b/netforce_clinic/layouts/clinic_payment_form.xml
new file mode 100644
index 0000000..850141c
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_payment_form.xml
@@ -0,0 +1,10 @@
+
diff --git a/netforce_clinic/layouts/fin_clinic_settings.xml b/netforce_clinic/layouts/fin_clinic_settings.xml
index bf317e6..0eb1044 100644
--- a/netforce_clinic/layouts/fin_clinic_settings.xml
+++ b/netforce_clinic/layouts/fin_clinic_settings.xml
@@ -1,8 +1,11 @@
-
-
-
+
+
+
+
+
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index ae82cb7..e2be6ea 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -20,6 +20,7 @@ from . import hd_case
from . import hd_case_line
from . import hd_case_gmline
from . import hd_case_discont
+from . import hd_case_payment
from . import dialyzer
from . import dialyzer_line
from . import import_payment
@@ -30,10 +31,10 @@ from . import gen_visit_line
from . import report_hd_detail
from . import report_hd_summary
from . import report_hd_madical
-from . import payment
from . import input_data
from . import fin_setting
from . import import_data_mg
from . import import_data_nhso
from . import import_data_sc
from . import translate
+from . import payment
diff --git a/netforce_clinic/models/fin_setting.py b/netforce_clinic/models/fin_setting.py
index 009a5a6..f9bebba 100644
--- a/netforce_clinic/models/fin_setting.py
+++ b/netforce_clinic/models/fin_setting.py
@@ -3,9 +3,12 @@ from netforce.model import Model, fields
class Settings(Model):
_inherit="settings"
_fields={
- "mg_account_id": fields.Many2One("account.account","Account Payment Medical Government"),
- "nhso_account_id": fields.Many2One("account.account","Account Payment NHSO 30B"),
- "sc_account_id": fields.Many2One("account.account","Account Payment Social Security"),
+ "ap_mg_id": fields.Many2One("account.account","Account Payment Medical Government"),
+ "ap_nhso_id": fields.Many2One("account.account","Account Payment NHSO 30B"),
+ "ap_sc_id": fields.Many2One("account.account","Account Payment Social Security"),
+ "ar_mg_id": fields.Many2One("account.account","Account Recieve Medical Government"),
+ "ar_nhso_id": fields.Many2One("account.account","Account Recieve NHSO 30B"),
+ "ar_sc_id": fields.Many2One("account.account","Account Recieve Social Security"),
}
Settings.register()
diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py
index 7a615a4..2d06cf8 100644
--- a/netforce_clinic/models/hd_case.py
+++ b/netforce_clinic/models/hd_case.py
@@ -22,6 +22,12 @@ class HDcase(Model):
res[obj.id]=total_time
return res
+ def get_pay_amount(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ res[obj.id]=obj.amount
+ return res
+
_fields={
"number": fields.Char("Number",required=True,search=True),
@@ -47,7 +53,6 @@ class HDcase(Model):
"state": fields.Selection([("draft","Draft"),("in_progress","In Progress"),("completed","Completed"),("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"),
- "gm_lines": fields.One2Many("clinic.hd.case.gm.line","hd_case_id","GM Lines"),
"comments": fields.One2Many("message","related_id","Comments"),
"company_id": fields.Many2One("company","Company"),
"amount": fields.Float("Due Amount",function="get_total",readonly=True,function_multi=True),
@@ -61,11 +66,10 @@ class HDcase(Model):
'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("Due Amount",function="get_gmtotal",readonly=True,function_multi=True),
- "fee_total": fields.Float("Total",function="get_gmtotal",readonly=True,function_multi=True),
+ "fee_amount": fields.Float("Fee",function="get_total",readonly=True,function_multi=True),
'note': fields.Text("Note"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
- 'pay_amount': fields.Float("Amount"),
+ 'pay_amount': fields.Float("Amount",function="get_pay_amount"),
'pay_date': fields.Date("Pay Date"),
'pay_account_id': fields.Many2One("account.account","Account"),
}
@@ -166,15 +170,21 @@ class HDcase(Model):
def onchange_line(self,context={}):
data=context['data']
total=0.0
+ fee_amt=0.0
for line in data['lines']:
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
- total+=amt
+ #product_id=line.get("product_id")
+ #if product_id:
+ line['amount']=amt
+ if line['type']=='fee':
+ fee_amt+=amt
+ else:
+ total+=amt
+
data['total']=total
+ data['fee_amount']=fee_amt
for line in data['payment_lines']:
total-=line['amount'] or 0.0
data['amount']=total
@@ -191,8 +201,6 @@ class HDcase(Model):
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={}):
@@ -219,6 +227,10 @@ class HDcase(Model):
account_id=obj.pay_account_id.id
if not account_id:
raise Exception("No Account for payment")
+ pay_amount=obj.pay_amount
+ # XXX get from popup
+ if context.get("amount",0):
+ pay_amount=context['amount'] or 0.0
vals={
"partner_id": partner_id,
"company_id": company_id,
@@ -233,17 +245,17 @@ class HDcase(Model):
'description': 'Payment; %s'%obj.number,
'account_id': account_id,
'qty': 1,
- 'unit_price': obj.pay_amount,
- 'amount': obj.pay_amount,
+ 'unit_price': pay_amount,
+ 'amount': pay_amount,
}))
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
obj.write({
#'pay_amount': remaining_amt-obj.pay_amount,
- 'pay_amount': 0, # reset
+ #'pay_amount': 0, # reset
'payment_lines': [('create',{
'payment_id': payment_id,
- 'amount': obj.pay_amount,
+ 'amount': pay_amount,
})],
})
return {
@@ -275,21 +287,6 @@ class HDcase(Model):
data=self.onchange_gmline(context)
return data
- def onchange_gmline(self,context={}):
- data=context['data']
- total=0.0
- for line in data['gm_lines']:
- 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
- total+=amt
- data['fee_total']=total
- data['fee_amount']=total
- return data
-
def make_invoices(self,ids,context={}):
setting=get_model("settings").browse(1)
currency_id=setting.currency_id.id
@@ -303,8 +300,7 @@ class HDcase(Model):
context['type']='out'
context['inv_type']='invoice'
- # TODO payment without invoice
- if obj.lines and obj.total:
+ if obj.lines and obj.amount:
vals={
"type": "out",
"inv_type": "invoice",
@@ -321,11 +317,13 @@ class HDcase(Model):
if not partner:
raise Exception("No contact for patient %s"%obj.patient_id.name)
vals["partner_id"]=partner.id
+ fee_lines=[]
for line in obj.lines:
- account_id=line.product_id.sale_account_id.id or account_receivable_id
- if not account_id:
- raise Exception("%s not found account recievable %s"%partner.name)
- line={
+ if line.product_id:
+ account_id=line.product_id.sale_account_id.id or account_receivable_id
+ else:
+ account_id=account_receivable_id
+ inv_line={
"product_id": line.product_id.id,
"description": line.description,
"qty": line.qty,
@@ -334,11 +332,16 @@ class HDcase(Model):
"amount": line.amount,
'account_id': account_id,
}
- vals['lines'].append(('create',line))
+ if line.type=='fee':
+ fee_lines.append(inv_line)
+ else:
+ vals['lines'].append(('create',inv_line))
+
inv_id=get_model("account.invoice").create(vals,context)
# create picking
obj.make_pickings()
- if obj.fee_total:
+
+ if fee_lines:
vals={
"type": "out",
"inv_type": "invoice",
@@ -352,22 +355,20 @@ class HDcase(Model):
"company_id": company_id,
}
vals["partner_id"]=obj.fee_partner_id.id
- if not obj.fee_partner_id.account_receivable_id:
- account_id=obj.fee_partner_id.account_receivable_id.id or account_receivable_id
- if not account_id:
- raise Exception("%s not found account recievable %s"%obj.fee_partner_id.name)
- for line in obj.gm_lines:
- prod=line.product_id
- inv_line={
- "product_id": prod.id,
- "description": prod.name,
- "qty": 1,
- "uom_id": prod.uom_id.id,
- "unit_price": line.price,
- "amount": line.amount,
- 'account_id': account_id, # XXX
- }
- vals['lines'].append(('create',inv_line))
+ #XXX
+
+ account_id=account_receivable_id
+ patient_type=obj.patient_id.type
+ if patient_type=='mg':
+ account_id=setting.ar_mg_id.id
+ elif patient_type=='sc':
+ account_id=setting.ar_sc_id.id
+ elif patient_type=='nhso':
+ account_id=setting.ar_nhso_id.id
+
+ for fee_line in fee_lines:
+ fee_line['account_id']=account_id
+ vals['lines'].append(('create',fee_line))
inv_id=get_model("account.invoice").create(vals,context)
def make_pickings(self,ids,context={}):
@@ -490,34 +491,23 @@ class HDcase(Model):
vals={}
for obj in self.browse(ids):
total=0
- amt=0
+ due_amt=0
+ fee_amt=0
for line in obj.lines:
+ if line.type=='fee':
+ fee_amt+=line.amount or 0.0
total+=line.amount or 0.0
- amt=total
+
+ due_amt=total-fee_amt
for line in obj.payment_lines:
- amt-=line.amount or 0.0
+ due_amt-=line.amount or 0.0
vals[obj.id]={
"total": total,
- "amount": amt,
+ "amount": due_amt,
+ 'fee_amount': fee_amt,
}
return vals
- def get_gmtotal(self,ids,context={}):
- vals={}
- for obj in self.browse(ids):
- total=0
- amt=0
- fee=obj.fee or 0
- for line in obj.gm_lines:
- total+=line.amount or 0
- fee=0 # XXX
- amt=total+fee
- vals[obj.id]={
- "fee_total": total,
- "fee_amount": amt,
- }
- return vals
-
def delete(self,ids,context={}):
for obj in self.browse(ids):
if obj.state != 'draft':
@@ -568,7 +558,7 @@ class HDcase(Model):
pm_line.delete()
obj.write({
- 'state': 'draft',
+ 'state': 'in_progress',
})
return {
'next': {
@@ -578,5 +568,9 @@ class HDcase(Model):
},
'flash': '%s has been undo'%obj.number,
}
+
+ def view_payment(self,ids,context={}):
+ print("clinic_view_payment")
+ pass
HDcase.register()
diff --git a/netforce_clinic/models/hd_case_line.py b/netforce_clinic/models/hd_case_line.py
index 02f7af0..49025da 100644
--- a/netforce_clinic/models/hd_case_line.py
+++ b/netforce_clinic/models/hd_case_line.py
@@ -10,6 +10,11 @@ class Hdcaseline(Model):
"uom_id": fields.Many2One("uom","UOM",required=True,search=True),
"price":fields.Float("Price"),
"amount":fields.Float("Amount"),
+ "type": fields.Selection([("fee","Fee"),("other","Other")],"Type",required=True),
+ }
+
+ _defaults={
+ 'type': 'other',
}
Hdcaseline.register()
diff --git a/netforce_clinic/models/hd_case_payment.py b/netforce_clinic/models/hd_case_payment.py
new file mode 100644
index 0000000..f63457a
--- /dev/null
+++ b/netforce_clinic/models/hd_case_payment.py
@@ -0,0 +1,53 @@
+from netforce.model import Model, fields, get_model
+
+class HDCasePayment(Model):
+ _name="clinic.hd.case.payment"
+ _transient=True
+
+ _fields={
+ "hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"),
+ "pay_amount": fields.Float("Amount"),
+ }
+
+ def _get_hd_case_id(self,context={}):
+ hd_case_id=context.get("refer_id")
+ if not hd_case_id:
+ return None
+ return int(hd_case_id)
+
+ def _get_pay_amount(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,
+ }
+
+ 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',
+ }
+
+ def credit(self,ids,context):
+ obj=self.browse(ids)[0]
+ hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
+
+HDCasePayment.register()
+
diff --git a/netforce_clinic/models/import_payment.py b/netforce_clinic/models/import_payment.py
index cd2f4ca..4cfd415 100644
--- a/netforce_clinic/models/import_payment.py
+++ b/netforce_clinic/models/import_payment.py
@@ -31,7 +31,7 @@ class ImportPayment(Model):
curr_row=-1
while curr_row < num_rows:
curr_row +=1
- worksheet.cell_value(curr_row,1)
+ worksheet.cell_value(curr_row,2)
return data
def read_xml(self,fpath=None):
diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py
index 5c0c914..0e53b0f 100644
--- a/netforce_clinic/models/visit.py
+++ b/netforce_clinic/models/visit.py
@@ -104,14 +104,7 @@ class Visit(Model):
}
obj.write(vals)
hd_case_obj=get_model("clinic.hd.case")
- #dt=datetime
- #datenow=dt.now().strftime("%Y-%m-%d")
obj=self.browse(ids)[0]
- #date_visit=obj.time_start[0:10]
- # cannot treatment if current date is not same visit date
- #if date_visit!=datenow:
- #raise Exception("Today is not treament date!")
-
vals={
'patient_id': obj.patient_id.id,
'doctor_id': obj.doctor_id.id,
@@ -124,14 +117,14 @@ class Visit(Model):
'cycle_id': obj.cycle_id.id,
'fee_type': obj.patient_id.type,
'lines':[],
- 'gm_lines':[],
'dialyzers': [],
'state': 'draft',
}
products=get_model("product").search_browse([['code','=','FEE']])
for product in products:
- vals['gm_lines'].append(('create',{
+ vals['lines'].append(('create',{
+ 'type': 'fee',
'product_id': product.id,
'description': product.name or "",
'qty': 1,