Skip to content

Commit

Permalink
Merge pull request #23 from jordanwalsh23/add_currencies_support
Browse files Browse the repository at this point in the history
added currencies support
  • Loading branch information
jordanwalsh23 committed Mar 16, 2017
2 parents 7c4f516 + 60d0287 commit 1bd4eb9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/core.js
Expand Up @@ -8,6 +8,7 @@ var HELPERS = {
bankTransactions: { file: 'banktransactions' },
bankTransfers: { file: 'banktransfers' },
brandingThemes: { file: 'brandingthemes' },
currencies: { file: 'currencies' },
journals: { file: 'journals' },
attachments: { file: 'attachments' },
accounts: { file: 'accounts' },
Expand Down
19 changes: 19 additions & 0 deletions lib/entities/accounting/currency.js
@@ -0,0 +1,19 @@
var _ = require('lodash'),
Entity = require('../entity'),
logger = require('../../logger');

var CurrencySchema = new Entity.SchemaObject({
Code: { type: String },
Description: { type: String }
});

var Currency = Entity.extend(CurrencySchema, {
constructor: function(application, data, options) {
logger.debug('Currency::constructor');
this.Entity.apply(this, arguments);
},
initialize: function(data, options) {}
});


module.exports = Currency;
19 changes: 19 additions & 0 deletions lib/entity_helpers/accounting/currencies.js
@@ -0,0 +1,19 @@
var _ = require('lodash'),
logger = require('../../logger'),
EntityHelper = require('../entity_helper'),
Currency = require('../../entities/accounting/currency'),
util = require('util')

var Currencies = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, Object.assign({ entityName: 'Currency', entityPlural: 'Currencies' }, options));
},
getCurrencies: function(options, callback) {
var self = this;
var clonedOptions = _.clone(options || {});
clonedOptions.entityConstructor = function(data) { return new Currency(data) };
return this.getEntities(clonedOptions)
}
})

module.exports = Currencies;
23 changes: 22 additions & 1 deletion test/accountingtests.js
Expand Up @@ -498,7 +498,28 @@ describe('regression tests', function() {
done(wrapError(err));
})
})
})
});

describe('currencies', function() {

it('get', function(done) {
currentApp.core.currencies.getCurrencies()
.then(function(currencies) {
expect(currencies).to.have.length.greaterThan(0);
currencies.forEach(function(currencies) {
expect(currencies.Code).to.not.equal(undefined);
expect(currencies.Code).to.not.equal("");
expect(currencies.Description).to.not.equal(undefined);
expect(currencies.Description).to.not.equal("");
});
done();
})
.catch(function(err) {
console.log(err);
done(wrapError(err));
})
});
});

describe('branding themes', function() {

Expand Down

0 comments on commit 1bd4eb9

Please sign in to comment.