On 1/14/11 7:47 AM, Carey Gagnon wrote: > Can conditional statements be put in string object of the report writer? > > Here's what I'm trying to do. > I have two cost fields. One delivering only, and one with delivery and > installation. We offer both prices to a customer if they request it. > > The two database fields are amountdelivered and amountinstalled. Most times > the only price we give them is delivery only. In my report I want to be able > to print out the amountdelivered field only if it exists. > > Something like this in a string object in the report: (bear with me I'm > still learning python) > > if not self.Record['amountinstalled'] "print nothing" else "Total Cost > Delivery + Installation: %s" % self.Record['amountinstalled'] > > I actually tried this expression in the report but got an "invalid syntax > error". > > Can something like this even be done?
Yes, it can be done. Do you really mean that the 'amountdelivered' field may or may not exist in a given record, or do you mean that it may be 0.00 or None? If the former, I'd encourage you to make the field exist but set it to None if you don't want it printed. Anyway, you'd make the string object's expr property something like: "Total Cost Delivery + Installation: %s" % self.Record['amountdelivered'] if self.Record['amountdelivered'] is not None else "Installed Cost: %s" % self.Record['amountinstalled'] That is one long single line of python code that can be evaluated at runtime, which is what the report writer needs in the expr property of objects. I hope this gets you started! 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]
