Multi-currency "Post invoice" improvements

- only pop up the exhange rate notification message when an exchange
  rate is effectively asked. Still only pop it up once per post operation.
- ask for conversion rates again if an invoice is reposted on a different date
- only keep one price per foreign currency in the invoice's price list

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23491 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens 2013-12-05 10:53:32 +00:00
parent 361a803de5
commit 71654e984c
2 changed files with 31 additions and 8 deletions

View File

@ -830,19 +830,25 @@ gnc_invoice_post(InvoiceWindow *iw, struct post_invoice_params *post_params)
GNCPrice *convprice;
gnc_commodity *account_currency = (gnc_commodity*)key;
gnc_numeric *amount = (gnc_numeric*)value;
Timespec pricedate;
if (show_dialog)
{
gnc_info_dialog(iw_get_window(iw), "%s", text);
show_dialog = FALSE;
}
convprice = gncInvoiceGetPrice(invoice, account_currency);
if (convprice == NULL)
convprice = gncInvoiceGetPrice (invoice, account_currency);
if (convprice)
pricedate = gnc_price_get_time (convprice);
if (!convprice || !timespec_equal (&postdate, &pricedate))
{
XferDialog *xfer;
gnc_numeric exch_rate;
/* Explain to the user we're about to ask for an exchange rate.
* Only show this dialog once, right before the first xfer dialog pops up.
*/
if (show_dialog)
{
gnc_info_dialog(iw_get_window(iw), "%s", text);
show_dialog = FALSE;
}
/* Note some twisted logic here:
* We ask the exchange rate
* FROM invoice currency

View File

@ -642,9 +642,26 @@ void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry)
void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price)
{
GList *node;
gnc_commodity *commodity;
if (!invoice || !price) return;
/* Keep only one price per commodity per invoice
* So if a price was set previously remove it first */
node = g_list_first(invoice->prices);
commodity = gnc_price_get_commodity (price);
while (node != NULL)
{
GNCPrice *curr = (GNCPrice*)node->data;
if (gnc_commodity_equal (commodity, gnc_price_get_commodity (curr)))
break;
node = g_list_next (node);
}
gncInvoiceBeginEdit (invoice);
if (node)
invoice->prices = g_list_delete_link (invoice->prices, node);
invoice->prices = g_list_prepend(invoice->prices, price);
mark_invoice (invoice);
gncInvoiceCommitEdit (invoice);