feat(docuware_upload): send to trash last file
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
5bb66fec3f
commit
def41c011c
|
@ -16,6 +16,12 @@ module.exports = Self => {
|
|||
type: 'string',
|
||||
required: true,
|
||||
description: 'The fileCabinet name'
|
||||
},
|
||||
{
|
||||
arg: 'signed',
|
||||
type: 'boolean',
|
||||
required: true,
|
||||
description: 'If pdf is necessary to be signed'
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
|
@ -28,7 +34,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.checkFile = async function(ctx, id, fileCabinet) {
|
||||
Self.checkFile = async function(ctx, id, fileCabinet, signed) {
|
||||
const models = Self.app.models;
|
||||
const action = 'find';
|
||||
|
||||
|
@ -70,7 +76,7 @@ module.exports = Self => {
|
|||
if (!documents) return false;
|
||||
|
||||
const state = documents.Fields.find(field => field.FieldName == 'ESTADO');
|
||||
if (state.Item != 'Firmado') return false;
|
||||
if (signed && state.Item != 'Firmado') return false;
|
||||
|
||||
return {id: documents.Id};
|
||||
} catch (error) {
|
||||
|
|
|
@ -20,8 +20,8 @@ module.exports = Self => {
|
|||
|
||||
const options = await Self.getOptions();
|
||||
|
||||
// if (!process.env.NODE_ENV)
|
||||
// return Math.round();
|
||||
if (!process.env.NODE_ENV)
|
||||
return Math.round();
|
||||
|
||||
const response = await axios.get(`${options.url}/FileCabinets/${fileCabinetId}/dialogs`, options.headers);
|
||||
const dialogs = response.data.Dialog;
|
||||
|
@ -44,8 +44,8 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
// if (!process.env.NODE_ENV)
|
||||
// return Math.round();
|
||||
if (!process.env.NODE_ENV)
|
||||
return Math.round();
|
||||
|
||||
const fileCabinetResponse = await axios.get(`${options.url}/FileCabinets`, options.headers);
|
||||
const fileCabinets = fileCabinetResponse.data.FileCabinet;
|
||||
|
@ -66,7 +66,7 @@ module.exports = Self => {
|
|||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'Cookie': docuwareConfig.token
|
||||
'Cookie': docuwareConfig.cookie
|
||||
}
|
||||
};
|
||||
|
|
@ -43,7 +43,7 @@ module.exports = Self => {
|
|||
|
||||
Self.download = async function(ctx, id, fileCabinet) {
|
||||
const models = Self.app.models;
|
||||
const docuwareFile = await models.Docuware.checkFile(ctx, id, fileCabinet);
|
||||
const docuwareFile = await models.Docuware.checkFile(ctx, id, fileCabinet, true);
|
||||
if (!docuwareFile) throw new UserError('The DOCUWARE PDF document does not exists');
|
||||
|
||||
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const axios = require('axios');
|
||||
|
||||
fdescribe('docuware download()', () => {
|
||||
describe('docuware download()', () => {
|
||||
const ticketId = 1;
|
||||
const userId = 9;
|
||||
const ctx = {
|
||||
|
@ -28,7 +28,7 @@ fdescribe('docuware download()', () => {
|
|||
};
|
||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
|
||||
|
||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName);
|
||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
|
||||
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
|
@ -51,7 +51,7 @@ fdescribe('docuware download()', () => {
|
|||
};
|
||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
|
||||
|
||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName);
|
||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
|
||||
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
|
@ -75,7 +75,7 @@ fdescribe('docuware download()', () => {
|
|||
};
|
||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
|
||||
|
||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName);
|
||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
|
||||
|
||||
expect(result.id).toEqual(docuwareId);
|
||||
});
|
||||
|
|
|
@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models;
|
|||
const axios = require('axios');
|
||||
const stream = require('stream');
|
||||
|
||||
fdescribe('docuware download()', () => {
|
||||
describe('docuware download()', () => {
|
||||
const userId = 9;
|
||||
const ticketId = 1;
|
||||
const ctx = {
|
||||
|
|
|
@ -1,35 +1,37 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
fdescribe('docuware download()', () => {
|
||||
describe('docuware upload()', () => {
|
||||
const userId = 9;
|
||||
const ticketId = 1;
|
||||
const ticketId = 10;
|
||||
const ctx = {
|
||||
req: {
|
||||
|
||||
getLocale: () => {
|
||||
return 'en';
|
||||
},
|
||||
accessToken: {userId: userId},
|
||||
headers: {origin: 'http://localhost:5000'},
|
||||
}
|
||||
};
|
||||
|
||||
const docuwareModel = models.Docuware;
|
||||
const ticketModel = models.Ticket;
|
||||
const fileCabinetName = 'deliveryNote';
|
||||
|
||||
beforeAll(() => {
|
||||
spyOn(docuwareModel, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
spyOn(docuwareModel, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
spyOn(docuwareModel, 'getFileCabinet').and.returnValue(new Promise(resolve => resolve(Math.random())));
|
||||
spyOn(docuwareModel, 'getDialog').and.returnValue(new Promise(resolve => resolve(Math.random())));
|
||||
});
|
||||
|
||||
it('should try upload file', async() => {
|
||||
spyOn(docuwareModel, 'checkFile').and.returnValue(false);
|
||||
spyOn(axios, 'get').and.returnValue(new stream.PassThrough({objectMode: true}));
|
||||
spyOn(ticketModel, 'deliveryNotePdf').and.returnValue(new Promise(resolve => resolve({})));
|
||||
|
||||
let error;
|
||||
try {
|
||||
await models.Docuware.download(ctx, ticketId, fileCabinetName);
|
||||
await models.Docuware.upload(ctx, ticketId, fileCabinetName);
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
|
||||
expect(error).toEqual('The DOCUWARE PDF document does not exists');
|
||||
expect(error).toEqual('Action not allowed on the test environment');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -380,27 +380,20 @@ module.exports = Self => {
|
|||
]
|
||||
};
|
||||
|
||||
// if (process.env.NODE_ENV != 'production')
|
||||
// throw new UserError('Action not allowed on the test environment');
|
||||
const docuwareFile = await models.Docuware.checkFile(ctx, id, fileCabinet);
|
||||
if (process.env.NODE_ENV != 'production')
|
||||
throw new UserError('Action not allowed on the test environment');
|
||||
|
||||
console.log(docuwareFile, id, fileCabinet);
|
||||
// replace
|
||||
// delete old
|
||||
const docuwareFile = await models.Docuware.checkFile(ctx, id, fileCabinet, false);
|
||||
if (docuwareFile) {
|
||||
console.log(docuwareFile);
|
||||
const uri = `${options.url}/FileCabinets/${fileCabinetId}/Sections?DocId=${docuwareFile.id}`;
|
||||
console.log(uri);
|
||||
return await axios.post(uri, deliveryNote[0], {headers: {
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Disposition': 'file; filename="10.pdf"',
|
||||
'X-File-ModifiedDate': '2020-08-26T00:00:00.000Z'
|
||||
}
|
||||
|
||||
});
|
||||
const deleteJson = {
|
||||
'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}]
|
||||
};
|
||||
const deleteUri = `${options.url}/FileCabinets/${fileCabinetId}/Documents/${docuwareFile.id}/Fields`;
|
||||
await axios.put(deleteUri, deleteJson, options.headers);
|
||||
}
|
||||
|
||||
let uploadUri = `${options.url}/FileCabinets/${fileCabinetId}/Documents?StoreDialogId=${dialogId}`;
|
||||
|
||||
const uploadUri = `${options.url}/FileCabinets/${fileCabinetId}/Documents?StoreDialogId=${dialogId}`;
|
||||
const FormData = require('form-data');
|
||||
const data = new FormData();
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"token": {
|
||||
"cookie": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
|
@ -29,4 +29,4 @@
|
|||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@ module.exports = Self => {
|
|||
require('../methods/docuware/upload')(Self);
|
||||
require('../methods/docuware/checkFile')(Self);
|
||||
require('../methods/docuware/deliveryNoteEmail')(Self);
|
||||
require('../methods/docuware/basic')(Self);
|
||||
require('../methods/docuware/core')(Self);
|
||||
};
|
||||
|
|
|
@ -19,3 +19,5 @@ INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`princip
|
|||
('Docuware','download','READ','ALLOW','salesPerson'),
|
||||
('Docuware','upload','WRITE','ALLOW','productionAssi'),
|
||||
('Docuware','deliveryNoteEmail','WRITE','ALLOW','salesPerson');
|
||||
|
||||
ALTER TABLE `vn`.`docuwareConfig` CHANGE token cookie varchar(1000) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL;
|
||||
|
|
|
@ -2582,7 +2582,7 @@ INSERT INTO `bs`.`sale` (`saleFk`, `amount`, `dated`, `typeFk`, `clientFk`)
|
|||
|
||||
INSERT INTO `vn`.`docuwareConfig` (`url`)
|
||||
VALUES
|
||||
('https://verdnatura.docuware.cloud/docuware/platform');
|
||||
('http://docuware.url/');
|
||||
|
||||
INSERT INTO `vn`.`calendarHolidaysName` (`id`, `name`)
|
||||
VALUES
|
||||
|
|
|
@ -59,6 +59,7 @@ TABLES=(
|
|||
componentType
|
||||
continent
|
||||
department
|
||||
docuware
|
||||
itemPackingType
|
||||
pgc
|
||||
sample
|
||||
|
|
|
@ -252,5 +252,6 @@
|
|||
"Receipt's bank was not found": "No se encontró el banco del recibo",
|
||||
"This receipt was not compensated": "Este recibo no ha sido compensado",
|
||||
"Client's email was not found": "No se encontró el email del cliente",
|
||||
"Failed to upload file": "Error al subir archivo"
|
||||
}
|
||||
"Failed to upload file": "Error al subir archivo",
|
||||
"The DOCUWARE PDF document does not exists": "The DOCUWARE PDF document does not exists"
|
||||
}
|
|
@ -63,7 +63,7 @@
|
|||
Send PDF
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="$ctrl.uploadDocuware()"
|
||||
ng-click="$ctrl.uploadDocuware(!$ctrl.hasDocuwareFile)"
|
||||
translate>
|
||||
Send PDF to tablet
|
||||
</vn-item>
|
||||
|
@ -333,3 +333,11 @@
|
|||
company-fk="$ctrl.vnConfig.companyFk"
|
||||
client-fk="$ctrl.ticket.client.id">
|
||||
</vn-client-balance-create>
|
||||
|
||||
<!-- Send pdf to tablet -->
|
||||
<vn-confirm
|
||||
vn-id="pdfToTablet"
|
||||
on-accept="$ctrl.uploadDocuware(true)"
|
||||
question="Are you sure you want to replace this delivery note?"
|
||||
message="Already exist signed delivery note">
|
||||
</vn-confirm>
|
||||
|
|
|
@ -307,13 +307,16 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
hasDocuware() {
|
||||
this.$http.post(`Docuwares/${this.id}/checkFile`, {fileCabinet: 'deliveryNote'})
|
||||
this.$http.post(`Docuwares/${this.id}/checkFile`, {fileCabinet: 'deliveryNote', signed: true})
|
||||
.then(res => {
|
||||
this.hasDocuwareFile = res.data;
|
||||
});
|
||||
}
|
||||
|
||||
uploadDocuware() {
|
||||
uploadDocuware(force) {
|
||||
if (!force)
|
||||
return this.$.pdfToTablet.show();
|
||||
|
||||
return this.$http.post(`Docuwares/${this.id}/upload`, {fileCabinet: 'deliveryNote'})
|
||||
.then(() => {
|
||||
this.vnApp.showSuccess(this.$t('PDF sent!'));
|
||||
|
|
|
@ -286,9 +286,34 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
|
|||
|
||||
describe('hasDocuware()', () => {
|
||||
it('should call hasDocuware method', () => {
|
||||
$httpBackend.whenPOST(`Docuwares/${ticket.id}/checkFile`).respond();
|
||||
$httpBackend.whenPOST(`Docuwares/${ticket.id}/checkFile`).respond(true);
|
||||
controller.hasDocuware();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.hasDocuwareFile).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('uploadDocuware()', () => {
|
||||
it('should open dialog if not force', () => {
|
||||
controller.$.pdfToTablet = {show: () => {}};
|
||||
jest.spyOn(controller.$.pdfToTablet, 'show');
|
||||
controller.uploadDocuware(false);
|
||||
|
||||
expect(controller.$.pdfToTablet.show).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should make a query and show balance create', () => {
|
||||
controller.$.balanceCreate = {show: () => {}};
|
||||
jest.spyOn(controller.$.balanceCreate, 'show');
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
$httpBackend.whenPOST(`Docuwares/${ticket.id}/upload`).respond(true);
|
||||
controller.uploadDocuware(true);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
expect(controller.$.balanceCreate.show).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -16,3 +16,5 @@ The following refund ticket have been created: "Se ha creado siguiente ticket de
|
|||
Transfer client: Transferir cliente
|
||||
SMS Notify changes: SMS Notificar cambios
|
||||
PDF sent!: ¡PDF enviado!
|
||||
Already exist signed delivery note: Ya existe albarán de entrega firmado
|
||||
Are you sure you want to replace this delivery note?: ¿Seguro que quieres reemplazar este albarán de entrega?
|
||||
|
|
Loading…
Reference in New Issue