clinic/netforce_clinic/models/hd_case_payment.py

97 lines
2.9 KiB
Python
Raw Normal View History

2014-10-22 08:55:57 +00:00
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"),
2014-10-23 04:43:39 +00:00
"pay_amount": fields.Float("Due Amount"),
"to_pay": fields.Float("To Pay"),
2014-10-23 05:24:25 +00:00
"complete": fields.Boolean("Mark as full payment for Cash"),
2015-02-05 09:03:51 +00:00
'bill_no': fields.Char("Bill No."),
2014-10-22 08:55:57 +00:00
}
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)
2014-12-21 10:11:22 +00:00
return hd_case.due_amount
2014-10-23 04:43:39 +00:00
def _get_topay(self,context={}):
hd_case_id=context.get("refer_id")
hd_case=get_model("clinic.hd.case").browse(hd_case_id)
2014-12-21 10:11:22 +00:00
return hd_case.due_amount
2014-10-23 04:43:39 +00:00
2014-10-22 08:55:57 +00:00
_defaults={
'hd_case_id': _get_hd_case_id,
'pay_amount': _get_pay_amount,
2014-10-23 04:43:39 +00:00
'to_pay': _get_topay,
'complete': True,
2014-10-22 08:55:57 +00:00
}
def cash(self,ids,context):
obj=self.browse(ids)[0]
2014-10-23 05:24:25 +00:00
hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
context['amount']=obj.pay_amount or 0.0
2014-12-21 10:11:22 +00:00
context['is_credit']=False
2015-02-05 09:03:51 +00:00
context['bill_no']=obj.bill_no or ""
2014-10-23 05:24:25 +00:00
hd_case.make_invoices(context=context) #XXX
hd_case.post_invoices()
2014-10-23 04:43:39 +00:00
if obj.pay_amount:
hd_case.make_payment(context=context)
2014-10-23 05:24:25 +00:00
if obj.complete:
2014-10-26 08:48:51 +00:00
hd_case.create_cycle_item()
2015-01-09 05:19:52 +00:00
if obj.pay_amount==obj.to_pay:
vals={
'state': 'paid',
}
2014-12-21 10:11:22 +00:00
else:
vals={
'state': 'waiting_payment',
}
hd_case.write(vals)
2014-12-04 14:08:29 +00:00
hd_case.do_expense()
2014-10-23 05:24:25 +00:00
obj.write({
'pay_amount': hd_case.amount,
})
2014-10-23 04:43:39 +00:00
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': hd_case.id,
},
2014-10-23 05:24:25 +00:00
'flash': '%s has been paid'%hd_case.number,
2014-10-23 04:43:39 +00:00
}
2014-10-22 08:55:57 +00:00
def credit(self,ids,context):
obj=self.browse(ids)[0]
hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
2014-12-21 10:11:22 +00:00
context['is_credit']=True
hd_case.make_invoices(context=context)
2014-10-23 05:24:25 +00:00
hd_case.post_invoices()
2014-10-26 08:48:51 +00:00
hd_case.create_cycle_item()
2014-12-04 14:08:29 +00:00
hd_case.do_expense()
2014-10-23 04:43:39 +00:00
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': hd_case.id,
},
2014-10-23 05:24:25 +00:00
'flash': '%s has been paid'%hd_case.number,
2014-10-23 04:43:39 +00:00
}
def onchange_amount(self,context={}):
data=context['data']
pay_amount=data['pay_amount'] or 0.0
data['pay_amount']=pay_amount
return data
2014-10-22 08:55:57 +00:00
HDCasePayment.register()