On 5/20/10 8:04 AM, Ed Leafe wrote:
> On May 20, 2010, at 10:19 AM, Carey Gagnon wrote:
>
>> The brick wall I hit is this:
>>
>> I have a database with different customers, projects, and tasks, with start
>> times and end times. I have created a virtual field to get the duration of
>> those tasks. Works great to here.
>>
>> The brick wall??
>>
>> Now I want to take that duration virtual field and create another virtual
>> field that will calculate the total time for the project.
>
>       I'm not sure that another virtual field is the best solution, unless it 
> is defined as part of the project bizobj. Is that what you're doing? It would 
> be pretty meaningless as part of the tasks bizobj.
>
>       If the virtual field is defined in the project bizobj, it is 
> straightforward to calculate the sum of the child values for a given project. 
> Paul has done much more work on this, so I'm hoping he can give you a better 
> example than I could come up with.

If I understand correctly, you have a Projects bizobj that has a Tasks bizobj 
as a 
child. The Tasks bizobj has a virtual field that figures out the time_spent on 
each 
row by deriving it from time_start and time_finished. That is working.

Now, you want a VirtualField in the Projects bizobj that totals all the 
Tasks.Record.time_spent values. There are different ways to accomplish this but 
I 
tend to do:

from decimal import Decimal

class Projects(dabo.biz.dBizobj):
   def initProperties(self):
     self.bizTasks = BizTasks(self.Application.dbConnection)
     self.addChild(self.bizTasks)
     self.VirtualFields["project_time_spent"] = self.getProjectTimeSpent
     ...

def getProjectTimeSpent():
   tasks = self.bizTasks
   ds = tasks.getDataSet(flds=("time_spent","))
   if not ds:
     return Decimal("0")
   return sum([r["time_spent"] for r in ds])

Paul
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/[email protected]

Reply via email to