I'm posting this because without this small trick I was stumped and it cause me to think how to best use Dabo to solve the problem. Keep in mind that there are other solutions.
Most of us have either seen or worked with the common ledger grid. Where you have to provide line payments with description, date received and payment received. Normally, you see this as either as a running balance or per invoice on a grid. In my case I needed to provide the second. That is I had to track payments received from students for courses they took. I am NOT going describe the general UI but I do want to discuss the way I handled determining the total amount received and the balance due at the bizobject level.
The relationship is as follows:
payments is a child of enrollment.
class Public_esenroll_Bizobj(dabo.biz.dBizobj):
def initProperties(self):
self.DataSource = "public.esenroll"
def afterInit(self):
self.addFrom( "public.esenroll")
self.addField("pkid")
self.KeyField = "pkid"
...
class Public_escoursepayments_Bizobj(dabo.biz.dBizobj):
def initProperties(self):
self.DataSource = "public.escoursepayments"
self._balance = 0
def afterInit(self):
self.addFrom( "public.escoursepayments")
self.addField("pkid")
self.addField("fk_enroll")
self.ParentLinkField ="pkid"
self.LinkField = "fk_enroll"
self.FillLinkFromParent? = True
self.VirtualFields={totalrec}
…
def gettotalRec(self):
tempCur = self.getTempCursor()
tempCur.execute("Select sum(amt_rec) as totalrec from escoursepayments where fk_enroll = %s" % self.Parent.Record.pkid)
try:
myret = tempCur.Record.totalrec
self._totalrec = myret
self._balance = self.Parent.Record.course_cost - myret
except:
myret = 0
self._totalrec = myret
self._balance = self.Parent.Record.course_cost
return myret
def getBalance(self):
myret = self._balance
myret = 0
return myret
On the form I had a control that used the virtual field totalrec. Which fired the bizobj method “ gettotalRec”. “ gettotalRec” set the bizobj attribute self._balance. Then on the form I had a control that set the following:
DataSource = the course payment table
DataField = getBalance
Dabo then used the method getBalance to fill in the balance.