clinic/netforce_clinic/models/payment.py

66 lines
1.9 KiB
Python

#from netforce.access import get_active_user
from netforce.model import Model, fields, get_model
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),
}
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()