Added permissions to role administrative #543

Merged
carlosjr merged 5 commits from 2782-Add_permisions_administrative_entry_module into dev 2021-02-12 16:01:44 +00:00
10 changed files with 88 additions and 31 deletions
Showing only changes of commit 1634c81682 - Show all commits

View File

@ -34,4 +34,5 @@ rules:
no-multiple-empty-lines: ["error", { "max": 1, "maxEOF": 1 }]
space-in-parens: ["error", "never"]
jasmine/no-focused-tests: 0
jasmine/prefer-toHaveBeenCalledWith: 0
jasmine/prefer-toHaveBeenCalledWith: 0
arrow-spacing: ["error", { "before": true, "after": true }]

View File

@ -150,20 +150,20 @@ INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `park
INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`code`)
VALUES
(1, 'CC y Polizas de crédito', NULL, NULL),
(2, 'Cash', NULL, 'cash'),
(3, 'Credit card', NULL, 'creditCard'),
(4, 'Finalcial lines', NULL, NULL),
(5, 'Other products', NULL, NULL),
(6, 'Loans', NULL, NULL),
(7, 'Leasing', NULL, NULL),
(8, 'Compensations', 'Compensations', 'Compensations');
(1, 'CC y Polizas de crédito', NULL, NULL),
(2, 'Cash', 'Cash', 'cash'),
(3, 'Credit card', 'Credit Card', 'creditCard'),
(4, 'Finalcial lines', NULL, NULL),
(5, 'Other products', NULL, NULL),
(6, 'Loans', NULL, NULL),
(7, 'Leasing', NULL, NULL),
(8, 'Compensations', 'Compensations', 'compensation');
INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`, `currencyFk`)
VALUES
(1, 'Pay on receipt', '0000000000', 3, 0, 1, 1),
(2, 'Cash', '1111111111', 2, 0, 1, 1),
(3, 'Compensation', '0000000000', 8, 0, 1, 1);
(1, 'Pay on receipt', '5720000001', 3, 0, 1, 1),
(2, 'Cash', '5700000001', 2, 0, 1, 1),
(3, 'Compensation', '4000000000', 8, 0, 1, 1);
INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`)
VALUES

View File

@ -171,5 +171,6 @@
"New ticket request has been created with price": "Se ha creado una nueva petición de compra *'{{description}}'* para el día *{{shipped}}*, con una cantidad de *{{quantity}}* y un precio de *{{price}} €*",
"New ticket request has been created": "Se ha creado una nueva petición de compra *'{{description}}'* para el día *{{shipped}}*, con una cantidad de *{{quantity}}*",
"That item doesn't exists": "Ese artículo no existe",
"There's a new urgent ticket": "Hay un nuevo ticket urgente: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})"
"There's a new urgent ticket": "Hay un nuevo ticket urgente: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})",
"Compensation account is empty": "La cuenta para compensar está vacia"
}

View File

@ -62,7 +62,10 @@ module.exports = function(Self) {
const bank = await models.Bank.findById(args.bankFk);
const accountingType = await models.AccountingType.findById(bank.accountingTypeFk);
if (args.compensationAccount) {
if (accountingType.code == 'compensation') {
if (!args.compensationAccount)
throw new UserError('Compensation account is empty');
const supplierCompensation = await models.Supplier.findOne({
where: {
account: args.compensationAccount
@ -92,12 +95,11 @@ module.exports = function(Self) {
],
options);
} else {
const description = `${clientOriginal.id} : ${clientOriginal.nickname} - ${accountingType.receiptDescription}`;
const description = `${clientOriginal.id} : ${clientOriginal.socialName} - ${accountingType.receiptDescription}`;
const [xdiarioNew] = await Self.rawSql(
`SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`,
`SELECT xdiario_new(?, CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`,
[
null,
Date(),
bank.account,
clientOriginal.accountingAccount,
description,
@ -114,10 +116,9 @@ module.exports = function(Self) {
options);
await Self.rawSql(
`SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
`SELECT xdiario_new(?, CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
[
xdiarioNew.ledger,
Date(),
clientOriginal.accountingAccount,
bank.account,
description,

View File

@ -38,6 +38,29 @@ describe('Client createReceipt', () => {
await till.destroy();
});
it('should throw Compensation account is empty', async() => {
const bankFk = 3;
let ctx = {
args: {
clientFk: clientFk,
payed: payed,
companyFk: companyFk,
bankFk: bankFk,
amountPaid: amountPaid,
description: description
}
};
try {
await app.models.Client.createReceipt(ctx);
} catch (e) {
error = e;
}
expect(error).toBeDefined();
expect(error.message).toEqual('Compensation account is empty');
});
it('should throw Invalid account if compensationAccount does not belongs to a client nor a supplier', async() => {
let error;
const bankFk = 3;

View File

@ -37,7 +37,7 @@ class Controller extends Component {
};
filter = encodeURIComponent(JSON.stringify(filter));
let query = `Clients?filter=${filter}`;
this.$http.get(query).then(res => {
this.$http.get(query).then(res=> {
if (res.data) {
let client = res.data[0];
let defaultAddress = client.defaultAddress;

View File

@ -101,7 +101,7 @@ module.exports = Self => {
if (!shipped && landed) {
const shippedResult = await models.Agency.getShipped(landed,
address.id, agencyModeId, warehouseId);
shipped = shippedResult && shippedResult.shipped;
shipped = (shippedResult && shippedResult.shipped) || landed;
}
if (shipped && !landed) {

View File

@ -2,12 +2,13 @@ const app = require('vn-loopback/server/server');
let UserError = require('vn-loopback/util/user-error');
describe('ticket new()', () => {
let ticket;
let ticketIdsToDelete = [];
let today = new Date();
let ctx = {req: {accessToken: {userId: 1}}};
afterAll(async done => {
await app.models.Ticket.destroyById(ticket.id);
for (id of ticketIdsToDelete)
await app.models.Ticket.destroyById(id);
done();
});
@ -28,7 +29,7 @@ describe('ticket new()', () => {
params.shipped,
params.landed,
params.warehouseId,
params.companyFk,
params.companyId,
params.addressId
).catch(e => {
error = e;
@ -53,7 +54,7 @@ describe('ticket new()', () => {
params.shipped,
params.landed,
params.warehouseId,
params.companyFk,
params.companyId,
params.addressId
).catch(response => {
expect(response.message).toEqual(`This address doesn't exist`);
@ -74,17 +75,44 @@ describe('ticket new()', () => {
agencyModeId: 1
};
ticket = await app.models.Ticket.new(ctx,
const ticket = await app.models.Ticket.new(ctx,
params.clientId,
params.shipped,
params.landed,
params.warehouseId,
params.companyFk,
params.companyId,
params.addressId,
params.agencyModeId);
let newestTicketIdInFixtures = 21;
ticketIdsToDelete.push(ticket.id);
expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures);
});
it('should return the set a shipped when the agency is not especified', async() => {
let params = {
clientId: 104,
landed: today,
shipped: null,
warehouseId: 2,
companyId: 442,
addressId: 4,
agencyModeId: null
};
const ticket = await app.models.Ticket.new(ctx,
params.clientId,
params.shipped,
params.landed,
params.warehouseId,
params.companyId,
params.addressId,
params.agencyModeId);
ticketIdsToDelete.push(ticket.id);
expect(ticket.shipped).toEqual(jasmine.any(Date));
});
});

View File

@ -39,7 +39,7 @@
</vn-autocomplete>
<vn-autocomplete
disabled="!$ctrl.clientId || !$ctrl.landed || !$ctrl.warehouseId"
data="$ctrl._availableAgencies"
data="$ctrl.agencies"
label="Agency"
show-field="agencyMode"
value-field="agencyModeFk"

View File

@ -100,9 +100,12 @@ class Controller extends Component {
ticket.agencyModeFk = null;
this.$http.get(`Agencies/getAgenciesWithWarehouse`, {params}).then(res => {
this._availableAgencies = res.data;
this.agencyModeId = this.defaultAddress.agencyModeFk;
this.agencies = res.data;
const defaultAgency = this.agencies.find(agency=> {
return agency.agencyModeFk == this.defaultAddress.agencyModeFk;
});
if (defaultAgency)
this.agencyModeId = defaultAgency.agencyModeFk;
});
}
}