[ic] mv_metadata & derived (calculated) data

David Kelly interchange-users@icdevgroup.org
Thu Jun 13 01:45:01 2002


On Thu, 13 Jun 2002 3:55 pm, Mike Heins wrote:
-- [snip]
> Actually it will honor that already, I discover. If you can
> get extended.ui_display_only set to "na", you can use the field
> name "na" without having a column of that name.
>
> I think this patch to lib/UI/pages/admin/db_metaconfig_edit.html
> will get it (only for 4.9, mind you):
>
> --- /DP/db_metaconfig_edit.html	Tue Oct  9 16:40:37 2001
> +++ /dp/db_metaconfig_edit.html	Wed Jun 12 23:52:33 2002
> @@ -70,6 +70,7 @@
>  		code							=> 'View::Table',
>  		name							=> 'Description',
>  		'extended.ui_data_fields'		=> 'Fields to edit',
> +		'extended.ui_display_only'		=> 'Fields for display only',
>  		'extended.left_width' => 'Width specification for label column',
>  		'extended.table_width' => 'Width specification for editor table',
>  	}`
> @@ -78,6 +79,7 @@
>  		code							=> 'hidden_text',
>  		name							=> 'value',
>  		'extended.ui_data_fields'		=> 'move_combo_8',
> +		'extended.ui_display_only'		=> 'text_40',
>  		'extended.table_width'		    => 'text_8',
>  		'extended.left_width'			=> 'text_8',
>  	}`

Ok I seem to have got it honoring alright using IC 4.8.3 by specifing na:na.   
It is now referencing the mv_metadata entry fine.  Next step is the custom 
widget.

> 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:

Is it possible to write a custom widget in 4.8.3 without having to jump 
through too many hoops and do any nasty hacks?  If it is, how would I go 
about it, where would I put the code?

Because this has to be stable, unfortnately I am restricted to 4.8.3 as this 
what our live servers are currently running.

> 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.

Thanks for your help Mike.  It has being invaluable.

Cheers
-- 
David Kelly
CEO / Development Team Leader
Zeald Ltd