From 5cbd8d632d115037130b22df304a3ec54d071096 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 9 Mar 2021 10:01:40 +0100 Subject: [PATCH] Changes --- db/dump/fixtures.sql | 1 + modules/entry/back/methods/entry/import.js | 6 +- modules/entry/front/buy/import/index.html | 52 +------- modules/entry/front/buy/import/index.js | 29 +++-- modules/entry/front/buy/import/index.spec.js | 128 +++++++++++++++++++ modules/entry/front/buy/import/locale/es.yml | 2 + 6 files changed, 156 insertions(+), 62 deletions(-) create mode 100644 modules/entry/front/buy/import/index.spec.js create mode 100644 modules/entry/front/buy/import/locale/es.yml diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index c5486459c..0f25a94f3 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2179,6 +2179,7 @@ INSERT INTO `vn`.`rate`(`dated`, `warehouseFk`, `rate0`, `rate1`, `rate2`, `rate VALUES (DATE_ADD(CURDATE(), INTERVAL -1 YEAR), 1, 10, 15, 20, 25), (CURDATE(), 1, 12, 17, 22, 27); + INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk) VALUES (1, '07546501420', 67, 671, CURDATE(), 1761, 1, 1), diff --git a/modules/entry/back/methods/entry/import.js b/modules/entry/back/methods/entry/import.js index 137d67441..cbb2e9ace 100644 --- a/modules/entry/back/methods/entry/import.js +++ b/modules/entry/back/methods/entry/import.js @@ -43,7 +43,7 @@ module.exports = Self => { const entry = await models.Entry.findById(id); await entry.updateAttributes({ - observation: args.notes + observation: args.observation }); const buys = []; @@ -63,7 +63,7 @@ module.exports = Self => { const createdBuys = await models.Buy.create(buys); const buyIds = createdBuys.map(buy => buy.id); - /* let stmts = []; + let stmts = []; let stmt; stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc'); @@ -77,6 +77,6 @@ module.exports = Self => { stmts.push('CALL buy_recalcPrices()'); const sql = ParameterizedSQL.join(stmts, ';'); - await conn.executeStmt(sql); */ + await conn.executeStmt(sql); }; }; diff --git a/modules/entry/front/buy/import/index.html b/modules/entry/front/buy/import/index.html index 903c61edc..ad812244a 100644 --- a/modules/entry/front/buy/import/index.html +++ b/modules/entry/front/buy/import/index.html @@ -7,53 +7,13 @@ name="form" ng-submit="$ctrl.onSubmit()" class="vn-ma-md"> -
+
- - - + ng-model="$ctrl.import.ref"> @@ -84,7 +44,7 @@ - + @@ -96,7 +56,7 @@ -
Item IDItem Description Size Packing
+ + label="Import"> { - this.import.invoice = invoice.id_invoice; this.import.observation = invoice.tx_awb; const boxes = invoice.boxes; @@ -49,21 +46,27 @@ class Controller extends Section { } } - const params = {buys}; - const query = `Entries/${this.entry.id}/importPreview`; - this.$http.get(query, {params}).then(res => { - this.import.buys = res.data; - }); - // this.import.buys = buys; + const boxesId = boxes.map(box => box.id_box); + this.import.ref = boxesId.join(', '); + + this.fetchBuys(buys); + }); + } + + fetchBuys(buys) { + const params = {buys}; + const query = `Entries/${this.entry.id}/importPreview`; + this.$http.get(query, {params}).then(res => { + this.import.buys = res.data; }); } onSubmit() { - const params = {buys: this.import.buys}; + const params = this.import; const query = `Entries/${this.entry.id}/import`; - return this.$http.post(query, params).then(() => { - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + return this.$http.post(query, params) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) + .then(() => this.$state.go('entry.card.buy.index')); } itemSearchFunc($search) { diff --git a/modules/entry/front/buy/import/index.spec.js b/modules/entry/front/buy/import/index.spec.js new file mode 100644 index 000000000..408fdab83 --- /dev/null +++ b/modules/entry/front/buy/import/index.spec.js @@ -0,0 +1,128 @@ +import './index.js'; + +describe('Entry', () => { + describe('Component vnEntryBuyImport', () => { + let controller; + let $httpParamSerializer; + let $httpBackend; + + beforeEach(ngModule('entry')); + + beforeEach(angular.mock.inject(($componentController, $compile, $rootScope, _$httpParamSerializer_, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + $httpParamSerializer = _$httpParamSerializer_; + let $element = $compile(' { + it(`should call to the fillData() method`, () => { + controller.fetchBuys = jest.fn(); + + const rawData = `{ + "invoices": [ + { + "tx_awb": "123456", + "boxes": [ + { + "id_box": 1, + "nu_length": 1, + "nu_width": 15, + "nu_height": 80, + "products": [ + { + "nm_product": "Bow", + "nu_length": 1, + "nu_stems_bunch": 1, + "nu_bunches": 1, + "mny_rate_stem": 5.77 + } + + ] + }, + { + "id_box": 2, + "nu_length": 25, + "nu_width": 1, + "nu_height": 45, + "products": [ + { + "nm_product": "Arrow", + "nu_length": 25, + "nu_stems_bunch": 1, + "nu_bunches": 1, + "mny_rate_stem": 2.16 + } + ] + } + ] + } + ]}`; + const expectedBuys = [ + {'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200}, + {'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125} + ]; + controller.fillData(rawData); + controller.$.$apply(); + + const importData = controller.import; + + expect(importData.observation).toEqual('123456'); + expect(importData.ref).toEqual('1, 2'); + + expect(controller.fetchBuys).toHaveBeenCalledWith(expectedBuys); + }); + }); + + describe('fetchBuys()', () => { + it(`should perform a query to fetch the buys data`, () => { + const buys = [ + {'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200}, + {'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125} + ]; + + const serializedParams = $httpParamSerializer({buys}); + const query = `Entries/1/importPreview?${serializedParams}`; + $httpBackend.expectGET(query).respond(200, buys); + controller.fetchBuys(buys); + $httpBackend.flush(); + + const importData = controller.import; + + expect(importData.buys.length).toEqual(2); + }); + }); + + describe('onSubmit()', () => { + it(`should perform a query to update columns`, () => { + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$state, 'go'); + + controller.import = { + observation: '123456', + ref: '1, 2', + buys: [ + {'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200}, + {'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125} + ] + }; + const params = controller.import; + + const query = `Entries/1/import`; + $httpBackend.expectPOST(query, params).respond(200, params.buys); + controller.onSubmit(); + $httpBackend.flush(); + + const importData = controller.import; + + expect(importData.buys.length).toEqual(2); + + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.$state.go).toHaveBeenCalledWith('foo.card.summary', {id: 1}, undefined); + }); + }); + }); +}); diff --git a/modules/entry/front/buy/import/locale/es.yml b/modules/entry/front/buy/import/locale/es.yml new file mode 100644 index 000000000..7962a2870 --- /dev/null +++ b/modules/entry/front/buy/import/locale/es.yml @@ -0,0 +1,2 @@ +#Ordenar alfabeticamente +reference: Referencia \ No newline at end of file