From 1bff4e3c4e2254a239d480d86cf18d39afac00d3 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Wed, 30 Sep 2020 12:24:33 +0200 Subject: [PATCH 1/7] fix test and refactor transferlines --- e2e/helpers/selectors.js | 3 +- e2e/paths/04-item/09_regularize.spec.js | 1 - e2e/paths/05-ticket/18_index_payout.spec.js | 2 +- e2e/paths/12-entry/03_latestBuys.spec.js | 2 +- .../back/methods/client/lastActiveTickets.js | 9 ++-- .../client/specs/threeLastActive.spec.js | 6 +-- modules/ticket/front/sale/index.html | 45 +++++++++---------- modules/ticket/front/sale/style.scss | 4 +- 8 files changed, 37 insertions(+), 35 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 91961c5e3..64fef6690 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -20,7 +20,8 @@ export default { userConfigFirstAutocomplete: '#localWarehouse', userConfigSecondAutocomplete: '#localBank', userConfigThirdAutocomplete: '#localCompany', - acceptButton: '.vn-confirm.shown button[response=accept]' + acceptButton: '.vn-confirm.shown button[response=accept]', + searchButton: 'vn-searchbar vn-icon[icon="search"]', }, clientsIndex: { topbarSearch: 'vn-topbar', diff --git a/e2e/paths/04-item/09_regularize.spec.js b/e2e/paths/04-item/09_regularize.spec.js index 6de995515..fdb1e0184 100644 --- a/e2e/paths/04-item/09_regularize.spec.js +++ b/e2e/paths/04-item/09_regularize.spec.js @@ -124,7 +124,6 @@ describe('Item regularize path', () => { page.waitForNavigation({waitUntil: ['load', 'networkidle0', 'domcontentloaded']}), page.waitToClick(selectors.globalItems.ticketsButton) ]); - await page.waitForTransitionEnd('vn-searchbar'); await page.waitForState('ticket.index'); }); diff --git a/e2e/paths/05-ticket/18_index_payout.spec.js b/e2e/paths/05-ticket/18_index_payout.spec.js index 37e5261dc..24214228b 100644 --- a/e2e/paths/05-ticket/18_index_payout.spec.js +++ b/e2e/paths/05-ticket/18_index_payout.spec.js @@ -20,7 +20,7 @@ describe('Ticket index payout path', () => { }); it('should check the second ticket from a client and 1 of another', async() => { - await page.keyboard.press('Enter'); + await page.waitToClick(selectors.globalItems.searchButton); await page.waitToClick(selectors.ticketsIndex.secondTicketCheckbox); await page.waitToClick(selectors.ticketsIndex.sixthTicketCheckbox); await page.waitToClick(selectors.ticketsIndex.payoutButton); diff --git a/e2e/paths/12-entry/03_latestBuys.spec.js b/e2e/paths/12-entry/03_latestBuys.spec.js index e3cfadbcc..33acdb318 100644 --- a/e2e/paths/12-entry/03_latestBuys.spec.js +++ b/e2e/paths/12-entry/03_latestBuys.spec.js @@ -18,7 +18,7 @@ describe('Entry lastest buys path', () => { it('should access the latest buys seccion and search not seeing the edit buys button yet', async() => { await page.waitToClick(selectors.entryLatestBuys.latestBuysSectionButton); await page.waitFor(250); - await page.keyboard.press('Enter'); + await page.waitToClick(selectors.globalItems.searchButton); await page.waitForSelector(selectors.entryLatestBuys.editBuysButton, {visible: false}); }); diff --git a/modules/client/back/methods/client/lastActiveTickets.js b/modules/client/back/methods/client/lastActiveTickets.js index 5f8ef1393..be790eb03 100644 --- a/modules/client/back/methods/client/lastActiveTickets.js +++ b/modules/client/back/methods/client/lastActiveTickets.js @@ -25,6 +25,9 @@ module.exports = Self => { Self.lastActiveTickets = async(id, ticketId) => { const ticket = await Self.app.models.Ticket.findById(ticketId); + let shipped = ticket.shipped; + shipped.setDate(shipped.getDate() + 15); + const query = ` SELECT t.id, t.shipped, a.name AS agencyName, w.name AS warehouseName, ad.city AS address FROM vn.ticket t @@ -32,11 +35,11 @@ module.exports = Self => { JOIN vn.agencyMode a ON t.agencyModeFk = a.id JOIN vn.warehouse w ON t.warehouseFk = w.id JOIN vn.address ad ON t.addressFk = ad.id - WHERE t.shipped >= CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0 + WHERE t.shipped BETWEEN CURDATE() AND ? AND t.clientFk = ? AND ts.alertLevel = 0 AND t.id <> ? AND t.warehouseFk = ? ORDER BY t.shipped - LIMIT 3`; + LIMIT 10`; - return Self.rawSql(query, [id, ticketId, ticket.warehouseFk]); + return Self.rawSql(query, [shipped, id, ticketId, ticket.warehouseFk]); }; }; diff --git a/modules/client/back/methods/client/specs/threeLastActive.spec.js b/modules/client/back/methods/client/specs/threeLastActive.spec.js index cd76a0b5b..8a30d0f13 100644 --- a/modules/client/back/methods/client/specs/threeLastActive.spec.js +++ b/modules/client/back/methods/client/specs/threeLastActive.spec.js @@ -2,11 +2,11 @@ const app = require('vn-loopback/server/server'); describe('client lastActiveTickets()', () => { it('should return the last three active tickets', async() => { - const clientId = 109; - const ticketId = 19; + const clientId = 104; + const ticketId = 9; let result = await app.models.Client.lastActiveTickets(clientId, ticketId); - expect(result.length).toEqual(3); + expect(result.length).toEqual(1); }); }); diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index ab3277e31..90cfa39d1 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -323,32 +323,31 @@ icon="info"> - - - - - - - - - - - - - - - + + + Id + Shipped + Agency + Warehouse + Address + + + + + + - - - - - - - -
IdShippedAgencyWarehouseAddress
No results
{{::ticket.id}}{{::ticket.shipped | date: 'dd/MM/yyyy'}}{{::ticket.agencyName}}{{::ticket.warehouseName}}{{::ticket.address}}
+ {{::ticket.id}} + {{::ticket.shipped | date: 'dd/MM/yyyy'}} + {{::ticket.agencyName}} + {{::ticket.warehouseName}} + {{::ticket.address}} + + +
Date: Wed, 30 Sep 2020 13:35:37 +0200 Subject: [PATCH 2/7] fix lastActiveTickets --- modules/client/back/methods/client/lastActiveTickets.js | 8 +++----- .../back/methods/client/specs/threeLastActive.spec.js | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/client/back/methods/client/lastActiveTickets.js b/modules/client/back/methods/client/lastActiveTickets.js index be790eb03..c69c860c9 100644 --- a/modules/client/back/methods/client/lastActiveTickets.js +++ b/modules/client/back/methods/client/lastActiveTickets.js @@ -25,9 +25,6 @@ module.exports = Self => { Self.lastActiveTickets = async(id, ticketId) => { const ticket = await Self.app.models.Ticket.findById(ticketId); - let shipped = ticket.shipped; - shipped.setDate(shipped.getDate() + 15); - const query = ` SELECT t.id, t.shipped, a.name AS agencyName, w.name AS warehouseName, ad.city AS address FROM vn.ticket t @@ -35,11 +32,12 @@ module.exports = Self => { JOIN vn.agencyMode a ON t.agencyModeFk = a.id JOIN vn.warehouse w ON t.warehouseFk = w.id JOIN vn.address ad ON t.addressFk = ad.id - WHERE t.shipped BETWEEN CURDATE() AND ? AND t.clientFk = ? AND ts.alertLevel = 0 + WHERE t.shipped >= CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0 AND t.id <> ? AND t.warehouseFk = ? ORDER BY t.shipped LIMIT 10`; - return Self.rawSql(query, [shipped, id, ticketId, ticket.warehouseFk]); + return Self.rawSql(query, [id, ticketId, ticket.warehouseFk]); }; }; + diff --git a/modules/client/back/methods/client/specs/threeLastActive.spec.js b/modules/client/back/methods/client/specs/threeLastActive.spec.js index 8a30d0f13..cd76a0b5b 100644 --- a/modules/client/back/methods/client/specs/threeLastActive.spec.js +++ b/modules/client/back/methods/client/specs/threeLastActive.spec.js @@ -2,11 +2,11 @@ const app = require('vn-loopback/server/server'); describe('client lastActiveTickets()', () => { it('should return the last three active tickets', async() => { - const clientId = 104; - const ticketId = 9; + const clientId = 109; + const ticketId = 19; let result = await app.models.Client.lastActiveTickets(clientId, ticketId); - expect(result.length).toEqual(1); + expect(result.length).toEqual(3); }); }); From 998bfcd4dfe9b8e263b4a22130c10bb924cd8eb0 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 1 Oct 2020 08:53:31 +0200 Subject: [PATCH 3/7] refactor selectors --- e2e/helpers/selectors.js | 25 +++---------------- e2e/paths/02-client/01_create_client.spec.js | 2 +- .../02-client/03_edit_fiscal_data.spec.js | 8 +++--- .../12_lock_of_verified_data.spec.js | 2 +- e2e/paths/04-item/10_index.spec.js | 6 ++--- .../05-ticket/01-sale/01_list_sales.spec.js | 2 +- .../05-ticket/01-sale/02_edit_sale.spec.js | 2 +- .../05-ticket/02_expeditions_and_log.spec.js | 2 +- e2e/paths/05-ticket/12_descriptor.spec.js | 2 +- e2e/paths/07-order/02_basic_data.spec.js | 2 +- e2e/paths/07-order/05_index.spec.js | 2 +- 11 files changed, 19 insertions(+), 36 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 64fef6690..a729c613f 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -22,13 +22,10 @@ export default { userConfigThirdAutocomplete: '#localCompany', acceptButton: '.vn-confirm.shown button[response=accept]', searchButton: 'vn-searchbar vn-icon[icon="search"]', + globalItems: `button[type=submit]` }, clientsIndex: { - topbarSearch: 'vn-topbar', - searchButton: 'vn-searchbar vn-icon[icon="search"]', - searchResult: 'vn-client-index .vn-item', - createClientButton: `vn-float-button`, - othersButton: 'vn-left-menu li[name="Others"] > a' + createClientButton: `vn-float-button` }, clientSummary: { header: 'vn-client-summary > vn-card > h5', @@ -76,7 +73,6 @@ export default { socialName: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.socialName"]', fiscalId: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.fi"]', equalizationTaxCheckbox: 'vn-client-fiscal-data vn-check[ng-model="$ctrl.client.isEqualizated"]', - acceptPropagationButton: '.vn-confirm.shown button[response=accept]', address: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.street"]', postcode: 'vn-client-fiscal-data vn-datalist[ng-model="$ctrl.client.postcode"]', city: 'vn-client-fiscal-data vn-datalist[ng-model="$ctrl.client.city"]', @@ -90,7 +86,6 @@ export default { notifyByMailCheckbox: 'vn-client-fiscal-data vn-check[label="Notify by email"]', viesCheckbox: 'vn-client-fiscal-data vn-check[label="Vies"]', saveButton: 'button[type=submit]', - acceptDuplicationButton: '.vn-confirm.shown button[response=accept]', watcher: 'vn-client-fiscal-data vn-watcher' }, clientBillingData: { @@ -211,15 +206,12 @@ export default { saveButton: 'button[type=submit]' }, itemsIndex: { - searchIcon: 'vn-searchbar vn-icon[icon="search"]', createItemButton: `vn-float-button`, firstSearchResult: 'vn-item-index a:nth-child(1)', searchResult: 'vn-item-index a.vn-tr', firstResultPreviewButton: 'vn-item-index vn-tbody > :nth-child(1) .buttons > [icon="desktop_windows"]', searchResultCloneButton: 'vn-item-index .buttons > [icon="icon-clone"]', acceptClonationAlertButton: '.vn-confirm.shown [response="accept"]', - topbarSearch: 'vn-topbar', - searchButton: 'vn-searchbar vn-icon[icon="search"]', closeItemSummaryPreview: '.vn-popup.shown', fieldsToShowButton: 'vn-item-index vn-table > div > div > vn-icon-button[icon="more_vert"]', fieldsToShowForm: '.vn-popover.shown .content', @@ -388,7 +380,6 @@ export default { searchWeeklyResult: 'vn-ticket-weekly-index vn-table vn-tbody > vn-tr', searchResultDate: 'vn-ticket-summary [label=Landed] span', topbarSearch: 'vn-searchbar', - searchButton: 'vn-searchbar vn-icon[icon="search"]', moreMenu: 'vn-ticket-index vn-icon-button[icon=more_vert]', sixthWeeklyTicket: 'vn-ticket-weekly-index vn-table vn-tr:nth-child(6)', weeklyTicket: 'vn-ticket-weekly-index vn-table > div > vn-tbody > vn-tr', @@ -438,7 +429,6 @@ export default { ticketExpedition: { expeditionButton: 'vn-left-menu a[ui-sref="ticket.card.expedition"]', secondExpeditionRemoveButton: 'vn-ticket-expedition vn-table div > vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(1) > vn-icon-button[icon="delete"]', - acceptDeleteRowButton: '.vn-confirm.shown button[response=accept]', expeditionRow: 'vn-ticket-expedition vn-table vn-tbody > vn-tr' }, ticketPackages: { @@ -506,8 +496,6 @@ export default { moveToTicketInput: 'form vn-input-number[ng-model="$ctrl.transfer.ticketId"] input', moveToTicketButton: '.vn-popover.shown vn-icon[icon="arrow_forward_ios"]', moveToNewTicketButton: '.vn-popover.shown vn-button[label="New ticket"]', - acceptDeleteLineButton: '.vn-confirm.shown button[response=accept]', - acceptDeleteTicketButton: '.vn-confirm.shown button[response=accept]', stateMenuButton: 'vn-ticket-sale vn-tool-bar > vn-button-menu[label="State"]', stateMenuFixOption: '' }, @@ -571,9 +559,7 @@ export default { saveStateButton: `button[type=submit]` }, claimsIndex: { - searchClaimInput: 'vn-searchbar', - searchResult: 'vn-claim-index vn-card > vn-table > div > vn-tbody > a', - searchButton: 'vn-searchbar vn-icon[icon="search"]' + searchResult: 'vn-claim-index vn-card > vn-table > div > vn-tbody > a' }, claimDescriptor: { moreMenu: 'vn-claim-descriptor vn-icon-button[icon=more_vert]', @@ -639,15 +625,13 @@ export default { secondSearchResultTotal: 'vn-order-index vn-card > vn-table > div > vn-tbody vn-tr:nth-child(2) vn-td:nth-child(9)', searchResultDate: 'vn-order-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(4)', searchResultAddress: 'vn-order-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(6)', - searchButton: 'vn-searchbar vn-icon[icon="search"]', advancedSearchButton: 'vn-order-search-panel vn-submit[label="Search"]', openAdvancedSearch: 'vn-searchbar vn-icon[icon="arrow_drop_down"]', advancedSearchShowEmptyCheckbox: 'vn-order-search-panel vn-check[label="Show empty"]', createOrderButton: 'vn-float-button', }, orderDescriptor: { - returnToModuleIndexButton: 'vn-order-descriptor a[ui-sref="order.index"]', - acceptNavigationButton: '.vn-confirm.shown button[response=accept]' + returnToModuleIndexButton: 'vn-order-descriptor a[ui-sref="order.index"]' }, createOrderView: { client: 'vn-autocomplete[label="Client"]', @@ -832,7 +816,6 @@ export default { }, invoiceOutIndex: { topbarSearch: 'vn-searchbar', - searchButton: 'vn-searchbar vn-icon[icon="search"]', searchResult: 'vn-invoice-out-index vn-card > vn-table > div > vn-tbody > a.vn-tr', }, invoiceOutDescriptor: { diff --git a/e2e/paths/02-client/01_create_client.spec.js b/e2e/paths/02-client/01_create_client.spec.js index 2fdc4b091..f7a996f48 100644 --- a/e2e/paths/02-client/01_create_client.spec.js +++ b/e2e/paths/02-client/01_create_client.spec.js @@ -17,7 +17,7 @@ describe('Client create path', () => { it(`should search for the user Carol Danvers to confirm it isn't created yet`, async() => { await page.doSearch('Carol Danvers'); - const result = await page.countElement(selectors.clientsIndex.searchResult); + const result = await page.countElement(selectors.globalItems.searchResult); expect(result).toEqual(0); }); diff --git a/e2e/paths/02-client/03_edit_fiscal_data.spec.js b/e2e/paths/02-client/03_edit_fiscal_data.spec.js index 66eeb8b56..b2279062a 100644 --- a/e2e/paths/02-client/03_edit_fiscal_data.spec.js +++ b/e2e/paths/02-client/03_edit_fiscal_data.spec.js @@ -77,7 +77,7 @@ describe('Client Edit fiscalData path', () => { await page.waitToClick(selectors.clientFiscalData.equalizationTaxCheckbox); await page.waitToClick(selectors.clientFiscalData.verifiedDataCheckbox); await page.waitToClick(selectors.clientFiscalData.saveButton); - await page.waitToClick(selectors.clientFiscalData.acceptDuplicationButton); + await page.waitToClick(selectors.globalItems.acceptButton); const message = await page.waitForSnackbar(); expect(message.text).toBe('Invalid Tax number'); @@ -87,14 +87,14 @@ describe('Client Edit fiscalData path', () => { await page.clearInput(selectors.clientFiscalData.fiscalId); await page.write(selectors.clientFiscalData.fiscalId, '94980061C'); await page.waitToClick(selectors.clientFiscalData.saveButton); - await page.waitToClick(selectors.clientFiscalData.acceptDuplicationButton); + await page.waitToClick(selectors.globalItems.acceptButton); const message = await page.waitForSnackbar(); expect(message.type).toBe('success'); }); it('should propagate the Equalization tax', async() => { - await page.waitToClick(selectors.clientFiscalData.acceptPropagationButton); + await page.waitToClick(selectors.globalItems.acceptButton); const message = await page.waitForSnackbar(); expect(message.text).toBe('Equivalent tax spreaded'); @@ -157,7 +157,7 @@ describe('Client Edit fiscalData path', () => { it('should propagate the Equalization tax changes', async() => { await page.waitFor(1000); - await page.waitToClick(selectors.clientFiscalData.acceptPropagationButton); + await page.waitToClick(selectors.globalItems.acceptButton); const message = await page.waitForSnackbar(); expect(message.text).toBe('Equivalent tax spreaded'); diff --git a/e2e/paths/02-client/12_lock_of_verified_data.spec.js b/e2e/paths/02-client/12_lock_of_verified_data.spec.js index 79a9e17ac..b90ab7dfc 100644 --- a/e2e/paths/02-client/12_lock_of_verified_data.spec.js +++ b/e2e/paths/02-client/12_lock_of_verified_data.spec.js @@ -59,7 +59,7 @@ describe('Client lock verified data path', () => { it('should check the Verified data checkbox', async() => { await page.waitToClick(selectors.clientFiscalData.verifiedDataCheckbox); await page.waitToClick(selectors.clientFiscalData.saveButton); - await page.waitToClick(selectors.clientFiscalData.acceptDuplicationButton); + await page.waitToClick(selectors.globalItems.acceptButton); const message = await page.waitForSnackbar(); expect(message.type).toBe('success'); diff --git a/e2e/paths/04-item/10_index.spec.js b/e2e/paths/04-item/10_index.spec.js index a6c0d4919..655b72b2a 100644 --- a/e2e/paths/04-item/10_index.spec.js +++ b/e2e/paths/04-item/10_index.spec.js @@ -8,7 +8,7 @@ describe('Item index path', () => { browser = await getBrowser(); page = browser.page; await page.loginAndModule('salesPerson', 'item'); - await page.waitToClick(selectors.itemsIndex.searchIcon); + await page.waitToClick(selectors.globalItems.searchButton); }); afterAll(async() => { @@ -42,7 +42,7 @@ describe('Item index path', () => { it('should navigate forth and back to see the images column is still visible', async() => { await page.waitToClick(selectors.itemsIndex.firstSearchResult); await page.waitToClick(selectors.itemDescriptor.goBackToModuleIndexButton); - await page.waitToClick(selectors.itemsIndex.searchIcon); + await page.waitToClick(selectors.globalItems.searchButton); await page.wait(selectors.itemsIndex.searchResult); await page.waitImgLoad(selectors.itemsIndex.firstItemImage); const imageVisible = await page.isVisible(selectors.itemsIndex.firstItemImageTd); @@ -76,7 +76,7 @@ describe('Item index path', () => { it('should now navigate forth and back to see the ids column is now visible', async() => { await page.waitToClick(selectors.itemsIndex.firstSearchResult); await page.waitToClick(selectors.itemDescriptor.goBackToModuleIndexButton); - await page.waitToClick(selectors.itemsIndex.searchIcon); + await page.waitToClick(selectors.globalItems.searchButton); await page.wait(selectors.itemsIndex.searchResult); const idVisible = await page.isVisible(selectors.itemsIndex.firstItemId); diff --git a/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js b/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js index f883d08dc..4f5f9b76c 100644 --- a/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js +++ b/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js @@ -101,7 +101,7 @@ describe('Ticket List sale path', () => { await page.waitToClick(selectors.ticketSales.secondSaleCheckbox); await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox); await page.waitToClick(selectors.ticketSales.deleteSaleButton); - await page.waitToClick(selectors.ticketSales.acceptDeleteLineButton); + await page.waitToClick(selectors.globalItems.acceptButton); const message = await page.waitForSnackbar(); expect(message.type).toBe('success'); diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index 08ff97b96..e530f1cb5 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -219,7 +219,7 @@ describe('Ticket Edit sale path', () => { await page.wait(2000); await page.waitToClick(selectors.ticketSales.deleteSaleButton); await page.wait(2000); - await page.waitToClick(selectors.ticketSales.acceptDeleteLineButton); + await page.waitToClick(selectors.globalItems.acceptButton); await page.wait(2000); await page.waitForSpinnerLoad(); const message = await page.waitForSnackbar(); diff --git a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js index 2d046e3a9..e4f8a7754 100644 --- a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js +++ b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js @@ -19,7 +19,7 @@ describe('Ticket expeditions and log path', () => { it(`should delete a former expedition and confirm the remaining expedition are the expected ones`, async() => { await page.waitToClick(selectors.ticketExpedition.secondExpeditionRemoveButton); - await page.waitToClick(selectors.ticketExpedition.acceptDeleteRowButton); + await page.waitToClick(selectors.globalItems.acceptButton); await page.reloadSection('ticket.card.expedition'); await page.waitForSelector(selectors.ticketExpedition.expeditionRow, {}); diff --git a/e2e/paths/05-ticket/12_descriptor.spec.js b/e2e/paths/05-ticket/12_descriptor.spec.js index faeae0c3f..9d67365a8 100644 --- a/e2e/paths/05-ticket/12_descriptor.spec.js +++ b/e2e/paths/05-ticket/12_descriptor.spec.js @@ -53,7 +53,7 @@ describe('Ticket descriptor path', () => { it(`should search for the deleted ticket and check it's date`, async() => { await page.write(selectors.ticketsIndex.topbarSearch, '18'); - await page.waitToClick(selectors.ticketsIndex.searchButton); + await page.waitToClick(selectors.globalItems.searchButton); await page.waitForState('ticket.card.summary'); const result = await page.waitToGetProperty(selectors.ticketsIndex.searchResultDate, 'innerText'); diff --git a/e2e/paths/07-order/02_basic_data.spec.js b/e2e/paths/07-order/02_basic_data.spec.js index 38d6619e0..a76f7dbcc 100644 --- a/e2e/paths/07-order/02_basic_data.spec.js +++ b/e2e/paths/07-order/02_basic_data.spec.js @@ -34,7 +34,7 @@ describe('Order edit basic data path', () => { const orderId = '16'; await page.waitToClick(selectors.orderDescriptor.returnToModuleIndexButton); - await page.waitToClick(selectors.orderDescriptor.acceptNavigationButton); + await page.waitToClick(selectors.globalItems.acceptButton); await page.waitForContentLoaded(); await page.accessToSearchResult(orderId); await page.accessToSection('order.card.basicData'); diff --git a/e2e/paths/07-order/05_index.spec.js b/e2e/paths/07-order/05_index.spec.js index c07a9c6f7..23769766c 100644 --- a/e2e/paths/07-order/05_index.spec.js +++ b/e2e/paths/07-order/05_index.spec.js @@ -16,7 +16,7 @@ describe('Order Index', () => { }); it(`should check the second search result doesn't contain a total of 0€`, async() => { - await page.waitToClick(selectors.ordersIndex.searchButton); + await page.waitToClick(selectors.globalItems.searchButton); const result = await page.waitToGetProperty(selectors.ordersIndex.secondSearchResultTotal, 'innerText'); expect(result).not.toContain('0.00'); From 6d8b13423f7fd686edbda59c1ced53aa0fe4d241 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 1 Oct 2020 10:02:19 +0200 Subject: [PATCH 4/7] SQL hotfix --- db/changes/10221-accountModule/00-role_syncPrivileges.sql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/db/changes/10221-accountModule/00-role_syncPrivileges.sql b/db/changes/10221-accountModule/00-role_syncPrivileges.sql index 0d6d8975b..e5e62abf2 100644 --- a/db/changes/10221-accountModule/00-role_syncPrivileges.sql +++ b/db/changes/10221-accountModule/00-role_syncPrivileges.sql @@ -194,7 +194,12 @@ BEGIN vTplHost, JSON_MERGE_PATCH( IFNULL(t.`Priv`, '{}'), - IFNULL(u.`Priv`, '{}') + IFNULL(u.`Priv`, '{}'), + JSON_OBJECT( + 'mysql_old_password', JSON_VALUE(t.`Priv`, '$.mysql_old_password'), + 'mysql_native_password', JSON_VALUE(t.`Priv`, '$.mysql_native_password'), + 'authentication_string', JSON_VALUE(t.`Priv`, '$.authentication_string') + ) ) FROM tRole r LEFT JOIN mysql.global_priv t From a7bee03b3d4932b923cc0ba876938a1845d21dc1 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 1 Oct 2020 10:38:02 +0200 Subject: [PATCH 5/7] refactor selectors --- e2e/helpers/selectors.js | 65 +++++----------------------------------- 1 file changed, 8 insertions(+), 57 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index a729c613f..6f3c9f3f8 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -50,15 +50,13 @@ export default { userName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.userName"]', email: 'vn-client-create vn-textfield[ng-model="$ctrl.client.email"]', salesPerson: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.salesPersonFk"]', - createButton: 'vn-client-create button[type=submit]', - cancelButton: 'vn-button[href="#!/client/index"]' + createButton: 'vn-client-create button[type=submit]' }, clientDescriptor: { moreMenu: 'vn-client-descriptor vn-icon-button[icon=more_vert]', simpleTicketButton: '.vn-menu [name="simpleTicket"]' }, clientBasicData: { - basicDataButton: 'vn-left-menu a[ui-sref="client.card.basicData"]', name: 'vn-client-basic-data vn-textfield[ng-model="$ctrl.client.name"]', contact: 'vn-client-basic-data vn-textfield[ng-model="$ctrl.client.contact"]', email: 'vn-client-basic-data vn-textfield[ng-model="$ctrl.client.email"]', @@ -136,12 +134,10 @@ export default { secondObservationDescription: 'vn-client-address-edit [name=observations] vn-horizontal:nth-child(2) vn-textfield[ng-model="observation.description"]', addObservationButton: 'vn-client-address-edit div[name="observations"] vn-icon-button[icon="add_circle"]', saveButton: 'button[type=submit]', - cancelCreateAddressButton: 'button[ui-sref="client.card.address.index"]', cancelEditAddressButton: 'vn-client-address-edit > form > vn-button-bar > vn-button > button', watcher: 'vn-client-address-edit vn-watcher' }, clientWebAccess: { - webAccessButton: 'vn-left-menu a[ui-sref="client.card.webAccess"]', enableWebAccessCheckbox: 'vn-check[label="Enable web access"]', userName: 'vn-client-web-access vn-textfield[ng-model="$ctrl.account.name"]', saveButton: 'button[type=submit]' @@ -169,12 +165,7 @@ export default { clientMandate: { firstMandateText: 'vn-client-mandate vn-card vn-table vn-tbody > vn-tr' }, - clientInvoices: { - firstInvoiceText: 'vn-client-invoice vn-card vn-table vn-tbody > vn-tr' - }, clientLog: { - logButton: 'vn-left-menu a[ui-sref="client.card.log"]', - lastModificationDate: 'vn-client-log > vn-log vn-table vn-tbody > vn-tr > vn-td:nth-child(1)', lastModificationPreviousValue: 'vn-client-log vn-table vn-td.before', lastModificationCurrentValue: 'vn-client-log vn-table vn-td.after' @@ -247,8 +238,7 @@ export default { regularizeWarehouse: '.vn-dialog.shown vn-autocomplete[ng-model="$ctrl.warehouseFk"]', editButton: 'vn-item-descriptor vn-float-button[icon="edit"]', regularizeSaveButton: '.vn-dialog.shown tpl-buttons > button', - inactiveIcon: 'vn-item-descriptor vn-icon[icon="icon-unavailable"]', - navigateBackToIndex: 'vn-item-descriptor [name="goToModuleIndex"]' + inactiveIcon: 'vn-item-descriptor vn-icon[icon="icon-unavailable"]' }, itemRequest: { firstRequestItemID: 'vn-item-request vn-tbody > vn-tr:nth-child(1) > vn-td-editable:nth-child(7)', @@ -257,11 +247,9 @@ export default { secondRequestStatus: 'vn-item-request vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(10)', firstRequestStatus: 'vn-item-request vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(10)', secondRequestDecline: 'vn-item-request vn-tbody > vn-tr:nth-child(1) vn-icon-button[icon="thumb_down"]', - declineReason: 'vn-textarea[ng-model="$ctrl.denyObservation"]', - acceptDeclineReason: 'button[response="accept"]', + declineReason: 'vn-textarea[ng-model="$ctrl.denyObservation"]' }, itemBasicData: { - basicDataButton: 'vn-left-menu a[ui-sref="item.card.basicData"]', goToItemIndexButton: 'vn-item-descriptor [ui-sref="item.index"]', type: 'vn-autocomplete[ng-model="$ctrl.item.typeFk"]', intrastat: 'vn-autocomplete[ng-model="$ctrl.item.intrastatFk"]', @@ -280,8 +268,6 @@ export default { submitBasicDataButton: `button[type=submit]` }, itemTags: { - goToItemIndexButton: 'vn-item-descriptor [ui-sref="item.index"]', - tagsButton: 'vn-left-menu a[ui-sref="item.card.tags"]', fourthTag: 'vn-item-tags vn-horizontal:nth-child(4) > vn-autocomplete[ng-model="itemTag.tagFk"]', fourthValue: 'vn-item-tags vn-horizontal:nth-child(4) vn-textfield[ng-model="itemTag.value"]', fourthRelevancy: 'vn-item-tags vn-horizontal:nth-child(4) [ng-model="itemTag.priority"]', @@ -339,8 +325,7 @@ export default { itemDiary: { secondTicketId: 'vn-item-diary vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(2) > span', fourthBalance: 'vn-item-diary vn-tbody > vn-tr:nth-child(4) > vn-td.balance > span', - firstBalance: 'vn-item-diary vn-tbody > vn-tr:nth-child(1) > vn-td.balance', - warehouse: 'vn-item-diary vn-autocomplete[ng-model="$ctrl.warehouseFk"]', + firstBalance: 'vn-item-diary vn-tbody > vn-tr:nth-child(1) > vn-td.balance' }, itemLog: { anyLineCreated: 'vn-item-log > vn-log vn-tbody > vn-tr', @@ -427,12 +412,10 @@ export default { submitNotesButton: 'button[type=submit]' }, ticketExpedition: { - expeditionButton: 'vn-left-menu a[ui-sref="ticket.card.expedition"]', secondExpeditionRemoveButton: 'vn-ticket-expedition vn-table div > vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(1) > vn-icon-button[icon="delete"]', expeditionRow: 'vn-ticket-expedition vn-table vn-tbody > vn-tr' }, ticketPackages: { - packagesButton: 'vn-left-menu a[ui-sref="ticket.card.package"]', firstPackage: 'vn-autocomplete[label="Package"]', firstQuantity: 'vn-ticket-package vn-horizontal:nth-child(1) vn-input-number[ng-model="package.quantity"]', firstRemovePackageButton: 'vn-icon-button[vn-tooltip="Remove package"]', @@ -441,12 +424,9 @@ export default { }, ticketSales: { setOk: 'vn-ticket-sale vn-tool-bar > vn-button[label="Ok"] > button', - saleButton: 'vn-left-menu a[ui-sref="ticket.card.sale"]', saleLine: 'vn-table div > vn-tbody > vn-tr', saleDescriptorPopover: '.vn-popover.shown vn-item-descriptor', saleDescriptorPopoverSummaryButton: '.vn-popover.shown vn-item-descriptor a[ui-sref="item.card.summary({id: $ctrl.descriptor.id})"]', - descriptorItemDiaryButton: '.vn-popover vn-item-descriptor vn-quick-link[icon="icon-transaction"] > a', - newItemFromCatalogButton: 'vn-ticket-sale vn-float-button[icon="add"]', newItemButton: 'vn-ticket-sale vn-card vn-icon-button[icon="add_circle"]', moreMenu: 'vn-ticket-sale vn-button[label="More"]', moreMenuCreateClaim: 'vn-item[name="claim"]', @@ -459,12 +439,10 @@ export default { firstSaleId: 'vn-ticket-sale vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > span', firstSaleClaimIcon: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(1) vn-icon[icon="icon-claims"]', firstSaleDescriptorImage: '.vn-popover.shown vn-item-descriptor img', - firstSaleText: 'vn-table div > vn-tbody > vn-tr:nth-child(1)', firstSaleThumbnailImage: 'vn-ticket-sale:nth-child(1) vn-tr:nth-child(1) vn-td:nth-child(3) > img', firstSaleZoomedImage: 'body > div > div > img', firstSaleQuantity: 'vn-ticket-sale [ng-model="sale.quantity"]', firstSaleQuantityCell: 'vn-ticket-sale vn-tr:nth-child(1) > vn-td-editable:nth-child(5)', - firstSaleIdAutocomplete: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > vn-autocomplete', firstSalePrice: 'vn-ticket-sale vn-table vn-tr:nth-child(1) > vn-td:nth-child(7) > span', firstSalePriceInput: '.vn-popover.shown input[ng-model="$ctrl.field"]', firstSaleDiscount: 'vn-ticket-sale vn-table vn-tr:nth-child(1) > vn-td:nth-child(8) > span', @@ -472,16 +450,9 @@ export default { firstSaleImport: 'vn-ticket-sale:nth-child(1) vn-td:nth-child(9)', firstSaleReservedIcon: 'vn-ticket-sale vn-tr:nth-child(1) > vn-td:nth-child(2) > vn-icon:nth-child(3)', firstSaleColour: 'vn-ticket-sale vn-tr:nth-child(1) vn-fetched-tags section', - firstSaleLength: 'vn-ticket-sale vn-tr:nth-child(1) vn-td-editable:nth-child(6) section:nth-child(3)', firstSaleCheckbox: 'vn-ticket-sale vn-tr:nth-child(1) vn-check[ng-model="sale.checked"]', - secondSaleColour: 'vn-tr:nth-child(2) vn-fetched-tags section', - secondSalePrice: 'vn-ticket-sale vn-tr:nth-child(2) vn-td:nth-child(7) > span', - secondSaleDiscount: 'vn-ticket-sale vn-tr:nth-child(2) vn-td:nth-child(8)', - secondSaleImport: 'vn-ticket-sale vn-tr:nth-child(2) vn-td:nth-child(9)', secondSaleText: 'vn-table div > vn-tbody > vn-tr:nth-child(2)', secondSaleId: 'vn-ticket-sale:nth-child(2) vn-td-editable:nth-child(4) text > span', - secondSaleIdCell: 'vn-ticket-sale vn-tr:nth-child(2) > vn-td-editable:nth-child(4)', - secondSaleIdInput: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(4) > vn-autocomplete', secondSaleIdAutocomplete: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(4) > vn-autocomplete', secondSaleQuantity: 'vn-ticket-sale vn-table vn-tr:nth-child(2) vn-input-number', secondSaleQuantityCell: 'vn-ticket-sale > div > vn-card > vn-table > div > vn-tbody > vn-tr:nth-child(2) > vn-td-editable:nth-child(5)', @@ -496,17 +467,12 @@ export default { moveToTicketInput: 'form vn-input-number[ng-model="$ctrl.transfer.ticketId"] input', moveToTicketButton: '.vn-popover.shown vn-icon[icon="arrow_forward_ios"]', moveToNewTicketButton: '.vn-popover.shown vn-button[label="New ticket"]', - stateMenuButton: 'vn-ticket-sale vn-tool-bar > vn-button-menu[label="State"]', - stateMenuFixOption: '' + stateMenuButton: 'vn-ticket-sale vn-tool-bar > vn-button-menu[label="State"]' }, ticketTracking: { - trackingButton: 'vn-left-menu a[ui-sref="ticket.card.tracking.index"]', - createStateButton: 'vn-float-button', - saveButton: 'button[type=submit]', - cancelButton: 'vn-ticket-tracking-edit vn-button[ui-sref="ticket.card.tracking.index"]' + createStateButton: 'vn-float-button' }, ticketBasicData: { - basicDataButton: 'vn-left-menu a[ui-sref="ticket.card.basicData.stepOne"]', agency: 'vn-autocomplete[ng-model="$ctrl.agencyModeId"]', zone: 'vn-autocomplete[ng-model="$ctrl.zoneId"]', nextStepButton: 'vn-step-control .buttons > section:last-child vn-button', @@ -581,7 +547,6 @@ export default { }, claimBasicData: { claimState: 'vn-claim-basic-data vn-autocomplete[ng-model="$ctrl.claim.claimStateFk"]', - responsabilityInputRange: 'vn-range', observation: 'vn-textarea[ng-model="$ctrl.claim.observation"]', hasToPickUpCheckbox: 'vn-claim-basic-data vn-check[ng-model="$ctrl.claim.hasToPickUp"]', saveButton: `button[type=submit]` @@ -621,10 +586,7 @@ export default { isPaidWithManaCheckbox: 'vn-claim-action vn-check[ng-model="$ctrl.claim.isChargedToMana"]' }, ordersIndex: { - searchResult: 'vn-order-index vn-card > vn-table > div > vn-tbody > a.vn-tr', secondSearchResultTotal: 'vn-order-index vn-card > vn-table > div > vn-tbody vn-tr:nth-child(2) vn-td:nth-child(9)', - searchResultDate: 'vn-order-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(4)', - searchResultAddress: 'vn-order-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(6)', advancedSearchButton: 'vn-order-search-panel vn-submit[label="Search"]', openAdvancedSearch: 'vn-searchbar vn-icon[icon="arrow_drop_down"]', advancedSearchShowEmptyCheckbox: 'vn-order-search-panel vn-check[label="Show empty"]', @@ -637,11 +599,9 @@ export default { client: 'vn-autocomplete[label="Client"]', agency: 'vn-autocomplete[label="Agency"]', landedDatePicker: 'vn-date-picker[label="Landed"]', - createButton: 'button[type=submit]', - cancelButton: 'vn-button[href="#!/client/index"]' + createButton: 'button[type=submit]' }, orderSummary: { - header: 'vn-order-summary h5', id: 'vn-order-summary vn-one:nth-child(1) > vn-label-value:nth-child(1) span', alias: 'vn-order-summary vn-one:nth-child(1) > vn-label-value:nth-child(2) span', consignee: 'vn-order-summary vn-one:nth-child(2) > vn-label-value:nth-child(3) span', @@ -653,7 +613,6 @@ export default { orderCatalog: { plantRealmButton: 'vn-order-catalog > vn-side-menu vn-icon[icon="icon-plant"]', type: 'vn-order-catalog vn-autocomplete[data="$ctrl.itemTypes"]', - itemId: 'vn-order-catalog > vn-side-menu vn-textfield[vn-id="itemId"]', itemTagValue: 'vn-order-catalog vn-textfield[vn-id="search"]', openTagSearch: 'vn-order-catalog vn-vertical:nth-child(4) append > vn-icon > i', tag: 'vn-order-catalog-search-panel vn-autocomplete[ng-model="filter.tagFk"]', @@ -698,7 +657,6 @@ export default { }, routeSummary: { header: 'vn-route-summary > vn-card > h5', - routeId: 'vn-route-summary > vn-card > vn-horizontal > vn-one:nth-child(1) > vn-label-value:nth-child(1) > section > span', cost: 'vn-route-summary vn-label-value[label="Cost"]', firstTicketID: 'vn-route-summary vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(2) > span', firstTicketDescriptor: '.vn-popover.shown vn-ticket-descriptor', @@ -717,10 +675,6 @@ export default { }, routeTickets: { firstTicketPriority: 'vn-route-tickets vn-tr:nth-child(1) vn-textfield[ng-model="ticket.priority"]', - secondTicketPriority: 'vn-route-tickets vn-tr:nth-child(2) vn-textfield[ng-model="ticket.priority"]', - thirdTicketPriority: 'vn-route-tickets vn-tr:nth-child(3) vn-textfield[ng-model="ticket.priority"]', - fourthTicketPriority: 'vn-route-tickets vn-tr:nth-child(4) vn-textfield[ng-model="ticket.priority"]', - eleventhTicketPriority: 'vn-route-tickets vn-tr:nth-child(11) vn-textfield[ng-model="ticket.priority"]', firstTicketCheckbox: 'vn-route-tickets vn-tr:nth-child(1) vn-check', buscamanButton: 'vn-route-tickets vn-button[icon="icon-buscaman"]', firstTicketDeleteButton: 'vn-route-tickets vn-tr:nth-child(1) vn-icon[icon="delete"]', @@ -795,8 +749,7 @@ export default { weekWorkedHours: 'vn-worker-time-control vn-side-menu vn-label-value > section > span', nextMonthButton: 'vn-worker-time-control vn-side-menu vn-calendar vn-button[icon=keyboard_arrow_right]', secondWeekDay: 'vn-worker-time-control vn-side-menu vn-calendar .day:nth-child(8) > .day-number', - navigateBackToIndex: 'vn-worker-descriptor [name="goToModuleIndex"]', - acceptDeleteDialog: '.vn-confirm.shown button[response="accept"]' + navigateBackToIndex: 'vn-worker-descriptor [name="goToModuleIndex"]' }, workerCalendar: { year: 'vn-worker-calendar vn-autocomplete[ng-model="$ctrl.year"]', @@ -837,7 +790,6 @@ export default { travelBasicDada: { reference: 'vn-travel-basic-data vn-textfield[ng-model="$ctrl.travel.ref"]', agency: 'vn-travel-basic-data vn-autocomplete[ng-model="$ctrl.travel.agencyModeFk"]', - shippingDate: 'vn-travel-basic-data vn-date-picker[ng-model="$ctrl.travel.shipped"]', deliveryDate: 'vn-travel-basic-data vn-date-picker[ng-model="$ctrl.travel.landed"]', outputWarehouse: 'vn-travel-basic-data vn-autocomplete[ng-model="$ctrl.travel.warehouseOutFk"]', inputWarehouse: 'vn-travel-basic-data vn-autocomplete[ng-model="$ctrl.travel.warehouseInFk"]', @@ -857,7 +809,6 @@ export default { newThermographWarehouse: 'vn-autocomplete[ng-model="$ctrl.newThermograph.warehouseId"]', newThermographTemperature: 'vn-autocomplete[ng-model="$ctrl.newThermograph.temperature"]', createThermographButton: 'form button[response="accept"]', - thermographID: 'vn-travel-thermograph-create vn-autocomplete[ng-model="$ctrl.dms.thermographId"]', uploadIcon: 'vn-travel-thermograph-create vn-icon[icon="icon-attach"]', createdThermograph: 'vn-travel-thermograph-index vn-tbody > vn-tr', upload: 'vn-travel-thermograph-create button[type=submit]' From 5807f6ca38dd4d40c20bbf14f5ce2c4789a82e2e Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 1 Oct 2020 11:21:23 +0200 Subject: [PATCH 6/7] delete selector --- e2e/helpers/selectors.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 6f3c9f3f8..c04d8791c 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -21,8 +21,7 @@ export default { userConfigSecondAutocomplete: '#localBank', userConfigThirdAutocomplete: '#localCompany', acceptButton: '.vn-confirm.shown button[response=accept]', - searchButton: 'vn-searchbar vn-icon[icon="search"]', - globalItems: `button[type=submit]` + searchButton: 'vn-searchbar vn-icon[icon="search"]' }, clientsIndex: { createClientButton: `vn-float-button` From 161313ad15b69235d0f73d5cd16e7cf34d77b24f Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Fri, 2 Oct 2020 13:58:48 +0200 Subject: [PATCH 7/7] refactor getComponentSum --- .../back/methods/ticket/getComponentsSum.js | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/modules/ticket/back/methods/ticket/getComponentsSum.js b/modules/ticket/back/methods/ticket/getComponentsSum.js index c5333288e..c611913d8 100644 --- a/modules/ticket/back/methods/ticket/getComponentsSum.js +++ b/modules/ticket/back/methods/ticket/getComponentsSum.js @@ -20,34 +20,33 @@ module.exports = Self => { }); Self.getComponentsSum = async id => { const models = Self.app.models; - let salesComponents = []; let componentsSum = []; - let sales = await models.Sale.find({where: {ticketFk: id}}); - let components = await models.Component.find(); - if (sales.length > 0) { - for (let sale of sales) { - let myComponents = await models.SaleComponent.find({where: {saleFk: sale.id}}); - salesComponents = salesComponents.concat(myComponents); - } - - salesComponents.reduce((acumulator, currentValue) => { - if (!acumulator[currentValue.componentFk]) { - let defaultValue = 0; - let tarjetComponent = components.find(component => component.id === currentValue.componentFk); - - acumulator[currentValue.componentFk] = { - componentFk: currentValue.componentFk, - value: defaultValue, - name: tarjetComponent.name - }; - componentsSum.push(acumulator[currentValue.componentFk]); + let sales = await models.Sale.find({ + include: { + relation: 'components', + scope: {fields: ['value', 'componentFk'], + include: { + relation: 'component', + } } - - acumulator[currentValue.componentFk].value += currentValue.value; - - return acumulator; - }); + }, + where: {ticketFk: id} + }); + for (let sale of sales) { + for (let component of sale.components()) { + let componentId = componentsSum[component.componentFk]; + if (!componentId) { + componentsSum[component.componentFk] = { + componentFk: component.componentFk, + value: 0, + name: component.component().name + }; + } + componentsSum[component.componentFk].value += component.value * sale.quantity; + } } - return componentsSum; + return componentsSum.filter(component => { + return component != null; + }); }; };