diff --git a/ChangeLog b/ChangeLog index 3b401718cc..0b1aee80f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2002-09-16 Derek Atkins + Fix bug #91413 -- Add TaxTable defaults to Customers and Vendors + + * business-core/gncCustomer.[ch] -- add API for TaxTable and TaxTableOverride + * business-core/gncVendor.[ch] -- add API for TaxTable and TaxTableOverride + * business-core/file/gnc-customer-xml-v2.c -- store TaxTable and TTOverride + * business-core/file/gnc-vendor-xml-v2.c -- store TaxTable and TTOverride + * business-gnome/dialog-customer.c -- display/choose TaxTable and TTOverride + * business-gnome/dialog-vendor.c -- display/choose TaxTable and TTOverride + * business-gnome/glade/customer.glade -- add TaxTable Menu and Override button + * business-gnome/glade/vendor.glade -- add TaxTable Menu and Override button + * business-ledger/gncEntryLedger.c -- set traverse_to_new = TRUE when + you create a new ledger. + * business-ledger/gncEntryLedgerLoad.c -- don't load the ledger the + first time through (e.g. when there is no invoice and no entries). + Pull in the default TaxTable, TaxIncluded, and Discount flags. + 2002-09-16 David Hampton * src/business/business-gnome/search-owner.c: diff --git a/src/business/business-core/file/gnc-customer-xml-v2.c b/src/business/business-core/file/gnc-customer-xml-v2.c index 81aa39733e..6abe070a24 100644 --- a/src/business/business-core/file/gnc-customer-xml-v2.c +++ b/src/business/business-core/file/gnc-customer-xml-v2.c @@ -43,6 +43,7 @@ #include "gncBillTermP.h" #include "gncCustomerP.h" +#include "gncTaxTableP.h" #include "gnc-customer-xml-v2.h" #include "gnc-address-xml-v2.h" #include "gnc-engine-util.h" @@ -69,6 +70,8 @@ const gchar *customer_version_string = "2.0.0"; #define cust_discount_string "cust:discount" #define cust_credit_string "cust:credit" #define cust_commodity_string "cust:commodity" +#define cust_taxtable_string "cust:taxtable" +#define cust_taxtableoverride_string "cust:use-tt" static void maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str) @@ -83,6 +86,7 @@ customer_dom_tree_create (GncCustomer *cust) xmlNodePtr ret; gnc_numeric num; GncBillTerm *term; + GncTaxTable *taxtable; ret = xmlNewNode(NULL, gnc_customer_string); xmlSetProp(ret, "version", customer_version_string); @@ -127,6 +131,13 @@ customer_dom_tree_create (GncCustomer *cust) commodity_ref_to_dom_tree(cust_commodity_string, gncCustomerGetCommodity (cust))); + xmlAddChild (ret, int_to_dom_tree (cust_taxtableoverride_string, + gncCustomerGetTaxTableOverride (cust))); + taxtable = gncCustomerGetTaxTable (cust); + if (taxtable) + xmlAddChild (ret, guid_to_dom_tree (cust_taxtable_string, + gncTaxTableGetGUID (taxtable))); + return ret; } @@ -152,6 +163,20 @@ set_string(xmlNodePtr node, GncCustomer* cust, return TRUE; } +static gboolean +set_boolean(xmlNodePtr node, GncCustomer* cust, + void (*func)(GncCustomer* cust, gboolean b)) +{ + gint64 val; + gboolean ret; + + ret = dom_tree_to_integer(node, &val); + if (ret) + func(cust, (gboolean)val); + + return ret; +} + static gboolean customer_name_handler (xmlNodePtr node, gpointer cust_pdata) { @@ -262,14 +287,7 @@ static gboolean customer_active_handler (xmlNodePtr node, gpointer cust_pdata) { struct customer_pdata *pdata = cust_pdata; - gint64 val; - gboolean ret; - - ret = dom_tree_to_integer(node, &val); - if (ret) - gncCustomerSetActive(pdata->customer, (gboolean)val); - - return ret; + return set_boolean (node, pdata->customer, gncCustomerSetActive); } static gboolean @@ -316,6 +334,34 @@ customer_commodity_handler (xmlNodePtr node, gpointer customer_pdata) return TRUE; } +static gboolean +customer_taxtable_handler (xmlNodePtr node, gpointer cust_pdata) +{ + struct customer_pdata *pdata = cust_pdata; + GUID *guid; + GncTaxTable *taxtable; + + guid = dom_tree_to_guid (node); + g_return_val_if_fail (guid, FALSE); + taxtable = gncTaxTableLookup (pdata->book, guid); + if (!taxtable) { + taxtable = gncTaxTableCreate (pdata->book); + gncTaxTableSetGUID (taxtable, guid); + } else + gncTaxTableDecRef (taxtable); + + gncCustomerSetTaxTable (pdata->customer, taxtable); + g_free(guid); + return TRUE; +} + +static gboolean +customer_taxtableoverride_handler (xmlNodePtr node, gpointer cust_pdata) +{ + struct customer_pdata *pdata = cust_pdata; + return set_boolean (node, pdata->customer, gncCustomerSetTaxTableOverride); +} + static struct dom_tree_handler customer_handlers_v2[] = { { cust_name_string, customer_name_handler, 1, 0 }, { cust_guid_string, customer_guid_handler, 1, 0 }, @@ -329,6 +375,8 @@ static struct dom_tree_handler customer_handlers_v2[] = { { cust_discount_string, customer_discount_handler, 1, 0 }, { cust_credit_string, customer_credit_handler, 1, 0 }, { cust_commodity_string, customer_commodity_handler, 1, 0 }, + { cust_taxtable_string, customer_taxtable_handler, 0, 0 }, + { cust_taxtableoverride_string, customer_taxtableoverride_handler, 0, 0 }, { NULL, 0, 0, 0 } }; diff --git a/src/business/business-core/file/gnc-vendor-xml-v2.c b/src/business/business-core/file/gnc-vendor-xml-v2.c index 2aa9fa5204..de316f5171 100644 --- a/src/business/business-core/file/gnc-vendor-xml-v2.c +++ b/src/business/business-core/file/gnc-vendor-xml-v2.c @@ -43,6 +43,7 @@ #include "gncBillTermP.h" #include "gncVendorP.h" +#include "gncTaxTableP.h" #include "gnc-vendor-xml-v2.h" #include "gnc-address-xml-v2.h" #include "gnc-engine-util.h" @@ -66,6 +67,8 @@ const gchar *vendor_version_string = "2.0.0"; #define vendor_taxincluded_string "vendor:taxincluded" #define vendor_active_string "vendor:active" #define vendor_commodity_string "vendor:commodity" +#define vendor_taxtable_string "vendor:taxtable" +#define vendor_taxtableoverride_string "vendor:use-tt" static void maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str) @@ -79,6 +82,7 @@ vendor_dom_tree_create (GncVendor *vendor) { xmlNodePtr ret; GncBillTerm *term; + GncTaxTable *taxtable; ret = xmlNewNode(NULL, gnc_vendor_string); xmlSetProp(ret, "version", vendor_version_string); @@ -114,6 +118,13 @@ vendor_dom_tree_create (GncVendor *vendor) commodity_ref_to_dom_tree(vendor_commodity_string, gncVendorGetCommodity (vendor))); + xmlAddChild (ret, int_to_dom_tree (vendor_taxtableoverride_string, + gncVendorGetTaxTableOverride (vendor))); + taxtable = gncVendorGetTaxTable (vendor); + if (taxtable) + xmlAddChild (ret, guid_to_dom_tree (vendor_taxtable_string, + gncTaxTableGetGUID (taxtable))); + return ret; } @@ -139,6 +150,20 @@ set_string(xmlNodePtr node, GncVendor* vendor, return TRUE; } +static gboolean +set_boolean(xmlNodePtr node, GncVendor* vendor, + void (*func)(GncVendor* vendor, gboolean b)) +{ + gint64 val; + gboolean ret; + + ret = dom_tree_to_integer(node, &val); + if (ret) + func(vendor, (gboolean)val); + + return ret; +} + static gboolean vendor_name_handler (xmlNodePtr node, gpointer vendor_pdata) { @@ -239,14 +264,7 @@ static gboolean vendor_active_handler (xmlNodePtr node, gpointer vendor_pdata) { struct vendor_pdata *pdata = vendor_pdata; - gint64 val; - gboolean ret; - - ret = dom_tree_to_integer(node, &val); - if (ret) - gncVendorSetActive(pdata->vendor, (gboolean)val); - - return ret; + set_boolean (node, pdata->vendor, gncVendorSetActive); } static gboolean @@ -263,6 +281,34 @@ vendor_commodity_handler (xmlNodePtr node, gpointer vendor_pdata) return TRUE; } +static gboolean +vendor_taxtable_handler (xmlNodePtr node, gpointer vendor_pdata) +{ + struct vendor_pdata *pdata = vendor_pdata; + GUID *guid; + GncTaxTable *taxtable; + + guid = dom_tree_to_guid (node); + g_return_val_if_fail (guid, FALSE); + taxtable = gncTaxTableLookup (pdata->book, guid); + if (!taxtable) { + taxtable = gncTaxTableCreate (pdata->book); + gncTaxTableSetGUID (taxtable, guid); + } else + gncTaxTableDecRef (taxtable); + + gncVendorSetTaxTable (pdata->vendor, taxtable); + g_free(guid); + return TRUE; +} + +static gboolean +vendor_taxtableoverride_handler (xmlNodePtr node, gpointer vendor_pdata) +{ + struct vendor_pdata *pdata = vendor_pdata; + return set_boolean (node, pdata->vendor, gncVendorSetTaxTableOverride); +} + static struct dom_tree_handler vendor_handlers_v2[] = { { vendor_name_string, vendor_name_handler, 1, 0 }, { vendor_guid_string, vendor_guid_handler, 1, 0 }, @@ -273,6 +319,8 @@ static struct dom_tree_handler vendor_handlers_v2[] = { { vendor_taxincluded_string, vendor_taxincluded_handler, 1, 0 }, { vendor_active_string, vendor_active_handler, 1, 0 }, { vendor_commodity_string, vendor_commodity_handler, 1, 0 }, + { vendor_taxtable_string, vendor_taxtable_handler, 0, 0 }, + { vendor_taxtableoverride_string, vendor_taxtableoverride_handler, 0, 0 }, { NULL, 0, 0, 0 } }; diff --git a/src/business/business-core/gncCustomer.c b/src/business/business-core/gncCustomer.c index 8c2418c7ae..05e4720b8f 100644 --- a/src/business/business-core/gncCustomer.c +++ b/src/business/business-core/gncCustomer.c @@ -38,6 +38,9 @@ struct _gncCustomer { GncTaxIncluded taxincluded; gboolean active; GList * jobs; + + GncTaxTable* taxtable; + gboolean taxtable_override; gboolean dirty; }; @@ -203,6 +206,26 @@ void gncCustomerSetCommodity (GncCustomer *cust, gnc_commodity *com) mark_customer (cust); } +void gncCustomerSetTaxTableOverride (GncCustomer *customer, gboolean override) +{ + if (!customer) return; + if (customer->taxtable_override == override) return; + customer->taxtable_override = override; + mark_customer (customer); +} + +void gncCustomerSetTaxTable (GncCustomer *customer, GncTaxTable *table) +{ + if (!customer) return; + if (customer->taxtable == table) return; + if (customer->taxtable) + gncTaxTableDecRef (customer->taxtable); + if (table) + gncTaxTableIncRef (table); + customer->taxtable = table; + mark_customer (customer); +} + /* Note that JobList changes do not affect the "dirtiness" of the customer */ void gncCustomerAddJob (GncCustomer *cust, GncJob *job) { @@ -325,6 +348,18 @@ gnc_numeric gncCustomerGetCredit (GncCustomer *cust) return cust->credit; } +gboolean gncCustomerGetTaxTableOverride (GncCustomer *customer) +{ + if (!customer) return FALSE; + return customer->taxtable_override; +} + +GncTaxTable* gncCustomerGetTaxTable (GncCustomer *customer) +{ + if (!customer) return NULL; + return customer->taxtable; +} + GList * gncCustomerGetJoblist (GncCustomer *cust, gboolean show_all) { if (!cust) return NULL; diff --git a/src/business/business-core/gncCustomer.h b/src/business/business-core/gncCustomer.h index 609386fa8f..9b46842be5 100644 --- a/src/business/business-core/gncCustomer.h +++ b/src/business/business-core/gncCustomer.h @@ -36,6 +36,9 @@ void gncCustomerSetDiscount (GncCustomer *customer, gnc_numeric discount); void gncCustomerSetCredit (GncCustomer *customer, gnc_numeric credit); void gncCustomerSetCommodity (GncCustomer *customer, gnc_commodity *com); +void gncCustomerSetTaxTableOverride (GncCustomer *customer, gboolean override); +void gncCustomerSetTaxTable (GncCustomer *customer, GncTaxTable *table); + void gncCustomerAddJob (GncCustomer *customer, GncJob *job); void gncCustomerRemoveJob (GncCustomer *customer, GncJob *job); @@ -57,6 +60,9 @@ gnc_numeric gncCustomerGetDiscount (GncCustomer *customer); gnc_numeric gncCustomerGetCredit (GncCustomer *customer); gnc_commodity * gncCustomerGetCommodity (GncCustomer *customer); +gboolean gncCustomerGetTaxTableOverride (GncCustomer *customer); +GncTaxTable* gncCustomerGetTaxTable (GncCustomer *customer); + GList * gncCustomerGetJoblist (GncCustomer *customer, gboolean show_all); GUID gncCustomerRetGUID (GncCustomer *customer); diff --git a/src/business/business-core/gncVendor.c b/src/business/business-core/gncVendor.c index 46f45d939a..3ed846980a 100644 --- a/src/business/business-core/gncVendor.c +++ b/src/business/business-core/gncVendor.c @@ -34,6 +34,8 @@ struct _gncVendor { GncTaxIncluded taxincluded; gboolean active; GList * jobs; + GncTaxTable* taxtable; + gboolean taxtable_override; gboolean dirty; }; @@ -180,6 +182,26 @@ void gncVendorSetActive (GncVendor *vendor, gboolean active) mark_vendor (vendor); } +void gncVendorSetTaxTableOverride (GncVendor *vendor, gboolean override) +{ + if (!vendor) return; + if (vendor->taxtable_override == override) return; + vendor->taxtable_override = override; + mark_vendor (vendor); +} + +void gncVendorSetTaxTable (GncVendor *vendor, GncTaxTable *table) +{ + if (!vendor) return; + if (vendor->taxtable == table) return; + if (vendor->taxtable) + gncTaxTableDecRef (vendor->taxtable); + if (table) + gncTaxTableIncRef (table); + vendor->taxtable = table; + mark_vendor (vendor); +} + /* Get Functions */ GNCBook * gncVendorGetBook (GncVendor *vendor) @@ -242,6 +264,18 @@ gboolean gncVendorGetActive (GncVendor *vendor) return vendor->active; } +gboolean gncVendorGetTaxTableOverride (GncVendor *vendor) +{ + if (!vendor) return FALSE; + return vendor->taxtable_override; +} + +GncTaxTable* gncVendorGetTaxTable (GncVendor *vendor) +{ + if (!vendor) return NULL; + return vendor->taxtable; +} + /* Note that JobList changes do not affect the "dirtiness" of the vendor */ void gncVendorAddJob (GncVendor *vendor, GncJob *job) { diff --git a/src/business/business-core/gncVendor.h b/src/business/business-core/gncVendor.h index c8c663e968..71b30add58 100644 --- a/src/business/business-core/gncVendor.h +++ b/src/business/business-core/gncVendor.h @@ -32,6 +32,9 @@ void gncVendorSetTaxIncluded (GncVendor *vendor, GncTaxIncluded taxincl); void gncVendorSetCommodity (GncVendor *vendor, gnc_commodity *com); void gncVendorSetActive (GncVendor *vendor, gboolean active); +void gncVendorSetTaxTableOverride (GncVendor *vendor, gboolean override); +void gncVendorSetTaxTable (GncVendor *vendor, GncTaxTable *table); + void gncVendorAddJob (GncVendor *vendor, GncJob *job); void gncVendorRemoveJob (GncVendor *vendor, GncJob *job); @@ -50,6 +53,9 @@ GncTaxIncluded gncVendorGetTaxIncluded (GncVendor *vendor); gnc_commodity * gncVendorGetCommodity (GncVendor *vendor); gboolean gncVendorGetActive (GncVendor *vendor); +gboolean gncVendorGetTaxTableOverride (GncVendor *vendor); +GncTaxTable* gncVendorGetTaxTable (GncVendor *vendor); + GList * gncVendorGetJoblist (GncVendor *vendor, gboolean show_all); GUID gncVendorRetGUID (GncVendor *vendor); diff --git a/src/business/business-gnome/dialog-customer.c b/src/business/business-gnome/dialog-customer.c index be56d7556f..352301ec42 100644 --- a/src/business/business-gnome/dialog-customer.c +++ b/src/business/business-gnome/dialog-customer.c @@ -78,6 +78,9 @@ struct _customer_window { GtkWidget * taxincluded_menu; GtkWidget * notes_text; + GtkWidget * taxtable_check; + GtkWidget * taxtable_menu; + GncTaxIncluded taxincluded; GncBillTerm * terms; CustomerDialogType dialog_type; @@ -86,8 +89,21 @@ struct _customer_window { GNCBook * book; GncCustomer * created_customer; + GncTaxTable * taxtable; }; +static void +gnc_customer_taxtable_check_cb (GtkToggleButton *togglebutton, + gpointer user_data) +{ + CustomerWindow *cw = user_data; + + if (gtk_toggle_button_get_active (togglebutton)) + gtk_widget_set_sensitive (cw->taxtable_menu, TRUE); + else + gtk_widget_set_sensitive (cw->taxtable_menu, FALSE); +} + static GncCustomer * cw_get_customer (CustomerWindow *cw) { @@ -158,6 +174,10 @@ static void gnc_ui_to_customer (CustomerWindow *cw, GncCustomer *cust) gncCustomerSetCredit (cust, gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (cw->credit_amount))); + gncCustomerSetTaxTableOverride + (cust, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cw->taxtable_check))); + gncCustomerSetTaxTable (cust, cw->taxtable); + gncCustomerCommitEdit (cust); gnc_resume_gui_refresh (); } @@ -425,6 +445,9 @@ gnc_customer_new_window (GNCBook *bookp, GncCustomer *cust) cw->terms_menu = glade_xml_get_widget (xml, "terms_menu"); + cw->taxtable_check = glade_xml_get_widget (xml, "taxtable_button"); + cw->taxtable_menu = glade_xml_get_widget (xml, "taxtable_menu"); + /* DISCOUNT: Percentage Value */ edit = gnc_amount_edit_new(); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE); @@ -497,6 +520,9 @@ gnc_customer_new_window (GNCBook *bookp, GncCustomer *cust) gtk_signal_connect(GTK_OBJECT (cw->company_entry), "changed", GTK_SIGNAL_FUNC(gnc_customer_name_changed_cb), cw); + gtk_signal_connect(GTK_OBJECT (cw->taxtable_check), "toggled", + GTK_SIGNAL_FUNC(gnc_customer_taxtable_check_cb), cw); + /* Setup initial values */ if (cust != NULL) { GncAddress *addr, *shipaddr; @@ -572,6 +598,11 @@ gnc_customer_new_window (GNCBook *bookp, GncCustomer *cust) gnc_ui_taxincluded_optionmenu (cw->taxincluded_menu, &cw->taxincluded); gnc_ui_billterms_optionmenu (cw->terms_menu, bookp, TRUE, &cw->terms); + cw->taxtable = gncCustomerGetTaxTable (cust); + gnc_ui_taxtables_optionmenu (cw->taxtable_menu, bookp, TRUE, &cw->taxtable); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cw->taxtable_check), + gncCustomerGetTaxTableOverride (cust)); + gnc_customer_taxtable_check_cb (cw->taxtable_check, cw); /* Set the Discount, and Credit amounts */ gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->discount_amount), diff --git a/src/business/business-gnome/dialog-vendor.c b/src/business/business-gnome/dialog-vendor.c index 764d1f9675..3a6b6e7524 100644 --- a/src/business/business-gnome/dialog-vendor.c +++ b/src/business/business-gnome/dialog-vendor.c @@ -65,6 +65,9 @@ struct _vendor_window { GtkWidget * taxincluded_menu; GtkWidget * notes_text; + GtkWidget * taxtable_check; + GtkWidget * taxtable_menu; + GncTaxIncluded taxincluded; GncBillTerm * terms; VendorDialogType dialog_type; @@ -73,8 +76,21 @@ struct _vendor_window { GNCBook * book; GncVendor * created_vendor; + GncTaxTable * taxtable; }; +static void +gnc_vendor_taxtable_check_cb (GtkToggleButton *togglebutton, + gpointer user_data) +{ + VendorWindow *vw = user_data; + + if (gtk_toggle_button_get_active (togglebutton)) + gtk_widget_set_sensitive (vw->taxtable_menu, TRUE); + else + gtk_widget_set_sensitive (vw->taxtable_menu, FALSE); +} + static GncVendor * vw_get_vendor (VendorWindow *vw) { @@ -121,6 +137,10 @@ static void gnc_ui_to_vendor (VendorWindow *vw, GncVendor *vendor) (GTK_EDITABLE (vw->notes_text), 0, -1)); gncVendorSetTerms (vendor, vw->terms); + gncVendorSetTaxTableOverride + (vendor, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (vw->taxtable_check))); + gncVendorSetTaxTable (vendor, vw->taxtable); + gncVendorCommitEdit (vendor); gnc_resume_gui_refresh (); } @@ -337,6 +357,9 @@ gnc_vendor_new_window (GNCBook *bookp, GncVendor *vendor) vw->notes_text = glade_xml_get_widget (xml, "notes_text"); vw->terms_menu = glade_xml_get_widget (xml, "terms_menu"); + vw->taxtable_check = glade_xml_get_widget (xml, "taxtable_button"); + vw->taxtable_menu = glade_xml_get_widget (xml, "taxtable_menu"); + /* Setup Dialog for Editing */ gnome_dialog_set_default (vwd, 0); @@ -373,6 +396,9 @@ gnc_vendor_new_window (GNCBook *bookp, GncVendor *vendor) gtk_signal_connect(GTK_OBJECT (vw->company_entry), "changed", GTK_SIGNAL_FUNC(gnc_vendor_name_changed_cb), vw); + gtk_signal_connect(GTK_OBJECT (vw->taxtable_check), "toggled", + GTK_SIGNAL_FUNC(gnc_vendor_taxtable_check_cb), vw); + /* Setup initial values */ if (vendor != NULL) { GncAddress *addr; @@ -438,6 +464,11 @@ gnc_vendor_new_window (GNCBook *bookp, GncVendor *vendor) gnc_ui_taxincluded_optionmenu (vw->taxincluded_menu, &vw->taxincluded); gnc_ui_billterms_optionmenu (vw->terms_menu, bookp, TRUE, &vw->terms); + vw->taxtable = gncVendorGetTaxTable (vendor); + gnc_ui_taxtables_optionmenu (vw->taxtable_menu, bookp, TRUE, &vw->taxtable); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vw->taxtable_check), + gncVendorGetTaxTableOverride (vendor)); + gnc_vendor_taxtable_check_cb (vw->taxtable_check, vw); gnc_gui_component_watch_entity_type (vw->component_id, GNC_VENDOR_MODULE_NAME, diff --git a/src/business/business-gnome/glade/customer.glade b/src/business/business-gnome/glade/customer.glade index 8d71bfe17f..f2c006222c 100644 --- a/src/business/business-gnome/glade/customer.glade +++ b/src/business/business-gnome/glade/customer.glade @@ -703,6 +703,23 @@ False + + + GtkLabel + label35 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + @@ -776,6 +793,48 @@ False + + + GtkHBox + hbox7 + False + 0 + + 0 + True + True + + + + GtkCheckButton + taxtable_button + Override the global Tax Table? + True + + False + True + + 0 + False + False + + + + + GtkOptionMenu + taxtable_menu + What Tax Table should be applied to this customer? + True + (taxtables) + + 0 + + 0 + True + True + + + diff --git a/src/business/business-gnome/glade/vendor.glade b/src/business/business-gnome/glade/vendor.glade index ca7c22f0b8..d7bacc1f39 100644 --- a/src/business/business-gnome/glade/vendor.glade +++ b/src/business/business-gnome/glade/vendor.glade @@ -670,6 +670,23 @@ False + + + GtkLabel + label35 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + @@ -711,6 +728,48 @@ False + + + GtkHBox + hbox7 + False + 0 + + 0 + True + True + + + + GtkCheckButton + taxtable_button + Override the global Tax Table? + True + + False + True + + 0 + False + False + + + + + GtkOptionMenu + taxtable_menu + What Tax Table should be applied to this vendor? + True + (taxtables) + + 0 + + 0 + True + True + + + diff --git a/src/business/business-ledger/gncEntryLedger.c b/src/business/business-ledger/gncEntryLedger.c index e4e3d3c635..d238bbb478 100644 --- a/src/business/business-ledger/gncEntryLedger.c +++ b/src/business/business-ledger/gncEntryLedger.c @@ -208,6 +208,7 @@ GncEntryLedger * gnc_entry_ledger_new (GNCBook *book, GncEntryLedgerType type) ledger = g_new0 (GncEntryLedger, 1); ledger->type = type; ledger->book = book; + ledger->traverse_to_new = TRUE; /* Orders and Invoices are "invoices" for lookups */ switch (type) { diff --git a/src/business/business-ledger/gncEntryLedgerLoad.c b/src/business/business-ledger/gncEntryLedgerLoad.c index 2a8004d995..10178694e6 100644 --- a/src/business/business-ledger/gncEntryLedgerLoad.c +++ b/src/business/business-ledger/gncEntryLedgerLoad.c @@ -191,7 +191,10 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list) blank_entry = gnc_entry_ledger_get_blank_entry (ledger); - if (blank_entry == NULL) { + if (blank_entry == NULL && ledger->invoice == NULL && entry_list == NULL) + return; + + if (blank_entry == NULL && ledger->invoice) { switch (ledger->type) { case GNCENTRY_ORDER_ENTRY: case GNCENTRY_INVOICE_ENTRY: @@ -200,13 +203,14 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list) gncEntrySetDate (blank_entry, ledger->last_date_entered); ledger->blank_entry_guid = *gncEntryGetGUID (blank_entry); - if (ledger->type == GNCENTRY_INVOICE_ENTRY) { + { GncOwner *owner = gncInvoiceGetOwner (ledger->invoice); - GncTaxTable *table = NULL; + GncTaxTable *table; GncTaxIncluded taxincluded_p = GNC_TAXINCLUDED_USEGLOBAL; gboolean taxincluded = FALSE; gnc_numeric discount = gnc_numeric_zero (); + /* Determine the TaxIncluded and Discount values */ owner = gncOwnerGetEndOwner (owner); switch (gncOwnerGetType (owner)) { case GNC_OWNER_CUSTOMER: @@ -219,8 +223,6 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list) default: } - /* XXX: Get the default tax-table */ - /* Compute the default taxincluded */ switch (taxincluded_p) { case GNC_TAXINCLUDED_YES: @@ -237,6 +239,22 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list) break; } + /* XXX: Get the default tax-table */ + table = NULL; + + /* Maybe override the global taxtable */ + switch (gncOwnerGetType (owner)) { + case GNC_OWNER_CUSTOMER: + if (gncCustomerGetTaxTableOverride (owner->owner.customer)) + table = gncCustomerGetTaxTable (owner->owner.customer); + break; + case GNC_OWNER_VENDOR: + if (gncVendorGetTaxTableOverride (owner->owner.vendor)) + table = gncVendorGetTaxTable (owner->owner.vendor); + break; + default: + } + if (ledger->is_invoice) { gncEntrySetInvTaxTable (blank_entry, table); gncEntrySetInvTaxIncluded (blank_entry, taxincluded);