mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug #638543: Centralize the counter formatting in qofbook.
Patch by Matthijs Kooijman: Instead of querying qofbook for the next counter number and then doing the formatting in all the different business modules (all using the same format string), the formatting is now moved inside qof_book_increment_and_get_counter (which is renamed to qof_book_increment_and_format_counter). This changes the return value of a bunch of helper functions from gint64 (the counter value) to gchar* (the formatted counter value), but does not have any user-visible changes. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20054 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
670b3b63da
commit
aa151f0ae0
@ -305,8 +305,7 @@ gnc_customer_window_ok_cb (GtkWidget *widget, gpointer data)
|
||||
/* Set the customer id if one has not been chosen */
|
||||
if (safe_strcmp (gtk_entry_get_text (GTK_ENTRY (cw->id_entry)), "") == 0)
|
||||
{
|
||||
string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
|
||||
gncCustomerNextID (cw->book));
|
||||
string = gncCustomerNextID (cw->book);
|
||||
gtk_entry_set_text (GTK_ENTRY (cw->id_entry), string);
|
||||
g_free(string);
|
||||
}
|
||||
|
@ -241,8 +241,7 @@ gnc_employee_window_ok_cb (GtkWidget *widget, gpointer data)
|
||||
/* Set the employee id if one has not been chosen */
|
||||
if (safe_strcmp (gtk_entry_get_text (GTK_ENTRY (ew->id_entry)), "") == 0)
|
||||
{
|
||||
string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
|
||||
gncEmployeeNextID (ew->book));
|
||||
string = gncEmployeeNextID (ew->book);
|
||||
gtk_entry_set_text (GTK_ENTRY (ew->id_entry), string);
|
||||
g_free(string);
|
||||
}
|
||||
|
@ -364,8 +364,7 @@ gnc_invoice_window_verify_ok (InvoiceWindow *iw)
|
||||
Therefore we pass the GncOwer to gncInvoiceNextID
|
||||
so it knows whether we are creating a bill
|
||||
or an invoice. */
|
||||
string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
|
||||
gncInvoiceNextID(iw->book, &(iw->owner)));
|
||||
string = gncInvoiceNextID(iw->book, &(iw->owner));
|
||||
gtk_entry_set_text (GTK_ENTRY (iw->id_entry), string);
|
||||
g_free(string);
|
||||
}
|
||||
|
@ -149,8 +149,7 @@ gnc_job_verify_ok (JobWindow *jw)
|
||||
res = gtk_entry_get_text (GTK_ENTRY (jw->id_entry));
|
||||
if (safe_strcmp (res, "") == 0)
|
||||
{
|
||||
string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
|
||||
gncJobNextID(jw->book));
|
||||
string = gncJobNextID(jw->book);
|
||||
gtk_entry_set_text (GTK_ENTRY (jw->id_entry), string);
|
||||
g_free(string);
|
||||
}
|
||||
|
@ -705,8 +705,7 @@ gnc_order_window_new_order (QofBook *bookp, GncOwner *owner)
|
||||
ow);
|
||||
/* Setup initial values */
|
||||
ow->order_guid = *gncOrderGetGUID (order);
|
||||
string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
|
||||
gncOrderNextID(bookp));
|
||||
string = gncOrderNextID(bookp);
|
||||
gtk_entry_set_text (GTK_ENTRY (ow->id_entry), string);
|
||||
g_free(string);
|
||||
|
||||
|
@ -225,8 +225,7 @@ gnc_vendor_window_ok_cb (GtkWidget *widget, gpointer data)
|
||||
/* Check for valid id and set one if necessary */
|
||||
if (safe_strcmp (gtk_entry_get_text (GTK_ENTRY (vw->id_entry)), "") == 0)
|
||||
{
|
||||
string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
|
||||
gncVendorNextID(vw->book));
|
||||
string = gncVendorNextID(vw->book);
|
||||
gtk_entry_set_text (GTK_ENTRY (vw->id_entry), string);
|
||||
g_free(string);
|
||||
}
|
||||
|
@ -949,7 +949,7 @@ gboolean gncCustomerRegister (void)
|
||||
return qof_object_register (&gncCustomerDesc);
|
||||
}
|
||||
|
||||
gint64 gncCustomerNextID (QofBook *book)
|
||||
gchar *gncCustomerNextID (QofBook *book)
|
||||
{
|
||||
return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
|
||||
return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "gncCustomer.h"
|
||||
|
||||
gboolean gncCustomerRegister (void);
|
||||
gint64 gncCustomerNextID (QofBook *book);
|
||||
gchar *gncCustomerNextID (QofBook *book);
|
||||
|
||||
/** The gncCloneCustomer() routine makes a copy of the indicated
|
||||
* customer, placing it in the indicated book. It copies
|
||||
|
@ -740,7 +740,7 @@ gboolean gncEmployeeRegister (void)
|
||||
return qof_object_register (&gncEmployeeDesc);
|
||||
}
|
||||
|
||||
gint64 gncEmployeeNextID (QofBook *book)
|
||||
gchar *gncEmployeeNextID (QofBook *book)
|
||||
{
|
||||
return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
|
||||
return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "gncEmployee.h"
|
||||
|
||||
gboolean gncEmployeeRegister (void);
|
||||
gint64 gncEmployeeNextID (QofBook *book);
|
||||
gchar *gncEmployeeNextID (QofBook *book);
|
||||
|
||||
/** The gncCloneEmployee() routine makes a copy of the indicated
|
||||
* employee, placing it in the indicated book. It copies
|
||||
|
@ -2125,22 +2125,22 @@ gboolean gncInvoiceRegister (void)
|
||||
return qof_object_register (&gncInvoiceDesc);
|
||||
}
|
||||
|
||||
gint64 gncInvoiceNextID (QofBook *book, GncOwner *owner)
|
||||
gchar *gncInvoiceNextID (QofBook *book, GncOwner *owner)
|
||||
{
|
||||
gint64 nextID;
|
||||
gchar *nextID;
|
||||
switch (gncOwnerGetType(gncOwnerGetEndOwner(owner)))
|
||||
{
|
||||
case GNC_OWNER_CUSTOMER:
|
||||
nextID = qof_book_increment_and_get_counter (book, "gncInvoice");
|
||||
nextID = qof_book_increment_and_format_counter (book, "gncInvoice");
|
||||
break;
|
||||
case GNC_OWNER_VENDOR:
|
||||
nextID = qof_book_increment_and_get_counter (book, "gncBill");
|
||||
nextID = qof_book_increment_and_format_counter (book, "gncBill");
|
||||
break;
|
||||
case GNC_OWNER_EMPLOYEE:
|
||||
nextID = qof_book_increment_and_get_counter (book, "gncExpVoucher");
|
||||
nextID = qof_book_increment_and_format_counter (book, "gncExpVoucher");
|
||||
break;
|
||||
default:
|
||||
nextID = qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
|
||||
nextID = qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
|
||||
break;
|
||||
}
|
||||
return nextID;
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include "gncOwner.h"
|
||||
|
||||
gboolean gncInvoiceRegister (void);
|
||||
gint64 gncInvoiceNextID (QofBook *book, GncOwner *owner);
|
||||
gchar *gncInvoiceNextID (QofBook *book, GncOwner *owner);
|
||||
void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc);
|
||||
void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn);
|
||||
void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot);
|
||||
|
@ -583,7 +583,7 @@ gboolean gncJobRegister (void)
|
||||
return qof_object_register (&gncJobDesc);
|
||||
}
|
||||
|
||||
gint64 gncJobNextID (QofBook *book)
|
||||
gchar *gncJobNextID (QofBook *book)
|
||||
{
|
||||
return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
|
||||
return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "gncJob.h"
|
||||
|
||||
gboolean gncJobRegister (void);
|
||||
gint64 gncJobNextID (QofBook *book);
|
||||
gchar *gncJobNextID (QofBook *book);
|
||||
|
||||
/** The gncCloneTaxTable() routine makes a copy of the indicated
|
||||
* tax table, placing it in the indicated book. It copies
|
||||
|
@ -604,7 +604,7 @@ gboolean gncOrderRegister (void)
|
||||
return qof_object_register (&gncOrderDesc);
|
||||
}
|
||||
|
||||
gint64 gncOrderNextID (QofBook *book)
|
||||
gchar *gncOrderNextID (QofBook *book)
|
||||
{
|
||||
return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
|
||||
return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "gncOrder.h"
|
||||
|
||||
gboolean gncOrderRegister (void);
|
||||
gint64 gncOrderNextID (QofBook *book);
|
||||
gchar *gncOrderNextID (QofBook *book);
|
||||
|
||||
/** The gncCloneOrder() routine makes a copy of the indicated
|
||||
* order, placing it in the indicated book. It copies
|
||||
|
@ -859,7 +859,7 @@ gboolean gncVendorRegister (void)
|
||||
return qof_object_register (&gncVendorDesc);
|
||||
}
|
||||
|
||||
gint64 gncVendorNextID (QofBook *book)
|
||||
gchar *gncVendorNextID (QofBook *book)
|
||||
{
|
||||
return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
|
||||
return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "gncVendor.h"
|
||||
|
||||
gboolean gncVendorRegister (void);
|
||||
gint64 gncVendorNextID (QofBook *book);
|
||||
gchar *gncVendorNextID (QofBook *book);
|
||||
|
||||
/** The gncCloneVendor() routine makes a copy of the indicated
|
||||
* vendor, placing it in the indicated book. It copies
|
||||
|
@ -429,8 +429,8 @@ qof_book_get_counter (QofBook *book, const char *counter_name)
|
||||
}
|
||||
}
|
||||
|
||||
gint64
|
||||
qof_book_increment_and_get_counter (QofBook *book, const char *counter_name)
|
||||
gchar *
|
||||
qof_book_increment_and_format_counter (QofBook *book, const char *counter_name)
|
||||
{
|
||||
QofBackend *be;
|
||||
KvpFrame *kvp;
|
||||
@ -440,13 +440,13 @@ qof_book_increment_and_get_counter (QofBook *book, const char *counter_name)
|
||||
if (!book)
|
||||
{
|
||||
PWARN ("No book!!!");
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!counter_name || *counter_name == '\0')
|
||||
{
|
||||
PWARN ("Invalid counter name.");
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get the current counter value from the KVP in the book. */
|
||||
@ -454,7 +454,7 @@ qof_book_increment_and_get_counter (QofBook *book, const char *counter_name)
|
||||
|
||||
/* Check if an error occured */
|
||||
if (counter < 0)
|
||||
return -1;
|
||||
return NULL;
|
||||
|
||||
/* Increment the counter */
|
||||
counter++;
|
||||
@ -465,7 +465,7 @@ qof_book_increment_and_get_counter (QofBook *book, const char *counter_name)
|
||||
if (!kvp)
|
||||
{
|
||||
PWARN ("Book has no KVP_Frame");
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Save off the new counter */
|
||||
@ -476,7 +476,8 @@ qof_book_increment_and_get_counter (QofBook *book, const char *counter_name)
|
||||
qof_book_mark_dirty(book);
|
||||
qof_book_commit_edit(book);
|
||||
|
||||
return counter;
|
||||
/* Generate a string version of the counter */
|
||||
return g_strdup_printf ("%.6" G_GINT64_FORMAT, counter);
|
||||
}
|
||||
|
||||
/* Determine whether this book uses trading accounts */
|
||||
|
@ -283,11 +283,11 @@ gboolean qof_book_equal (const QofBook *book_1, const QofBook *book_2);
|
||||
*/
|
||||
gint64 qof_book_get_counter (QofBook *book, const char *counter_name);
|
||||
|
||||
/** This will increment the named counter for this book and return it.
|
||||
* The return value is -1 on error or the (new) value of the
|
||||
* counter.
|
||||
/** This will increment the named counter for this book and format it.
|
||||
* The return value is NULL on error or the formatted (new) value of
|
||||
* the counter. The caller should free the result with g_gree.
|
||||
*/
|
||||
gint64 qof_book_increment_and_get_counter (QofBook *book, const char *counter_name);
|
||||
gchar *qof_book_increment_and_format_counter (QofBook *book, const char *counter_name);
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user