multi payment
parent
d22408c748
commit
1fa886de89
|
@ -1,6 +0,0 @@
|
|||
<action>
|
||||
<field name="string">Payment</field>
|
||||
<field name="view_cls">form_popup</field>
|
||||
<field name="model">clinic.payment</field>
|
||||
<field name="target">_popup</field>
|
||||
</action>
|
|
@ -10,7 +10,7 @@
|
|||
<field name="time_start"/>
|
||||
<field name="cycle_id"/>
|
||||
<field name="department_id"/>
|
||||
<field name="visit_id"/>
|
||||
<field name="visit_id" readonly="1"/>
|
||||
</group>
|
||||
<group span="6" columns="1">
|
||||
<field name="patient_id" onchange="onchange_patient"/>
|
||||
|
@ -28,7 +28,6 @@
|
|||
<field name="bp_stop"/>
|
||||
<field name="per_bp_stop"/>
|
||||
<field name="hct" onchange="onchange_hct"/>
|
||||
<field name="pop_txt" nolabel="1"/>
|
||||
<field name="dialyzers" nolabel="1">
|
||||
<list>
|
||||
<field name="dialyzer_id" domain="[['patient_id','=',parent.patient_id],['state','=','active']]" onchange="onchange_dialyzer"/>
|
||||
|
@ -77,12 +76,30 @@
|
|||
<field name="amount"/>
|
||||
</list>
|
||||
</field>
|
||||
<group span="8" columns="1">
|
||||
<group span="8" form_layout="stacked" attrs='{"invisible":[["amount","=",0]]}'>
|
||||
<separator string="Make a payment"/>
|
||||
<field name="pay_amount" attrs='{"required":[["amount","!=",0]]}' onchange="onchange_pay" span="3"/>
|
||||
<field name="pay_date" span="3"/>
|
||||
<field name="pay_account_id" span="3"/>
|
||||
<button string="Add Payment" method="make_payment" icon="ok" size="small" type="success"/>
|
||||
</group>
|
||||
<group span="4" columns="1">
|
||||
<field name="total"/>
|
||||
<field name="payment_lines" nolabel="1">
|
||||
<template>
|
||||
{{#each context.data}}
|
||||
<div class="form-group nf-field">
|
||||
<label class="control-label col-md-4">Less
|
||||
<a href="#name=payment&mode=form&active_id={{payment_id.0.}}">Payment</a>
|
||||
</label>
|
||||
<div class="col-md-8" style="text-align:right">
|
||||
{{currency amount}}
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
</template>
|
||||
</field>
|
||||
<field name="amount"/>
|
||||
<button string="Pay Now" span="2" size="small" action="clinic_payment" icon="arrow-right" type="success"/>
|
||||
</group>
|
||||
</tab>
|
||||
<tab string="Notes">
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<form model="clinic.payment">
|
||||
<field name="partner_id" />
|
||||
<field name="lines" nolabel="1">
|
||||
<list>
|
||||
<field name="description"/>
|
||||
<field name="qty"/>
|
||||
<field name="price"/>
|
||||
<field name="amount"/>
|
||||
</list>
|
||||
</field>
|
||||
<group span="4">
|
||||
</group>
|
||||
<group span="8">
|
||||
<field offset="6" name="total"/>
|
||||
</group>
|
||||
<foot>
|
||||
<button string="POST" type="success" method="post"/>
|
||||
</foot>
|
||||
</form>
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
Loading…
Reference in New Issue