Cory Cross wrote:
>> From: Paul McNett <[EMAIL PROTECTED]>
>> Sounds like DOW is derived from orders.date. I'd use VirtualFields for
>> this.
>> pkm ~ http://paulmcnett.com
> 
> Looks like I gave a faulty analogy. Sorry to waste your time.
> The correct analogy:
> PCG: Order-LineItem-Part

No problem. VirtualFields are great for making columns with reformatting 
or additional calculations of existing actual fields. You are needing 
something similar: to update the values of derived fields originally 
gotten via a sql join, but without executing the query all over again. 
Here's what I do.

##- in my base bizobj, I have:

        def afterSave(self):
                self.fillDerivedFields()


        def fillDerivedFields(self):
                """Hook for subclasses."""
                pass

##- in my bizobjs, that have derived fields to fill upon save,
##- I create a tempcursor to get the derived values, and then
##- set the field values appropriately. Here's sample code
##- that fills in derived values from several sources:

        def fillDerivedFields(self):
                cur = self.getTempCursor()

                # cust_name, cust_account:
                cur.UserSQL = "select name, account from customers where 
id='%s'" % 
self.Record.cust_id
                cur.requery()
                if cur.RowCount > 0:
                        self.Record.cust_name = cur.Record.name
                        self.Record.cust_account = cur.Record.account
                else:
                        self.Record.cust_name = None
                        self.Record.cust_account = None

                # prod_name:
                cur.UserSQL = """
select product_lines.name
   from prod_cust
  inner join product_lines
     on product_lines.id = prod_cust.prod_id
  where prod_cust.id='%s'""" % self.Record.prod_cust_id
                cur.requery()
                if cur.RowCount > 0:
                        self.Record.prod_name = cur.Record.name
                else:
                        self.Record.prod_name = None

                # status_name:
                cur.UserSQL = "select name from production_order_status where 
id=%s" % 
self.Record.status_id
                cur.requery()
                if cur.RowCount > 0:
                        self.Record.status_name = cur.Record.name
                else:
                        self.Record.status_name = None


> "description" fields change appropriately. What is the proper way to
> update them without requerying the whole Form? Or should I just
> manipulate the display boxes manually from a cursor?

I'm not sure I've come up with the best way, but it works well for me.

Paul


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

Reply via email to