From be37334f497d0b98cd5216046db8f884e946d410 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 12 Mar 2021 08:17:56 +0100 Subject: [PATCH] Requested changes --- front/core/components/input-file/index.html | 2 +- .../entry/back/methods/entry/importBuys.js | 2 +- .../methods/entry/specs/importBuys.spec.js | 2 -- .../entry/specs/importBuysPreview.spec.js | 3 ++- modules/entry/front/buy/import/index.html | 11 +++++----- modules/entry/front/buy/import/index.js | 22 ++++++++++++++----- modules/entry/front/buy/locale/es.yml | 5 +++-- 7 files changed, 30 insertions(+), 17 deletions(-) diff --git a/front/core/components/input-file/index.html b/front/core/components/input-file/index.html index bdfdcdcb48..5ec7e1da49 100644 --- a/front/core/components/input-file/index.html +++ b/front/core/components/input-file/index.html @@ -13,7 +13,7 @@ diff --git a/modules/entry/back/methods/entry/importBuys.js b/modules/entry/back/methods/entry/importBuys.js index 57877f80cd..10871f4ade 100644 --- a/modules/entry/back/methods/entry/importBuys.js +++ b/modules/entry/back/methods/entry/importBuys.js @@ -69,7 +69,7 @@ module.exports = Self => { packing: buy.packing, grouping: buy.grouping, buyingValue: buy.buyingValue, - packageFk: 1 + packageFk: buy.packageFk }); } diff --git a/modules/entry/back/methods/entry/specs/importBuys.spec.js b/modules/entry/back/methods/entry/specs/importBuys.spec.js index 89d2a3f359..06fb46d3a3 100644 --- a/modules/entry/back/methods/entry/specs/importBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/importBuys.spec.js @@ -71,8 +71,6 @@ describe('entry import()', () => { expect(entryBuys.length).toEqual(2); // Restores - await newEntry.destroy(options); - await tx.rollback(); }); }); diff --git a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js index 4eb4ec916f..db77767816 100644 --- a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js +++ b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js @@ -2,6 +2,7 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); describe('entry importBuysPreview()', () => { + const entryId = 1; beforeAll(async done => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx @@ -30,7 +31,7 @@ describe('entry importBuysPreview()', () => { } ]; - const result = await app.models.Entry.importBuysPreview(1, buys); + const result = await app.models.Entry.importBuysPreview(entryId, buys); const randomIndex = Math.floor(Math.random() * result.length); const buy = result[randomIndex]; diff --git a/modules/entry/front/buy/import/index.html b/modules/entry/front/buy/import/index.html index 00fa709b2a..74b6c708ad 100644 --- a/modules/entry/front/buy/import/index.html +++ b/modules/entry/front/buy/import/index.html @@ -75,13 +75,13 @@ {{::buy.description | dashIfEmpty}} {{::buy.size | dashIfEmpty}} - - {{::buy.packing | dashIfEmpty}} + + {{::buy.packing | dashIfEmpty}} - - {{::buy.grouping | dashIfEmpty}} + + {{::buy.grouping | dashIfEmpty}} {{::buy.buyingValue | currency: 'EUR':2}} @@ -108,7 +108,8 @@ + ui-sref="entry.card.buy.index"> + diff --git a/modules/entry/front/buy/import/index.js b/modules/entry/front/buy/import/index.js index fbf3343f81..9dc3418f0e 100644 --- a/modules/entry/front/buy/import/index.js +++ b/modules/entry/front/buy/import/index.js @@ -62,11 +62,23 @@ class Controller extends Section { } onSubmit() { - const params = this.import; - const query = `Entries/${this.entry.id}/importBuys`; - return this.$http.post(query, params) - .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) - .then(() => this.$state.go('entry.card.buy.index')); + try { + const params = this.import; + const hasAnyEmptyRow = params.buys.some(buy => { + return buy.itemFk == null; + }); + + if (hasAnyEmptyRow) + throw new Error(`Some of the imported buys doesn't have an item`); + + const query = `Entries/${this.entry.id}/importBuys`; + return this.$http.post(query, params) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) + .then(() => this.$state.go('entry.card.buy.index')); + } catch (e) { + this.vnApp.showError(this.$t(e.message)); + return false; + } } itemSearchFunc($search) { diff --git a/modules/entry/front/buy/locale/es.yml b/modules/entry/front/buy/locale/es.yml index 8d035e9a7c..b5a82948b4 100644 --- a/modules/entry/front/buy/locale/es.yml +++ b/modules/entry/front/buy/locale/es.yml @@ -1,4 +1,5 @@ reference: Referencia Observation: Observación -Box: Embalage -Import buys: Importar compras \ No newline at end of file +Box: Embalaje +Import buys: Importar compras +Some of the imported buys doesn't have an item: Algunas de las compras importadas no tienen un artículo \ No newline at end of file