Bug 25655

Summary: Additionally store actual cost in foreign currency and currency from the invoice
Product: Koha Reporter: Katrin Fischer <katrin.fischer>
Component: AcquisitionsAssignee: Jonathan Druart <jonathan.druart>
Status: CLOSED FIXED QA Contact: Katrin Fischer <katrin.fischer>
Severity: enhancement    
Priority: P4 CC: caroline.cyr-la-rose, jonathan.druart, matt.blenkinsop, michaela.sieber, nick, tomascohen
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24158
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24971
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=18412
Change sponsored?: Sponsored Patch complexity: Medium patch
Documentation contact: Documentation submission:
Text to go in the release notes:
When receiving an item with a price in a foreign currency, you already had the option to calculate the price in the active currency, but the original price and currency were not stored. They will now be stored in `invoice_unitprice` and `invoice_currency` in the `aqorders` table.
Version(s) released in:
23.05.00
Circulation function:
Bug Depends on:    
Bug Blocks: 32705, 36626, 33863    
Attachments: Receive Order in acq / Additionally store actual cost in foreign currency
Bug 25655: DB changes
Bug 25655: DBIC changes
Bug 25655: REST API specs
Bug 25655: Store actual cost in foreign currency and currency from the invoice
Bug 25655: Save values from ModOrderReceive
Bug 25655: Select currency and prefill unitprice with previous receipt
Bug 25655: Add tests
Bug 25655: DB changes
Bug 25655: DBIC changes
Bug 25655: REST API specs
Bug 25655: Store actual cost in foreign currency and currency from the invoice
Bug 25655: Save values from ModOrderReceive
Bug 25655: Select currency and prefill unitprice with previous receipt
Bug 25655: Add tests
Bug 25655: DB changes
Bug 25655: DBIC changes
Bug 25655: REST API specs
Bug 25655: Store actual cost in foreign currency and currency from the invoice
Bug 25655: Save values from ModOrderReceive
Bug 25655: Select currency and prefill unitprice with previous receipt
Bug 25655: Add tests
Bug 25655: Store invoice price and currency even if no currency change
Bug 25655: Update existing orders in DB
Bug 25655: DB changes
Bug 25655: DBIC changes
Bug 25655: REST API specs
Bug 25655: Store actual cost in foreign currency and currency from the invoice
Bug 25655: Save values from ModOrderReceive
Bug 25655: Select currency and prefill unitprice with previous receipt
Bug 25655: Add tests
Bug 25655: Store invoice price and currency even if no currency change
Bug 25655: Update existing orders in DB

Description Katrin Fischer 2020-06-02 15:39:19 UTC
Bug 24158 allows to calculate the actual cost on time of receive from a foreign currency. If I understand our current database structure correctly, we store in aqorders.currency the currency used at the time of ordering, but we don't store the conversion rate used or the original price. 

I think it would make sense to store them as well. It will also allow to display the orginal prices and rates used on invoices and possibly other pages, which will help staff when checking that everythign was handled correctly.
Comment 1 Katrin Fischer 2022-12-13 09:26:49 UTC
After looking at the current database schema, the new columns in aqorders could be named:

* invoice_currency: defaults to aqbooksellers.invoiceprice, can be changed on receive. We already have the option to enter the price in foreign currency on receive, but it is not stored. (see also bug 24971)
* invoice_unitprice: the unit price in foreign currency as listed on the invoice
Comment 2 Michaela Sieber 2022-12-15 14:21:36 UTC
For further information see attached documentation.


Test plan
1. Receive an order.
2. Mark checkbox ‚Change currency‘
3. select currency from drop down (invoice currency)
4. enter invoice unitprice in foreign currency as listed on the invoice
5. Save invoice
6. Make sure that invoice_unitprice and invoice_currency are stored in the database table aqorders
Comment 3 Michaela Sieber 2022-12-15 14:22:37 UTC
Created attachment 144618 [details]
Receive Order in acq / Additionally store actual cost in foreign currency

