[ic] mv_metadata & derived (calculated) data

Mike Heins interchange-users@icdevgroup.org
Wed Jun 12 22:44:01 2002


Quoting David Kelly (david@zeald.com):
> On Thu, 13 Jun 2002 11:04 am, Mike Heins wrote:
--snip
> > It sounds like a custom widget, which is easy to do in 4.9. Instead
> > of using the value widget, you would make a custom one which would
> > expect the "options" field to be set to the expression, or you could
> > make the expression in a lookup_query. With this:
> >
> > mv_metadata record:
> >
> >     code: na::na
> >     options: cost,exch_rate,margin
> >     type: calc_price
> >
> > Somewhere in code/UserTag:
> >
> > Widget calc_price addAttr
> > Widget calc_price Routine <<EOR
> > sub {
> >     my $opt = shift;
> >     my $fields = $opt->{options};
> >     my $key = $opt->{key};
> >     my $tab = $opt->{table};
> >
> >     my $db = ::database_exists_ref($tab)
> > 	or return "NO TABLE $tab!";
> >
> >     my $ary = $db->query("select $fields from $tab where sku = '$key'");
> >     my $result = $ary->[0]
> > 	    or return '';
> >     my ($cost, $exch, $margin) = @$result;
> >
> >     if($margin <= 0 or $margin >= 1) {
> > 	my $msg =
> > 	    errmsg("margin for %s must be between 0 and 1, is %s", $key, $margin);
> > 	Log($msg);
> > 	return 'ERROR';
> >     }
> >
> >     return $cost / $margin * $exch;
> > }
> > EOR
> >
> > That even covers multiple table lookups with a fields entry of
> > "cost,exchange.usd,inventory.margin" and an appropriate query.
> > You could get more elaborate and template the expression and
> > the lookup query.
> 
> Ok great! .... that is a good idea - never thought of coming at it from that 
> angle.   The one question that I still have about this solution though is:
> 
> In reference to the previous example from above - the item_edit page uses the 
> table editor tag to display the edit form on the page.   The table editor tag 
> looks up the mv_metadata->products record and checks the "option" field for a 
> list of table fields that are to be displayed by the table editor tag.   
> 
> How would I specify in the mv_metadata -> "products" record that to display 
> the retail price it needs to use this new mv_metadata record "na:na"?  If I 
> just list 'na' along with the other fields in the 'option' field then it just 
> seems to ignore it?   

You need to use just that I think, na:na. I believe it should get put in
the display_only group. Looking at it though, I don't see how the code
does that. You can do it by the link you call things with (i.e. add
ui_display_only=na:na), but what we need is an extended.display_only
setting which will be read and honored.

> 
> Do I need to alter the table editor tag so that when it comes across a entry 
> under 'options' that is not a valid field in the database table it first 
> checks the mv_metadata for a valid record for it before it just ignores it?
> 
> Hope that makes sense.

It does. I think the above, honoring display_only for a field thereby
obviating the need for it to actually exist, is what we need.

-- 
Mike Heins
Perusion -- Expert Interchange Consulting
phone +1.513.523.7621      <mike@perusion.com>

For a successful technology, reality must take precedence over public
relations, for Nature cannot be fooled. -- Dick Feynman