Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple TrackingCategory Not Possible #31

Open
psenger opened this issue Nov 9, 2017 · 1 comment
Open

Multiple TrackingCategory Not Possible #31

psenger opened this issue Nov 9, 2017 · 1 comment

Comments

@psenger
Copy link

psenger commented Nov 9, 2017

According to the XERO Developer SDK Regarding TrackingCategory and thier support team. You should be able to submit up to Two Tracking Categories per Line Item in an Invoice. However, it would appear using easyxml actually prevents this API from properly forming the following valid XML:

 <Tracking>
     <TrackingCategory>
         <TrackingCategoryID>5caaf317-e4f1-4dc3-b6fa-c79c437a222c</TrackingCategoryID>
         <Name>Tracking1</Name>
         <Option>option1</Option>
     </TrackingCategory>
     <TrackingCategory>
         <TrackingCategoryID>a8b67858-3713-4c63-8019-132c36c08ba0</TrackingCategoryID>
         <Name>Tracking2</Name>
         <Option>Option2</Option>
     </TrackingCategory>
 </Tracking>

Attempt 1

Testing the following JSON to find it produces the following XML:

Tracking: [
    {
        TrackingCategory: {
            Name: "Melbourne",
            Option: "e44c3446-b741-4717-9710-057c1fc14603",
            TrackingCategoryID: "bf8a9440-37bd-44fd-ab97-f207a2588ac1",
        },
    },{
        TrackingCategory: {
            Name: "Virtual Reality Design",
            Option: "c712bb31-2d5e-470f-90da-70f2cc6fe595",
            TrackingCategoryID: "2d002487-1540-442d-bb8a-b2d7d3ff11c7",
        },
    }
]                 
<Tracking>
    <Tracking>
        <TrackingCategory>
            <Name>Melbourne</Name>
            <Option>e44c3446-b741-4717-9710-057c1fc14603</Option>
            <TrackingCategoryID>bf8a9440-37bd-44fd-ab97-f207a2588ac1</TrackingCategoryID>
        </TrackingCategory>
    </Tracking>
    <Tracking>
        <TrackingCategory>
            <Name>Virtual Reality Design</Name>
            <Option>c712bb31-2d5e-470f-90da-70f2cc6fe595</Option>
            <TrackingCategoryID>2d002487-1540-442d-bb8a-b2d7d3ff11c7</TrackingCategoryID>
        </TrackingCategory>
    </Tracking>
</Tracking>

Attempt 2

Testing the following illegal JSON to find it produces the following XML:

Tracking: {
    TrackingCategory: {
        Name: "Melbourne",
            Option: "e44c3446-b741-4717-9710-057c1fc14603",
            TrackingCategoryID: "bf8a9440-37bd-44fd-ab97-f207a2588ac1",
    },
    TrackingCategory: {
        Name: "Virtual Reality Design",
            Option: "c712bb31-2d5e-470f-90da-70f2cc6fe595",
            TrackingCategoryID: "2d002487-1540-442d-bb8a-b2d7d3ff11c7",
    },
}
<Tracking>
    <Tracking>
        <TrackingCategory>
            <Name>Melbourne</Name>
            <Option>e44c3446-b741-4717-9710-057c1fc14603</Option>
            <TrackingCategoryID>bf8a9440-37bd-44fd-ab97-f207a2588ac1</TrackingCategoryID>
        </TrackingCategory>
    </Tracking>
    <Tracking>
        <TrackingCategory>
            <Name>Virtual Reality Design</Name>
            <Option>c712bb31-2d5e-470f-90da-70f2cc6fe595</Option>
            <TrackingCategoryID>2d002487-1540-442d-bb8a-b2d7d3ff11c7</TrackingCategoryID>
        </TrackingCategory>
    </Tracking>
</Tracking>

Attempt 3

Testing the following JSON to find it produces the following XML:

Tracking: {
    TrackingCategory: [
        {
            Name: "Melbourne",
            Option: "e44c3446-b741-4717-9710-057c1fc14603",
            TrackingCategoryID: "bf8a9440-37bd-44fd-ab97-f207a2588ac1",
        }, {
            Name: "Virtual Reality Design",
            Option: "c712bb31-2d5e-470f-90da-70f2cc6fe595",
            TrackingCategoryID: "2d002487-1540-442d-bb8a-b2d7d3ff11c7",
        },
    ]
}
<Tracking>
    <TrackingCategory>
        <TrackingCategory>
            <Name>Melbourne</Name>
            <Option>e44c3446-b741-4717-9710-057c1fc14603</Option>
            <TrackingCategoryID>bf8a9440-37bd-44fd-ab97-f207a2588ac1</TrackingCategoryID>
        </TrackingCategory>
        <TrackingCategory>
            <Name>Virtual Reality Design</Name>
            <Option>c712bb31-2d5e-470f-90da-70f2cc6fe595</Option>
            <TrackingCategoryID>2d002487-1540-442d-bb8a-b2d7d3ff11c7</TrackingCategoryID>
        </TrackingCategory>
    </TrackingCategory>
</Tracking>

Reviewing the docs at easyxml and the test cases. This api simply can not creat the require xml shape.

@psenger
Copy link
Author

psenger commented Nov 9, 2017

It would appear using unwrappedArrays: true as a parameter to EasyXml fixes this problem but is a breaking change. May I suggest you expose this parameter to the caller? Let the caller decide if they want to unwrap the Arrays. You can default it to the orginal settings of false. I would be glad to do a PR for this change.

