WIP: a falta de e2e
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
c14e13a2e6
commit
4aea284703
|
@ -0,0 +1,9 @@
|
|||
ALTER TABLE `vn`.`observationType`
|
||||
ADD COLUMN `code` VARCHAR(45) NOT NULL AFTER `description`;
|
||||
|
||||
UPDATE `vn`.`observationType` SET `code` = 'itemPicker' WHERE (`id` = '1');
|
||||
UPDATE `vn`.`observationType` SET `code` = 'packager' WHERE (`id` = '2');
|
||||
UPDATE `vn`.`observationType` SET `code` = 'salesPerson' WHERE (`id` = '4');
|
||||
UPDATE `vn`.`observationType` SET `code` = 'administrative' WHERE (`id` = '5');
|
||||
UPDATE `vn`.`observationType` SET `code` = 'weight' WHERE (`id` = '6');
|
||||
UPDATE `vn`.`observationType` SET `code` = 'delivery' WHERE (`id` = '3');
|
|
@ -154,7 +154,8 @@ module.exports = function(Self) {
|
|||
const showFieldNames = [
|
||||
'name',
|
||||
'description',
|
||||
'code'
|
||||
'code',
|
||||
'nickname'
|
||||
];
|
||||
for (field of showFieldNames) {
|
||||
const propField = properties && properties[field];
|
||||
|
|
|
@ -4,7 +4,7 @@ module.exports = function(Self) {
|
|||
Self.remoteMethodCtx('createAddress', {
|
||||
description: 'Creates client address updating default address',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
arg: 'clientFk',
|
||||
type: 'number',
|
||||
description: 'The client id',
|
||||
http: {source: 'path'}
|
||||
|
@ -37,19 +37,19 @@ module.exports = function(Self) {
|
|||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'provinceId',
|
||||
arg: 'provinceFk',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'agencyModeId',
|
||||
arg: 'agencyModeFk',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'incotermsId',
|
||||
arg: 'incotermsFk',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'customsAgentId',
|
||||
arg: 'customsAgentFk',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
|
@ -66,44 +66,33 @@ module.exports = function(Self) {
|
|||
},
|
||||
http: {
|
||||
verb: 'post',
|
||||
path: '/:id/createAddress'
|
||||
path: '/:clientFk/createAddress'
|
||||
}
|
||||
});
|
||||
|
||||
Self.createAddress = async(ctx, clientId) => {
|
||||
Self.createAddress = async(ctx, clientFk) => {
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
const tx = await models.Address.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const province = await models.Province.findById(args.provinceId, {
|
||||
const province = await models.Province.findById(args.provinceFk, {
|
||||
include: {
|
||||
relation: 'country'
|
||||
}
|
||||
}, options);
|
||||
|
||||
const isUeeMember = province.country().isUeeMember;
|
||||
if (!isUeeMember && !args.incotermsId)
|
||||
if (!isUeeMember && !args.incotermsFk)
|
||||
throw new UserError(`Incoterms is required for a non UEE member`);
|
||||
|
||||
if (!isUeeMember && !args.customsAgentId)
|
||||
if (!isUeeMember && !args.customsAgentFk)
|
||||
throw new UserError(`Customs agent is required for a non UEE member`);
|
||||
|
||||
const newAddress = await models.Address.create({
|
||||
clientFk: clientId,
|
||||
nickname: args.nickname,
|
||||
incotermsFk: args.incotermsId,
|
||||
customsAgentFk: args.customsAgentId,
|
||||
city: args.city,
|
||||
street: args.street,
|
||||
phone: args.phone,
|
||||
postalCode: args.postalCode,
|
||||
provinceFk: args.provinceId,
|
||||
agencyModeFk: args.agencyModeId,
|
||||
isActive: args.isActive
|
||||
}, options);
|
||||
const client = await Self.findById(clientId, null, options);
|
||||
delete args.ctx; // Remove unwanted properties
|
||||
const newAddress = await models.Address.create(args, options);
|
||||
const client = await Self.findById(clientFk, null, options);
|
||||
|
||||
if (args.isDefaultAddress) {
|
||||
await client.updateAttributes({
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('Address createAddress', () => {
|
||||
const clientId = 101;
|
||||
const provinceId = 5;
|
||||
const incotermsId = 'FAS';
|
||||
const clientFk = 101;
|
||||
const provinceFk = 5;
|
||||
const incotermsFk = 'FAS';
|
||||
const customAgentOneId = 1;
|
||||
|
||||
it('should throw a non uee member error if no incoterms is defined', async() => {
|
||||
const expectedResult = 'My edited address';
|
||||
const ctx = {
|
||||
args: {
|
||||
provinceId: provinceId,
|
||||
provinceFk: provinceFk,
|
||||
nickname: expectedResult,
|
||||
street: 'Wall Street',
|
||||
city: 'New York',
|
||||
customsAgentId: customAgentOneId
|
||||
customsAgentFk: customAgentOneId
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
await app.models.Client.createAddress(ctx, clientId);
|
||||
await app.models.Client.createAddress(ctx, clientFk);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
@ -32,16 +32,16 @@ describe('Address createAddress', () => {
|
|||
const expectedResult = 'My edited address';
|
||||
const ctx = {
|
||||
args: {
|
||||
provinceId: provinceId,
|
||||
provinceFk: provinceFk,
|
||||
nickname: expectedResult,
|
||||
street: 'Wall Street',
|
||||
city: 'New York',
|
||||
incotermsId: incotermsId
|
||||
incotermsFk: incotermsFk
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
await app.models.Client.createAddress(ctx, clientId);
|
||||
await app.models.Client.createAddress(ctx, clientFk);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ describe('Address createAddress', () => {
|
|||
});
|
||||
|
||||
it('should verify that client defaultAddressFk is untainted', async() => {
|
||||
const client = await app.models.Client.findById(clientId);
|
||||
const client = await app.models.Client.findById(clientFk);
|
||||
|
||||
expect(client.defaultAddressFk).toEqual(1);
|
||||
});
|
||||
|
@ -59,18 +59,23 @@ describe('Address createAddress', () => {
|
|||
it('should create a new address and set as a client default address', async() => {
|
||||
const ctx = {
|
||||
args: {
|
||||
provinceId: 1,
|
||||
clientFk: 101,
|
||||
provinceFk: 1,
|
||||
nickname: 'My address',
|
||||
street: 'Wall Street',
|
||||
city: 'New York',
|
||||
incotermsId: incotermsId,
|
||||
customsAgentId: customAgentOneId,
|
||||
phone: 678678678,
|
||||
mobile: 678678678,
|
||||
postalCode: 46680,
|
||||
agencyModeFk: 1,
|
||||
incotermsFk: incotermsFk,
|
||||
customsAgentFk: customAgentOneId,
|
||||
isDefaultAddress: true
|
||||
}
|
||||
};
|
||||
|
||||
const address = await app.models.Client.createAddress(ctx, clientId);
|
||||
const client = await app.models.Client.findById(clientId);
|
||||
const address = await app.models.Client.createAddress(ctx, clientFk);
|
||||
const client = await app.models.Client.findById(clientFk);
|
||||
|
||||
expect(client.defaultAddressFk).toEqual(address.id);
|
||||
|
||||
|
@ -78,4 +83,31 @@ describe('Address createAddress', () => {
|
|||
await client.updateAttributes({defaultAddressFk: 1});
|
||||
await address.destroy();
|
||||
});
|
||||
|
||||
it('should create a new address and set all properties', async() => {
|
||||
const ctx = {
|
||||
args: {
|
||||
clientFk: 101,
|
||||
provinceFk: 1,
|
||||
nickname: 'My address',
|
||||
street: 'Wall Street',
|
||||
city: 'New York',
|
||||
phone: '678678678',
|
||||
mobile: '678678678',
|
||||
postalCode: '46680',
|
||||
agencyModeFk: 1,
|
||||
incotermsFk: incotermsFk,
|
||||
customsAgentFk: customAgentOneId,
|
||||
isDefaultAddress: true
|
||||
}
|
||||
};
|
||||
|
||||
address = await app.models.Client.createAddress(ctx, clientFk);
|
||||
|
||||
expect(address.__data).toEqual(jasmine.objectContaining(ctx.args));
|
||||
// restores
|
||||
const client = await app.models.Client.findById(clientFk);
|
||||
await client.updateAttributes({defaultAddressFk: 1});
|
||||
await address.destroy();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
</vn-datalist>
|
||||
<vn-autocomplete vn-id="province" vn-one
|
||||
label="Province"
|
||||
ng-model="$ctrl.address.provinceId"
|
||||
ng-model="$ctrl.address.provinceFk"
|
||||
data="provincesLocation"
|
||||
fields="['id', 'name', 'countryFk']"
|
||||
show-field="name"
|
||||
|
@ -100,7 +100,7 @@
|
|||
<vn-horizontal>
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
ng-model="$ctrl.address.agencyModeId"
|
||||
ng-model="$ctrl.address.agencyModeFk"
|
||||
url="AgencyModes/isActive"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
|
@ -121,14 +121,14 @@
|
|||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete vn-one
|
||||
ng-model="$ctrl.address.incotermsId"
|
||||
ng-model="$ctrl.address.incotermsFk"
|
||||
data="incoterms"
|
||||
show-field="name"
|
||||
value-field="code"
|
||||
label="Incoterms">
|
||||
</vn-autocomplete>
|
||||
<vn-autocomplete vn-one
|
||||
ng-model="$ctrl.address.customsAgentId"
|
||||
ng-model="$ctrl.address.customsAgentFk"
|
||||
data="customsAgents"
|
||||
show-field="fiscalName"
|
||||
value-field="id"
|
||||
|
|
|
@ -29,7 +29,7 @@ export default class Controller extends Section {
|
|||
|
||||
onCustomAgentAccept() {
|
||||
return this.$http.post(`CustomsAgents`, this.newCustomsAgent)
|
||||
.then(res => this.address.customsAgentId = res.data.id);
|
||||
.then(res => this.address.customsAgentFk = res.data.id);
|
||||
}
|
||||
|
||||
get town() {
|
||||
|
@ -45,8 +45,8 @@ export default class Controller extends Section {
|
|||
const province = selection.province;
|
||||
const postcodes = selection.postcodes;
|
||||
|
||||
if (!this.address.provinceI)
|
||||
this.address.provinceId = province.id;
|
||||
if (!this.address.provinceFk)
|
||||
this.address.provinceFk = province.id;
|
||||
|
||||
if (postcodes.length === 1)
|
||||
this.address.postalCode = postcodes[0].code;
|
||||
|
@ -68,8 +68,8 @@ export default class Controller extends Section {
|
|||
if (!this.address.city)
|
||||
this.address.city = town.name;
|
||||
|
||||
if (!this.address.provinceId)
|
||||
this.address.provinceId = province.id;
|
||||
if (!this.address.provinceFk)
|
||||
this.address.provinceFk = province.id;
|
||||
}
|
||||
|
||||
onResponse(response) {
|
||||
|
|
|
@ -54,7 +54,7 @@ describe('Client', () => {
|
|||
});
|
||||
|
||||
describe('town() setter', () => {
|
||||
it(`should set provinceId property`, () => {
|
||||
it(`should set provinceFk property`, () => {
|
||||
controller.town = {
|
||||
provinceFk: 1,
|
||||
code: 46001,
|
||||
|
@ -69,10 +69,10 @@ describe('Client', () => {
|
|||
postcodes: []
|
||||
};
|
||||
|
||||
expect(controller.address.provinceId).toEqual(1);
|
||||
expect(controller.address.provinceFk).toEqual(1);
|
||||
});
|
||||
|
||||
it(`should set provinceId property and fill the postalCode if there's just one`, () => {
|
||||
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
|
||||
controller.town = {
|
||||
provinceFk: 1,
|
||||
code: 46001,
|
||||
|
@ -87,7 +87,7 @@ describe('Client', () => {
|
|||
postcodes: [{code: '46001'}]
|
||||
};
|
||||
|
||||
expect(controller.address.provinceId).toEqual(1);
|
||||
expect(controller.address.provinceFk).toEqual(1);
|
||||
expect(controller.address.postalCode).toEqual('46001');
|
||||
});
|
||||
});
|
||||
|
@ -112,7 +112,7 @@ describe('Client', () => {
|
|||
};
|
||||
|
||||
expect(controller.address.city).toEqual('New York');
|
||||
expect(controller.address.provinceId).toEqual(1);
|
||||
expect(controller.address.provinceFk).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -123,7 +123,7 @@ describe('Client', () => {
|
|||
controller.onCustomAgentAccept();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.address.customsAgentId).toEqual(1);
|
||||
expect(controller.address.customsAgentFk).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -190,8 +190,6 @@ module.exports = Self => {
|
|||
item.prices.push(price);
|
||||
else
|
||||
item.prices = [price];
|
||||
|
||||
item.available = price.grouping;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -88,9 +88,29 @@ module.exports = Self => {
|
|||
if (!zoneShipped || zoneShipped.zoneFk != zoneFk)
|
||||
throw new UserError(`You don't have privileges to change the zone`);
|
||||
}
|
||||
const originalTicket = await models.Ticket.findById(id, {fields:
|
||||
['id', 'clientFk', 'agencyModeFk', 'addressFk', 'zoneFk',
|
||||
'warehouseFk', 'companyFk', 'shipped', 'landed', 'isDeleted']
|
||||
const observationTypeDelivery = await models.ObservationType.findOne({
|
||||
where: {code: 'delivery'}
|
||||
});
|
||||
const originalTicket = await models.Ticket.findOne({
|
||||
where: {id: id},
|
||||
fields: ['id', 'clientFk', 'agencyModeFk', 'addressFk', 'zoneFk',
|
||||
'warehouseFk', 'companyFk', 'shipped', 'landed', 'isDeleted'],
|
||||
include: [
|
||||
{
|
||||
relation: 'address',
|
||||
scope: {
|
||||
include: {
|
||||
relation: 'observations',
|
||||
scope: {
|
||||
where: {observationTypeFk: observationTypeDelivery.id},
|
||||
include: {
|
||||
relation: 'observationType'
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
});
|
||||
const updatedTicket = Object.assign({}, ctx.args);
|
||||
delete updatedTicket.ctx;
|
||||
|
@ -125,6 +145,25 @@ module.exports = Self => {
|
|||
option
|
||||
]);
|
||||
|
||||
if (originalTicket.addressFk != updatedTicket.addressFk) {
|
||||
const ticketObservation = await models.TicketObservation.findOne({
|
||||
where: {
|
||||
ticketFk: id,
|
||||
observationTypeFk: observationTypeDelivery.id}
|
||||
});
|
||||
|
||||
if (ticketObservation)
|
||||
await ticketObservation.destroy();
|
||||
|
||||
const [observation] = originalTicket.address().observations();
|
||||
if (observation) {
|
||||
await models.TicketObservation.upsert({
|
||||
ticketFk: id,
|
||||
observationTypeFk: observation.observationTypeFk,
|
||||
description: observation.description
|
||||
});
|
||||
}
|
||||
}
|
||||
await models.TicketLog.create(logRecord);
|
||||
return res;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue