Merge branch 'price_and_reconcile' into maint #1165

This commit is contained in:
Christopher Lam
2021-10-13 09:08:51 +08:00
5 changed files with 27 additions and 38 deletions

View File

@@ -313,6 +313,7 @@ gnc_reconcile_view_new (Account *account, GNCReconcileViewType type,
GList *accounts = NULL;
GList *splits;
Query *query;
QofNumericMatch sign;
g_return_val_if_fail (account, NULL);
g_return_val_if_fail ((type == RECLIST_DEBIT) ||
@@ -345,15 +346,11 @@ gnc_reconcile_view_new (Account *account, GNCReconcileViewType type,
g_list_free (accounts);
/* limit the matches to CREDITs and DEBITs only, depending on the type */
if (type == RECLIST_CREDIT)
xaccQueryAddValueMatch(query, gnc_numeric_zero (),
QOF_NUMERIC_MATCH_CREDIT,
QOF_COMPARE_GTE, QOF_QUERY_AND);
else
xaccQueryAddValueMatch(query, gnc_numeric_zero (),
QOF_NUMERIC_MATCH_DEBIT,
QOF_COMPARE_GTE, QOF_QUERY_AND);
sign = (type == RECLIST_CREDIT) ?
QOF_NUMERIC_MATCH_CREDIT : QOF_NUMERIC_MATCH_DEBIT;
xaccQueryAddNumericMatch (query, gnc_numeric_zero (), sign, QOF_COMPARE_GTE,
QOF_QUERY_AND, SPLIT_AMOUNT, NULL);
/* limit the matches only to Cleared and Non-reconciled splits */
xaccQueryAddClearedMatch (query, CLEARED_NO | CLEARED_CLEARED, QOF_QUERY_AND);

View File

@@ -32,6 +32,7 @@
#include "gnc-prefs.h"
#include "gnc-ui.h"
#include "gnc-uri-utils.h"
#include "gnc-glib-utils.h"
#include "gnc-filepath-utils.h"
#include "gnc-warnings.h"
#include "doclinkcell.h"
@@ -89,7 +90,7 @@ gnc_split_register_get_rbaln (VirtualLocation virt_loc, gpointer user_data,
if (subaccounts)
{
children = gnc_account_get_descendants (account);
children = g_list_append (children, account);
children = g_list_prepend (children, account);
}
/* Get the row number we're on, then start with the first row. */
@@ -1388,11 +1389,12 @@ gnc_split_register_get_price_entry (VirtualLocation virt_loc,
split = gnc_split_register_get_split (reg, virt_loc.vcell_loc);
price = xaccSplitGetSharePrice (split);
curr = xaccTransGetCurrency (xaccSplitGetParent (split));
if (gnc_numeric_zero_p (price))
if (gnc_numeric_zero_p (xaccSplitGetAmount(split)) ||
gnc_numeric_zero_p (xaccSplitGetValue(split)))
return NULL;
price = xaccSplitGetSharePrice (split);
curr = xaccTransGetCurrency (xaccSplitGetParent (split));
return xaccPrintAmount (price, gnc_default_price_print_info (curr));
}
@@ -1601,7 +1603,7 @@ get_trans_total_value_subaccounts (SplitRegister* reg, Transaction* trans)
return total;
children = gnc_account_get_descendants (parent);
children = g_list_append (children, parent);
children = g_list_prepend (children, parent);
for (child = children; child; child = child->next)
{
@@ -2191,37 +2193,27 @@ gnc_split_register_confirm (VirtualLocation virt_loc, gpointer user_data)
if (protected_trans_cell)
{
GList* node;
GList* acc_g_list = NULL;
gchar* acc_list = NULL;
gchar* message_format;
for (node = xaccTransGetSplitList (trans); node; node = node->next)
for (GList *node = xaccTransGetSplitList (trans); node; node = node->next)
{
Split* split = node->data;
if (xaccSplitGetReconcile (split) == YREC)
{
Account* acc = xaccSplitGetAccount (split);
gchar* name = gnc_account_get_full_name (acc);
if (acc_list == NULL)
acc_list = g_strconcat ("\n", name, NULL);
else
{
gchar* acc_list_copy = g_strdup (acc_list);
g_free (acc_list);
acc_list = g_strconcat (acc_list_copy, "\n", name, NULL);
g_free (acc_list_copy);
}
g_free (name);
gchar* name = gnc_account_get_full_name (xaccSplitGetAccount (split));
acc_g_list = g_list_prepend (acc_g_list, name);
}
}
acc_list = gnc_g_list_stringjoin (acc_g_list, "\n");
title = _ ("Change transaction containing a reconciled split?");
message_format =
_ ("The transaction you are about to change contains reconciled splits in the following accounts:\n%s"
"\n\nAre you sure you want to continue with this change?");
message = g_strdup_printf (message_format, acc_list);
g_list_free_full (acc_g_list, g_free);
g_free (acc_list);
}

View File

@@ -194,11 +194,6 @@ commissions in cumulative average cost and gain/loss after commission")
(define cap-purch-costs? (opt-val gnc:pagename-general optname-cap-purch-costs))
(define document (gnc:make-html-document))
(define (elt->cell split)
(gnc:html-markup-anchor
(gnc:split-anchor-text split)
(amount->monetary (xaccSplitGetAmount split))))
(define large 10000000)
(define (get-fx db from to time)
(/ (gnc-pricedb-convert-balance-nearest-price-t64 db large from to time)
@@ -232,7 +227,9 @@ commissions in cumulative average cost and gain/loss after commission")
(let ((query (qof-query-create-for-splits)))
(qof-query-set-book query (gnc-get-current-book))
(xaccQueryAddSingleAccountMatch query stock-acct QOF-QUERY-AND)
(xaccQueryGetSplitsUniqueTrans query))))
(let ((result (xaccQueryGetSplitsUniqueTrans query)))
(qof-query-destroy query)
result))))
(define (to-commodity amt)
(if format-cells

View File

@@ -108,7 +108,9 @@
query (logand CLEARED-ALL (lognot CLEARED-VOIDED)) QOF-QUERY-AND)
(xaccQueryAddSingleAccountMatch query account QOF-QUERY-AND)
(xaccQueryAddDateMatchTT query #t from-date #t to-date QOF-QUERY-AND)
(filter desc-filter? (qof-query-run query))))
(let ((result (filter desc-filter? (qof-query-run query))))
(qof-query-destroy query)
result)))
(transactions
(sort-and-delete-duplicates
(map xaccSplitGetParent splits)

View File

@@ -63,7 +63,8 @@
(qof-query-set-book query (gnc-get-current-book))
(xaccQueryAddAccountMatch query (list bank)
QOF-GUID-MATCH-ANY QOF-QUERY-AND)
(set-option options "__reg" "query" (gnc-query2scm query)))
(set-option options "__reg" "query" (gnc-query2scm query))
(qof-query-destroy query))
(let ((sxml (options->sxml options "basic")))
;; this is a simplistic test - counts the number of populated