jsgoupil / quickbooks-sync

Sync Quickbooks Desktop
MIT License
87 stars 40 forks source link

Bug fix for TransactionTypeFilter generated property type #46

Closed tofer closed 4 years ago

tofer commented 4 years ago

An old bugfix we discussed once upon a time and I never did a PR for. The XSD definition for TransactionFilter specifies ref element TransactionTypeFilter:

<xsd:group name="TransactionFilter">
    <xsd:sequence>
        <xsd:element ref="MaxReturned" minOccurs="0"/>
        <xsd:choice minOccurs="0">
            <xsd:element ref="RefNumber" maxOccurs="unbounded"/>
            <xsd:element ref="RefNumberCaseSensitive" maxOccurs="unbounded"/>
            <xsd:element ref="RefNumberFilter"/>
            <xsd:element ref="RefNumberRangeFilter"/>
        </xsd:choice>
        <xsd:element ref="TransactionModifiedDateRangeFilter" minOccurs="0"/>
        <xsd:element ref="TransactionDateRangeFilter" minOccurs="0"/>
        <xsd:element ref="TransactionEntityFilter" minOccurs="0"/>
        <xsd:element ref="TransactionAccountFilter" minOccurs="0"/>
        <xsd:element ref="TransactionItemFilter" minOccurs="0"/>
        <xsd:element ref="TransactionClassFilter" minOccurs="0"/>
        <xsd:element ref="TransactionTypeFilter" minOccurs="0"/>
        <xsd:element ref="TransactionDetailLevelFilter" minOccurs="0"/>
        <xsd:element ref="TransactionPostingStatusFilter" minOccurs="0"/>
        <xsd:element ref="TransactionPaidStatusFilter" minOccurs="0"/>
        <xsd:element ref="CurrencyFilter" minOccurs="0"/>
    </xsd:sequence>
</xsd:group>
<xsd:element name="TransactionTypeFilter">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element ref="TxnTypeFilter" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

Before this fix, when trying to use the TransactionTypeFilter property, QuickBooks would return an error, ie:

var req = new TransactionQueryRqType
{
    TransactionTypeFilter = TxnTypeFilter.Check
};

QuickBooks is expecting an array of TxnTypeFilter (note the 'maxOccurs="unbounded"'). This fix updates the generator so the TransactionTypeFilter property has type TxnTypeFilter[]. This changes the usage to:

var req = new TransactionQueryRqType
{
    TransactionTypeFilter = new[] { TxnTypeFilter.Check }
};

This is technically a breaking change, however if anyone was using that property before their application was probably already broken.

jsgoupil commented 4 years ago

I confirm.

fail: MyProject.Common.QuickBooks.Application.C.WebConnectorHandler[0]
      An exception occurred during processing a step for ticket 22a294ee-7f99-4677-a1e4-50b7353ab5c2. Step: TransactionQuery
QbSync.WebConnector.Core.QbSyncException: Exception of type 'QbSync.WebConnector.Core.QbSyncException' was thrown.
 ---> System.InvalidOperationException: There was an error generating the XML document.
 ---> System.InvalidOperationException: Value of ItemsElementName mismatches the type of QbSync.QbXml.Objects.TxnTypeFilter[]; you need to set it to QbSync.QbXml.Objects.ItemsChoiceType92.@TransactionTypeFilter.

Will be bumping Minor only.