Skip to content

Commit

Permalink
Replace overly indirect gnc_business_get_default_tax_table.
Browse files Browse the repository at this point in the history
With gncTaxTableGetDefault.

qof_book_get_default_tax_table would have been even better but it
would have created a circular dependency between QofBook and
GncTaxTable.
  • Loading branch information
jralls committed Aug 22, 2019
1 parent 33b1a19 commit fcc1653
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 123 deletions.
10 changes: 4 additions & 6 deletions gnucash/register/ledger-core/gncEntryLedgerLoad.c
Expand Up @@ -34,8 +34,6 @@
#include "gnc-ui-util.h"
#include "recncell.h"

#include "business-helpers.h"

#include "gncEntry.h"
#include "gncEntryLedger.h"
#include "gncEntryLedgerP.h"
Expand Down Expand Up @@ -430,16 +428,16 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
switch (gncOwnerGetType (owner))
{
case GNC_OWNER_CUSTOMER:
table = gnc_business_get_default_tax_table (ledger->book,
GNC_OWNER_CUSTOMER);
table = gncTaxTableGetDefault (ledger->book,
GNC_OWNER_CUSTOMER);

if (gncCustomerGetTaxTableOverride (owner->owner.customer))
table = gncCustomerGetTaxTable (owner->owner.customer);
break;

case GNC_OWNER_VENDOR:
table = gnc_business_get_default_tax_table (ledger->book,
GNC_OWNER_VENDOR);
table = gncTaxTableGetDefault (ledger->book,
GNC_OWNER_VENDOR);

if (gncVendorGetTaxTableOverride (owner->owner.vendor))
table = gncVendorGetTaxTable (owner->owner.vendor);
Expand Down
2 changes: 0 additions & 2 deletions libgnucash/app-utils/CMakeLists.txt
Expand Up @@ -11,7 +11,6 @@ set (app_utils_noinst_HEADERS

set (app_utils_HEADERS
QuickFill.h
business-helpers.h
business-options.h
file-utils.h
gfec.h
Expand Down Expand Up @@ -52,7 +51,6 @@ gnc_add_swig_python_command (swig-app-utils-python
set (app_utils_SOURCES
calculation/expression_parser.c
calculation/fin.c
business-helpers.c
business-options.c
QuickFill.c
file-utils.c
Expand Down
60 changes: 0 additions & 60 deletions libgnucash/app-utils/business-helpers.c

This file was deleted.

35 changes: 0 additions & 35 deletions libgnucash/app-utils/business-helpers.h

This file was deleted.

20 changes: 20 additions & 0 deletions libgnucash/engine/gncTaxTable.c
Expand Up @@ -681,6 +681,26 @@ GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name)
return NULL;
}

GncTaxTable*
gncTaxTableGetDefault (QofBook *book, GncOwnerType type)
{
GSList *path = NULL;
const GncGUID *guid = NULL;
const char *vendor = "Default Vendor TaxTable";
const char *customer = "Default Customer TaxTable";
const char *section = "Business";

g_return_val_if_fail (book != NULL, NULL);
g_return_val_if_fail (type == GNC_OWNER_CUSTOMER || \
type == GNC_OWNER_VENDOR, NULL);
path = g_slist_prepend (path, type == GNC_OWNER_CUSTOMER ? (void*)customer : (void*)vendor);
path = g_slist_prepend (path, (void*)section);

guid = qof_book_get_guid_option (book, path);
g_return_val_if_fail (guid, NULL);

This comment has been minimized.

Copy link
@Bob-IT

Bob-IT Aug 23, 2019

Contributor

Just wondering if the g_return_val_if_fail is a good option, would it be normal to set these default options, I just noticed the assertion 'guid' failed in the trace file as both options are set to 'None'.

This comment has been minimized.

Copy link
@jralls

jralls Aug 23, 2019

Author Member

Good point. It's not an error if the user hasn't set the defaults so no reason to log it as one.

return gncTaxTableLookup (book, guid);
}

GncTaxTableList * gncTaxTableGetTables (QofBook *book)
{
struct _book_info *bi;
Expand Down
39 changes: 20 additions & 19 deletions libgnucash/engine/gncTaxTable.h
Expand Up @@ -60,15 +60,32 @@ typedef struct _gncTaxTableClass GncTaxTableClass;
};
*/
/**
* How to interpret the amount.
* You can interpret it as a VALUE or a PERCENT.
*/
typedef enum
{
GNC_AMT_TYPE_VALUE = 1, /**< tax is a number */
GNC_AMT_TYPE_PERCENT /**< tax is a percentage */
} GncAmountType;

/** How to interpret the TaxIncluded */
typedef enum
{
GNC_TAXINCLUDED_YES = 1, /**< tax is included */
GNC_TAXINCLUDED_NO, /**< tax is not included */
GNC_TAXINCLUDED_USEGLOBAL, /**< use the global setting */
} GncTaxIncluded;

typedef struct _gncTaxTableEntry GncTaxTableEntry;

typedef struct _gncAccountValue GncAccountValue;

#include "Account.h"
#include "qof.h"
#ifdef GNUCASH_MAJOR_VERSION
#include "gncBusiness.h"
#endif
#include "gncOwner.h"

#define GNC_ID_TAXTABLE "gncTaxTable"

Expand All @@ -86,23 +103,6 @@ typedef struct _gncAccountValue GncAccountValue;
(G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_TAXTABLE, GncTaxTableClass))
GType gnc_taxtable_get_type(void);

/**
* How to interpret the amount.
* You can interpret it as a VALUE or a PERCENT.
*/
typedef enum
{
GNC_AMT_TYPE_VALUE = 1, /**< tax is a number */
GNC_AMT_TYPE_PERCENT /**< tax is a percentage */
} GncAmountType;

/** How to interpret the TaxIncluded */
typedef enum
{
GNC_TAXINCLUDED_YES = 1, /**< tax is included */
GNC_TAXINCLUDED_NO, /**< tax is not included */
GNC_TAXINCLUDED_USEGLOBAL, /**< use the global setting */
} GncTaxIncluded;

const char * gncAmountTypeToString (GncAmountType type);
gboolean gncAmountStringToType (const char *str, GncAmountType *type);
Expand Down Expand Up @@ -151,6 +151,7 @@ static inline GncTaxTable *gncTaxTableLookup (const QofBook* book, const GncGUID
}

GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name);
GncTaxTable *gncTaxTableGetDefault (QofBook *book, GncOwnerType type);

typedef GList GncTaxTableList;
GncTaxTableList * gncTaxTableGetTables (QofBook *book);
Expand Down
12 changes: 12 additions & 0 deletions libgnucash/engine/qofbook.cpp
Expand Up @@ -1173,6 +1173,18 @@ qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_
qof_book_commit_edit(book);
}

