From 8f2e29787b2ef3dee96210e283eb6c82bc920e41 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 19 Nov 2021 10:07:33 +0100 Subject: [PATCH 1/8] fix(payMethod): alter colums name --- db/changes/10390-constitution/00-payMethod.sql | 2 ++ db/dump/fixtures.sql | 2 +- modules/client/back/models/client.js | 2 +- modules/client/back/models/pay-method.json | 4 ++-- modules/client/front/billing-data/index.html | 2 +- modules/supplier/back/models/supplier.js | 2 +- modules/supplier/front/billing-data/index.html | 2 +- 7 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 db/changes/10390-constitution/00-payMethod.sql diff --git a/db/changes/10390-constitution/00-payMethod.sql b/db/changes/10390-constitution/00-payMethod.sql new file mode 100644 index 000000000..6e196af95 --- /dev/null +++ b/db/changes/10390-constitution/00-payMethod.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.payMethod CHANGE ibanRequiredForClients isIbanRequiredForClients tinyint(3) DEFAULT 0 NULL; +ALTER TABLE vn.payMethod CHANGE ibanRequiredForSuppliers isIbanRequiredForSuppliers tinyint(3) DEFAULT 0 NULL; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index b46056135..bb48d40b4 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -217,7 +217,7 @@ UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com' UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23; -INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `ibanRequiredForClients`, `ibanRequiredForSuppliers`) +INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `isIbanRequiredForClients`, `isIbanRequiredForSuppliers`) VALUES (1, NULL, 'PayMethod one', 0, 001, 0, 0), (2, NULL, 'PayMethod two', 10, 001, 0, 0), diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index f3591750d..1a4e9bcb3 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -138,7 +138,7 @@ module.exports = Self => { function hasIban(err, done) { Self.app.models.PayMethod.findById(this.payMethodFk, (_, instance) => { - if (instance && instance.ibanRequiredForClients && !this.iban) + if (instance && instance.isIbanRequiredForClients && !this.iban) err(); done(); }); diff --git a/modules/client/back/models/pay-method.json b/modules/client/back/models/pay-method.json index 0666be7a5..4080a0953 100644 --- a/modules/client/back/models/pay-method.json +++ b/modules/client/back/models/pay-method.json @@ -25,10 +25,10 @@ "outstandingDebt": { "type": "Number" }, - "ibanRequiredForClients": { + "isIbanRequiredForClients": { "type": "boolean" }, - "ibanRequiredForSuppliers": { + "isIbanRequiredForSuppliers": { "type": "boolean" } } diff --git a/modules/client/front/billing-data/index.html b/modules/client/front/billing-data/index.html index 8c7c6cfe9..06d7d7d73 100644 --- a/modules/client/front/billing-data/index.html +++ b/modules/client/front/billing-data/index.html @@ -19,7 +19,7 @@ vn-acl="salesAssistant" ng-model="$ctrl.client.payMethodFk" data="paymethods" - fields="['ibanRequiredForClients']" + fields="['isIbanRequiredForClients']" initial-data="$ctrl.client.payMethod"> { const supplierAccount = await Self.app.models.SupplierAccount.findOne({where: {supplierFk: this.id}}); const hasIban = supplierAccount && supplierAccount.iban; - if (payMethod && payMethod.ibanRequiredForSuppliers && !hasIban) + if (payMethod && payMethod.isIbanRequiredForSuppliers && !hasIban) err(); done(); diff --git a/modules/supplier/front/billing-data/index.html b/modules/supplier/front/billing-data/index.html index c1c57e135..238760c1a 100644 --- a/modules/supplier/front/billing-data/index.html +++ b/modules/supplier/front/billing-data/index.html @@ -24,7 +24,7 @@ vn-acl="salesAssistant" ng-model="$ctrl.supplier.payMethodFk" data="paymethods" - fields="['ibanRequiredForSuppliers']" + fields="['isIbanRequiredForSuppliers']" initial-data="$ctrl.supplier.payMethod"> Date: Fri, 19 Nov 2021 12:10:53 +0100 Subject: [PATCH 2/8] feat(client): change phone for payMethod in descriptor --- modules/client/front/descriptor/index.html | 4 ++-- modules/client/front/descriptor/locale/es.yml | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/client/front/descriptor/index.html b/modules/client/front/descriptor/index.html index d5beca282..d1a88aee7 100644 --- a/modules/client/front/descriptor/index.html +++ b/modules/client/front/descriptor/index.html @@ -17,8 +17,8 @@
+ label="Pay method" + value="{{$ctrl.client.payMethod.name}}"> Date: Mon, 22 Nov 2021 08:27:14 +0100 Subject: [PATCH 3/8] feat(item and latest-buys: add supplier filter --- .../entry/back/methods/entry/latestBuysFilter.js | 11 ++++++++++- .../entry/front/latest-buys-search-panel/index.html | 11 +++++++++++ modules/item/back/methods/item/filter.js | 11 ++++++++++- modules/item/front/search-panel/index.html | 13 ++++++++++++- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index 7711bc0f1..3b6da1acd 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -39,6 +39,11 @@ module.exports = Self => { type: 'integer', description: 'The buyer of the item', }, + { + arg: 'supplierFk', + type: 'integer', + description: 'The supplier of the item', + }, { arg: 'active', type: 'boolean', @@ -99,6 +104,8 @@ module.exports = Self => { return {'ic.id': value}; case 'salesPersonFk': return {'it.workerFk': value}; + case 'supplierFk': + return {'s.id': value}; case 'code': return {'it.code': value}; case 'active': @@ -172,7 +179,9 @@ module.exports = Self => { LEFT JOIN itemCategory ic ON ic.id = it.categoryFk LEFT JOIN itemType t ON t.id = i.typeFk LEFT JOIN intrastat intr ON intr.id = i.intrastatFk - LEFT JOIN origin ori ON ori.id = i.originFk` + LEFT JOIN origin ori ON ori.id = i.originFk + LEFT JOIN entry e ON e.id = b.entryFk + LEFT JOIN supplier s ON s.id = e.supplierFk` ); if (ctx.args.tags) { diff --git a/modules/entry/front/latest-buys-search-panel/index.html b/modules/entry/front/latest-buys-search-panel/index.html index 4693141f8..7d570f798 100644 --- a/modules/entry/front/latest-buys-search-panel/index.html +++ b/modules/entry/front/latest-buys-search-panel/index.html @@ -46,6 +46,17 @@ where="{role: {inq: ['logistic', 'buyer']}}" label="Buyer"> + + {{name}}: {{nickname}} + { type: 'integer', description: 'The buyer of the item', }, + { + arg: 'supplierFk', + type: 'integer', + description: 'The supplier of the item', + }, { arg: 'description', type: 'string', @@ -120,6 +125,8 @@ module.exports = Self => { return {'ic.id': value}; case 'buyerFk': return {'it.workerFk': value}; + case 'supplierFk': + return {'s.id': value}; case 'origin': return {'ori.code': value}; case 'intrastat': @@ -170,7 +177,9 @@ module.exports = Self => { LEFT JOIN producer pr ON pr.id = i.producerFk LEFT JOIN origin ori ON ori.id = i.originFk LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = it.warehouseFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id` + LEFT JOIN buy b ON b.id = lb.buy_id + LEFT JOIN entry e ON e.id = b.entryFk + LEFT JOIN supplier s ON s.id = e.supplierFk` ); if (ctx.args.tags) { diff --git a/modules/item/front/search-panel/index.html b/modules/item/front/search-panel/index.html index 57f05bb54..7cbe9c56d 100644 --- a/modules/item/front/search-panel/index.html +++ b/modules/item/front/search-panel/index.html @@ -43,10 +43,21 @@ ng-model="filter.buyerFk" url="Items/activeBuyers" show-field="nickname" - search-function="{firstName: $search}" + search-function="{nickname: {like: '%'+ $search +'%'}}" value-field="workerFk" label="Buyer"> + + {{name}}: {{nickname}} + From 1e6805a1614ca860a53cdba621c7602ccdbbbbcf Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 22 Nov 2021 08:30:28 +0100 Subject: [PATCH 4/8] remove unnecessary tabulation --- modules/entry/back/methods/entry/latestBuysFilter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index 3b6da1acd..c877612e1 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -181,7 +181,7 @@ module.exports = Self => { LEFT JOIN intrastat intr ON intr.id = i.intrastatFk LEFT JOIN origin ori ON ori.id = i.originFk LEFT JOIN entry e ON e.id = b.entryFk - LEFT JOIN supplier s ON s.id = e.supplierFk` + LEFT JOIN supplier s ON s.id = e.supplierFk` ); if (ctx.args.tags) { From 97a66754a7518238566d86d961582cb0afbef8c8 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 22 Nov 2021 08:58:54 +0100 Subject: [PATCH 5/8] feat(item and entry): add back test --- .../entry/specs/latestBuysFilter.spec.js | 12 ++++++ .../back/methods/item/specs/filter.spec.js | 40 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js index f386894dd..bdd302adb 100644 --- a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js +++ b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js @@ -136,5 +136,17 @@ describe('Buy latests buys filter()', () => { expect(results.length).toBe(1); }); + + it('should return results matching "supplierFk"', async() => { + let ctx = { + args: { + supplierFk: 1 + } + }; + + let results = await app.models.Buy.latestBuysFilter(ctx); + + expect(results.length).toBe(2); + }); }); diff --git a/modules/item/back/methods/item/specs/filter.spec.js b/modules/item/back/methods/item/specs/filter.spec.js index 7b1fac9ac..30bdcec32 100644 --- a/modules/item/back/methods/item/specs/filter.spec.js +++ b/modules/item/back/methods/item/specs/filter.spec.js @@ -79,4 +79,44 @@ describe('item filter()', () => { throw e; } }); + + it('should return 2 result filtering by buyerFk', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {}; + const ctx = {args: {filter: filter, buyerFk: 16}}; + const result = await models.Item.filter(ctx, filter, options); + + expect(result.length).toEqual(2); + expect(result[0].id).toEqual(16); + expect(result[1].id).toEqual(71); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return 2 result filtering by supplierFk', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {}; + const ctx = {args: {filter: filter, supplierFk: 1}}; + const result = await models.Item.filter(ctx, filter, options); + + expect(result.length).toEqual(2); + expect(result[0].id).toEqual(1); + expect(result[1].id).toEqual(3); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From fe46dbd34312de5826b0315ab66a8f9b31aeb8bf Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 22 Nov 2021 11:49:30 +0100 Subject: [PATCH 6/8] feat(entry_last-buys): add filter isFloramondo --- db/dump/fixtures.sql | 2 +- .../back/methods/entry/latestBuysFilter.js | 7 ++++++ .../entry/specs/latestBuysFilter.spec.js | 24 +++++++++++++++++++ .../front/latest-buys-search-panel/index.html | 5 ++++ modules/entry/front/latest-buys/locale/es.yml | 2 ++ .../back/methods/item/specs/filter.spec.js | 4 ++-- 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index b46056135..1fce7ae38 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -806,7 +806,7 @@ INSERT INTO `vn`.`item`(`id`, `typeFk`, `size`, `inkFk`, `stems`, `originFk`, `d (6, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '6', NULL, 0, 4, 'VT', 0), (7, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '7', NULL, 0, 4, 'VT', 0), (8, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '8', NULL, 0, 5, 'VT', 0), - (9, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 4, 'VT', 0), + (9, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 4, 'VT', 1), (10, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '10', NULL, 0, 4, 'VT', 0), (11, 1, 60, 'YEL', 1, 1, NULL, 1, 05080000, 4751000000, NULL, 0, '11', NULL, 0, 4, 'VT', 0), (12, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '12', NULL, 0, 3, 'VT', 0), diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index 7711bc0f1..435427448 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -49,6 +49,11 @@ module.exports = Self => { type: 'boolean', description: 'Whether the item is or not visible', }, + { + arg: 'floramondo', + type: 'boolean', + description: 'Whether the item is or not floramondo', + }, { arg: 'typeFk', type: 'integer', @@ -103,6 +108,8 @@ module.exports = Self => { return {'it.code': value}; case 'active': return {'i.isActive': value}; + case 'floramondo': + return {'i.isFloramondo': value}; case 'visible': if (value) return {'v.visible': {gt: 0}}; diff --git a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js index f386894dd..f983b8a4d 100644 --- a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js +++ b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js @@ -113,6 +113,30 @@ describe('Buy latests buys filter()', () => { expect(results.length).toBe(0); }); + it('should return results matching "floramondo"', async() => { + let ctx = { + args: { + floramondo: true + } + }; + + let results = await app.models.Buy.latestBuysFilter(ctx); + + expect(results.length).toBe(1); + }); + + it('should return results matching "not floramondo"', async() => { + let ctx = { + args: { + floramondo: false + } + }; + + let results = await app.models.Buy.latestBuysFilter(ctx); + + expect(results.length).toBe(5); + }); + it('should return results matching "salesPersonFk"', async() => { let ctx = { args: { diff --git a/modules/entry/front/latest-buys-search-panel/index.html b/modules/entry/front/latest-buys-search-panel/index.html index 4693141f8..8597ab0ea 100644 --- a/modules/entry/front/latest-buys-search-panel/index.html +++ b/modules/entry/front/latest-buys-search-panel/index.html @@ -58,6 +58,11 @@ ng-model="filter.visible" triple-state="true"> + + diff --git a/modules/entry/front/latest-buys/locale/es.yml b/modules/entry/front/latest-buys/locale/es.yml index 21eae0307..8d70844fa 100644 --- a/modules/entry/front/latest-buys/locale/es.yml +++ b/modules/entry/front/latest-buys/locale/es.yml @@ -4,6 +4,8 @@ Freight value: Porte Commission value: ComisiĆ³n Package value: Embalaje Is ignored: Ignorado +Is visible: Visible +Is floramondo: Floramondo Grouping price: Precio grouping Packing price: Precio packing Min price: Precio min diff --git a/modules/item/back/methods/item/specs/filter.spec.js b/modules/item/back/methods/item/specs/filter.spec.js index 7b1fac9ac..3e798bcca 100644 --- a/modules/item/back/methods/item/specs/filter.spec.js +++ b/modules/item/back/methods/item/specs/filter.spec.js @@ -70,8 +70,8 @@ describe('item filter()', () => { const ctx = {args: {filter: filter, isFloramondo: true}}; const result = await models.Item.filter(ctx, filter, options); - expect(result.length).toEqual(2); - expect(result[0].id).toEqual(13); + expect(result.length).toEqual(3); + expect(result[0].id).toEqual(9); await tx.rollback(); } catch (e) { From 80f651f37d0757551a7db7f8ca664d16f39f4dee Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 22 Nov 2021 12:34:20 +0100 Subject: [PATCH 7/8] add entries less than a year ago --- modules/entry/back/methods/entry/latestBuysFilter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index c877612e1..0c8ce3f99 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -180,7 +180,7 @@ module.exports = Self => { LEFT JOIN itemType t ON t.id = i.typeFk LEFT JOIN intrastat intr ON intr.id = i.intrastatFk LEFT JOIN origin ori ON ori.id = i.originFk - LEFT JOIN entry e ON e.id = b.entryFk + LEFT JOIN entry e ON e.id = b.entryFk AND e.created >= DATE_SUB(CURDATE(),INTERVAL 1 YEAR) LEFT JOIN supplier s ON s.id = e.supplierFk` ); From 709a300388e5d02d72bba3fb07e934dd4daa0e03 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 22 Nov 2021 13:44:22 +0100 Subject: [PATCH 8/8] fix: extracting logic gates to constants --- modules/client/back/models/client.js | 3 ++- modules/supplier/back/models/supplier.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 1a4e9bcb3..b4961771d 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -138,7 +138,8 @@ module.exports = Self => { function hasIban(err, done) { Self.app.models.PayMethod.findById(this.payMethodFk, (_, instance) => { - if (instance && instance.isIbanRequiredForClients && !this.iban) + const isMissingIban = instance && instance.isIbanRequiredForClients && !this.iban; + if (isMissingIban) err(); done(); }); diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index bab725903..1ac6e3bd2 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -79,8 +79,9 @@ module.exports = Self => { const payMethod = await Self.app.models.PayMethod.findById(this.payMethodFk); const supplierAccount = await Self.app.models.SupplierAccount.findOne({where: {supplierFk: this.id}}); const hasIban = supplierAccount && supplierAccount.iban; + const isMissingIban = payMethod && payMethod.isIbanRequiredForSuppliers && !hasIban; - if (payMethod && payMethod.isIbanRequiredForSuppliers && !hasIban) + if (isMissingIban) err(); done();