refs #5297 feat(worker_new): add payMethod
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2023-04-28 14:17:19 +02:00
parent e00edf0266
commit ac55dc4cc7
11 changed files with 72 additions and 8 deletions

View File

@ -10,9 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- (Usuarios -> Histórico) Nueva sección
- (Roles -> Histórico) Nueva sección
- (Trabajadores -> Dar de alta) Permite elegir el método de pago
### Changed
- (Artículo -> Precio fijado) Modificado el buscador superior por uno lateral
- (Trabajadores -> Dar de alta) Quitada obligatoriedad del iban
### Fixed
-

View File

@ -0,0 +1,7 @@
ALTER TABLE `vn`.`workerConfig` ADD payMethodFk tinyint(3) unsigned NULL;
ALTER TABLE `vn`.`workerConfig` ADD CONSTRAINT workerConfig_FK FOREIGN KEY (roleFk) REFERENCES account.`role`(id) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `vn`.`workerConfig` ADD CONSTRAINT workerConfig_FK_1 FOREIGN KEY (payMethodFk) REFERENCES `vn`.`payMethod`(id) ON DELETE SET NULL ON UPDATE CASCADE;
-- Cuando se apruebe el PR quitar y poner en redmine para hacerse manualmente
UPDATE `vn`.`workerConfig`
SET payMethodFk = 4
WHERE id=1;

View File

@ -2801,9 +2801,9 @@ INSERT INTO `vn`.`payDemDetail` (`id`, `detail`)
VALUES
(1, 1);
INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`)
INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `payMethodFk`)
VALUES
(1, NULL, 1);
(1, NULL, 1, 4);
INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`)
VALUES

View File

@ -1041,6 +1041,7 @@ export default {
email: 'vn-worker-create vn-textfield[ng-model="$ctrl.worker.email"]',
boss: 'vn-worker-create vn-autocomplete[ng-model="$ctrl.worker.bossFk"]',
role: 'vn-worker-create vn-autocomplete[ng-model="$ctrl.worker.roleFk"]',
payMethod: 'vn-worker-create vn-autocomplete[ng-model="$ctrl.worker.payMethodFk"]',
iban: 'vn-worker-create vn-textfield[ng-model="$ctrl.worker.iban"]',
createButton: 'vn-worker-create vn-submit[label="Create"]',
},

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer';
describe('Worker create path', () => {
fdescribe('Worker create path', () => {
let browser;
let page;
let newWorker;
@ -25,6 +25,7 @@ describe('Worker create path', () => {
await page.write(selectors.workerCreate.postcode, '46680');
await page.write(selectors.workerCreate.street, 'S/ Doomstadt');
await page.write(selectors.workerCreate.email, 'doctorDoom@marvel.com');
await page.autocompleteSearch(selectors.workerCreate.payMethod, 'one');
// should check for autocompleted worker code and worker user name
const workerCode = await page

View File

@ -90,15 +90,21 @@ module.exports = Self => {
description: `The worker birth`,
required: true,
},
{
arg: 'payMethodFk',
type: 'number',
description: `The client payMethod`,
required: true,
},
{
arg: 'iban',
type: 'string',
description: `The worker iban`,
description: `The client iban`,
},
{
arg: 'bankEntityFk',
type: 'number',
description: `The worker bank entity`,
description: `The client bank entity`,
}
],
returns: {
@ -160,6 +166,10 @@ module.exports = Self => {
myOptions
);
const payMethod = await models.PayMethod.findById(args.payMethodFk, {fields: ['isIbanRequiredForClients']});
if (payMethod.isIbanRequiredForClients && !args.iban)
throw new UserError(`That payment method requires an IBAN`);
await models.Worker.rawSql(
'CALL vn.clientCreate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
[
@ -200,6 +210,7 @@ module.exports = Self => {
await client.updateAttributes(
{
payMethod: args.payMethod,
iban: args.iban,
bankEntityFk: args.bankEntityFk,
defaultAddressFk: address.id,

View File

@ -32,7 +32,8 @@ describe('Worker new', () => {
phone: '123456789',
code: 'DWW',
bossFk: 9,
birth: '2022-12-11T23:00:00.000Z'
birth: '2022-12-11T23:00:00.000Z',
payMethodFk: 1
};
it('should return error if personal mail already exists', async() => {
@ -103,6 +104,33 @@ describe('Worker new', () => {
expect(error.message).toEqual('This worker already exists');
});
it('should return error if payMethod require iban', async() => {
const payMethodIbanRequired = await models.PayMethod.findOne({
where: {
isIbanRequiredForClients: true
},
fields: ['id']
});
const tx = await models.Worker.beginTransaction({});
let error;
try {
const options = {transaction: tx};
const ctx = {
args: Object.assign({}, defaultWorker, {payMethodFk: payMethodIbanRequired.id})
};
await models.Worker.new(ctx, options);
await tx.rollback();
} catch (e) {
error = e;
await tx.rollback();
}
expect(error.message).toEqual('That payment method requires an IBAN');
});
it('should create a new worker', async() => {
const newWorker = await models.Worker.new({args: defaultWorker});

View File

@ -14,6 +14,9 @@
},
"roleFk": {
"type": "number"
},
"payMethodFk": {
"type": "number"
}
},
"acls": [

View File

@ -142,12 +142,19 @@
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Pay method"
url="Paymethods"
ng-model="$ctrl.worker.payMethodFk"
initial-data="$ctrl.workerConfig.payMethodFk">
</vn-autocomplete>
<vn-textfield
vn-one
label="IBAN"
ng-model="$ctrl.worker.iban"
rule
on-change="$ctrl.autofillBic()">
on-change="$ctrl.autofillBic()"
rule>
</vn-textfield>
<vn-autocomplete
vn-one

View File

@ -5,6 +5,9 @@ export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.worker = {companyFk: this.vnConfig.user.companyFk};
this.$http.get(`WorkerConfigs/findOne`, {field: ['payMethodFk']}).then(res => {
if (res.data) this.worker.payMethodFk = res.data.payMethodFk;
});
}
onSubmit() {

View File

@ -10,3 +10,4 @@ Street: Dirección
Postcode: Código postal
Web user: Usuario Web
Access permission: Permiso de acceso
Pay method: Metodo de pago