const GncGUID*
qof_book_get_guid_option(QofBook* book, GSList* path)
{
g_return_val_if_fail(book != nullptr, nullptr);
g_return_val_if_fail(path != nullptr, nullptr);

auto table_value = qof_book_get_option(book, path);
if (!table_value)
return nullptr;
return table_value->get<GncGUID*>();
}

void
qof_book_option_frame_delete (QofBook *book, const char* opt_name)
{
Expand Down
1 change: 1 addition & 0 deletions libgnucash/engine/qofbook.h
Expand Up @@ -375,6 +375,7 @@ char *qof_book_get_counter_format (const QofBook *book,

const char* qof_book_get_string_option(const QofBook* book, const char* opt_name);
void qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_val);
const GncGUID* qof_book_get_guid_option(QofBook* book, GSList* path);
void qof_book_option_frame_delete (QofBook *book, const char* opt_name);

/** Access functions for reading and setting the used-features on this book.
Expand Down
1 change: 0 additions & 1 deletion po/POTFILES.in
Expand Up @@ -506,7 +506,6 @@ gnucash/report/utility-reports/utility-reports.scm
gnucash/report/utility-reports/view-column.scm
gnucash/report/utility-reports/welcome-to-gnucash.scm
libgnucash/app-utils/app-utils.scm
libgnucash/app-utils/business-helpers.c
libgnucash/app-utils/business-options.c
libgnucash/app-utils/business-options.scm
libgnucash/app-utils/business-prefs.scm
Expand Down

0 comments on commit fcc1653

Please sign in to comment.