Alternera.Resources.Finance.Convert (alternera_resources_finance v0.9.0)

Copy Markdown View Source

The units of measure's Convert: an amount in one unit, in another of the same base unit. It reads the two units in the caller's tenant, as the caller, and changes nothing.

It is the Ash action UnitOfMeasure.convert (run/3), which the REST API (GET …/unit_of_measure/convert?amount=2&from=KG&to=G) and the MCP tool run_resource_calculation run, and the page's Convert button (handle_action/4) runs that same action.

Summary

Functions

amount of from in to: {:ok, decimal}, or {:error, message} when the two have different base units or to has a factor of 0. The Unit converter in the Workbench uses it too.

What an Ash error from a convert action says, for the action's dialog: each error's own message (KG and L have different base units), not the error's report with its bread crumbs.

A decimal as it is: no trailing zeros, no exponent.

A unit conversion's result as the converter shows it: at most 12 significant digits, but every digit before the point, with no trailing zeros and no exponent. A division by a factor such as 453.59237 (G to LB) runs to Decimal's 28 digits, more than any reader needs; an amount the reader typed is shown with show/1, as it is.

Functions

convert(amount, from, to)

@spec convert(Decimal.t(), struct(), struct()) ::
  {:ok, Decimal.t()} | {:error, String.t()}

amount of from in to: {:ok, decimal}, or {:error, message} when the two have different base units or to has a factor of 0. The Unit converter in the Workbench uses it too.

message(error)

@spec message(term()) :: String.t()

What an Ash error from a convert action says, for the action's dialog: each error's own message (KG and L have different base units), not the error's report with its bread crumbs.

show(decimal)

@spec show(Decimal.t()) :: String.t()

A decimal as it is: no trailing zeros, no exponent.

show_result(decimal)

@spec show_result(Decimal.t()) :: String.t()

A unit conversion's result as the converter shows it: at most 12 significant digits, but every digit before the point, with no trailing zeros and no exponent. A division by a factor such as 453.59237 (G to LB) runs to Decimal's 28 digits, more than any reader needs; an amount the reader typed is shown with show/1, as it is.