Merge pull request '3312-ibanRequired' (#772) from 3312-ibanRequired into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #772
Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
Carlos Jimenez Ruiz 2021-11-15 08:52:54 +00:00
commit d53a07dbf2
10 changed files with 53 additions and 31 deletions

View File

@ -0,0 +1,4 @@
ALTER TABLE vn.payMethod CHANGE ibanRequired ibanRequiredForClients tinyint(3) DEFAULT 0 NULL;
ALTER TABLE vn.payMethod ADD ibanRequiredForSuppliers tinyint(3) DEFAULT 0 NULL;
ALTER TABLE vn.payMethod CHANGE ibanRequiredForSuppliers ibanRequiredForSuppliers tinyint(3) DEFAULT 0 NULL AFTER ibanRequiredForClients;
UPDATE vn.payMethod SET ibanRequiredForSuppliers = 1 WHERE code = 'wireTransfer';

View File

@ -217,14 +217,14 @@ UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com'
UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23; UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23;
INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `ibanRequired`) INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `ibanRequiredForClients`, `ibanRequiredForSuppliers`)
VALUES VALUES
(1, NULL, 'PayMethod one', 0, 001, 0), (1, NULL, 'PayMethod one', 0, 001, 0, 0),
(2, NULL, 'PayMethod two', 10, 001, 0), (2, NULL, 'PayMethod two', 10, 001, 0, 0),
(3, 'compensation', 'PayMethod three', 0, 001, 0), (3, 'compensation', 'PayMethod three', 0, 001, 0, 0),
(4, NULL, 'PayMethod with IBAN', 0, 001, 1), (4, NULL, 'PayMethod with IBAN', 0, 001, 1, 0),
(5, NULL, 'PayMethod five', 10, 001, 0), (5, NULL, 'PayMethod five', 10, 001, 0, 0),
(8,'wireTransfer', 'WireTransfer', 5, 001, 1); (8,'wireTransfer', 'WireTransfer', 5, 001, 1, 1);
INSERT INTO `vn`.`payDem`(`id`, `payDem`) INSERT INTO `vn`.`payDem`(`id`, `payDem`)
VALUES VALUES

View File