/**
 * Created by psenger on 1/08/2016.
 */

const describe = require('mocha').describe,
    it = require('mocha').it,
    expect = require('chai').expect,
    EasyXml = require('easyxml'),
    inflect = require('inflect');

describe('EASYXML:', () => {
    it('Should work', function ( ) {
        let tc1 = {
            Name: {"_": "Melbourne"},
            Option: {"_": "e44c3446-b741-4717-9710-057c1fc14603"},
            TrackingCategoryID: {"_": "bf8a9440-37bd-44fd-ab97-f207a2588ac1"}
        };
        let tc2 = {
            Name: {"_": "Virtual Reality Design"},
            Option: {"_": "c712bb31-2d5e-470f-90da-70f2cc6fe595"},
            TrackingCategoryID: {"_": "2d002487-1540-442d-bb8a-b2d7d3ff11c7"}
        };
        let anInvoice = {
            "Type": "ACCREC",
            "Contact": {
                "ContactID": "d0edfa00-7eab-4737-a8b2-bc1389b56a50"
            },
            "Reference": "UXE001-D189719D",
            "DueDate": "2017-12-07",
            "Status": "SUBMITTED",
            "LineAmountTypes": "Inclusive",
            "LineItems": {
                "LineItem": [
                    {
                        "Description": "User Experience Elevate",
                        "Quantity": "1",
                        "UnitAmount": 1000,
                        "AccountCode": "200",
                        "TaxType": "OUTPUT",
                        "Tracking": {
                            "TrackingCategory": [
                                tc1,
                                tc2
                            ]
                        }
                    },
                    {
                        "Description": "User Experience Elevate",
                        "Quantity": "1",
                        "UnitAmount": 2000,
                        "AccountCode": "200",
                        "TaxType": "OUTPUT",
                        "Tracking": {
                            "TrackingCategory": [
                                tc1,
                                tc2
                            ]
                        }
                    }
                ]
            }
        };
        let root = 'Invoices';
        let desired = '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n' +
            '<Invoice>\n' +
            '    <Type>ACCREC</Type>\n' +
            '    <Contact>\n' +
            '        <ContactID>d0edfa00-7eab-4737-a8b2-bc1389b56a50</ContactID>\n' +
            '    </Contact>\n' +
            '    <Reference>UXE001-D189719D</Reference>\n' +
            '    <DueDate>2017-12-07</DueDate>\n' +
            '    <Status>SUBMITTED</Status>\n' +
            '    <LineAmountTypes>Inclusive</LineAmountTypes>\n' +
            '    <LineItems>\n' +
            '        <LineItem>\n' +
            '            <Description>User Experience Elevate</Description>\n' +
            '            <Quantity>1</Quantity>\n' +
            '            <UnitAmount>1000</UnitAmount>\n' +
            '            <AccountCode>200</AccountCode>\n' +
            '            <TaxType>OUTPUT</TaxType>\n' +
            '            <Tracking>\n' +
            '                <TrackingCategory>\n' +
            '                    <Name>Melbourne</Name>\n' +
            '                    <Option>e44c3446-b741-4717-9710-057c1fc14603</Option>\n' +
            '                    <TrackingCategoryID>bf8a9440-37bd-44fd-ab97-f207a2588ac1</TrackingCategoryID>\n' +
            '                </TrackingCategory>\n' +
            '                <TrackingCategory>\n' +
            '                    <Name>Virtual Reality Design</Name>\n' +
            '                    <Option>c712bb31-2d5e-470f-90da-70f2cc6fe595</Option>\n' +
            '                    <TrackingCategoryID>2d002487-1540-442d-bb8a-b2d7d3ff11c7</TrackingCategoryID>\n' +
            '                </TrackingCategory>\n' +
            '            </Tracking>\n' +
            '        </LineItem>\n' +
            '        <LineItem>\n' +
            '            <Description>User Experience Elevate</Description>\n' +
            '            <Quantity>1</Quantity>\n' +
            '            <UnitAmount>2000</UnitAmount>\n' +
            '            <AccountCode>200</AccountCode>\n' +
            '            <TaxType>OUTPUT</TaxType>\n' +
            '            <Tracking>\n' +
            '                <TrackingCategory>\n' +
            '                    <Name>Melbourne</Name>\n' +
            '                    <Option>e44c3446-b741-4717-9710-057c1fc14603</Option>\n' +
            '                    <TrackingCategoryID>bf8a9440-37bd-44fd-ab97-f207a2588ac1</TrackingCategoryID>\n' +
            '                </TrackingCategory>\n' +
            '                <TrackingCategory>\n' +
            '                    <Name>Virtual Reality Design</Name>\n' +
            '                    <Option>c712bb31-2d5e-470f-90da-70f2cc6fe595</Option>\n' +
            '                    <TrackingCategoryID>2d002487-1540-442d-bb8a-b2d7d3ff11c7</TrackingCategoryID>\n' +
            '                </TrackingCategory>\n' +
            '            </Tracking>\n' +
            '        </LineItem>\n' +
            '    </LineItems>\n' +
            '</Invoice>\n' +
            '';
        let post_body = new EasyXml({rootElement: inflect.singularize(root), rootArray: 'Invoices', manifest: true, unwrappedArrays: true}).render(anInvoice);
        expect(post_body).to.equal(desired)
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant