r23491 - gnucash/trunk/src - Multi-currency "Post invoice" improvements

Geert Janssens gjanssens at code.gnucash.org
Thu Dec 5 05:53:33 EST 2013


Author: gjanssens
Date: 2013-12-05 05:53:32 -0500 (Thu, 05 Dec 2013)
New Revision: 23491
Trac: http://svn.gnucash.org/trac/changeset/23491

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
   gnucash/trunk/src/engine/gncInvoice.c
Log:
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

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2013-12-05 09:41:30 UTC (rev 23490)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2013-12-05 10:53:32 UTC (rev 23491)
@@ -830,19 +830,25 @@
         GNCPrice *convprice;
         gnc_commodity *account_currency = (gnc_commodity*)key;
         gnc_numeric *amount = (gnc_numeric*)value;
+        Timespec pricedate;
 
-        if (show_dialog)
+        convprice = gncInvoiceGetPrice (invoice, account_currency);
+        if (convprice)
+            pricedate = gnc_price_get_time (convprice);
+        if (!convprice || !timespec_equal (&postdate, &pricedate))
         {
-            gnc_info_dialog(iw_get_window(iw), "%s", text);
-            show_dialog = FALSE;
-        }
-
-        convprice = gncInvoiceGetPrice(invoice, account_currency);
-        if (convprice == NULL)
-        {
             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

Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c	2013-12-05 09:41:30 UTC (rev 23490)
+++ gnucash/trunk/src/engine/gncInvoice.c	2013-12-05 10:53:32 UTC (rev 23491)
@@ -642,9 +642,26 @@
 
 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);



More information about the gnucash-changes mailing list