<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=Tricks_with_Virtual_Fields</id>
	<title>Tricks with Virtual Fields - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=Tricks_with_Virtual_Fields"/>
	<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=Tricks_with_Virtual_Fields&amp;action=history"/>
	<updated>2026-11-21T21:05:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://wiki.dabo.leafe.com/index.php?title=Tricks_with_Virtual_Fields&amp;diff=4044&amp;oldid=prev</id>
		<title>Ed: Created page with &quot;I&#039;m posting this because without this small trick I was stumped and it caused me to think how to best use Dabo to solve the problem. Keep in mind that there are other solution...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=Tricks_with_Virtual_Fields&amp;diff=4044&amp;oldid=prev"/>
		<updated>2020-05-11T16:04:52Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;I&amp;#039;m posting this because without this small trick I was stumped and it caused me to think how to best use Dabo to solve the problem. Keep in mind that there are other solution...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;I&amp;#039;m posting this because without this small trick I was stumped and it caused me to think how to best use Dabo to solve the problem. Keep in mind that there are other solutions.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The relationship is as follows:&lt;br /&gt;
&lt;br /&gt;
payments is a child of enrollment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class Public_esenroll_Bizobj(dabo.biz.dBizobj):&lt;br /&gt;
    def initProperties(self):&lt;br /&gt;
        self.DataSource = &amp;quot;public.esenroll&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def afterInit(self):&lt;br /&gt;
        self.addFrom( &amp;quot;public.esenroll&amp;quot;)&lt;br /&gt;
        self.addField(&amp;quot;pkid&amp;quot;)&lt;br /&gt;
        self.KeyField = &amp;quot;pkid&amp;quot;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
class Public_escoursepayments_Bizobj(dabo.biz.dBizobj):&lt;br /&gt;
    def initProperties(self):&lt;br /&gt;
        self.DataSource = &amp;quot;public.escoursepayments&amp;quot;&lt;br /&gt;
        self._balance = 0&lt;br /&gt;
&lt;br /&gt;
    def afterInit(self):&lt;br /&gt;
        self.addFrom( &amp;quot;public.escoursepayments&amp;quot;)&lt;br /&gt;
        self.addField(&amp;quot;pkid&amp;quot;)&lt;br /&gt;
        self.addField(&amp;quot;fk_enroll&amp;quot;)&lt;br /&gt;
        self.ParentLinkField =&amp;quot;pkid&amp;quot;&lt;br /&gt;
        self.LinkField = &amp;quot;fk_enroll&amp;quot;&lt;br /&gt;
        self.FillLinkFromParent? = True&lt;br /&gt;
        self.VirtualFields={totalrec}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    def gettotalRec(self):&lt;br /&gt;
        tempCur = self.getTempCursor()&lt;br /&gt;
        tempCur.execute(&amp;quot;Select sum(amt_rec) as totalrec from escoursepayments where fk_enroll = %s&amp;quot;,&lt;br /&gt;
                self.Parent.Record.pkid)&lt;br /&gt;
&lt;br /&gt;
        try:&lt;br /&gt;
            myret = tempCur.Record.totalrec&lt;br /&gt;
            self._totalrec = myret&lt;br /&gt;
            self._balance = self.Parent.Record.course_cost - myret&lt;br /&gt;
        except:&lt;br /&gt;
            myret = 0&lt;br /&gt;
            self._totalrec = myret&lt;br /&gt;
            self._balance = self.Parent.Record.course_cost&lt;br /&gt;
        return myret&lt;br /&gt;
&lt;br /&gt;
    def getBalance(self):&lt;br /&gt;
        try:&lt;br /&gt;
            myret = self._balance&lt;br /&gt;
        except:&lt;br /&gt;
            myret = 0&lt;br /&gt;
        return myret&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the form I had a control that used the virtual field &amp;lt;code&amp;gt;totalrec&amp;lt;/code&amp;gt;. Which fired the bizobj method &amp;lt;code&amp;gt;gettotalRec()&amp;lt;/code&amp;gt; to set the bizobj attribute &amp;lt;code&amp;gt;self._balance&amp;lt;/code&amp;gt;. Then on the form I had a control that set the following:&lt;br /&gt;
&lt;br /&gt;
: DataSource = the course payment table&lt;br /&gt;
: DataField = getBalance&lt;br /&gt;
&lt;br /&gt;
Dabo then used the method getBalance to fill in the balance.&lt;/div&gt;</summary>
		<author><name>Ed</name></author>
	</entry>
</feed>