This patch adds a new account selection filter allowing valid commodity to be restricted, and makes use of it for bill posting. This filter is allowed to be NULL (just as with the 'account type' filter) and when NULL, isn't used. The patch also fixes a bug where gnc commodity copy wasn't copying mnemonic, thus erroneously making a copy not equal to the original when comparison happens. The behaviour is that the user isn't able to select a post account in the wrong currency. If there is no possible account (aka, EVERYTHING gets filtered out) they get a blank combo box. This is consistent with what the account type filter does when there are no valid account-type accounts.

-Jamie
diff -r gnucash17663/src/business/business-gnome/business-gnome-utils.c gnucash17663mc/src/business/business-gnome/business-gnome-utils.c
368a369,376
> GList *
> gnc_business_commodities (GncOwner *owner)
> {
>   g_return_val_if_fail (owner, NULL);
> 
>   return (g_list_prepend (NULL, gncOwnerGetCurrency(owner)));
> }
> 
diff -r gnucash17663/src/business/business-gnome/business-gnome-utils.h gnucash17663mc/src/business/business-gnome/business-gnome-utils.h
64a65,67
> /* Return a list of currencies associated with the owner */
> GList * gnc_business_commodities (GncOwner *owner);
> 
diff -r gnucash17663/src/business/business-gnome/dialog-date-close.c gnucash17663mc/src/business/business-gnome/dialog-date-close.c
49a50
>   GList * acct_commodities;
109c110
<   gnc_account_sel_set_acct_filters( gas, ddc->acct_types );
---
>   gnc_account_sel_set_acct_filters( gas, ddc->acct_types, ddc->acct_commodities );
231,232c232,233
< 				GList * acct_types, GNCBook *book,
< 				GncBillTerm *terms,
---
> 				GList * acct_types, GList * acct_commodities, 
>                                 GNCBook *book, GncBillTerm *terms,
255a257
>   ddc->acct_commodities = acct_commodities;
diff -r gnucash17663/src/business/business-gnome/dialog-date-close.h gnucash17663mc/src/business/business-gnome/dialog-date-close.h
55,57c55,57
< 				gboolean set_default_acct,
< 				GList * acct_types, GNCBook *book,
< 				GncBillTerm *terms,
---
>                                 gboolean set_default_acct,
> 				GList * acct_types, GList * acct_commodities, 
>                                 GNCBook *book, GncBillTerm *terms,
diff -r gnucash17663/src/business/business-gnome/dialog-employee.c gnucash17663mc/src/business/business-gnome/dialog-employee.c
477c477
<   gnc_account_sel_set_acct_filters (GNC_ACCOUNT_SEL(edit), acct_types);
---
>   gnc_account_sel_set_acct_filters (GNC_ACCOUNT_SEL(edit), acct_types, NULL);
diff -r gnucash17663/src/business/business-gnome/dialog-invoice.c gnucash17663mc/src/business/business-gnome/dialog-invoice.c
604a605
>   GList * acct_commodities = NULL;
652a654,656
>   /* Determine which commodity we're working with */
>   acct_commodities = gnc_business_commodities(&(iw->owner));
>   
668c672
< 				       acct_types, iw->book, iw->terms,
---
> 				       acct_types, acct_commodities, iw->book, iw->terms,
diff -r gnucash17663/src/engine/gnc-commodity.c gnucash17663mc/src/engine/gnc-commodity.c
890a891
>   gnc_commodity_set_mnemonic (dest, gnc_commodity_get_mnemonic(src));
1495a1497,1507
> int gnc_commodity_compare(const gnc_commodity * a, const gnc_commodity * b)
> {
>     if (gnc_commodity_equal(a,b))
>     {
>         return 0;
>     }
>     else
>     {
>         return 1;
>     }
> }
diff -r gnucash17663/src/engine/gnc-commodity.h gnucash17663mc/src/engine/gnc-commodity.h
644a645,653
> 
> /** This routine returns 0 if the two commodities are equal, 1 otherwise.
>  *  Commodities are equal if they have the same namespace, mnemonic,
>  *  fullname, exchange private code and fraction.
>  *  This function is useful for list-traversal comparison purposes where
>  *  The semantics are 0, <0, or >0 (equal, greater than, less than) rather
>  *   than "true or false"
>  */
> int gnc_commodity_compare(const gnc_commodity * a, const gnc_commodity * b);
diff -r gnucash17663/src/gnome/druid-loan.c gnucash17663mc/src/gnome/druid-loan.c
506c506
<                                                 gas, gas_data[i].allowableAccounts );
---
>                                                 gas, gas_data[i].allowableAccounts, NULL );
diff -r gnucash17663/src/gnome/gnc-plugin-page-account-tree.c gnucash17663mc/src/gnome/gnc-plugin-page-account-tree.c
855c855
<   gnc_account_sel_set_acct_filters (gas, filter);
---
>   gnc_account_sel_set_acct_filters (gas, filter, NULL);
diff -r gnucash17663/src/gnome-utils/dialog-book-close.c gnucash17663mc/src/gnome-utils/dialog-book-close.c
336c336
< 				   equity_list);
---
> 				   equity_list, NULL);
344c344
< 				   equity_list);
---
> 				   equity_list, NULL);
diff -r gnucash17663/src/gnome-utils/dialog-options.c gnucash17663mc/src/gnome-utils/dialog-options.c
1831c1831
<   gnc_account_sel_set_acct_filters(GNC_ACCOUNT_SEL(value), acct_type_list);
---
>   gnc_account_sel_set_acct_filters(GNC_ACCOUNT_SEL(value), acct_type_list, NULL);
diff -r gnucash17663/src/gnome-utils/gnc-account-sel.c gnucash17663mc/src/gnome-utils/gnc-account-sel.c
33a34
> #include "gnc-commodity.h"
37a39
> #include "gnc-session.h"
251a254,264
> 
>         if ( atnd->gas->acctCommodityFilters ) {
>                 if ( g_list_find_custom( atnd->gas->acctCommodityFilters,
>                                   GINT_TO_POINTER(xaccAccountGetCommodity( a )),
>                                   gnc_commodity_compare) 
>                      == NULL ) {
>                         return;
>                 }
>         }
> 
>         
327c340
< gnc_account_sel_set_acct_filters( GNCAccountSel *gas, GList *filters )
---
> gnc_account_sel_set_acct_filters( GNCAccountSel *gas, GList *typeFilters, GList *commodityFilters )
328a342,345
>         GList *src=NULL;
>         GList *dest=NULL;
>         gnc_commodity* commClone=NULL;
> 
333,334c350,357
<         /* If it's null, then no filters exist. */
<         if ( ! filters ) {
---
> 
>         if ( gas->acctCommodityFilters != NULL) {
>                 g_list_free( gas->acctCommodityFilters );
>                 gas->acctCommodityFilters = NULL;
>         }
> 
>         /* If both filters are null, then no filters exist. */
>         if (( ! typeFilters ) && ( ! commodityFilters)) {
336a360
> 
339c363,387
<         gas->acctTypeFilters = g_list_copy( filters );
---
>         if (typeFilters)
>         {
>             gas->acctTypeFilters = g_list_copy( typeFilters );
>         }
> 
>         if (commodityFilters)
>         {
>             src = commodityFilters;
> 
>             while (src->data != NULL)
>             {
>                 //gnc_commodity_clone would have been nice but it expects me to 
>                 //insert the clone into a book, which I don't want to do.
>                 commClone = gnc_commodity_new(qof_session_get_book(gnc_get_current_session()), "","","","",1);
>                 gnc_commodity_copy(commClone, src->data);
>                 dest = g_list_prepend(dest, commClone);
>                 if (src->next == NULL)
>                 {
>                     break;
>                 }
>                 src = src->next;
>             }
>             gas->acctCommodityFilters = dest;
>         }
> 
diff -r gnucash17663/src/gnome-utils/gnc-account-sel.h gnucash17663mc/src/gnome-utils/gnc-account-sel.h
48a49
> 	GList *acctCommodityFilters;
84c85,86
<  * @param filters A GList of GNCAccountType identifiers which are allowed.
---
>  * @param typeFilters A GList of GNCAccountType identifiers which are allowed.
>  * @param commodityFilters A GList of gnc_commodity types which are allowed.
87c89
< void gnc_account_sel_set_acct_filters( GNCAccountSel *gas, GList *filters );
---
> void gnc_account_sel_set_acct_filters( GNCAccountSel *gas, GList *typeFilters, GList *commodityFilters );
_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to