@ -33928,7 +33928,8 @@ CREATE TABLE `payMethod` (
`solution` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `solution` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`outstandingDebt` tinyint(3) unsigned zerofill NOT NULL DEFAULT '000', `outstandingDebt` tinyint(3) unsigned zerofill NOT NULL DEFAULT '000',
`graceDays` int(11) unsigned NOT NULL DEFAULT '0', `graceDays` int(11) unsigned NOT NULL DEFAULT '0',
`ibanRequired` tinyint(3) DEFAULT '0', `ibanRequiredForClients` tinyint(3) DEFAULT '0',
`ibanRequiredForSuppliers` tinyint(3) DEFAULT '0',
`isNotified` tinyint(3) NOT NULL DEFAULT '1', `isNotified` tinyint(3) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

View File

@ -129,7 +129,7 @@ module.exports = Self => {
function hasIban(err, done) { function hasIban(err, done) {
Self.app.models.PayMethod.findById(this.payMethodFk, (_, instance) => { Self.app.models.PayMethod.findById(this.payMethodFk, (_, instance) => {
if (instance && instance.ibanRequired && !this.iban) if (instance && instance.ibanRequiredForClients && !this.iban)
err(); err();
done(); done();
}); });

View File

@ -25,7 +25,10 @@
"outstandingDebt": { "outstandingDebt": {
"type": "Number" "type": "Number"
}, },
"ibanRequired": { "ibanRequiredForClients": {
"type": "boolean"
},
"ibanRequiredForSuppliers": {
"type": "boolean" "type": "boolean"
} }
} }

View File

@ -19,7 +19,7 @@
vn-acl="salesAssistant" vn-acl="salesAssistant"
ng-model="$ctrl.client.payMethodFk" ng-model="$ctrl.client.payMethodFk"
data="paymethods" data="paymethods"
fields="['ibanRequired']" fields="['ibanRequiredForClients']"
initial-data="$ctrl.client.payMethod"> initial-data="$ctrl.client.payMethod">
</vn-autocomplete> </vn-autocomplete>
<vn-input-number <vn-input-number

View File

@ -1,12 +1,13 @@
const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('loopback model Supplier', () => { describe('loopback model Supplier', () => {
let supplierOne; let supplierOne;
let supplierTwo; let supplierTwo;
beforeAll(async() => { beforeAll(async() => {
supplierOne = await app.models.Supplier.findById(1); supplierOne = await models.Supplier.findById(1);
supplierTwo = await app.models.Supplier.findById(442); supplierTwo = await models.Supplier.findById(442);
}); });
afterAll(async() => { afterAll(async() => {
@ -18,9 +19,9 @@ describe('loopback model Supplier', () => {
it('should throw an error when attempting to set an invalid payMethod id in the supplier', async() => { it('should throw an error when attempting to set an invalid payMethod id in the supplier', async() => {
let error; let error;
const expectedError = 'You can not select this payment method without a registered bankery account'; const expectedError = 'You can not select this payment method without a registered bankery account';
const supplier = await app.models.Supplier.findById(1); const supplier = await models.Supplier.findById(1);
await supplier.updateAttribute('payMethodFk', 4) await supplier.updateAttribute('payMethodFk', 8)
.catch(e => { .catch(e => {
error = e; error = e;
@ -31,14 +32,27 @@ describe('loopback model Supplier', () => {
}); });
it('should not throw if the payMethod id is valid', async() => { it('should not throw if the payMethod id is valid', async() => {
const activeCtx = {
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
let error; let error;
const supplier = await app.models.Supplier.findById(442); const supplier = await models.Supplier.findById(442);
await supplier.updateAttribute('payMethodFk', 4) await supplier.updateAttribute('payMethodFk', 4)
.catch(e => { .catch(e => {
error = e; error = e;
}); });
expect(error).toBeDefined(); expect(error).not.toBeDefined();
}); });
}); });
}); });

View File

@ -9,40 +9,40 @@
"properties": { "properties": {
"id": { "id": {
"id": true, "id": true,
"type": "Number", "type": "number",
"forceId": false "forceId": false
}, },
"originFk": { "originFk": {
"type": "Number", "type": "number",
"required": true "required": true
}, },
"userFk": { "userFk": {
"type": "Number" "type": "number"
}, },
"action": { "action": {
"type": "String", "type": "string",
"required": true "required": true
}, },
"changedModel": { "changedModel": {
"type": "String" "type": "string"
}, },
"oldInstance": { "oldInstance": {
"type": "Object" "type": "object"
}, },
"newInstance": { "newInstance": {
"type": "Object" "type": "object"
}, },
"creationDate": { "creationDate": {
"type": "Date" "type": "date"
}, },
"changedModelId": { "changedModelId": {
"type": "String" "type": "string"
}, },
"changedModelValue": { "changedModelValue": {
"type": "String" "type": "string"
}, },
"description": { "description": {
"type": "String" "type": "string"
} }
}, },
"relations": { "relations": {

View File

@ -80,7 +80,7 @@ module.exports = Self => {
const supplierAccount = await Self.app.models.SupplierAccount.findOne({where: {supplierFk: this.id}}); const supplierAccount = await Self.app.models.SupplierAccount.findOne({where: {supplierFk: this.id}});
const hasIban = supplierAccount && supplierAccount.iban; const hasIban = supplierAccount && supplierAccount.iban;
if (payMethod && payMethod.ibanRequired && !hasIban) if (payMethod && payMethod.ibanRequiredForSuppliers && !hasIban)
err(); err();
done(); done();

View File

@ -24,7 +24,7 @@
vn-acl="salesAssistant" vn-acl="salesAssistant"
ng-model="$ctrl.supplier.payMethodFk" ng-model="$ctrl.supplier.payMethodFk"
data="paymethods" data="paymethods"
fields="['ibanRequired']" fields="['ibanRequiredForSuppliers']"
initial-data="$ctrl.supplier.payMethod"> initial-data="$ctrl.supplier.payMethod">
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete <vn-autocomplete