From 3a5d84b34ca5b4b49064cd0584560e209c741818 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 31 May 2021 08:21:16 +0200 Subject: [PATCH 1/6] rutas reparadas --- modules/invoiceIn/front/create/card.spec.js | 104 ++++++++++++++++++ modules/invoiceIn/front/create/index.html | 55 +++++++++ modules/invoiceIn/front/create/index.js | 57 ++++++++++ modules/invoiceIn/front/create/index.spec.js | 34 ++++++ modules/invoiceIn/front/create/locale/es.yml | 1 + modules/invoiceIn/front/index.js | 1 + modules/invoiceIn/front/locale/es.yml | 2 +- modules/invoiceIn/front/routes.json | 6 + modules/supplier/front/descriptor/index.html | 5 + .../supplier/front/descriptor/locale/es.yml | 3 +- package-lock.json | 74 ++++++++----- 11 files changed, 311 insertions(+), 31 deletions(-) create mode 100644 modules/invoiceIn/front/create/card.spec.js create mode 100644 modules/invoiceIn/front/create/index.html create mode 100644 modules/invoiceIn/front/create/index.js create mode 100644 modules/invoiceIn/front/create/index.spec.js create mode 100644 modules/invoiceIn/front/create/locale/es.yml diff --git a/modules/invoiceIn/front/create/card.spec.js b/modules/invoiceIn/front/create/card.spec.js new file mode 100644 index 0000000000..99e8c1f8ae --- /dev/null +++ b/modules/invoiceIn/front/create/card.spec.js @@ -0,0 +1,104 @@ +import './card.js'; + +describe('Order', () => { + describe('Component vnOrderCreateCard', () => { + let controller; + let $httpBackend; + let $scope; + + beforeEach(ngModule('order')); + + beforeEach(inject(($componentController, _$httpBackend_, _vnApp_, $rootScope) => { + $httpBackend = _$httpBackend_; + $scope = $rootScope.$new(); + const $element = angular.element(''); + controller = $componentController('vnOrderCreateCard', {$element, $scope}); + controller.item = {id: 3}; + })); + + describe('set order', () => { + it(`should set order if the value given is not null`, () => { + controller.order = 1; + + expect(controller.order).toEqual(1); + }); + }); + + describe('set clientFk', () => { + it(`should set addressFk to null and clientFk to a value and set addressFk to a value given`, () => { + let filter = { + include: { + relation: 'defaultAddress', + scope: { + fields: 'id' + } + }, + where: {id: 2} + }; + filter = encodeURIComponent(JSON.stringify(filter)); + let response = [ + { + defaultAddress: {id: 1} + } + ]; + $httpBackend.whenGET(`Clients?filter=${filter}`).respond(response); + $httpBackend.expectGET(`Clients?filter=${filter}`); + + controller.clientFk = 2; + $httpBackend.flush(); + + expect(controller.clientFk).toEqual(2); + expect(controller.order.addressFk).toBe(1); + }); + }); + + describe('set addressFk', () => { + it(`should set agencyModeFk property to null and addressFk to a value`, () => { + controller.addressFk = 101; + + expect(controller.addressFk).toEqual(101); + expect(controller.order.agencyModeFk).toBe(null); + }); + }); + + describe('getAvailableAgencies()', () => { + it(`should make a query if landed and addressFk exists`, () => { + controller.order.addressFk = 101; + controller.order.landed = 101; + + $httpBackend.whenRoute('GET', 'Agencies/landsThatDay') + .respond({data: 1}); + + controller.getAvailableAgencies(); + $httpBackend.flush(); + }); + }); + + describe('onSubmit()', () => { + it(`should call createOrder()`, () => { + jest.spyOn(controller, 'createOrder'); + controller.onSubmit(); + + expect(controller.createOrder).toHaveBeenCalledWith(); + }); + }); + + describe('createOrder()', () => { + it(`should make a query, call vnApp.showSuccess and $state.go if the response is defined`, () => { + controller.order.landed = 101; + controller.order.addressFk = 101; + controller.order.agencyModeFk = 101; + + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$state, 'go'); + $httpBackend.expect('POST', 'Orders/new', {landed: 101, addressId: 101, agencyModeId: 101}).respond(200, 1); + controller.createOrder(); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + expect(controller.$state.go).toHaveBeenCalledWith('order.card.catalog', {id: 1}); + }); + }); + }); +}); + diff --git a/modules/invoiceIn/front/create/index.html b/modules/invoiceIn/front/create/index.html new file mode 100644 index 0000000000..cacf71b052 --- /dev/null +++ b/modules/invoiceIn/front/create/index.html @@ -0,0 +1,55 @@ +
+ + + {{id}}: {{name}} + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/modules/invoiceIn/front/create/index.js b/modules/invoiceIn/front/create/index.js new file mode 100644 index 0000000000..4b4b94aa46 --- /dev/null +++ b/modules/invoiceIn/front/create/index.js @@ -0,0 +1,57 @@ +import ngModule from '../../../supplier/front/module'; +import Section from 'salix/components/section'; + +class Controller extends Section { + + constructor($element, $) { + super($element, $); + this.invoiceIn = {}; + } + + $onInit() { + if (this.$params && this.$params.supplierFk) + this.supplierFk = this.$params.supplierFk; + } + + set invoiceIn(value) { + if (value) + this._invoiceIn = value; + } + + get invoiceIn() { + return this._invoiceIn; + } + + set supplierFk(value) { + this.invoiceIn.supplierFk = value; + } + + get supplierFk() { + return this.invoiceIn.supplierFk; + } + + set issued(value) { + this.invoiceIn.landed = value; + } + + get issued() { + return this.invoiceIn.issued; + } + + get warehouseFk() { + return this.invoiceIn.warehouseFk; + } + + onSubmit() { + this.$http.post(`InvoicesIn/new`, this.invoiceIn).then(res => { + this.vnApp.showSuccess(this.$t('Data saved!')); + this.$state.go('invoiceIn.summary', {id: res.data}); + }); + } + +} + +ngModule.vnComponent('vnInvoiceInCreate', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/invoiceIn/front/create/index.spec.js b/modules/invoiceIn/front/create/index.spec.js new file mode 100644 index 0000000000..af8c8f9745 --- /dev/null +++ b/modules/invoiceIn/front/create/index.spec.js @@ -0,0 +1,34 @@ +import './index.js'; + +describe('Order', () => { + describe('Component vnOrderCreate', () => { + let $scope; + let controller; + + beforeEach(ngModule('order')); + + beforeEach(inject(($componentController, $rootScope) => { + $scope = $rootScope.$new(); + $scope.card = {createOrder: () => {}}; + const $element = angular.element(''); + controller = $componentController('vnOrderCreate', {$element, $scope}); + })); + + describe('onSubmit()', () => { + it(`should call createOrder()`, () => { + jest.spyOn(controller.$.card, 'createOrder'); + controller.onSubmit(); + + expect(controller.$.card.createOrder).toHaveBeenCalledWith(); + }); + + it(`should call go()`, async() => { + jest.spyOn(controller.$state, 'go'); + await controller.onSubmit(); + + expect(controller.$state.go).toHaveBeenCalledWith('order.card.summary', {id: undefined}); + }); + }); + }); +}); + diff --git a/modules/invoiceIn/front/create/locale/es.yml b/modules/invoiceIn/front/create/locale/es.yml new file mode 100644 index 0000000000..35bfe3ca49 --- /dev/null +++ b/modules/invoiceIn/front/create/locale/es.yml @@ -0,0 +1 @@ +a:a \ No newline at end of file diff --git a/modules/invoiceIn/front/index.js b/modules/invoiceIn/front/index.js index 6c175d9a00..bd21551b51 100644 --- a/modules/invoiceIn/front/index.js +++ b/modules/invoiceIn/front/index.js @@ -8,3 +8,4 @@ import './descriptor'; import './descriptor-popover'; import './summary'; import './basic-data'; +import './create'; diff --git a/modules/invoiceIn/front/locale/es.yml b/modules/invoiceIn/front/locale/es.yml index 2d8dc02dae..ac432aba8b 100644 --- a/modules/invoiceIn/front/locale/es.yml +++ b/modules/invoiceIn/front/locale/es.yml @@ -1,5 +1,5 @@ InvoiceIn: Facturas recibidas Search invoices in by reference: Buscar facturas recibidas por referencia Entries list: Listado de entradas -Invoice list: Listado de entradas +Invoice list: Listado de facturas recibidas InvoiceIn deleted: Factura eliminada \ No newline at end of file diff --git a/modules/invoiceIn/front/routes.json b/modules/invoiceIn/front/routes.json index 05eff347b2..05348e1500 100644 --- a/modules/invoiceIn/front/routes.json +++ b/modules/invoiceIn/front/routes.json @@ -54,6 +54,12 @@ "params": { "invoice-in": "$ctrl.invoiceIn" } + }, + { + "url" : "/create?supplierFk", + "state": "invoiceIn.create", + "component": "vn-invoice-in-create", + "description": "New InvoiceIn" } ] } \ No newline at end of file diff --git a/modules/supplier/front/descriptor/index.html b/modules/supplier/front/descriptor/index.html index 9603f77584..9781c95b87 100644 --- a/modules/supplier/front/descriptor/index.html +++ b/modules/supplier/front/descriptor/index.html @@ -56,6 +56,11 @@
+ +
diff --git a/modules/supplier/front/descriptor/locale/es.yml b/modules/supplier/front/descriptor/locale/es.yml index ad47a54773..d889a9eee5 100644 --- a/modules/supplier/front/descriptor/locale/es.yml +++ b/modules/supplier/front/descriptor/locale/es.yml @@ -3,4 +3,5 @@ All entries with current supplier: Todas las entradas con el proveedor actual Go to client: Ir al cliente Verified supplier: Proveedor verificado Unverified supplier: Proveedor no verificado -Inactive supplier: Proveedor inactivo \ No newline at end of file +Inactive supplier: Proveedor inactivo +Create invoiceIn: Crear factura recibida \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 1c02e021a7..987b545986 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3597,16 +3597,16 @@ } }, "browserslist": { - "version": "4.16.3", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.3.tgz", - "integrity": "sha512-vIyhWmIkULaq04Gt93txdh+j02yX/JzlyhLYbV3YQCn/zvES3JnY7TifHHvvr1w5hTDluNKMkV05cs4vy8Q7sw==", + "version": "4.16.6", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.6.tgz", + "integrity": "sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ==", "dev": true, "requires": { - "caniuse-lite": "^1.0.30001181", - "colorette": "^1.2.1", - "electron-to-chromium": "^1.3.649", + "caniuse-lite": "^1.0.30001219", + "colorette": "^1.2.2", + "electron-to-chromium": "^1.3.723", "escalade": "^3.1.1", - "node-releases": "^1.1.70" + "node-releases": "^1.1.71" } }, "bser": { @@ -3824,9 +3824,9 @@ "integrity": "sha1-FkpUg+Yw+kMh5a8HAg5TGDGyYJs=" }, "caniuse-lite": { - "version": "1.0.30001200", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001200.tgz", - "integrity": "sha512-ic/jXfa6tgiPBAISWk16jRI2q8YfjxHnSG7ddSL1ptrIP8Uy11SayFrjXRAk3NumHpDb21fdTkbTxb/hOrFrnQ==", + "version": "1.0.30001230", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001230.tgz", + "integrity": "sha512-5yBd5nWCBS+jWKTcHOzXwo5xzcj4ePE/yjtkZyUV1BTUmrBaA9MRGC+e7mxnqXSA90CmCA8L3eKLaSUkt099IQ==", "dev": true }, "canonical-json": { @@ -5031,9 +5031,9 @@ "dev": true }, "dns-packet": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-1.3.1.tgz", - "integrity": "sha512-0UxfQkMhYAUaZI+xrNZOz/as5KgDU0M/fQ9b6SpkyLbk3GEswDi6PADJVaYJradtRVsRIlF1zLyOodbcTCDzUg==", + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-1.3.4.tgz", + "integrity": "sha512-BQ6F4vycLXBvdrJZ6S3gZewt6rcrks9KBgM9vrhW+knGRqc8uEdT7fuCwloc7nny5xNoMJ17HGH0R/6fpo8ECA==", "dev": true, "requires": { "ip": "^1.1.0", @@ -5282,9 +5282,9 @@ "integrity": "sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==" }, "electron-to-chromium": { - "version": "1.3.687", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.687.tgz", - "integrity": "sha512-IpzksdQNl3wdgkzf7dnA7/v10w0Utf1dF2L+B4+gKrloBrxCut+au+kky3PYvle3RMdSxZP+UiCZtLbcYRxSNQ==", + "version": "1.3.740", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.740.tgz", + "integrity": "sha512-Mi2m55JrX2BFbNZGKYR+2ItcGnR4O5HhrvgoRRyZQlaMGQULqDhoGkLWHzJoshSzi7k1PUofxcDbNhlFrDZNhg==", "dev": true }, "elliptic": { @@ -8336,9 +8336,9 @@ } }, "hosted-git-info": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz", - "integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==", + "version": "2.8.9", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", + "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", "dev": true }, "hpack.js": { @@ -8709,12 +8709,12 @@ "integrity": "sha512-wcGvY31MpFNHIkUcXHHnvrE4IKYlpvitJw5P/1u892gMBAM46muQ+RH7UN1d+Ntnfx5apnOnVY6vcLmrWHOLwg==" }, "httpntlm": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/httpntlm/-/httpntlm-1.6.1.tgz", - "integrity": "sha1-rQFScUOi6Hc8+uapb1hla7UqNLI=", + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/httpntlm/-/httpntlm-1.7.7.tgz", + "integrity": "sha512-Pv2Rvrz8H0qv1Dne5mAdZ9JegG1uc6Vu5lwLflIY6s8RKHdZQbW39L4dYswSgqMDT0pkJILUTKjeyU0VPNRZjA==", "requires": { "httpreq": ">=0.4.22", - "underscore": "~1.7.0" + "underscore": "~1.12.1" } }, "httpreq": { @@ -13392,9 +13392,9 @@ } }, "node-releases": { - "version": "1.1.71", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.71.tgz", - "integrity": "sha512-zR6HoT6LrLCRBwukmrVbHv0EpEQjksO6GmFcZQQuCAy139BEsoVKPYnf3jongYW83fAa1torLGYwxxky/p28sg==", + "version": "1.1.72", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.72.tgz", + "integrity": "sha512-LLUo+PpH3dU6XizX3iVoubUNheF/owjXCZZ5yACDxNnPtgFuludV1ZL3ayK1kVep42Rmm0+R9/Y60NQbZ2bifw==", "dev": true }, "node-sass": { @@ -16669,6 +16669,22 @@ "requires": { "httpntlm": "1.6.1", "nodemailer-shared": "1.1.0" + }, + "dependencies": { + "httpntlm": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/httpntlm/-/httpntlm-1.6.1.tgz", + "integrity": "sha1-rQFScUOi6Hc8+uapb1hla7UqNLI=", + "requires": { + "httpreq": ">=0.4.22", + "underscore": "~1.7.0" + } + }, + "underscore": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz", + "integrity": "sha1-a7rwh3UA02vjTsqlhODbn+8DUgk=" + } } }, "snakeize": { @@ -18603,9 +18619,9 @@ } }, "underscore": { - "version": "1.7.0", - "resolved": "http://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz", - "integrity": "sha1-a7rwh3UA02vjTsqlhODbn+8DUgk=" + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.12.1.tgz", + "integrity": "sha512-hEQt0+ZLDVUMhebKxL4x1BTtDY7bavVofhZ9KZ4aI26X9SRaE+Y3m83XUL1UP2jn8ynjndwCCpEHdUG+9pP1Tw==" }, "underscore.string": { "version": "3.3.5", From 70fc260eae73b32006be3e4e1729f3734e09dfa4 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 1 Jun 2021 10:10:09 +0200 Subject: [PATCH 2/6] vnConfig solucionado --- modules/invoiceIn/front/create/card.spec.js | 2 +- modules/invoiceIn/front/create/index.html | 117 ++++++++++--------- modules/invoiceIn/front/create/index.js | 46 ++------ modules/invoiceIn/front/create/index.spec.js | 30 +++-- 4 files changed, 92 insertions(+), 103 deletions(-) diff --git a/modules/invoiceIn/front/create/card.spec.js b/modules/invoiceIn/front/create/card.spec.js index 99e8c1f8ae..31fed01406 100644 --- a/modules/invoiceIn/front/create/card.spec.js +++ b/modules/invoiceIn/front/create/card.spec.js @@ -1,6 +1,6 @@ import './card.js'; -describe('Order', () => { +xdescribe('Order', () => { describe('Component vnOrderCreateCard', () => { let controller; let $httpBackend; diff --git a/modules/invoiceIn/front/create/index.html b/modules/invoiceIn/front/create/index.html index cacf71b052..4ec7248545 100644 --- a/modules/invoiceIn/front/create/index.html +++ b/modules/invoiceIn/front/create/index.html @@ -1,55 +1,62 @@ -
- - - {{id}}: {{name}} - - - - - - - - - - - - - - - - - -
\ No newline at end of file + + +
+
+ + + {{id}}: {{name}} + + + + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/modules/invoiceIn/front/create/index.js b/modules/invoiceIn/front/create/index.js index 4b4b94aa46..2eb76b931b 100644 --- a/modules/invoiceIn/front/create/index.js +++ b/modules/invoiceIn/front/create/index.js @@ -2,53 +2,25 @@ import ngModule from '../../../supplier/front/module'; import Section from 'salix/components/section'; class Controller extends Section { - - constructor($element, $) { - super($element, $); - this.invoiceIn = {}; - } - $onInit() { + this.invoiceIn = {}; if (this.$params && this.$params.supplierFk) - this.supplierFk = this.$params.supplierFk; + this.invoiceIn.supplierFk = this.$params.supplierFk; } - set invoiceIn(value) { - if (value) - this._invoiceIn = value; + get companyFk() { + return this.invoiceIn.companyFk || this.vnConfig.companyFk; } - get invoiceIn() { - return this._invoiceIn; - } - - set supplierFk(value) { - this.invoiceIn.supplierFk = value; - } - - get supplierFk() { - return this.invoiceIn.supplierFk; - } - - set issued(value) { - this.invoiceIn.landed = value; - } - - get issued() { - return this.invoiceIn.issued; - } - - get warehouseFk() { - return this.invoiceIn.warehouseFk; + set companyFk(value) { + this.invoiceIn.companyFk = value; } onSubmit() { - this.$http.post(`InvoicesIn/new`, this.invoiceIn).then(res => { - this.vnApp.showSuccess(this.$t('Data saved!')); - this.$state.go('invoiceIn.summary', {id: res.data}); - }); + this.$.watcher.submit().then( + res => this.$state.go('invoiceIn.card.basicData', {id: res.data.id}) + ); } - } ngModule.vnComponent('vnInvoiceInCreate', { diff --git a/modules/invoiceIn/front/create/index.spec.js b/modules/invoiceIn/front/create/index.spec.js index af8c8f9745..7269a44d1b 100644 --- a/modules/invoiceIn/front/create/index.spec.js +++ b/modules/invoiceIn/front/create/index.spec.js @@ -1,32 +1,42 @@ import './index.js'; -describe('Order', () => { - describe('Component vnOrderCreate', () => { +describe('InvoiceIn', () => { + describe('Component vnInvoiceInCreate', () => { let $scope; let controller; - beforeEach(ngModule('order')); + beforeEach(ngModule('invoiceIn')); beforeEach(inject(($componentController, $rootScope) => { $scope = $rootScope.$new(); - $scope.card = {createOrder: () => {}}; - const $element = angular.element(''); - controller = $componentController('vnOrderCreate', {$element, $scope}); + $scope.card = {createInvoiceIn: () => {}}; + const $element = angular.element(''); + console.log($element); + console.log($scope); + controller = $componentController('vnInvoiceIn', {$element, $scope}); })); describe('onSubmit()', () => { - it(`should call createOrder()`, () => { - jest.spyOn(controller.$.card, 'createOrder'); + it(`should call createInvoiceIn()`, () => { + jest.spyOn(controller, 'createOrder'); controller.onSubmit(); - expect(controller.$.card.createOrder).toHaveBeenCalledWith(); + expect(controller.createOrder).toHaveBeenCalledWith(); }); it(`should call go()`, async() => { jest.spyOn(controller.$state, 'go'); await controller.onSubmit(); - expect(controller.$state.go).toHaveBeenCalledWith('order.card.summary', {id: undefined}); + expect(controller.$state.go).toHaveBeenCalledWith('order.invoiceIn.summary', {id: undefined}); + }); + }); + + describe('set companyFk', () => { + it(`should set companyFk to a value`, () => { + controller.companyFk = 442; + + expect(controller.companyFk).toEqual(442); }); }); }); From 2604c81533be8a4defd8a55ad07dfdd690e985ee Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 4 Jun 2021 08:24:33 +0200 Subject: [PATCH 3/6] falta solucionar test --- modules/invoiceIn/front/create/card.spec.js | 104 ------------------- modules/invoiceIn/front/create/index.spec.js | 33 +++--- 2 files changed, 19 insertions(+), 118 deletions(-) delete mode 100644 modules/invoiceIn/front/create/card.spec.js diff --git a/modules/invoiceIn/front/create/card.spec.js b/modules/invoiceIn/front/create/card.spec.js deleted file mode 100644 index 31fed01406..0000000000 --- a/modules/invoiceIn/front/create/card.spec.js +++ /dev/null @@ -1,104 +0,0 @@ -import './card.js'; - -xdescribe('Order', () => { - describe('Component vnOrderCreateCard', () => { - let controller; - let $httpBackend; - let $scope; - - beforeEach(ngModule('order')); - - beforeEach(inject(($componentController, _$httpBackend_, _vnApp_, $rootScope) => { - $httpBackend = _$httpBackend_; - $scope = $rootScope.$new(); - const $element = angular.element(''); - controller = $componentController('vnOrderCreateCard', {$element, $scope}); - controller.item = {id: 3}; - })); - - describe('set order', () => { - it(`should set order if the value given is not null`, () => { - controller.order = 1; - - expect(controller.order).toEqual(1); - }); - }); - - describe('set clientFk', () => { - it(`should set addressFk to null and clientFk to a value and set addressFk to a value given`, () => { - let filter = { - include: { - relation: 'defaultAddress', - scope: { - fields: 'id' - } - }, - where: {id: 2} - }; - filter = encodeURIComponent(JSON.stringify(filter)); - let response = [ - { - defaultAddress: {id: 1} - } - ]; - $httpBackend.whenGET(`Clients?filter=${filter}`).respond(response); - $httpBackend.expectGET(`Clients?filter=${filter}`); - - controller.clientFk = 2; - $httpBackend.flush(); - - expect(controller.clientFk).toEqual(2); - expect(controller.order.addressFk).toBe(1); - }); - }); - - describe('set addressFk', () => { - it(`should set agencyModeFk property to null and addressFk to a value`, () => { - controller.addressFk = 101; - - expect(controller.addressFk).toEqual(101); - expect(controller.order.agencyModeFk).toBe(null); - }); - }); - - describe('getAvailableAgencies()', () => { - it(`should make a query if landed and addressFk exists`, () => { - controller.order.addressFk = 101; - controller.order.landed = 101; - - $httpBackend.whenRoute('GET', 'Agencies/landsThatDay') - .respond({data: 1}); - - controller.getAvailableAgencies(); - $httpBackend.flush(); - }); - }); - - describe('onSubmit()', () => { - it(`should call createOrder()`, () => { - jest.spyOn(controller, 'createOrder'); - controller.onSubmit(); - - expect(controller.createOrder).toHaveBeenCalledWith(); - }); - }); - - describe('createOrder()', () => { - it(`should make a query, call vnApp.showSuccess and $state.go if the response is defined`, () => { - controller.order.landed = 101; - controller.order.addressFk = 101; - controller.order.agencyModeFk = 101; - - jest.spyOn(controller.vnApp, 'showSuccess'); - jest.spyOn(controller.$state, 'go'); - $httpBackend.expect('POST', 'Orders/new', {landed: 101, addressId: 101, agencyModeId: 101}).respond(200, 1); - controller.createOrder(); - $httpBackend.flush(); - - expect(controller.vnApp.showSuccess).toHaveBeenCalled(); - expect(controller.$state.go).toHaveBeenCalledWith('order.card.catalog', {id: 1}); - }); - }); - }); -}); - diff --git a/modules/invoiceIn/front/create/index.spec.js b/modules/invoiceIn/front/create/index.spec.js index 7269a44d1b..2708b58608 100644 --- a/modules/invoiceIn/front/create/index.spec.js +++ b/modules/invoiceIn/front/create/index.spec.js @@ -1,39 +1,44 @@ import './index.js'; -describe('InvoiceIn', () => { +fdescribe('InvoiceIn', () => { describe('Component vnInvoiceInCreate', () => { - let $scope; let controller; + let $element; beforeEach(ngModule('invoiceIn')); - beforeEach(inject(($componentController, $rootScope) => { - $scope = $rootScope.$new(); - $scope.card = {createInvoiceIn: () => {}}; - const $element = angular.element(''); + beforeEach(inject(($componentController, $compile, $rootScope) => { + $element = angular.element(``); console.log($element); - console.log($scope); - controller = $componentController('vnInvoiceIn', {$element, $scope}); + controller = $componentController('vnInvoiceInCreate', {$element}); + // controller = $element.controller('Controller'); })); + afterEach(() => { + $element.remove(); + }); + describe('onSubmit()', () => { it(`should call createInvoiceIn()`, () => { - jest.spyOn(controller, 'createOrder'); + jest.spyOn(controller, 'createInvoiceIn'); controller.onSubmit(); - expect(controller.createOrder).toHaveBeenCalledWith(); + expect(controller.createInvoiceIn).toHaveBeenCalledWith(); }); + }); - it(`should call go()`, async() => { - jest.spyOn(controller.$state, 'go'); - await controller.onSubmit(); + describe('onInit()', () => { + it(`should define invoiceIn supplierFk with params values()`, () => { + controller.params = 'supplierId'; + controller.$onInit(); - expect(controller.$state.go).toHaveBeenCalledWith('order.invoiceIn.summary', {id: undefined}); + expect(controller.invoiceIn.supplierFk).toEqual('supplierId'); }); }); describe('set companyFk', () => { it(`should set companyFk to a value`, () => { + console.log(controller); controller.companyFk = 442; expect(controller.companyFk).toEqual(442); From 8fd7faa47b896856e130566bc06763c8d94f9af4 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Mon, 7 Jun 2021 11:12:56 +0200 Subject: [PATCH 4/6] fixed bug module importation + rewritten tests --- modules/invoiceIn/front/create/index.js | 2 +- modules/invoiceIn/front/create/index.spec.js | 47 +++++++++++--------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/modules/invoiceIn/front/create/index.js b/modules/invoiceIn/front/create/index.js index 2eb76b931b..186f5d478e 100644 --- a/modules/invoiceIn/front/create/index.js +++ b/modules/invoiceIn/front/create/index.js @@ -1,4 +1,4 @@ -import ngModule from '../../../supplier/front/module'; +import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { diff --git a/modules/invoiceIn/front/create/index.spec.js b/modules/invoiceIn/front/create/index.spec.js index 2708b58608..93109346c2 100644 --- a/modules/invoiceIn/front/create/index.spec.js +++ b/modules/invoiceIn/front/create/index.spec.js @@ -1,47 +1,50 @@ import './index.js'; +import watcher from 'core/mocks/watcher'; -fdescribe('InvoiceIn', () => { +describe('InvoiceIn', () => { describe('Component vnInvoiceInCreate', () => { let controller; let $element; beforeEach(ngModule('invoiceIn')); - beforeEach(inject(($componentController, $compile, $rootScope) => { - $element = angular.element(``); - console.log($element); - controller = $componentController('vnInvoiceInCreate', {$element}); - // controller = $element.controller('Controller'); + beforeEach(inject(($componentController, $rootScope) => { + const $scope = $rootScope.$new(); + $scope.watcher = watcher; + $element = angular.element(''); + controller = $componentController('vnInvoiceInCreate', {$element, $scope}); + controller.$params = {}; })); afterEach(() => { $element.remove(); }); - describe('onSubmit()', () => { - it(`should call createInvoiceIn()`, () => { - jest.spyOn(controller, 'createInvoiceIn'); - controller.onSubmit(); - - expect(controller.createInvoiceIn).toHaveBeenCalledWith(); - }); - }); - describe('onInit()', () => { - it(`should define invoiceIn supplierFk with params values()`, () => { - controller.params = 'supplierId'; + it(`should defined the controller's invoiceIn property`, () => { + expect(controller.invoiceIn).toBeUndefined(); + + controller.$onInit(); + + expect(controller.invoiceIn).toEqual({}); + }); + + it(`should define invoiceIn and it's supplierFk when received via params`, () => { + controller.$params.supplierFk = 'supplierId'; + controller.$onInit(); expect(controller.invoiceIn.supplierFk).toEqual('supplierId'); }); }); - describe('set companyFk', () => { - it(`should set companyFk to a value`, () => { - console.log(controller); - controller.companyFk = 442; + describe('onSubmit()', () => { + it(`should redirect to basic data by calling the $state.go function`, () => { + jest.spyOn(controller.$state, 'go'); - expect(controller.companyFk).toEqual(442); + controller.onSubmit(); + + expect(controller.$state.go).toHaveBeenCalledWith('invoiceIn.card.basicData', {id: 1234}); }); }); }); From 98621b9e4202cdbf1dcfbda8b53c3de345d92b4c Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 21 Jun 2021 10:00:38 +0000 Subject: [PATCH 5/6] Removed transaction --- .../10330-jun2021/01-ticket_componentMakeUpdate.sql | 8 -------- 1 file changed, 8 deletions(-) diff --git a/db/changes/10330-jun2021/01-ticket_componentMakeUpdate.sql b/db/changes/10330-jun2021/01-ticket_componentMakeUpdate.sql index ac3e85f084..058d6eb99e 100644 --- a/db/changes/10330-jun2021/01-ticket_componentMakeUpdate.sql +++ b/db/changes/10330-jun2021/01-ticket_componentMakeUpdate.sql @@ -31,16 +31,9 @@ BEGIN */ DECLARE vPrice DECIMAL(10,2); DECLARE vBonus DECIMAL(10,2); - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); - START TRANSACTION; - IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN UPDATE ticket t @@ -95,7 +88,6 @@ BEGIN DROP TEMPORARY TABLE tmp.sale; DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; END IF; - COMMIT; DROP TEMPORARY TABLE tmp.zoneGetShipped, tmp.ticketComponentPreview; END$$ From 273ebe9c5f5dbe8c24a42c03b17087caff8d3441 Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 21 Jun 2021 10:34:41 +0000 Subject: [PATCH 6/6] Removed risk min amount --- .../10330-jun2021/00-sale_getProblems.sql | 192 ++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 db/changes/10330-jun2021/00-sale_getProblems.sql diff --git a/db/changes/10330-jun2021/00-sale_getProblems.sql b/db/changes/10330-jun2021/00-sale_getProblems.sql new file mode 100644 index 0000000000..6685378b30 --- /dev/null +++ b/db/changes/10330-jun2021/00-sale_getProblems.sql @@ -0,0 +1,192 @@ +DROP PROCEDURE IF EXISTS `vn`.`sale_getProblems`; + +DELIMITER $$ +$$ +CREATE + DEFINER = root@`%` PROCEDURE `vn`.`sale_getProblems`(IN vIsTodayRelative TINYINT(1)) +BEGIN +/** + * Calcula los problemas de cada venta + * para un conjunto de tickets. + * + * @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular + * @return tmp.sale_problems + */ + DECLARE vWarehouse INT; + DECLARE vDate DATE; + DECLARE vAvailableCache INT; + DECLARE vDone INT DEFAULT 0; + DECLARE vComponentCount INT; + + DECLARE vCursor CURSOR FOR + SELECT DISTINCT tt.warehouseFk, IF(vIsTodayRelative, CURDATE(), date(tt.shipped)) + FROM tmp.sale_getProblems tt + WHERE DATE(tt.shipped) BETWEEN CURDATE() + AND TIMESTAMPADD(DAY, IF(vIsTodayRelative, 9.9, 1.9), CURDATE()); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; + + DROP TEMPORARY TABLE IF EXISTS tmp.sale_problems; + CREATE TEMPORARY TABLE tmp.sale_problems ( + ticketFk INT(11), + saleFk INT(11), + isFreezed INTEGER(1) DEFAULT 0, + risk DECIMAL(10,2) DEFAULT 0, + hasTicketRequest INTEGER(1) DEFAULT 0, + isAvailable INTEGER(1) DEFAULT 1, + itemShortage VARCHAR(250), + isTaxDataChecked INTEGER(1) DEFAULT 1, + itemDelay VARCHAR(250), + hasComponentLack INTEGER(1), + PRIMARY KEY (ticketFk, saleFk) + ) ENGINE = MEMORY; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; + CREATE TEMPORARY TABLE tmp.ticket_list + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT tp.ticketFk, c.id clientFk + FROM tmp.sale_getProblems tp + JOIN vn.client c ON c.id = tp.clientFk; + + SELECT COUNT(*) INTO vComponentCount + FROM vn.component c + WHERE c.isRequired; + + INSERT INTO tmp.sale_problems(ticketFk, hasComponentLack, saleFk) + SELECT tl.ticketFk, (COUNT(DISTINCT s.id) * vComponentCount > COUNT(c.id)), s.id + FROM tmp.ticket_list tl + JOIN vn.sale s ON s.ticketFk = tl.ticketFk + LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id + LEFT JOIN vn.component c ON c.id = sc.componentFk AND c.isRequired + GROUP BY tl.ticketFk, s.id; + + INSERT INTO tmp.sale_problems(ticketFk, isFreezed) + SELECT DISTINCT tl.ticketFk, TRUE + FROM tmp.ticket_list tl + JOIN vn.client c ON c.id = tl.clientFk + WHERE c.isFreezed + ON DUPLICATE KEY UPDATE + isFreezed = c.isFreezed; + + DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; + CREATE TEMPORARY TABLE tmp.clientGetDebt + (PRIMARY KEY (clientFk)) + ENGINE = MEMORY + SELECT DISTINCT clientFk + FROM tmp.ticket_list; + + CALL clientGetDebt(CURDATE()); + + INSERT INTO tmp.sale_problems(ticketFk, risk) + SELECT DISTINCT tl.ticketFk, r.risk + FROM tmp.ticket_list tl + JOIN vn.ticket t ON t.id = tl.ticketFk + JOIN vn.agencyMode a ON t.agencyModeFk = a.id + JOIN tmp.risk r ON r.clientFk = t.clientFk + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.clientConfig cc + WHERE r.risk > c.credit + 10 + AND a.isRiskFree = FALSE + ON DUPLICATE KEY UPDATE + risk = r.risk; + + INSERT INTO tmp.sale_problems(ticketFk, hasTicketRequest) + SELECT DISTINCT tl.ticketFk, TRUE + FROM tmp.ticket_list tl + JOIN vn.ticketRequest tr ON tr.ticketFk = tl.ticketFk + WHERE tr.isOK IS NULL + ON DUPLICATE KEY UPDATE + hasTicketRequest = TRUE; + + OPEN vCursor; + + WHILE NOT vDone + DO + FETCH vCursor INTO vWarehouse, vDate; + + CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouse, vDate); + + INSERT INTO tmp.sale_problems(ticketFk, isAvailable, saleFk) + SELECT tl.ticketFk, FALSE, s.id + FROM tmp.ticket_list tl + JOIN vn.ticket t ON t.id = tl.ticketFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it on it.id = i.typeFk + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + WHERE date(t.shipped) = vDate + AND it.categoryFk != 6 + AND IFNULL(av.available, 0) < 0 + AND s.isPicked = FALSE + AND NOT i.generic + AND vWarehouse = t.warehouseFk + GROUP BY tl.ticketFk + ON DUPLICATE KEY UPDATE + isAvailable = FALSE, saleFk = VALUE(saleFk); + + INSERT INTO tmp.sale_problems(ticketFk, itemShortage, saleFk) + SELECT ticketFk, problem, saleFk + FROM ( + SELECT tl.ticketFk, CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')) problem, s.id AS saleFk + FROM tmp.ticket_list tl + JOIN vn.ticket t ON t.id = tl.ticketFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it on it.id = i.typeFk + LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache + WHERE IFNULL(av.available, 0) < 0 + AND s.quantity > IFNULL(issw.visible, 0) + AND s.quantity > 0 + AND s.isPicked = FALSE + AND s.reserved = FALSE + AND it.categoryFk != 6 + AND IF(vIsTodayRelative, TRUE, date(t.shipped) = vDate) + AND NOT i.generic + AND CURDATE() = vDate + AND t.warehouseFk = vWarehouse + GROUP BY tl.ticketFk LIMIT 1) sub + ON DUPLICATE KEY UPDATE + itemShortage = sub.problem, saleFk = sub.saleFk; + + INSERT INTO tmp.sale_problems(ticketFk, itemDelay, saleFk) + SELECT ticketFk, problem, saleFk + FROM ( + SELECT tl.ticketFk, GROUP_CONCAT('I: ',i.id, ' ', i.longName, ' ') problem, s.id AS saleFk + FROM tmp.ticket_list tl + JOIN vn.ticket t ON t.id = tl.ticketFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it on it.id = i.typeFk + LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + WHERE s.quantity > IFNULL(issw.visible, 0) + AND s.quantity > 0 + AND s.isPicked = FALSE + AND s.reserved = FALSE + AND it.categoryFk != 6 + AND IF(vIsTodayRelative, TRUE, date(t.shipped) = vDate) + AND NOT i.generic + AND CURDATE() = vDate + AND t.warehouseFk = vWarehouse + GROUP BY tl.ticketFk LIMIT 1) sub + ON DUPLICATE KEY UPDATE + itemDelay = sub.problem, saleFk = sub.saleFk; + END WHILE; + + CLOSE vCursor; + + INSERT INTO tmp.sale_problems(ticketFk, isTaxDataChecked) + SELECT DISTINCT tl.ticketFk, FALSE + FROM tmp.ticket_list tl + JOIN vn.client c ON c.id = tl.clientFk + WHERE c.isTaxDataChecked = FALSE + ON DUPLICATE KEY UPDATE + isTaxDataChecked = FALSE; + + DROP TEMPORARY TABLE + tmp.clientGetDebt, + tmp.ticket_list; +END;;$$ +DELIMITER ;