-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated items to support retrieving and saving
- Loading branch information
Jordan Walsh
committed
Feb 22, 2017
1 parent
c4a9b24
commit b5b82ae
Showing
4 changed files
with
98 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,57 @@ | ||
var _ = require('lodash') | ||
, Entity = require('./entity') | ||
, logger = require('../logger') | ||
var _ = require('lodash'), | ||
Entity = require('./entity'), | ||
logger = require('../logger') | ||
|
||
var ItemDetailSchema = new Entity.SchemaObject({ | ||
UnitPrice: {type: Number}, | ||
AccountCode: {type: String}, | ||
TaxType: {type: String} | ||
UnitPrice: { type: Number, toObject: 'hasValue' }, | ||
AccountCode: { type: String, toObject: 'hasValue' }, | ||
COGSAccountCode: { type: String, toObject: 'hasValue' }, | ||
TaxType: { type: String, toObject: 'hasValue' } | ||
|
||
}); | ||
var ItemSchema = new Entity.SchemaObject({ | ||
Code: { type: String, toObject: 'always', validators: { maxLength: 30 } }, | ||
InventoryAssetAccountCode: { type: String, toObject: 'hasValue' }, | ||
Name: { type: String, toObject: 'always' }, | ||
IsSold: { type: Boolean, toObject: 'always' }, | ||
IsPurchased: { type: Boolean, toObject: 'always' }, | ||
Description: { type: String, toObject: 'always' }, | ||
PurchaseDescription: { type: String, toObject: 'always' }, | ||
ItemID: { type: String, toObject: 'never' }, | ||
Code: {type: String, toObject: 'always'}, | ||
Description: {type: String,toObject:'always'}, | ||
PurchaseDetails: {type: ItemDetailSchema}, | ||
SalesDetails: {type: ItemDetailSchema} | ||
PurchaseDetails: { type: ItemDetailSchema, toObject: 'always' }, | ||
SalesDetails: { type: ItemDetailSchema, toObject: 'always' }, | ||
IsTrackedAsInventory: { type: Boolean, toObject: 'hasValue' }, | ||
TotalCostPool: { type: String, toObject: 'hasValue' }, | ||
QuantityOnHand: { type: String, toObject: 'hasValue' }, | ||
UpdatedDateUTC: { type: String, toObject: 'hasValue' } | ||
}); | ||
|
||
|
||
var Item = Entity.extend(ItemSchema, { | ||
constructor: function (application, data, options) | ||
{ | ||
constructor: function(application, data, options) { | ||
logger.debug('Item::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function (data, options) | ||
{ | ||
}, | ||
toXml: function () | ||
{ | ||
initialize: function(data, options) {}, | ||
toXml: function() { | ||
var item = _.omit(this.toObject()); | ||
return this.application.js2xml(account, 'Item'); | ||
return this.application.js2xml(item, 'Item'); | ||
}, | ||
save:function(options) | ||
{ | ||
save: function(options) { | ||
var self = this; | ||
var xml = '<Items>' + this.toXml() + '</Items>'; | ||
var path, method; | ||
if (this.ItemID) | ||
{ | ||
if (this.ItemID) { | ||
path = 'Items/' + this.ItemID; | ||
method = 'post' | ||
} | ||
else | ||
{ | ||
} else { | ||
path = 'Items'; | ||
method = 'put' | ||
} | ||
return this.application.putOrPostEntity(method, path, xml,{ entityPath: 'Items.Item',entityConstructor: function(data) { return self.application.core.items.newItem(data)}}); | ||
return this.application.putOrPostEntity(method, path, xml, { entityPath: 'Items.Item', entityConstructor: function(data) { return self.application.core.items.newItem(data) } }); | ||
} | ||
}); | ||
|
||
|
||
module.exports = Item; | ||
module.exports.ItemSchema = ItemSchema; | ||
module.exports.ItemSchema = ItemSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,32 @@ | ||
var _ = require('lodash') | ||
, logger = require('../logger') | ||
, EntityHelper = require('./entity_helper') | ||
, Invoice = require('../entities/invoice') | ||
, p = require('../misc/promise') | ||
, util = require('util') | ||
var _ = require('lodash'), | ||
logger = require('../logger'), | ||
EntityHelper = require('./entity_helper'), | ||
Invoice = require('../entities/invoice'), | ||
p = require('../misc/promise'), | ||
util = require('util') | ||
|
||
var Invoices = EntityHelper.extend({ | ||
constructor: function (application, options) | ||
{ | ||
EntityHelper.call(this, application, _.extend({ entityName:'Invoice', entityPlural:'Invoices'}, options)); | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, _.extend({ entityName: 'Invoice', entityPlural: 'Invoices' }, options)); | ||
}, | ||
newInvoice: function (data, options) | ||
{ | ||
newInvoice: function(data, options) { | ||
return new Invoice(this.application, data, options) | ||
}, | ||
streamInvoice: function(id,format,stream) | ||
{ | ||
return this.streamEntity({id: id, stream: stream, format: 'pdf'}); | ||
streamInvoice: function(id, format, stream) { | ||
return this.streamEntity({ id: id, stream: stream, format: 'pdf' }); | ||
}, | ||
getInvoice: function (id, modifiedAfter,where, order) | ||
{ | ||
return this.getInvoices({ id: id, modifiedAfter: modifiedAfter, where: where, order: order}) | ||
.then(function (invoices) | ||
{ | ||
getInvoice: function(id, modifiedAfter, where, order) { | ||
return this.getInvoices({ id: id, modifiedAfter: modifiedAfter, where: where, order: order }) | ||
.then(function(invoices) { | ||
return _.first(invoices); | ||
}) | ||
}, | ||
saveInvoices: function (invoices, options) | ||
{ | ||
return this.saveEntities(invoices, options) | ||
}, | ||
getInvoices: function (options) | ||
{ | ||
getInvoices: function(options) { | ||
var self = this; | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityConstructor = function(data) { return self.newInvoice(data)}; | ||
clonedOptions.entityConstructor = function(data) { return self.newInvoice(data) }; | ||
return this.getEntities(clonedOptions) | ||
}, | ||
deleteInvoice: function(id) | ||
{ | ||
|
||
} | ||
}) | ||
|
||
module.exports = Invoices; | ||
|
||
module.exports = Invoices; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters