<div dir="ltr">I would request some advice in solving a problem that has been discussed on the gnucash-users list recently.<div><br></div><div>The symptom: a US-based user has reported that on the Accounts tab, when the Tax Info column is displayed, some accounts show 'Sched B: Total dividend income' for their assigned tax codes and others show 'Sched B(0): Total dividend income'. The number in parentheses is the 'copy number' which should never be zero and should only show up if it is greater than 1 (and the copy number issue doesn't even apply to Schedule B).</div><div><br></div><div>The problem: investigation shows that not only is the display in the Tax Info column on the Accounts tab wrong and confusing, but the US Tax Report can show incomplete information and the TXF export also comes out with incomplete data and invalid data (there is a copy number field that comes out as 'C0', which is not valid).</div><div><br></div><div>The cause: a commit was made on Oct 17, 2024, commit 63deaad, that changed logic, in Account.cpp:</div><div><br></div><div>From:</div><div><br></div><div>gint64<br>xaccAccountGetTaxUSCopyNumber (const Account *acc)<br>{<br>    gint64 copy_number = 0;<br>    GValue v = G_VALUE_INIT;<br>    g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);<br>    qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v, {"tax-US", "copy-number"});<br>    if (G_VALUE_HOLDS_INT64 (&v))<br>        copy_number = g_value_get_int64 (&v);<br><br>    return (copy_number == 0) ? 1 : copy_number;<br>}</div><div><br></div><div> to:</div><div><br></div><div>gint64<br>xaccAccountGetTaxUSCopyNumber (const Account *acc)<br>{<br>    auto copy_number = get_kvp_int64_path (acc, {"tax-US", "copy-number"});<br>    return copy_number ? *copy_number : 1;<br> }</div><div><br></div><div>If I read it correctly, this changed the logic from "if there is a copy number of '0', return '1'", to "if there is a copy number (even if it is zero) just return it, otherwise return '1'".</div><div><br></div><div>Also changed in commit 63deaad,

</div><div><br></div><div>From:</div><div><br></div><div>void<br>xaccAccountSetTaxUSCopyNumber (Account *acc, gint64 copy_number)<br>{<br>    g_return_if_fail(GNC_IS_ACCOUNT(acc));<br>    xaccAccountBeginEdit (acc);<br>    if (copy_number != 0)<br>    {<br>        GValue v = G_VALUE_INIT;<br>        g_value_init (&v, G_TYPE_INT64);<br>        g_value_set_int64 (&v, copy_number);<br>        qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"tax-US", "copy-number"});<br>    }<br>    else<br>    {<br>        qof_instance_set_path_kvp (QOF_INSTANCE (acc), nullptr, {"tax-US", "copy-number"});<br>    }<br>    mark_account (acc);<br>    xaccAccountCommitEdit (acc);<br>}</div><div><br></div><div>to </div><div><br></div><div>void<br>

xaccAccountSetTaxUSCopyNumber

 (Account *acc, gint64 copy_number)<br>{<br>    set_kvp_int64_path (acc, {"tax-US", "copy-number"}, copy_number);<br>}</div><div><br></div><div>Again, if I read it correctly, this changed the logic from "if the copy number is not zero, create a new KVP for it and save it or, if there is already a KVP for 'copy number', change it to the new value, otherwise, delete the KVP (but do not save a zero value)" to "just save the value, even if it is zero".</div><div><br></div><div>This change caused the problem and symptoms.</div><div><br></div><div>The fix: first correct/retore the logic in '

xaccAccountGetTaxUSCopyNumber' and '

xaccAccountGetTaxUSCopyNumber'. Second, if any of our users have used 'Edit->Tax Report Options' to modify their tax code assignments for releases since Oct 17, 2024, they may have data files with 'copy number' KVPs with zeros and inaccurate US Income Tax Reports/TXF Exports. We need to figure out how to clean up their data files.</div><div><br></div><div>The first correction (I implemented this first in 2009, so not sure of current syntax, thus need your feedback):</div><div><br></div><div>for '

xaccAccountGetTaxUSCopyNumber'</div><div><br></div><div>-    return copy_number ? *copy_number : 1;</div><div>+   return (copy_number == 0) ? 1 : copy_number;<br></div><div><br></div><div>for 'xaccAccountSetTaxUSCopyNumber'</div><div><br></div><div>-   set_kvp_int64_path (acc, {"tax-US", "copy-number"}, copy_number);</div><div>+  if (copy_number != 0)<br></div>+      {<br><div>+          set_kvp_int64_path (acc, {"tax-US", "copy-number"}, copy_number);</div><div>+      }<br>+  else</div><div>+     {<br>+         Get rid of KVP {"tax-US", "copy-number"}); <- how do I do this now!<br>+     }<br></div><div><br></div><div>For the second correction (clean up users data files), I was thinking to add logic to 'xaccAccountGetTaxUSCopyNumber' that would, if it gets a zero value, delete the  KVP, so it would look like this:</div><div><br></div><div><div>gint64<br>xaccAccountGetTaxUSCopyNumber (const Account *acc)<br>{<br>    auto copy_number = get_kvp_int64_path (acc, {"tax-US", "copy-number"});</div><div>    if 

(copy_number == 0) </div><div>       {</div><div>             Get rid of KVP {"tax-US", "copy-number"}); <- how do I do this now!</div><div>             return 1;</div><div>       }<br>    

return copy_number;<br> }</div><div></div></div><div><br></div><div>Since 'xaccAccountGetTaxUSCopyNumber' is basically used in only three places ('Edit->Tax Report Options', the 'Tax Info' column of the Accounts tab, and the 'US Tax Report"), the problem would simply be cleaned up by being called through normal activity (looking at the data or running a report).</div><div><br></div><div>Feedback welcome,</div><div><br></div><div>Alex</div></div>