mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Implement "Duplicate Invoice" feature, where a new invoice is created as a copy of an old one with new date and new ID.
This patch makes this feature available as button "Duplicate" in the search window. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20115 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -2285,6 +2285,70 @@ gnc_ui_invoice_modify (GncInvoice *invoice)
|
||||
return iw;
|
||||
}
|
||||
|
||||
static void
|
||||
set_gncEntry_date(gpointer data, gpointer user_data)
|
||||
{
|
||||
GncEntry *entry = data;
|
||||
const Timespec* new_date = user_data;
|
||||
//g_warning("Modifying date for entry with desc=\"%s\"", gncEntryGetDescription(entry));
|
||||
|
||||
gncEntrySetDate(entry, *new_date);
|
||||
gncEntrySetDateEntered(entry, *new_date);
|
||||
}
|
||||
|
||||
|
||||
InvoiceWindow * gnc_ui_invoice_duplicate (GncInvoice *old_invoice)
|
||||
{
|
||||
InvoiceWindow *iw;
|
||||
GncInvoice *new_invoice = NULL;
|
||||
Timespec new_date;
|
||||
gchar *new_id;
|
||||
GList *node;
|
||||
|
||||
g_assert(old_invoice);
|
||||
|
||||
// Create a deep copy of the old invoice
|
||||
new_invoice = gncInvoiceCopy(old_invoice);
|
||||
|
||||
// The new invoice is for sure active
|
||||
gncInvoiceSetActive(new_invoice, TRUE);
|
||||
|
||||
// and unposted
|
||||
if (gncInvoiceIsPosted (new_invoice))
|
||||
{
|
||||
gboolean result = gncInvoiceUnpost(new_invoice, TRUE);
|
||||
if (!result)
|
||||
{
|
||||
g_warning("Oops, error when unposting the copied invoice; ignoring.");
|
||||
}
|
||||
}
|
||||
|
||||
// Set a new id from the respective counter
|
||||
new_id = gncInvoiceNextID(gnc_get_current_book(),
|
||||
gncInvoiceGetOwner(new_invoice));
|
||||
gncInvoiceSetID(new_invoice, new_id);
|
||||
g_free(new_id);
|
||||
|
||||
// Modify the date to today
|
||||
timespecFromTime_t(&new_date, gnc_timet_get_today_start());
|
||||
gncInvoiceSetDateOpened(new_invoice, new_date);
|
||||
|
||||
// Also modify the date of all entries to today
|
||||
//g_warning("We have %d entries", g_list_length(gncInvoiceGetEntries(new_invoice)));
|
||||
g_list_foreach(gncInvoiceGetEntries(new_invoice),
|
||||
&set_gncEntry_date, &new_date);
|
||||
|
||||
// Now open that newly created invoice in the "edit" window
|
||||
iw = gnc_ui_invoice_edit (new_invoice);
|
||||
|
||||
// And also open the "properties" pop-up... however, changing the
|
||||
// invoice ID won't be copied over to the tab title even though
|
||||
// it's correctly copied into the invoice.
|
||||
iw = gnc_invoice_window_new_invoice (NULL, NULL, new_invoice);
|
||||
|
||||
return iw;
|
||||
}
|
||||
|
||||
InvoiceWindow *
|
||||
gnc_ui_invoice_new (GncOwner *ownerp, QofBook *bookp)
|
||||
{
|
||||
@@ -2343,6 +2407,22 @@ pay_invoice_cb (gpointer *invoice_p, gpointer user_data)
|
||||
pay_invoice_direct (*invoice_p, user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
duplicate_invoice_direct (gpointer invoice, gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (invoice);
|
||||
gnc_ui_invoice_duplicate (invoice);
|
||||
}
|
||||
|
||||
static void
|
||||
duplicate_invoice_cb (gpointer *invoice_p, gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (invoice_p && user_data);
|
||||
if (! *invoice_p)
|
||||
return;
|
||||
duplicate_invoice_direct (*invoice_p, user_data);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
new_invoice_cb (gpointer user_data)
|
||||
{
|
||||
@@ -2381,12 +2461,14 @@ gnc_invoice_search (GncInvoice *start, GncOwner *owner, QofBook *book)
|
||||
{
|
||||
{ N_("View/Edit Invoice"), edit_invoice_cb},
|
||||
{ N_("Process Payment"), pay_invoice_cb},
|
||||
{ N_("Duplicate"), duplicate_invoice_cb},
|
||||
{ NULL },
|
||||
};
|
||||
static GNCSearchCallbackButton bill_buttons[] =
|
||||
{
|
||||
{ N_("View/Edit Bill"), edit_invoice_cb},
|
||||
{ N_("Process Payment"), pay_invoice_cb},
|
||||
{ N_("Duplicate"), duplicate_invoice_cb},
|
||||
{ NULL },
|
||||
};
|
||||
static GNCSearchCallbackButton emp_buttons[] =
|
||||
@@ -2395,6 +2477,7 @@ gnc_invoice_search (GncInvoice *start, GncOwner *owner, QofBook *book)
|
||||
interchangeably in gnucash and mean the same thing. */
|
||||
{ N_("View/Edit Voucher"), edit_invoice_cb},
|
||||
{ N_("Process Payment"), pay_invoice_cb},
|
||||
{ N_("Duplicate"), duplicate_invoice_cb},
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ typedef enum
|
||||
/* Create and edit an invoice */
|
||||
InvoiceWindow * gnc_ui_invoice_edit (GncInvoice *invoice);
|
||||
InvoiceWindow * gnc_ui_invoice_new (GncOwner *owner, QofBook *book);
|
||||
InvoiceWindow * gnc_ui_invoice_duplicate (GncInvoice *invoice);
|
||||
|
||||
/* Search for invoices */
|
||||
GNCSearchWindow * gnc_invoice_search (GncInvoice *start, GncOwner *owner, QofBook *book);
|
||||
|
||||
@@ -343,7 +343,6 @@ GncInvoice *gncInvoiceCopy (const GncInvoice *from)
|
||||
|
||||
invoice->to_charge_amount = from->to_charge_amount;
|
||||
invoice->date_opened = from->date_opened;
|
||||
invoice->date_posted = from->date_posted;
|
||||
|
||||
// Copy all invoice->entries
|
||||
for (node = from->entries; node; node = node->next)
|
||||
@@ -364,6 +363,11 @@ GncInvoice *gncInvoiceCopy (const GncInvoice *from)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: The prices are not (yet) copied; is this a problem?
|
||||
|
||||
// Posted-date and the posted Txn is intentionally not copied; the
|
||||
// copy isn't "posted" but needs to be posted by the user.
|
||||
|
||||
gncInvoiceCommitEdit(invoice);
|
||||
|
||||
return invoice;
|
||||
|
||||
Reference in New Issue
Block a user