Merge pull request 'feat: refs #6403 add dynamic clientType' (!2714) from 6403-addDinamycClient into master
Reviewed-on: #2714 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
3d22192824
|
@ -2,7 +2,7 @@
|
|||
<soap:Header>
|
||||
<mrw:AuthInfo>
|
||||
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
|
||||
<mrw:CodigoAbonado><%= mrw.subscriberCode %></mrw:CodigoAbonado>
|
||||
<mrw:CodigoAbonado><%= clientType %></mrw:CodigoAbonado>
|
||||
<mrw:CodigoDepartamento/>
|
||||
<mrw:UserName><%= mrw.user %></mrw:UserName>
|
||||
<mrw:Password><%= mrw.password %></mrw:Password>
|
||||
|
|
|
@ -27,9 +27,9 @@ module.exports = Self => {
|
|||
|
||||
const mrw = await models.MrwConfig.findOne();
|
||||
const {externalId} = await models.Expedition.findById(expeditionFk);
|
||||
|
||||
const clientType = await models.MrwConfig.getClientType(expeditionFk);
|
||||
const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8');
|
||||
const renderedXml = ejs.render(template, {mrw, externalId});
|
||||
const renderedXml = ejs.render(template, {mrw, externalId, clientType});
|
||||
const response = await axios.post(mrw.url, renderedXml, {
|
||||
headers: {
|
||||
'Content-Type': 'application/soap+xml; charset=utf-8'
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<soap:Header>
|
||||
<mrw:AuthInfo>
|
||||
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
|
||||
<mrw:CodigoAbonado><%= expeditionData.clientType %></mrw:CodigoAbonado>
|
||||
<mrw:CodigoAbonado><%= clientType %></mrw:CodigoAbonado>
|
||||
<mrw:CodigoDepartamento/>
|
||||
<mrw:UserName><%= mrw.user %></mrw:UserName>
|
||||
<mrw:Password><%= mrw.password %></mrw:Password>
|
||||
|
|
|
@ -22,6 +22,7 @@ module.exports = Self => {
|
|||
Self.createShipment = async expeditionFk => {
|
||||
const models = Self.app.models;
|
||||
const mrw = await Self.getConfig();
|
||||
const clientType = await models.MrwConfig.getClientType(expeditionFk);
|
||||
|
||||
const today = Date.vnNew();
|
||||
const [hours, minutes] = mrw?.expeditionDeadLine ? mrw.expeditionDeadLine.split(':').map(Number) : [0, 0];
|
||||
|
@ -52,8 +53,7 @@ module.exports = Self => {
|
|||
CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference,
|
||||
LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth, '0') serviceType,
|
||||
IF(mw.weekdays, 'S', 'N') weekDays,
|
||||
oa.description deliveryObservation,
|
||||
LPAD(ms.clientType, mc.clientTypeWidth, '0') clientType
|
||||
oa.description deliveryObservation
|
||||
FROM expedition e
|
||||
JOIN ticket t ON e.ticketFk = t.id
|
||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||
|
@ -73,22 +73,19 @@ module.exports = Self => {
|
|||
|
||||
const [expeditionData] = await Self.rawSql(query, [expeditionFk]);
|
||||
|
||||
if (!expeditionData)
|
||||
throw new UserError(`This expedition is not a MRW shipment`);
|
||||
|
||||
if (expeditionData?.shipped.setHours(0, 0, 0, 0) < today.setHours(0, 0, 0, 0))
|
||||
throw new UserError(`This ticket has a shipped date earlier than today`);
|
||||
|
||||
const shipmentResponse = await Self.sendXmlDoc(
|
||||
__dirname + `/createShipment.ejs`,
|
||||
{mrw, expeditionData},
|
||||
{mrw, expeditionData, clientType},
|
||||
'application/soap+xml'
|
||||
);
|
||||
const shipmentId = Self.getTextByTag(shipmentResponse, 'NumeroEnvio');
|
||||
|
||||
if (!shipmentId) throw new UserError(Self.getTextByTag(shipmentResponse, 'Mensaje'));
|
||||
|
||||
const file = await models.MrwConfig.getLabel(shipmentId);
|
||||
const file = await models.MrwConfig.getLabel(shipmentId, clientType);
|
||||
|
||||
return {shipmentId, file};
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<soapenv:Header>
|
||||
<mrw:AuthInfo>
|
||||
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
|
||||
<mrw:CodigoAbonado><%= mrw.subscriberCode %></mrw:CodigoAbonado>
|
||||
<mrw:CodigoAbonado><%= clientType %></mrw:CodigoAbonado>
|
||||
<mrw:CodigoDepartamento/>
|
||||
<mrw:UserName><%= mrw.user %></mrw:UserName>
|
||||
<mrw:Password><%= mrw.password %></mrw:Password>
|
||||
|
|
|
@ -6,7 +6,13 @@ module.exports = Self => {
|
|||
arg: 'shipmentId',
|
||||
type: 'string',
|
||||
required: true
|
||||
}],
|
||||
},
|
||||
{
|
||||
arg: 'clientType',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
],
|
||||
returns: {
|
||||
type: 'string',
|
||||
root: true
|
||||
|
@ -17,10 +23,14 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.getLabel = async shipmentId => {
|
||||
Self.getLabel = async(shipmentId, clientType) => {
|
||||
const mrw = await Self.getConfig();
|
||||
|
||||
const getLabelResponse = await Self.sendXmlDoc(__dirname + `/getLabel.ejs`, {mrw, shipmentId}, 'text/xml');
|
||||
const getLabelResponse = await Self.sendXmlDoc(
|
||||
__dirname + `/getLabel.ejs`,
|
||||
{mrw, shipmentId, clientType},
|
||||
'text/xml'
|
||||
);
|
||||
|
||||
return Self.getTextByTag(getLabelResponse, 'EtiquetaFile');
|
||||
};
|
||||
|
|
|
@ -40,15 +40,12 @@ describe('MRWConfig createShipment()', () => {
|
|||
|
||||
);
|
||||
|
||||
await models.MrwService.create(
|
||||
{'agencyModeCodeFk': 'mrw', 'clientType': '000001', 'serviceType': 105, 'kg': 10}
|
||||
);
|
||||
|
||||
await createMrwConfig();
|
||||
|
||||
await models.Application.rawSql(
|
||||
`INSERT INTO vn.mrwService
|
||||
SET agencyModeCodeFk = 'mrw',
|
||||
clientType = 1,
|
||||
serviceType = 1,
|
||||
kg = 1`, null
|
||||
);
|
||||
await models.Ticket.create(ticket1);
|
||||
await models.Expedition.create(expedition1);
|
||||
});
|
||||
|
@ -82,7 +79,8 @@ describe('MRWConfig createShipment()', () => {
|
|||
'user': 'user',
|
||||
'password': 'password',
|
||||
'franchiseCode': 'franchiseCode',
|
||||
'subscriberCode': 'subscriberCode'
|
||||
'subscriberCode': 'subscriberCode',
|
||||
'clientTypeWidth': 6
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -115,10 +113,10 @@ describe('MRWConfig createShipment()', () => {
|
|||
|
||||
it('should fail if expeditionFk is not a MrwExpedition', async() => {
|
||||
let error;
|
||||
await models.MrwConfig.createShipment(undefined).catch(e => {
|
||||
await models.MrwConfig.createShipment(15).catch(e => {
|
||||
error = e;
|
||||
}).finally(async() => {
|
||||
expect(error.message).toEqual(`This expedition is not a MRW shipment`);
|
||||
expect(error.message).toEqual(`ClientType not available`);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.renderer = async (expeditionFk) => {
|
||||
Self.renderer = async expeditionFk => {
|
||||
const models = Self.app.models;
|
||||
|
||||
const viaexpressConfig = await models.ViaexpressConfig.findOne({
|
||||
|
@ -109,7 +109,7 @@ module.exports = Self => {
|
|||
const ticket = expedition.ticket();
|
||||
const sender = ticket.company().client();
|
||||
const shipped = ticket.shipped.toISOString();
|
||||
const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk)
|
||||
const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk);
|
||||
const data = {
|
||||
viaexpressConfig,
|
||||
sender,
|
||||
|
|
|
@ -192,5 +192,8 @@
|
|||
},
|
||||
"RouteConfig": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"MrwService": {
|
||||
"dataSource": "vn"
|
||||
}
|
||||
}
|
|
@ -31,5 +31,30 @@ module.exports = Self => {
|
|||
});
|
||||
return parser.parseFromString(data.data, 'text/xml');
|
||||
};
|
||||
|
||||
Self.getClientType = async function(expeditionFk) {
|
||||
if (!expeditionFk) throw new UserError(`No expeditionFk defined`);
|
||||
|
||||
const {clientTypeWidth} = await Self.getConfig();
|
||||
const result = await Self.app.models.Expedition.findById(expeditionFk,
|
||||
{include: [{
|
||||
relation: 'ticket',
|
||||
scope: {
|
||||
include: {
|
||||
relation: 'agencyMode',
|
||||
scope: {
|
||||
include: {
|
||||
relation: 'mrwService',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}]}
|
||||
);
|
||||
const clientType = result?.ticket()?.agencyMode()?.mrwService()?.clientType;
|
||||
if (!clientType || !clientTypeWidth) throw new UserError(`ClientType not available`);
|
||||
|
||||
return clientType.toString().padStart(clientTypeWidth, '0');
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -45,6 +45,9 @@
|
|||
},
|
||||
"notified":{
|
||||
"type": "date"
|
||||
},
|
||||
"clientTypeWidth": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"name": "MrwService",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "mrwService"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"agencyModeCodeFk": {
|
||||
"id": true,
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
"clientType": {
|
||||
"type": "number",
|
||||
"required": true
|
||||
},
|
||||
"serviceType": {
|
||||
"type": "number"
|
||||
},
|
||||
"kg": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
"agency": {
|
||||
"type": "hasOne",
|
||||
"model": "AgencyMode",
|
||||
"foreignKey": "code"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -60,6 +60,11 @@
|
|||
"type": "hasMany",
|
||||
"model": "Zone",
|
||||
"foreignKey": "agencyModeFk"
|
||||
},
|
||||
"mrwService": {
|
||||
"type": "belongsTo",
|
||||
"model": "MrwService",
|
||||
"foreignKey": "code"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
|
|
Loading…
Reference in New Issue