Skip to content

Commit

Permalink
updated DP rounding fix to remove double querystring additions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Walsh committed Feb 20, 2017
1 parent e1fce60 commit 0df589e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions lib/application.js
Expand Up @@ -96,6 +96,10 @@ _.extend(Application.prototype, {
if (options.summarizeErrors === false)
params.summarizeErrors = false;

//Added to support more than 2dp being added.
if (options.unitdp)
params.unitdp = options.unitdp;

var endPointUrl = options.api === 'payroll' ? this.options.payrollAPIEndPointUrl : this.options.coreAPIEndPointUrl;
var url = endPointUrl + path;
if (!_.isEmpty(params))
Expand Down
13 changes: 9 additions & 4 deletions lib/entities/invoice.js
Expand Up @@ -98,6 +98,9 @@ var Invoice = Entity.extend(InvoiceSchema, {
var self = this;
var xml = '<Invoices>' + this.toXml() + '</Invoices>';
var path, method;

options = options || {};

if (this.InvoiceID) {
path = 'Invoices/' + this.InvoiceID;
method = 'post'
Expand All @@ -106,11 +109,13 @@ var Invoice = Entity.extend(InvoiceSchema, {
method = 'put'
}

//Added to support decimal rounding when creating invoices
if (options.unitdp)
path += "?unitdp=" + options.unitdp;
//Adding other options for saving purposes
options.entityPath = 'Invoices.Invoice';
options.entityConstructor = function(data) {
return self.application.core.invoices.newInvoice(data)
};

return this.application.putOrPostEntity(method, path, xml, { entityPath: 'Invoices.Invoice', entityConstructor: function(data) { return self.application.core.invoices.newInvoice(data) } })
return this.application.putOrPostEntity(method, path, xml, options);
}

});
Expand Down
10 changes: 8 additions & 2 deletions test/tests.js
Expand Up @@ -284,9 +284,15 @@ describe('private application', function() {
invoice.save({ unitdp: 4 })
.then(function(ret) {
//(ret.entities[0].toObject().InvoiceID).should.not.be.empty();
console.log("Created: " + ret.entities[0].toObject().InvoiceID);
var invoice = ret.entities[0].toObject();

InvoiceID = invoice.InvoiceID;

expect(InvoiceID).to.not.equal("");
invoice.LineItems.forEach(function(lineItem) {
expect(lineItem.UnitAmount).to.match(/\.[0-9]{4}/);
});

InvoiceID = ret.entities[0].toObject().InvoiceID;

done();
})
Expand Down

0 comments on commit 0df589e

Please sign in to comment.