Receive Order in acq / Additionally store actual cost in foreign currency
Comment 4 Jonathan Druart 2023-01-31 20:24:21 UTC
Created attachment 145906 [details] [review]
Bug 25655: DB changes

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Comment 5 Jonathan Druart 2023-01-31 20:24:27 UTC
Created attachment 145907 [details] [review]
Bug 25655: DBIC changes

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Comment 6 Jonathan Druart 2023-01-31 20:24:32 UTC
Created attachment 145908 [details] [review]
Bug 25655: REST API specs

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Comment 7 Jonathan Druart 2023-01-31 20:24:37 UTC
Created attachment 145909 [details] [review]
Bug 25655: Store actual cost in foreign currency and currency from the invoice

Bug 24158 allows to calculate the actual cost on time of receive from a foreign currency.
This new enhancement is storing the price and the currency in database, into two new columns
invoice_unitprice an invoice_currency

Test plan:
Create a new order with several items to receive
Receive one or more items, and tick "change currency" on the order
receive page
Select a currency and finish the receiving
In DB notice that the price and the currency have been stored.
Receive remaining items and confirm that the form is prefilled with
previous price and currency

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Comment 8 Jonathan Druart 2023-01-31 20:24:42 UTC
Created attachment 145910 [details] [review]
Bug 25655: Save values from ModOrderReceive

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Comment 9 Jonathan Druart 2023-01-31 20:24:47 UTC
Created attachment 145911 [details] [review]
Bug 25655: Select currency and prefill unitprice with previous receipt

In case of partial order we want to prefill the unit price and the
currency with the value of the previous receipt.

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Comment 10 Jonathan Druart 2023-01-31 20:24:52 UTC
Created attachment 145912 [details] [review]
Bug 25655: Add tests

And fix a bug they caught. We need to undef if a modification is made
and invoice_currency is removed.

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Comment 11 PTFS Europe Sandboxes 2023-02-03 12:42:14 UTC
Created attachment 146082 [details] [review]
Bug 25655: DB changes

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 12 PTFS Europe Sandboxes 2023-02-03 12:42:19 UTC
Created attachment 146084 [details] [review]
Bug 25655: DBIC changes

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 13 PTFS Europe Sandboxes 2023-02-03 12:42:23 UTC
Created attachment 146085 [details] [review]
Bug 25655: REST API specs

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 14 PTFS Europe Sandboxes 2023-02-03 12:42:28 UTC
Created attachment 146086 [details] [review]
Bug 25655: Store actual cost in foreign currency and currency from the invoice

Bug 24158 allows to calculate the actual cost on time of receive from a foreign currency.
This new enhancement is storing the price and the currency in database, into two new columns
invoice_unitprice an invoice_currency

Test plan:
Create a new order with several items to receive
Receive one or more items, and tick "change currency" on the order
receive page
Select a currency and finish the receiving
In DB notice that the price and the currency have been stored.
Receive remaining items and confirm that the form is prefilled with
previous price and currency

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 15 PTFS Europe Sandboxes 2023-02-03 12:42:32 UTC
Created attachment 146087 [details] [review]
Bug 25655: Save values from ModOrderReceive

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 16 PTFS Europe Sandboxes 2023-02-03 12:42:36 UTC
Created attachment 146088 [details] [review]
Bug 25655: Select currency and prefill unitprice with previous receipt

In case of partial order we want to prefill the unit price and the
currency with the value of the previous receipt.

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 17 PTFS Europe Sandboxes 2023-02-03 12:42:40 UTC
Created attachment 146089 [details] [review]
Bug 25655: Add tests

And fix a bug they caught. We need to undef if a modification is made
and invoice_currency is removed.

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 18 Katrin Fischer 2023-02-10 14:36:31 UTC
This works well overall, unit tests and QA script pass. 

What I notice is an inconsistency:

* listprice and currency are used for the original price on ordering.
* invoice_unitprice and invoice_currency are used for the original price on receive.

But: 
* listprice and currency are always set, even if the currency is the active currency.
* invoice_unitprice and invoice_currency are NULL, when the currency matches the active currency.

I see some merit in making the invoice_unitprice behave like the listprice:
* It could make it easier to use these columns in reporting.
* It could make the transition easier if the active currency changes (just had that happen for a library in Croatia)

But maybe there are downsides as well or a reason to keep it like that.

Michaela and Joubu, what do you think?

Note:
* 'Bug 24971 - Pre-select invoice currency from vendor on receive' is not fixed by this patch. The pre-selected currency is the active one.
Comment 19 Jonathan Druart 2023-02-10 14:51:46 UTC
Created attachment 146478 [details] [review]
Bug 25655: DB changes

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 20 Jonathan Druart 2023-02-10 14:51:49 UTC
Created attachment 146479 [details] [review]
Bug 25655: DBIC changes

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 21 Jonathan Druart 2023-02-10 14:51:52 UTC
Created attachment 146480 [details] [review]
Bug 25655: REST API specs

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 22 Jonathan Druart 2023-02-10 14:51:55 UTC
Created attachment 146481 [details] [review]
Bug 25655: Store actual cost in foreign currency and currency from the invoice

Bug 24158 allows to calculate the actual cost on time of receive from a foreign currency.
This new enhancement is storing the price and the currency in database, into two new columns
invoice_unitprice an invoice_currency

Test plan:
Create a new order with several items to receive
Receive one or more items, and tick "change currency" on the order
receive page
Select a currency and finish the receiving
In DB notice that the price and the currency have been stored.
Receive remaining items and confirm that the form is prefilled with
previous price and currency

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 23 Jonathan Druart 2023-02-10 14:51:58 UTC
Created attachment 146482 [details] [review]
Bug 25655: Save values from ModOrderReceive

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 24 Jonathan Druart 2023-02-10 14:52:00 UTC
Created attachment 146483 [details] [review]
Bug 25655: Select currency and prefill unitprice with previous receipt

In case of partial order we want to prefill the unit price and the
currency with the value of the previous receipt.

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 25 Jonathan Druart 2023-02-10 14:52:03 UTC
Created attachment 146484 [details] [review]
Bug 25655: Add tests

And fix a bug they caught. We need to undef if a modification is made
and invoice_currency is removed.

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 26 Katrin Fischer 2023-02-10 15:19:02 UTC
Last changes just were a rebase - my testing overlapped with some changes on master that made it necessary. Marked the important comment important... :)
Comment 27 Jonathan Druart 2023-02-15 07:56:00 UTC
Created attachment 146658 [details] [review]
Bug 25655: Store invoice price and currency even if no currency change

We could need these info to be stored even if the currency is the same
as the active one, for statistic purpose for instance.
Comment 28 Jonathan Druart 2023-02-15 08:05:07 UTC
Created attachment 146660 [details] [review]
Bug 25655: Update existing orders in DB
Comment 29 Jonathan Druart 2023-02-15 08:06:49 UTC
Michaela, I've implemented Katrin's suggestion from comment 18. Could you confirm you are agreeing with it? And retest? :)
Comment 30 Michaela Sieber 2023-02-16 17:20:50 UTC
(In reply to Jonathan Druart from comment #27)
> 
> We could need these info to be stored even if the currency is the same
> as the active one, for statistic purpose for instance.

Good point!
So yes, I agree :-)
Comment 31 Katrin Fischer 2023-02-17 10:41:08 UTC
Created attachment 146818 [details] [review]
Bug 25655: DB changes

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Comment 32 Katrin Fischer 2023-02-17 10:41:10 UTC
Created attachment 146819 [details] [review]
Bug 25655: DBIC changes

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Comment 33 Katrin Fischer 2023-02-17 10:41:13 UTC
Created attachment 146820 [details] [review]
Bug 25655: REST API specs

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Comment 34 Katrin Fischer 2023-02-17 10:41:15 UTC
Created attachment 146821 [details] [review]
Bug 25655: Store actual cost in foreign currency and currency from the invoice

Bug 24158 allows to calculate the actual cost on time of receive from a foreign currency.
This new enhancement is storing the price and the currency in database, into two new columns
invoice_unitprice an invoice_currency

Test plan:
Create a new order with several items to receive
Receive one or more items, and tick "change currency" on the order
receive page
Select a currency and finish the receiving
In DB notice that the price and the currency have been stored.
Receive remaining items and confirm that the form is prefilled with
previous price and currency

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Comment 35 Katrin Fischer 2023-02-17 10:41:18 UTC
Created attachment 146822 [details] [review]
Bug 25655: Save values from ModOrderReceive

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Comment 36 Katrin Fischer 2023-02-17 10:41:21 UTC
Created attachment 146823 [details] [review]
Bug 25655: Select currency and prefill unitprice with previous receipt

In case of partial order we want to prefill the unit price and the
currency with the value of the previous receipt.

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Comment 37 Katrin Fischer 2023-02-17 10:41:23 UTC
Created attachment 146824 [details] [review]
Bug 25655: Add tests

And fix a bug they caught. We need to undef if a modification is made
and invoice_currency is removed.

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Comment 38 Katrin Fischer 2023-02-17 10:41:26 UTC
Created attachment 146825 [details] [review]
Bug 25655: Store invoice price and currency even if no currency change

We could need these info to be stored even if the currency is the same
as the active one, for statistic purpose for instance.

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Comment 39 Katrin Fischer 2023-02-17 10:41:29 UTC
Created attachment 146826 [details] [review]
Bug 25655: Update existing orders in DB

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Comment 40 Katrin Fischer 2023-02-17 10:42:52 UTC
As this patch adds the column invoice_currency I don't think the last patch with the database update is required :)
Comment 41 Katrin Fischer 2023-02-17 11:04:21 UTC
(In reply to Katrin Fischer from comment #40)
> As this patch adds the column invoice_currency I don't think the last patch
> with the database update is required :)

Thinking a bit more about this and correcting myself:

The new database update updates the old order lines, setting:

* invoice_currency to active currency code
* invoice_unitprice to unitprice

This is not wrong, it will not affect any calculations and if you run reports, you'll always get results.

Only thing maybe is that we don't know if they were actually paid in active currency... as we just didn't store this information before. So if you are running reports on how many invoices you have in foreign currencies etc. it could create a false impression.
Comment 42 Katrin Fischer 2023-02-17 11:22:33 UTC
There is no perfect solution for the pre-patch order lines as we are missing information. We need to pick one solution or the other, I am OK with Joubu's pick.
Comment 43 Nick Clemens (kidclamp) 2023-03-02 13:25:47 UTC
(In reply to Katrin Fischer from comment #42)
> There is no perfect solution for the pre-patch order lines as we are missing
> information. We need to pick one solution or the other, I am OK with Joubu's
> pick.

I would lean towards leaving older orders blank - we don't know if the active currency ever changed, or what was done. Leaving them blank and knowing that only the ones received after this patch are populated seems okay to me. Not blocking, but that would be my preference
Comment 44 Jonathan Druart 2023-03-02 14:17:00 UTC
I am ok with whatever you decide!
Comment 45 Tomás Cohen Arazi (tcohen) 2023-03-06 14:15:01 UTC
(In reply to Jonathan Druart from comment #44)
> I am ok with whatever you decide!

Can you please obsolete/amend things so it works as Nick proposed? Thanks!
Comment 46 Katrin Fischer 2023-03-06 14:25:15 UTC
I am also OK with Nicks solution and I know the sponsoring library won't care as they will have this patch from the beginning :)

Joubu, I think obsoleting the last patch should be enough, do you agree?
Comment 47 Tomás Cohen Arazi (tcohen) 2023-03-06 14:28:21 UTC
(In reply to Katrin Fischer from comment #46)
>
> Joubu, I think obsoleting the last patch should be enough, do you agree?

I thought the same but you suggested otherwise last week on IRC heh
Comment 48 Katrin Fischer 2023-03-06 14:36:46 UTC
(In reply to Tomás Cohen Arazi from comment #47)
> (In reply to Katrin Fischer from comment #46)
> >
> > Joubu, I think obsoleting the last patch should be enough, do you agree?
> 
> I thought the same but you suggested otherwise last week on IRC heh

I double checked now :)
Comment 49 Jonathan Druart 2023-03-06 14:57:31 UTC
Last patch obsoleted.
Comment 50 Tomás Cohen Arazi (tcohen) 2023-03-06 17:04:46 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 51 Matt Blenkinsop 2023-03-09 09:38:54 UTC
Enhancement - not backporting to 22.11.x. 
Setting to Needs documenting. 
Nice work everyone!
Comment 52 Caroline Cyr La Rose 2023-05-11 20:27:10 UTC
Not sure what needs documenting here. It seems to be only backend changes. I'll close, but feel free to add details if the manual needs to be changed.