r20608 - gnucash/trunk/src - Add validation of tax-entity-type in book relative to locale-based tsx.scm

J. Alex Aycinena alex.aycinena at code.gnucash.org
Mon May 2 20:06:12 EDT 2011


Author: alex.aycinena
Date: 2011-05-02 20:06:11 -0400 (Mon, 02 May 2011)
New Revision: 20608
Trac: http://svn.gnucash.org/trac/changeset/20608

Modified:
   gnucash/trunk/src/app-utils/gnc-ui-util.c
   gnucash/trunk/src/gnome/dialog-tax-info.c
Log:
Add validation of tax-entity-type in book relative to locale-based tsx.scm

Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c	2011-05-02 06:07:16 UTC (rev 20607)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c	2011-05-03 00:06:11 UTC (rev 20608)
@@ -459,6 +459,7 @@
 char *
 gnc_ui_account_get_tax_info_string (const Account *account)
 {
+    static SCM get_tax_entity_types = SCM_UNDEFINED;
     static SCM get_form = SCM_UNDEFINED;
     static SCM get_desc = SCM_UNDEFINED;
 
@@ -498,15 +499,17 @@
     }
     else  /* with tax code */
     {
+        SCM tax_types;
+        gboolean tax_type_valid = FALSE;
         const gchar *num_code = NULL;
         const gchar *prefix = "N";
 
         tax_type = gnc_get_current_book_tax_type ();
         if (tax_type == NULL || (safe_strcmp (tax_type, "") == 0))
             return g_strdup (_("Tax entity type not specified"));
+
         atype = xaccAccountGetType (account);
-        /*    tax_entity_type = scm_from_locale_string (tax_type); <- requires guile 1.8*/
-        tax_entity_type = scm_makfrom0str (tax_type); /* <-guile 1.6  */
+        tax_entity_type = scm_from_locale_string (tax_type);
 
         if (get_form == SCM_UNDEFINED)
         {
@@ -536,14 +539,38 @@
 
             g_return_val_if_fail (module, NULL);
 
-            get_form = scm_c_eval_string ("(false-if-exception gnc:txf-get-form)");
+            get_tax_entity_types = scm_c_eval_string
+                ("(false-if-exception gnc:txf-get-tax-entity-type-codes)");
+            get_form = scm_c_eval_string
+                ("(false-if-exception gnc:txf-get-form)");
             get_desc = scm_c_eval_string
-                       ("(false-if-exception gnc:txf-get-description)");
+                ("(false-if-exception gnc:txf-get-description)");
         }
 
+        g_return_val_if_fail (scm_is_procedure (get_tax_entity_types),
+            NULL);
         g_return_val_if_fail (scm_is_procedure (get_form), NULL);
         g_return_val_if_fail (scm_is_procedure (get_desc), NULL);
 
+        tax_types = scm_call_0 (get_tax_entity_types);
+        if (!scm_is_list (tax_types))
+            return g_strdup (_("Tax entity types not available"));
+        while (!scm_is_null (tax_types))
+        {
+            SCM type_scm;
+            gchar *str;
+
+            type_scm  = SCM_CAR (tax_types);
+            tax_types = SCM_CDR (tax_types);
+            str = scm_is_symbol(type_scm) ? SCM_SYMBOL_CHARS(type_scm) : "";
+            if (safe_strcmp (tax_type, str) == 0)
+                tax_type_valid = TRUE;
+            /* g_free (str); */
+        }
+        if (!tax_type_valid)
+            return g_strdup_printf (_("Tax entity type not valid: %s"),
+                        tax_type);
+
         category = scm_c_eval_string (atype == ACCT_TYPE_INCOME ?
                                       "txf-income-categories" :
                                       (atype == ACCT_TYPE_EXPENSE ?

Modified: gnucash/trunk/src/gnome/dialog-tax-info.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-tax-info.c	2011-05-02 06:07:16 UTC (rev 20607)
+++ gnucash/trunk/src/gnome/dialog-tax-info.c	2011-05-03 00:06:11 UTC (rev 20608)
@@ -227,6 +227,8 @@
     SCM tax_entity_type;
     SCM category;
     SCM codes;
+    SCM tax_types;
+    gboolean tax_type_valid = FALSE;
 
     if (ti_dialog->tax_type == NULL ||
             (safe_strcmp (ti_dialog->tax_type, "") == 0))
@@ -236,10 +238,34 @@
     }
     else
     {
-        /*     tax_entity_type = scm_from_locale_string (ti_dialog->tax_type); <- Req's guile 1.8 */
-        tax_entity_type = scm_makfrom0str (ti_dialog->tax_type); /* <-guile 1.6  */
+        tax_entity_type = scm_from_locale_string (ti_dialog->tax_type);
     }
 
+    /* validate that tax_type in book is valid (can be untrue if locales
+       are changed) */
+    tax_types = scm_call_0 (getters.tax_entity_types);
+    if (!scm_is_list (tax_types))
+    {
+        destroy_txf_infos (infos);
+        return NULL;
+    }
+    while (!scm_is_null (tax_types))
+    {
+        SCM type_scm;
+        gchar *str;
+
+        type_scm  = SCM_CAR (tax_types);
+        tax_types = SCM_CDR (tax_types);
+        str = scm_is_symbol(type_scm) ? SCM_SYMBOL_CHARS(type_scm) : "";
+        if (safe_strcmp (ti_dialog->tax_type, str) == 0)
+                tax_type_valid = TRUE;
+    }
+    if (!tax_type_valid)
+    {
+        destroy_txf_infos (infos);
+        return NULL;
+    }
+
     switch (acct_category)
     {
     case INCOME:



More information about the gnucash-changes mailing list