0015: find_buy_rate takes currency ID

This commit is contained in:
TMA 2025-07-17 17:30:09 +02:00
parent f962586e3a
commit 76a484ea5e

View file

@ -44,12 +44,15 @@ DECLARE
v_buy_rate NUMERIC;
v_cost NUMERIC;
v_transaction_id public.transactions.id%TYPE;
v_item_currency_id public.accounts.currency%TYPE;
BEGIN
-- this could fail and it would generate exception in python
-- FIXME: convert v_buy_rate < 0 into python exception
v_buy_rate := public.find_buy_rate(i_item_id, i_target_currency_id);
-- this could fail and it would generate exception in python, even though it is not used
--v_sell_rate := public.find_sell_rate(i_item_id, i_target_currency_id);
-- Get item's currency
SELECT currency
INTO STRICT v_item_currency_id
FROM public.accounts
WHERE id=i_item_id;
-- Get the buy rates from the stored functions
v_buy_rate := public.find_buy_rate(v_item_currency_id, i_target_currency_id);
-- Calculate cost and profit
v_cost := i_amount * v_buy_rate;