Merge pull request '2873-create-supplier-beneficiary' (#593) from 2873-create-supplier-beneficiary into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #593 Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
commit
2630fa8c43
|
@ -8,7 +8,9 @@ Salix is also the scientific name of a beautifull tree! :)
|
||||||
|
|
||||||
Required applications.
|
Required applications.
|
||||||
|
|
||||||
* Node.js = 14.15.1 LTS
|
* Node.js = 14.x LTS
|
||||||
|
* Docker
|
||||||
|
* Git
|
||||||
* Docker
|
* Docker
|
||||||
|
|
||||||
You will need to install globally the following items.
|
You will need to install globally the following items.
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE vn.`supplierAccount` ADD `beneficiary` VARCHAR(50) NULL DEFAULT NULL AFTER `bankFk`;
|
||||||
|
UPDATE vn.supplierAccount SET beneficiary = `description`;
|
|
@ -0,0 +1,64 @@
|
||||||
|
const app = require('vn-loopback/server/server');
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
|
describe('loopback model Supplier-account', () => {
|
||||||
|
describe('create', () => {
|
||||||
|
const supplierId = 1;
|
||||||
|
const bankEntityId = 2100;
|
||||||
|
it('should throw an error when attempting to set an invalid iban account', async() => {
|
||||||
|
let error;
|
||||||
|
const expectedError = 'The IBAN does not have the correct format';
|
||||||
|
const iban = 'incorrect format';
|
||||||
|
try {
|
||||||
|
await app.models.SupplierAccount.create(
|
||||||
|
{
|
||||||
|
supplierFk: supplierId,
|
||||||
|
bankEntityFk: bankEntityId,
|
||||||
|
iban: iban
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
|
||||||
|
expect(error.message).toContain(expectedError);
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a valid supplier account', async() => {
|
||||||
|
const tx = await app.models.Claim.beginTransaction({});
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const iban = 'ES91 2100 0418 4502 0005 1332';
|
||||||
|
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: 5},
|
||||||
|
http: {
|
||||||
|
req: {
|
||||||
|
headers: {origin: 'http://localhost'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
activeCtx.http.req.__ = value => {
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
const createdSupplierAccount = await app.models.SupplierAccount.create({
|
||||||
|
supplierFk: supplierId,
|
||||||
|
bankEntityFk: bankEntityId,
|
||||||
|
iban: iban
|
||||||
|
},
|
||||||
|
options);
|
||||||
|
|
||||||
|
expect(createdSupplierAccount.iban).toBe(iban);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,6 +1,6 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('loopback model address', () => {
|
describe('loopback model Supplier', () => {
|
||||||
let supplierOne;
|
let supplierOne;
|
||||||
let supplierTwo;
|
let supplierTwo;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
const validateIban = require('vn-loopback/util/validateIban');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.validateAsync('iban', ibanValidation, {
|
||||||
|
message: 'The IBAN does not have the correct format'
|
||||||
|
});
|
||||||
|
|
||||||
|
async function ibanValidation(err, done) {
|
||||||
|
let filter = {
|
||||||
|
fields: ['code'],
|
||||||
|
where: {id: this.countryFk}
|
||||||
|
};
|
||||||
|
let country = await Self.app.models.Country.findOne(filter);
|
||||||
|
let code = country ? country.code.toLowerCase() : null;
|
||||||
|
if (code != 'es')
|
||||||
|
return done();
|
||||||
|
|
||||||
|
if (!validateIban(this.iban))
|
||||||
|
err();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
};
|
|
@ -7,7 +7,7 @@
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "supplierAccount"
|
"table": "supplierAccount"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -16,39 +16,18 @@
|
||||||
"id": true,
|
"id": true,
|
||||||
"description": "Identifier"
|
"description": "Identifier"
|
||||||
},
|
},
|
||||||
"supplierFk": {
|
|
||||||
"type": "Number"
|
|
||||||
},
|
|
||||||
"iban": {
|
"iban": {
|
||||||
"type": "String"
|
"type": "String"
|
||||||
},
|
},
|
||||||
"office": {
|
"beneficiary": {
|
||||||
"type": "String"
|
"type": "String"
|
||||||
},
|
|
||||||
"DC": {
|
|
||||||
"type": "String"
|
|
||||||
},
|
|
||||||
"number": {
|
|
||||||
"type": "String"
|
|
||||||
},
|
|
||||||
"description": {
|
|
||||||
"type": "String"
|
|
||||||
},
|
|
||||||
"bicSufix": {
|
|
||||||
"type": "String"
|
|
||||||
},
|
|
||||||
"bankEntityFk": {
|
|
||||||
"type": "Number"
|
|
||||||
},
|
|
||||||
"bankFk": {
|
|
||||||
"type": "Number"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
"supplier": {
|
"supplier": {
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "Supplier",
|
"model": "Supplier",
|
||||||
"foreignKey": "supplierFk"
|
"foreignKey": "supplierFk"
|
||||||
},
|
},
|
||||||
"bankEntity": {
|
"bankEntity": {
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="SupplierAccounts"
|
url="SupplierAccounts"
|
||||||
fields="['id', 'supplierFk', 'iban', 'bankEntityFk']"
|
fields="['id', 'supplierFk', 'iban', 'bankEntityFk', 'beneficiary']"
|
||||||
link="{supplierFk: $ctrl.$params.id}"
|
link="{supplierFk: $ctrl.$params.id}"
|
||||||
include="$ctrl.include"
|
include="$ctrl.include"
|
||||||
data="$ctrl.supplierAccounts"
|
data="$ctrl.supplierAccounts"
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
data="$ctrl.supplierAccounts"
|
data="$ctrl.supplierAccounts"
|
||||||
form="form">
|
form="form">
|
||||||
</vn-watcher>
|
</vn-watcher>
|
||||||
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
|
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-lg">
|
||||||
<vn-card class="vn-pa-lg">
|
<vn-card class="vn-pa-lg">
|
||||||
<vn-horizontal ng-repeat="supplierAccount in $ctrl.supplierAccounts">
|
<vn-horizontal ng-repeat="supplierAccount in $ctrl.supplierAccounts">
|
||||||
<vn-textfield vn-three
|
<vn-textfield vn-three
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
ng-model="supplierAccount.iban"
|
ng-model="supplierAccount.iban"
|
||||||
rule>
|
rule>
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-autocomplete vn-two
|
<vn-autocomplete vn-three
|
||||||
label="Bank entity"
|
label="Bank entity"
|
||||||
ng-model="supplierAccount.bankEntityFk"
|
ng-model="supplierAccount.bankEntityFk"
|
||||||
url="BankEntities"
|
url="BankEntities"
|
||||||
|
@ -35,6 +35,11 @@
|
||||||
ng-click="$ctrl.showBankEntity($event, $index)">
|
ng-click="$ctrl.showBankEntity($event, $index)">
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
</append>
|
</append>
|
||||||
|
<vn-textfield vn-three
|
||||||
|
label="Beneficiary"
|
||||||
|
ng-model="supplierAccount.beneficiary"
|
||||||
|
info="Beneficiary information">
|
||||||
|
</vn-textfield>
|
||||||
<vn-none>
|
<vn-none>
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
vn-tooltip="Remove account"
|
vn-tooltip="Remove account"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Beneficiary information: Name of the bank account holder if different from the provider
|
|
@ -1,3 +1,5 @@
|
||||||
Bank entity: Entidad bancaria
|
Bank entity: Entidad bancaria
|
||||||
swift: Swift BIC
|
swift: Swift BIC
|
||||||
Add account: Añadir cuenta
|
Add account: Añadir cuenta
|
||||||
|
Beneficiary: Beneficiario
|
||||||
|
Beneficiary information: Nombre del titular de la cuenta bancaria en caso de ser diferente del proveedor
|
Loading…
Reference in New Issue