From 8723cf29582e155caf80450d6a7923a8aed362f6 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 28 Jun 2023 14:10:21 +0200 Subject: [PATCH] refs #5753 fix legacy bugs --- db/changes/232801/00-fix_editCredit.sql | 7 ++++++ db/dump/fixtures.sql | 6 ++--- e2e/paths/04-item/03_tax.spec.js | 8 ------- .../03_role_create_and_basic_data.spec.js | 2 +- modules/client/back/models/client.js | 22 ++++++++++++++----- .../client/back/models/specs/client.spec.js | 16 +++++++------- .../methods/invoiceOut/specs/refund.spec.js | 1 + .../methods/item/specs/getBalance.spec.js | 2 +- modules/item/back/methods/item/updateTaxes.js | 5 +++-- 9 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 db/changes/232801/00-fix_editCredit.sql diff --git a/db/changes/232801/00-fix_editCredit.sql b/db/changes/232801/00-fix_editCredit.sql new file mode 100644 index 000000000..40571ddb5 --- /dev/null +++ b/db/changes/232801/00-fix_editCredit.sql @@ -0,0 +1,7 @@ +UPDATE `salix`.`ACL` + SET principalId='financialBoss' + WHERE + model = 'Client' + AND property = 'editCredit'; + + diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 87b678917..9e0ac210a 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -552,10 +552,10 @@ INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif` VALUES (1, 'Plants SL', 'Plants nick', 4100000001, 1, '06089160W', 0, util.VN_CURDATE(), 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1, '400664487V'), (2, 'Farmer King', 'The farmer', 4000020002, 1, '87945234L', 0, util.VN_CURDATE(), 1, 'supplier address 2', 'GOTHAM', 2, 43022, 1, 2, 10, 93, 2, 8, 18, 'animals', 1, '400664487V'), - (69, 'Packaging', 'Packaging nick', 4100000069, 1, '94935005K', 0, util.VN_CURDATE(), 1, 'supplier address 5', 'PONTEVEDRA', 1, 15214, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1, '400664487V'), + (69, 'Packaging', 'Packaging nick', 4100000069, 1, '94935005K', 0, util.VN_CURDATE(), 1, 'supplier address 5', 'ASGARD', 3, 46600, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1, '400664487V'), (442, 'Verdnatura Levante SL', 'Verdnatura', 5115000442, 1, '06815934E', 0, util.VN_CURDATE(), 1, 'supplier address 3', 'GOTHAM', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'), - (567, 'Holland', 'Holland nick', 4000020567, 1, '14364089Z', 0, util.VN_CURDATE(), 1, 'supplier address 6', 'GOTHAM', 2, 43022, 1, 2, 10, 93, 2, 8, 18, 'animals', 1, '400664487V'), - (791, 'Bros SL', 'Bros nick', 5115000791, 1, '37718083S', 0, util.VN_CURDATE(), 1, 'supplier address 7', 'GOTHAM', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'), + (567, 'Holland', 'Holland nick', 4000020567, 1, '14364089Z', 0, util.VN_CURDATE(), 1, 'supplier address 6', 'ASGARD', 3, 46600, 1, 2, 10, 93, 2, 8, 18, 'animals', 1, '400664487V'), + (791, 'Bros SL', 'Bros nick', 5115000791, 1, '37718083S', 0, util.VN_CURDATE(), 1, 'supplier address 7', 'ASGARD', 3, 46600, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'), (1381, 'Ornamentales', 'Ornamentales', 7185001381, 1, '07972486L', 0, util.VN_CURDATE(), 1, 'supplier address 4', 'GOTHAM', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'); INSERT INTO `vn`.`supplierContact`(`id`, `supplierFk`, `phone`, `mobile`, `email`, `observation`, `name`) diff --git a/e2e/paths/04-item/03_tax.spec.js b/e2e/paths/04-item/03_tax.spec.js index 83f4e6bee..16cc1667d 100644 --- a/e2e/paths/04-item/03_tax.spec.js +++ b/e2e/paths/04-item/03_tax.spec.js @@ -19,7 +19,6 @@ describe('Item edit tax path', () => { it(`should add the item tax to all countries`, async() => { await page.autocompleteSearch(selectors.itemTax.firstClass, 'General VAT'); await page.autocompleteSearch(selectors.itemTax.secondClass, 'General VAT'); - await page.autocompleteSearch(selectors.itemTax.thirdClass, 'General VAT'); await page.waitToClick(selectors.itemTax.submitTaxButton); const message = await page.waitForSnackbar(); @@ -40,13 +39,6 @@ describe('Item edit tax path', () => { expect(secondVatType).toEqual('General VAT'); }); - it(`should confirm the third item tax class was edited`, async() => { - const thirdVatType = await page - .waitToGetProperty(selectors.itemTax.thirdClass, 'value'); - - expect(thirdVatType).toEqual('General VAT'); - }); - it(`should edit the first class without saving the form`, async() => { await page.autocompleteSearch(selectors.itemTax.firstClass, 'Reduced VAT'); const firstVatType = await page.waitToGetProperty(selectors.itemTax.firstClass, 'value'); diff --git a/e2e/paths/14-account/03_role_create_and_basic_data.spec.js b/e2e/paths/14-account/03_role_create_and_basic_data.spec.js index 294a500ca..6acf82318 100644 --- a/e2e/paths/14-account/03_role_create_and_basic_data.spec.js +++ b/e2e/paths/14-account/03_role_create_and_basic_data.spec.js @@ -81,6 +81,6 @@ describe('Account Role create and basic data path', () => { await page.accessToSection('account.role.card.inherited'); const rolesCount = await page.countElement(selectors.accountRoleInheritance.anyResult); - expect(rolesCount).toEqual(6); + expect(rolesCount).toEqual(7); }); }); diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 7b577fa98..efd39a118 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -14,7 +14,7 @@ module.exports = Self => { Self.validatesPresenceOf('street', { message: 'Street cannot be empty' }); - + Self.validatesPresenceOf('city', { message: 'City cannot be empty' }); @@ -401,22 +401,32 @@ module.exports = Self => { Self.changeCredit = async function changeCredit(ctx, finalState, changes) { const models = Self.app.models; const userId = ctx.options.accessToken.userId; - const accessToken = {req: {accessToken: ctx.options.accessToken} }; + const accessToken = {req: {accessToken: ctx.options.accessToken}}; const canEditCredit = await models.ACL.checkAccessAcl(accessToken, 'Client', 'editCredit', 'WRITE'); if (!canEditCredit) { const lastCredit = await models.ClientCredit.findOne({ + field: ['workerFk', 'amount'], where: { clientFk: finalState.id }, order: 'id DESC' }, ctx.options); - const lastAmount = lastCredit && lastCredit.amount; - const lastCreditIsNotEditable = !await models.ACL.checkAccessAcl(accessToken, 'Client', 'isNotEditableCredit', 'WRITE'); + if (lastCredit) { + const canEdit = + await models.ACL.checkAccessAcl(accessToken, 'Client', 'isNotEditableCredit', 'WRITE'); + const lastCreditIsNotEditable = + await models.ACL.checkAccessAcl( + {req: {accessToken: {userId: lastCredit.workerFk}}}, + 'Client', + 'isNotEditableCredit', + 'WRITE' + ); - if (lastAmount == 0 && lastCreditIsNotEditable) - throw new UserError(`You can't change the credit set to zero from a financialBoss`); + if (lastCredit.amount == 0 && lastCreditIsNotEditable && !canEdit) + throw new UserError(`You can't change the credit set to zero from a financialBoss`); + } const creditLimits = await models.ClientCreditLimit.find({ fields: ['roleFk'], diff --git a/modules/client/back/models/specs/client.spec.js b/modules/client/back/models/specs/client.spec.js index 45debc08a..201d14bb4 100644 --- a/modules/client/back/models/specs/client.spec.js +++ b/modules/client/back/models/specs/client.spec.js @@ -60,22 +60,22 @@ describe('Client Model', () => { try { const options = {transaction: tx}; - const context = {options}; + const ctx = {options}; // Set credit to zero by a financialBoss const financialBoss = await models.VnUser.findOne({ where: {name: 'financialBoss'} }, options); - context.options.accessToken = {userId: financialBoss.id}; + ctx.options.accessToken = {userId: financialBoss.id}; - await models.Client.changeCredit(context, instance, {credit: 0}); + await models.Client.changeCredit(ctx, instance, {credit: 0}); const salesAssistant = await models.VnUser.findOne({ where: {name: 'salesAssistant'} }, options); - context.options.accessToken = {userId: salesAssistant.id}; + ctx.options.accessToken = {userId: salesAssistant.id}; - await models.Client.changeCredit(context, instance, {credit: 300}); + await models.Client.changeCredit(ctx, instance, {credit: 300}); await tx.rollback(); } catch (e) { @@ -93,14 +93,14 @@ describe('Client Model', () => { try { const options = {transaction: tx}; - const context = {options}; + const ctx = {options}; const salesAssistant = await models.VnUser.findOne({ where: {name: 'salesAssistant'} }, options); - context.options.accessToken = {userId: salesAssistant.id}; + ctx.options.accessToken = {userId: salesAssistant.id}; - await models.Client.changeCredit(context, instance, {credit: 99999}); + await models.Client.changeCredit(ctx, instance, {credit: 99999}); await tx.rollback(); } catch (e) { diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/refund.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/refund.spec.js index 072fcc12c..6ecfe6015 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/refund.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/refund.spec.js @@ -17,6 +17,7 @@ describe('InvoiceOut refund()', () => { const options = {transaction: tx}; try { + await models.TicketRefund.destroyAll(null, options); const result = await models.InvoiceOut.refund(ctx, 'T1111111', withWarehouse, options); expect(result).toBeDefined(); diff --git a/modules/item/back/methods/item/specs/getBalance.spec.js b/modules/item/back/methods/item/specs/getBalance.spec.js index e013d8956..5e5148595 100644 --- a/modules/item/back/methods/item/specs/getBalance.spec.js +++ b/modules/item/back/methods/item/specs/getBalance.spec.js @@ -64,7 +64,7 @@ describe('item getBalance()', () => { const secondItemBalance = await models.Item.getBalance(ctx, secondFilter, options); expect(firstItemBalance[9].claimFk).toEqual(null); - expect(secondItemBalance[5].claimFk).toEqual(2); + expect(secondItemBalance[4].claimFk).toEqual(2); await tx.rollback(); } catch (e) { diff --git a/modules/item/back/methods/item/updateTaxes.js b/modules/item/back/methods/item/updateTaxes.js index 262f4dcb1..ae825ca6e 100644 --- a/modules/item/back/methods/item/updateTaxes.js +++ b/modules/item/back/methods/item/updateTaxes.js @@ -42,8 +42,9 @@ module.exports = Self => { promises.push(Self.app.models.ItemTaxCountry.updateAll( {id: tax.id}, - {taxClassFk: tax.taxClassFk} - ), myOptions); + {taxClassFk: tax.taxClassFk}, + myOptions + )); } await Promise.all(promises);