105 lines
3.2 KiB
Python
105 lines
3.2 KiB
Python
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("Due Amount"),
|
|
"fee": fields.Float("Fee"),
|
|
"to_pay": fields.Float("To Pay"),
|
|
"complete": fields.Boolean("Mark as full payment for Cash"),
|
|
}
|
|
|
|
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
|
|
|
|
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
|
|
context['make_invoice']=False
|
|
hd_case.make_invoices(context=context) #XXX
|
|
hd_case.post_invoices()
|
|
st=get_model("clinic.setting").browse(1)
|
|
if obj.pay_amount:
|
|
hd_case.make_payment(context=context)
|
|
if obj.complete:
|
|
hd_case.create_cycle_item()
|
|
vals={
|
|
'state': 'completed',
|
|
}
|
|
if st.waiting_approval:
|
|
vals['state']='waiting_approval'
|
|
hd_case.write(vals)
|
|
obj.write({
|
|
'pay_amount': hd_case.amount,
|
|
})
|
|
return {
|
|
'next': {
|
|
'name': 'clinic_hd_case',
|
|
'mode': 'form',
|
|
'active_id': hd_case.id,
|
|
},
|
|
'flash': '%s has been paid'%hd_case.number,
|
|
}
|
|
|
|
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()
|
|
hd_case.post_invoices()
|
|
hd_case.create_cycle_item()
|
|
st=get_model("clinic.setting").browse(1)
|
|
vals={
|
|
'state': 'completed',
|
|
}
|
|
if st.waiting_approval:
|
|
vals['state']='waiting_approval'
|
|
hd_case.write(vals)
|
|
return {
|
|
'next': {
|
|
'name': 'clinic_hd_case',
|
|
'mode': 'form',
|
|
'active_id': hd_case.id,
|
|
},
|
|
'flash': '%s has been paid'%hd_case.number,
|
|
}
|
|
|
|
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()
|
|
|