From aa505c58a4156c9d44bae59447bd343745668c9a Mon Sep 17 00:00:00 2001 From: DedrickEnc Date: Thu, 21 Sep 2017 11:03:05 +0100 Subject: [PATCH] fix(Stock): Fix the financial writting to avoid multiple transaction for one movement and refactor t --- client/src/modules/stock/entry/entry.js | 15 +-------------- server/controllers/stock/index.js | 6 +++--- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/client/src/modules/stock/entry/entry.js b/client/src/modules/stock/entry/entry.js index e8be564603..e60d7646c6 100644 --- a/client/src/modules/stock/entry/entry.js +++ b/client/src/modules/stock/entry/entry.js @@ -324,23 +324,10 @@ function StockEntryController( flux_id : bhConstants.flux.FROM_INTEGRATION, user_id : Session.user.id, }; - - var lots = vm.Stock.store.data.reduce(function (current, previous) { - return previous.lots.map(function (lot) { - return { - label : lot.lot, - initial_quantity : lot.quantity, - quantity : lot.quantity, - unit_cost : previous.unit_cost, - expiration_date : lot.expiration_date, - inventory_uuid : previous.inventory.uuid - }; - }).concat(current); - }, []); var entry = { integration : { date : vm.movement.date, description : vm.movement.description }, - lots : lots, + lots : processLotsFromStore(vm.Stock.store.data, movement.entity_uuid), movement : movement } diff --git a/server/controllers/stock/index.js b/server/controllers/stock/index.js index 46225f3e4d..fb4b8e44cd 100644 --- a/server/controllers/stock/index.js +++ b/server/controllers/stock/index.js @@ -341,7 +341,6 @@ function createIntegration(req, res, next) { const params = req.body; const identifier = uuid.v4(); const documentUuid = uuid.v4(); - let commonInfos; const integration = { uuid : db.bid(identifier), @@ -381,10 +380,12 @@ function createIntegration(req, res, next) { unit_cost : lot.unit_cost, is_exit : 0, user_id : params.movement.user_id, + description : integration.description, }); + }); // An arry of common info, to send to the store procedure in order to insert to the posting journal - commonInfos = [ + const commonInfos = [ db.bid(documentUuid), new Date(params.movement.date), req.session.enterprise.id, @@ -398,7 +399,6 @@ function createIntegration(req, res, next) { // transaction - movement reference transaction.addQuery('CALL ComputeMovementReference(?);', [db.bid(documentUuid)]); - }); // execute all operations as one transaction transaction.execute()