diff --git a/back/methods/dms/deleteTrashFiles.js b/back/methods/dms/deleteTrashFiles.js
index 6f9a2a211..828f9658c 100644
--- a/back/methods/dms/deleteTrashFiles.js
+++ b/back/methods/dms/deleteTrashFiles.js
@@ -17,61 +17,50 @@ module.exports = Self => {
});
Self.deleteTrashFiles = async options => {
- let tx;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
- if (!myOptions.transaction) {
- tx = await Self.beginTransaction({});
- myOptions.transaction = tx;
- }
+ if (process.env.NODE_ENV == 'test')
+ throw new UserError(`Action not allowed on the test environment`);
- try {
- if (process.env.NODE_ENV == 'test')
- throw new UserError(`Action not allowed on the test environment`);
+ const models = Self.app.models;
+ const DmsContainer = models.DmsContainer;
- const models = Self.app.models;
- const DmsContainer = models.DmsContainer;
+ const trashDmsType = await models.DmsType.findOne({
+ where: {code: 'trash'}
+ }, myOptions);
- const trashDmsType = await models.DmsType.findOne({
- where: {code: 'trash'}
- }, myOptions);
+ const date = new Date();
+ date.setMonth(date.getMonth() - 4);
- const date = new Date();
- date.setMonth(date.getMonth() - 4);
-
- const dmsToDelete = await models.Dms.find({
- where: {
- and: [
- {dmsTypeFk: trashDmsType.id},
- {created: {lt: date}}
- ]
- }
- }, myOptions);
-
- for (let dms of dmsToDelete) {
- const pathHash = DmsContainer.getHash(dms.id);
- const dmsContainer = await DmsContainer.container(pathHash);
- const dstFile = path.join(dmsContainer.client.root, pathHash, dms.file);
- try {
- await fs.unlink(dstFile);
- } catch (err) {
- continue;
- }
- const dstFolder = path.join(dmsContainer.client.root, pathHash);
- try {
- await fs.rmdir(dstFolder);
- } catch (err) {}
-
- await dms.destroy(myOptions);
+ const dmsToDelete = await models.Dms.find({
+ where: {
+ and: [
+ {dmsTypeFk: trashDmsType.id},
+ {created: {lt: date}}
+ ]
}
- if (tx) await tx.commit();
- } catch (e) {
- if (tx) await tx.rollback();
+ }, myOptions);
- throw e;
+ for (let dms of dmsToDelete) {
+ const pathHash = DmsContainer.getHash(dms.id);
+ const dmsContainer = await DmsContainer.container(pathHash);
+ const dstFile = path.join(dmsContainer.client.root, pathHash, dms.file);
+ try {
+ await fs.unlink(dstFile);
+ } catch (err) {
+ continue;
+ }
+ const dstFolder = path.join(dmsContainer.client.root, pathHash);
+ try {
+ await fs.rmdir(dstFolder);
+ } catch (err) {
+ continue;
+ }
+
+ await dms.destroy(myOptions);
}
};
};
diff --git a/db/changes/10490-august/00-acl_receiptPdf.sql b/db/changes/10490-august/00-acl_receiptPdf.sql
new file mode 100644
index 000000000..42f84b87d
--- /dev/null
+++ b/db/changes/10490-august/00-acl_receiptPdf.sql
@@ -0,0 +1,3 @@
+INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
+ VALUES
+ ('Receipt', 'receiptPdf', '*', 'ALLOW', 'ROLE', 'salesAssistant');
diff --git a/db/changes/10491-august/00-defaultPayDem_sameAs_production.sql b/db/changes/10491-august/00-defaultPayDem_sameAs_production.sql
new file mode 100644
index 000000000..294247338
--- /dev/null
+++ b/db/changes/10491-august/00-defaultPayDem_sameAs_production.sql
@@ -0,0 +1,2 @@
+INSERT INTO `vn`.`payDem` (id,payDem)
+ VALUES (7,'0');
diff --git a/db/changes/10491-august/00-newSupplier_ACL.sql b/db/changes/10491-august/00-newSupplier_ACL.sql
new file mode 100644
index 000000000..c88f3de3f
--- /dev/null
+++ b/db/changes/10491-august/00-newSupplier_ACL.sql
@@ -0,0 +1,2 @@
+INSERT INTO `salix`.`ACL` (model,property,accessType,principalId)
+ VALUES ('Supplier','newSupplier','WRITE','administrative');
diff --git a/db/changes/10491-august/00-payMethodFk_Allow_Null.sql b/db/changes/10491-august/00-payMethodFk_Allow_Null.sql
new file mode 100644
index 000000000..6d9931d3c
--- /dev/null
+++ b/db/changes/10491-august/00-payMethodFk_Allow_Null.sql
@@ -0,0 +1 @@
+ALTER TABLE `vn`.`supplier` MODIFY COLUMN payMethodFk tinyint(3) unsigned NULL;
\ No newline at end of file
diff --git a/db/changes/10491-august/00-supplierActivityFk_Allow_Null.sql b/db/changes/10491-august/00-supplierActivityFk_Allow_Null.sql
new file mode 100644
index 000000000..62aac0556
--- /dev/null
+++ b/db/changes/10491-august/00-supplierActivityFk_Allow_Null.sql
@@ -0,0 +1 @@
+ALTER TABLE `vn`.`supplier` MODIFY COLUMN supplierActivityFk varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL;
\ No newline at end of file
diff --git a/db/changes/10491-august/ticket_closeByTicket.sql b/db/changes/10491-august/00-ticket_closeByTicket.sql
similarity index 85%
rename from db/changes/10491-august/ticket_closeByTicket.sql
rename to db/changes/10491-august/00-ticket_closeByTicket.sql
index 25b04f629..f378b1146 100644
--- a/db/changes/10491-august/ticket_closeByTicket.sql
+++ b/db/changes/10491-august/00-ticket_closeByTicket.sql
@@ -1,7 +1,9 @@
drop procedure `vn`.`ticket_closeByTicket`;
+DELIMITER $$
+$$
create
- definer = root@localhost procedure `vn`.`ticket_closeByTicket`(IN vTicketFk int)
+ definer = `root`@`localhost` procedure `vn`.`ticket_closeByTicket`(IN vTicketFk int)
BEGIN
/**
@@ -27,5 +29,7 @@ BEGIN
CALL ticket_close();
DROP TEMPORARY TABLE tmp.ticket_close;
-END;
+END$$
+DELIMITER ;
+
diff --git a/db/changes/10491-august/delete.keep b/db/changes/10491-august/delete.keep
deleted file mode 100644
index e69de29bb..000000000
diff --git a/db/changes/10500-november/00-ACL.sql b/db/changes/10500-november/00-ACL.sql
new file mode 100644
index 000000000..0b726538c
--- /dev/null
+++ b/db/changes/10500-november/00-ACL.sql
@@ -0,0 +1,5 @@
+INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
+VALUES
+ ('ClaimRma', '*', 'READ', 'ALLOW', 'ROLE', 'claimManager'),
+ ('ClaimRma', '*', 'WRITE', 'ALLOW', 'ROLE', 'claimManager');
+
diff --git a/db/changes/10500-november/00-claim.sql b/db/changes/10500-november/00-claim.sql
new file mode 100644
index 000000000..0b9879878
--- /dev/null
+++ b/db/changes/10500-november/00-claim.sql
@@ -0,0 +1 @@
+ALTER TABLE `vn`.`claim` ADD rma varchar(100) NULL ;
\ No newline at end of file
diff --git a/db/changes/10500-november/00-claimRma.sql b/db/changes/10500-november/00-claimRma.sql
new file mode 100644
index 000000000..91e1ebaba
--- /dev/null
+++ b/db/changes/10500-november/00-claimRma.sql
@@ -0,0 +1,7 @@
+CREATE TABLE `vn`.`claimRma` (
+ id INT UNSIGNED auto_increment NOT NULL PRIMARY KEY,
+ code varchar(100) NOT NULL,
+ created timestamp DEFAULT current_timestamp() NOT NULL,
+ workerFk INTEGER UNSIGNED NOT NULL
+)
+ENGINE=InnoDB;
diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql
index 7e59c1a54..5b769e285 100644
--- a/db/dump/fixtures.sql
+++ b/db/dump/fixtures.sql
@@ -1380,13 +1380,6 @@ INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed
(7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'Movement 7', 0, 0, 'this is the note seven', 'observation seven'),
(8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'Movement 8', 1, 1, '', '');
-INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`)
- VALUES
- (1101, 500, NULL, 0.00, 0.00, 1.00),
- (1102, 1000, 2.00, 0.01, 0.05, 1.00),
- (1103, 2000, 0.00, 0.00, 0.02, 1.00),
- (1104, 2500, 150.00, 0.02, 0.10, 1.00);
-
INSERT INTO `bs`.`waste`(`buyer`, `year`, `week`, `family`, `itemFk`, `itemTypeFk`, `saleTotal`, `saleWaste`, `rate`)
VALUES
('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation', 1, 1, '1062', '51', '4.8'),
@@ -1743,12 +1736,12 @@ INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`,
( 6, 'mana', 'Mana', 1, 4, 0),
( 7, 'lack', 'Faltas', 1, 2, 0);
-INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`)
+INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `rma`)
VALUES
- (1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0),
- (2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1),
- (3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5),
- (4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10);
+ (1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, '02676A049183'),
+ (2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1, NULL),
+ (3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, NULL),
+ (4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, NULL);
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`)
VALUES
@@ -1790,6 +1783,23 @@ INSERT INTO `vn`.`claimConfig`(`id`, `pickupContact`, `maxResponsibility`)
(1, 'Contact description', 50),
(2, 'Contact description', 30);
+INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`)
+ VALUES
+ (1101, 500, NULL, 0.00, 0.00, 1.00),
+ (1102, 1000, 2.00, 0.01, 0.05, 1.00),
+ (1103, 2000, 0.00, 0.00, 0.02, 1.00),
+ (1104, 2500, 150.00, 0.02, 0.10, 1.00);
+
+INSERT INTO vn.claimRma (`id`, `code`, `created`, `workerFk`)
+VALUES
+ (1, '02676A049183', DEFAULT, 1106),
+ (2, '02676A049183', DEFAULT, 1106),
+ (3, '02676A049183', DEFAULT, 1107),
+ (4, '02676A049183', DEFAULT, 1107),
+ (5, '01837B023653', DEFAULT, 1106);
+
+
+
INSERT INTO `hedera`.`tpvMerchant`(`id`, `description`, `companyFk`, `bankFk`, `secretKey`)
VALUES
(1, 'Arkham Bank', 442, 1, 'h12387193H10238'),
diff --git a/e2e/paths/13-supplier/03_fiscal_data.spec.js b/e2e/paths/13-supplier/03_fiscal_data.spec.js
index 0238c8704..4f9581e32 100644
--- a/e2e/paths/13-supplier/03_fiscal_data.spec.js
+++ b/e2e/paths/13-supplier/03_fiscal_data.spec.js
@@ -31,7 +31,7 @@ describe('Supplier fiscal data path', () => {
await page.clearInput(selectors.supplierFiscalData.taxNumber);
await page.write(selectors.supplierFiscalData.taxNumber, 'Wrong tax number');
await page.clearInput(selectors.supplierFiscalData.account);
- await page.write(selectors.supplierFiscalData.account, 'edited account number');
+ await page.write(selectors.supplierFiscalData.account, '0123456789');
await page.autocompleteSearch(selectors.supplierFiscalData.sageWihholding, 'retencion estimacion objetiva');
await page.autocompleteSearch(selectors.supplierFiscalData.sageTaxType, 'operaciones no sujetas');
@@ -70,7 +70,7 @@ describe('Supplier fiscal data path', () => {
it('should check the account was edited', async() => {
const result = await page.waitToGetProperty(selectors.supplierFiscalData.account, 'value');
- expect(result).toEqual('edited account number');
+ expect(result).toEqual('0123456789');
});
it('should check the sageWihholding was edited', async() => {
diff --git a/modules/claim/back/methods/claim/getSummary.js b/modules/claim/back/methods/claim/getSummary.js
index 8ab39eb45..ca376f853 100644
--- a/modules/claim/back/methods/claim/getSummary.js
+++ b/modules/claim/back/methods/claim/getSummary.js
@@ -47,7 +47,7 @@ module.exports = Self => {
{
relation: 'claimState',
scope: {
- fields: ['id', 'description']
+ fields: ['id', 'code', 'description']
}
},
{
diff --git a/modules/claim/back/model-config.json b/modules/claim/back/model-config.json
index e99a455ac..83d88039c 100644
--- a/modules/claim/back/model-config.json
+++ b/modules/claim/back/model-config.json
@@ -2,6 +2,9 @@
"Claim": {
"dataSource": "vn"
},
+ "ClaimContainer": {
+ "dataSource": "claimStorage"
+ },
"ClaimBeginning": {
"dataSource": "vn"
},
@@ -41,7 +44,7 @@
"ClaimObservation": {
"dataSource": "vn"
},
- "ClaimContainer": {
- "dataSource": "claimStorage"
- }
+ "ClaimRma": {
+ "dataSource": "vn"
+ }
}
diff --git a/modules/claim/back/models/claim-rma.js b/modules/claim/back/models/claim-rma.js
new file mode 100644
index 000000000..6a93613bd
--- /dev/null
+++ b/modules/claim/back/models/claim-rma.js
@@ -0,0 +1,9 @@
+const LoopBackContext = require('loopback-context');
+
+module.exports = Self => {
+ Self.observe('before save', async function(ctx) {
+ const changes = ctx.data || ctx.instance;
+ const loopBackContext = LoopBackContext.getCurrentContext();
+ changes.workerFk = loopBackContext.active.accessToken.userId;
+ });
+};
diff --git a/modules/claim/back/models/claim-rma.json b/modules/claim/back/models/claim-rma.json
new file mode 100644
index 000000000..e3849422c
--- /dev/null
+++ b/modules/claim/back/models/claim-rma.json
@@ -0,0 +1,30 @@
+{
+ "name": "ClaimRma",
+ "base": "VnModel",
+ "options": {
+ "mysql": {
+ "table": "claimRma"
+ }
+ },
+ "properties": {
+ "id": {
+ "type": "number",
+ "id": true,
+ "description": "Identifier"
+ },
+ "code": {
+ "type": "string",
+ "required": true
+ },
+ "created": {
+ "type": "date"
+ }
+ },
+ "relations": {
+ "worker": {
+ "type": "belongsTo",
+ "model": "Worker",
+ "foreignKey": "workerFk"
+ }
+ }
+}
diff --git a/modules/claim/back/models/claim.json b/modules/claim/back/models/claim.json
index a3490ccf4..76125c483 100644
--- a/modules/claim/back/models/claim.json
+++ b/modules/claim/back/models/claim.json
@@ -46,6 +46,9 @@
},
"packages": {
"type": "number"
+ },
+ "rma": {
+ "type": "string"
}
},
"relations": {
@@ -54,6 +57,12 @@
"model": "ClaimState",
"foreignKey": "claimStateFk"
},
+ "claimRma": {
+ "type": "belongsTo",
+ "model": "ClaimRma",
+ "foreignKey": "rma",
+ "primaryKey": "code"
+ },
"client": {
"type": "belongsTo",
"model": "Client",
diff --git a/modules/client/back/methods/client/checkDuplicated.js b/modules/client/back/methods/client/checkDuplicated.js
index acaffbf42..522cd088f 100644
--- a/modules/client/back/methods/client/checkDuplicated.js
+++ b/modules/client/back/methods/client/checkDuplicated.js
@@ -25,10 +25,9 @@ module.exports = Self => {
const client = await Self.app.models.Client.findById(id, myOptions);
- const emails = client.email ? client.email.split(',') : null;
-
const findParams = [];
- if (emails.length) {
+ if (client.email) {
+ const emails = client.email.split(',');
for (let email of emails)
findParams.push({email: email});
}
diff --git a/modules/client/back/methods/receipt/receiptPdf.js b/modules/client/back/methods/receipt/receiptPdf.js
new file mode 100644
index 000000000..f55e05040
--- /dev/null
+++ b/modules/client/back/methods/receipt/receiptPdf.js
@@ -0,0 +1,55 @@
+const {Report} = require('vn-print');
+
+module.exports = Self => {
+ Self.remoteMethodCtx('receiptPdf', {
+ description: 'Returns the receipt pdf',
+ accepts: [
+ {
+ arg: 'id',
+ type: 'number',
+ required: true,
+ description: 'The claim id',
+ http: {source: 'path'}
+ },
+ {
+ arg: 'recipientId',
+ type: 'number',
+ description: 'The recipient id',
+ required: false
+ }
+ ],
+ returns: [
+ {
+ arg: 'body',
+ type: 'file',
+ root: true
+ }, {
+ arg: 'Content-Type',
+ type: 'String',
+ http: {target: 'header'}
+ }, {
+ arg: 'Content-Disposition',
+ type: 'String',
+ http: {target: 'header'}
+ }
+ ],
+ http: {
+ path: '/:id/receipt-pdf',
+ verb: 'GET'
+ }
+ });
+
+ Self.receiptPdf = async(ctx, id) => {
+ const args = Object.assign({}, ctx.args);
+ const params = {lang: ctx.req.getLocale()};
+
+ delete args.ctx;
+ for (const param in args)
+ params[param] = args[param];
+
+ const report = new Report('receipt', params);
+ const stream = await report.toPdfStream();
+
+ return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
+ };
+};
diff --git a/modules/client/back/models/receipt.js b/modules/client/back/models/receipt.js
index 36a4a8952..b79102e6b 100644
--- a/modules/client/back/models/receipt.js
+++ b/modules/client/back/models/receipt.js
@@ -2,6 +2,7 @@ const LoopBackContext = require('loopback-context');
module.exports = function(Self) {
require('../methods/receipt/filter')(Self);
+ require('../methods/receipt/receiptPdf')(Self);
Self.validateBinded('amountPaid', isNotZero, {
message: 'Amount cannot be zero',
diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js
index c6a6e7ff9..935129574 100644
--- a/modules/client/front/balance/create/index.js
+++ b/modules/client/front/balance/create/index.js
@@ -144,12 +144,8 @@ class Controller extends Dialog {
})
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
.then(() => {
- if (this.viewReceipt) {
- this.vnReport.show('receipt', {
- receiptId: receiptId,
- companyId: this.companyFk
- });
- }
+ if (this.viewReceipt)
+ this.vnReport.show(`Receipts/${receiptId}/receipt-pdf`);
});
}
diff --git a/modules/client/front/balance/create/index.spec.js b/modules/client/front/balance/create/index.spec.js
index 77fe32e0f..fa6b48ea4 100644
--- a/modules/client/front/balance/create/index.spec.js
+++ b/modules/client/front/balance/create/index.spec.js
@@ -85,6 +85,8 @@ describe('Client', () => {
});
it('should make an http POST query and then call to the report show() method', () => {
+ const receiptId = 1;
+
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.vnReport, 'show');
window.open = jest.fn();
@@ -92,14 +94,12 @@ describe('Client', () => {
controller.$params = {id: 1101};
controller.viewReceipt = true;
- $httpBackend.expect('POST', `Clients/1101/createReceipt`).respond({id: 1});
+ $httpBackend.expect('POST', `Clients/1101/createReceipt`).respond({id: receiptId});
controller.responseHandler('accept');
$httpBackend.flush();
- const expectedParams = {receiptId: 1, companyId: 442};
-
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
- expect(controller.vnReport.show).toHaveBeenCalledWith('receipt', expectedParams);
+ expect(controller.vnReport.show).toHaveBeenCalledWith(`Receipts/${receiptId}/receipt-pdf`);
});
});
diff --git a/modules/route/back/methods/route/driverRoutePdf.js b/modules/route/back/methods/route/driverRoutePdf.js
index 161eb71af..65748afad 100644
--- a/modules/route/back/methods/route/driverRoutePdf.js
+++ b/modules/route/back/methods/route/driverRoutePdf.js
@@ -6,9 +6,9 @@ module.exports = Self => {
accepts: [
{
arg: 'id',
- type: 'number',
+ type: 'string',
required: true,
- description: 'The client id',
+ description: 'The route id',
http: {source: 'path'}
},
{
diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js
index 6845bf73f..9258c8fac 100644
--- a/modules/route/front/index/index.js
+++ b/modules/route/front/index/index.js
@@ -39,10 +39,7 @@ export default class Controller extends Section {
routes.push(route.id);
const routesId = routes.join(',');
- this.vnReport.show('driver-route', {
- authorization: this.vnToken.token,
- routeId: routesId
- });
+ this.vnReport.show(`Routes/${routesId}/driver-route-pdf`);
}
openClonationDialog() {
diff --git a/modules/route/front/index/index.spec.js b/modules/route/front/index/index.spec.js
index 37386bc38..05dd56433 100644
--- a/modules/route/front/index/index.spec.js
+++ b/modules/route/front/index/index.spec.js
@@ -49,14 +49,12 @@ describe('Component vnRouteIndex', () => {
const data = controller.$.model.data;
data[0].checked = true;
data[2].checked = true;
- const expectedParams = {
- authorization: null,
- routeId: '1,3'
- };
+
+ const routeIds = '1,3';
controller.showRouteReport();
- expect(controller.vnReport.show).toHaveBeenCalledWith('driver-route', expectedParams);
+ expect(controller.vnReport.show).toHaveBeenCalledWith(`Routes/${routeIds}/driver-route-pdf`);
});
});
diff --git a/modules/supplier/back/methods/supplier/filter.js b/modules/supplier/back/methods/supplier/filter.js
index 3500afacd..0b473f7df 100644
--- a/modules/supplier/back/methods/supplier/filter.js
+++ b/modules/supplier/back/methods/supplier/filter.js
@@ -95,8 +95,8 @@ module.exports = Self => {
pm.name AS payMethod,
pd.payDem AS payDem
FROM vn.supplier s
- JOIN vn.payMethod pm ON pm.id = s.payMethodFk
- JOIN vn.payDem pd ON pd.id = s.payDemFk`
+ LEFT JOIN vn.payMethod pm ON pm.id = s.payMethodFk
+ LEFT JOIN vn.payDem pd ON pd.id = s.payDemFk`
);
stmt.merge(conn.makeSuffix(filter));
diff --git a/modules/supplier/back/methods/supplier/newSupplier.js b/modules/supplier/back/methods/supplier/newSupplier.js
new file mode 100644
index 000000000..f4059a259
--- /dev/null
+++ b/modules/supplier/back/methods/supplier/newSupplier.js
@@ -0,0 +1,45 @@
+module.exports = Self => {
+ Self.remoteMethod('newSupplier', {
+ description: 'Creates a new supplier and returns it',
+ accessType: 'WRITE',
+ accepts: [{
+ arg: 'params',
+ type: 'object',
+ http: {source: 'body'}
+ }],
+ returns: {
+ type: 'string',
+ root: true
+ },
+ http: {
+ path: `/newSupplier`,
+ verb: 'POST'
+ }
+ });
+
+ Self.newSupplier = async params => {
+ const models = Self.app.models;
+ const myOptions = {};
+
+ if (typeof(params) == 'string')
+ params = JSON.parse(params);
+
+ params.nickname = params.name;
+
+ if (!myOptions.transaction) {
+ tx = await Self.beginTransaction({});
+ myOptions.transaction = tx;
+ }
+
+ try {
+ const supplier = await models.Supplier.create(params, myOptions);
+
+ if (tx) await tx.commit();
+
+ return supplier;
+ } catch (e) {
+ if (tx) await tx.rollback();
+ return params;
+ }
+ };
+};
diff --git a/modules/supplier/back/methods/supplier/specs/filter.spec.js b/modules/supplier/back/methods/supplier/specs/filter.spec.js
index 1f74b10ff..2620bb687 100644
--- a/modules/supplier/back/methods/supplier/specs/filter.spec.js
+++ b/modules/supplier/back/methods/supplier/specs/filter.spec.js
@@ -10,7 +10,7 @@ describe('Supplier filter()', () => {
let result = await app.models.Supplier.filter(ctx);
- expect(result.length).toEqual(1);
+ expect(result.length).toBeGreaterThanOrEqual(1);
expect(result[0].id).toEqual(1);
});
diff --git a/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js b/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js
new file mode 100644
index 000000000..8f22a4f20
--- /dev/null
+++ b/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js
@@ -0,0 +1,30 @@
+const app = require('vn-loopback/server/server');
+const LoopBackContext = require('loopback-context');
+
+describe('Supplier newSupplier()', () => {
+ const newSupp = {
+ name: 'TestSupplier-1'
+ };
+ const administrativeId = 5;
+
+ it('should create a new supplier containing only the name', async() => {
+ const activeCtx = {
+ accessToken: {userId: administrativeId},
+ };
+ spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
+ active: activeCtx
+ });
+
+ let result = await app.models.Supplier.newSupplier(JSON.stringify(newSupp));
+
+ expect(result.name).toEqual('TestSupplier-1');
+ expect(result.id).toEqual(443);
+
+ const createdSupplier = await app.models.Supplier.findById(result.id);
+
+ expect(createdSupplier.id).toEqual(result.id);
+ expect(createdSupplier.name).toEqual(result.name);
+ expect(createdSupplier.payDemFk).toEqual(7);
+ expect(createdSupplier.nickname).toEqual(result.name);
+ });
+});
diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js
index c9af7b297..44549c65c 100644
--- a/modules/supplier/back/models/supplier.js
+++ b/modules/supplier/back/models/supplier.js
@@ -10,6 +10,7 @@ module.exports = Self => {
require('../methods/supplier/freeAgencies')(Self);
require('../methods/supplier/campaignMetricsPdf')(Self);
require('../methods/supplier/campaignMetricsEmail')(Self);
+ require('../methods/supplier/newSupplier')(Self);
Self.validatesPresenceOf('name', {
message: 'The social name cannot be empty'
@@ -19,13 +20,17 @@ module.exports = Self => {
message: 'The supplier name must be unique'
});
- Self.validatesPresenceOf('city', {
- message: 'City cannot be empty'
- });
+ if (this.city) {
+ Self.validatesPresenceOf('city', {
+ message: 'City cannot be empty'
+ });
+ }
- Self.validatesPresenceOf('nif', {
- message: 'The nif cannot be empty'
- });
+ if (this.nif) {
+ Self.validatesPresenceOf('nif', {
+ message: 'The nif cannot be empty'
+ });
+ }
Self.validatesUniquenessOf('nif', {
message: 'TIN must be unique'
@@ -57,6 +62,9 @@ module.exports = Self => {
}
async function tinIsValid(err, done) {
+ if (!this.countryFk)
+ return done();
+
const filter = {
fields: ['code'],
where: {id: this.countryFk}
@@ -80,6 +88,7 @@ module.exports = Self => {
});
async function hasSupplierAccount(err, done) {
+ if (!this.payMethodFk) return done();
const payMethod = await Self.app.models.PayMethod.findById(this.payMethodFk);
const supplierAccount = await Self.app.models.SupplierAccount.findOne({where: {supplierFk: this.id}});
const hasIban = supplierAccount && supplierAccount.iban;
@@ -92,6 +101,7 @@ module.exports = Self => {
}
Self.observe('before save', async function(ctx) {
+ if (ctx.isNewInstance) return;
const loopbackContext = LoopBackContext.getCurrentContext();
const changes = ctx.data || ctx.instance;
const orgData = ctx.currentInstance;
@@ -101,7 +111,7 @@ module.exports = Self => {
const isPayMethodChecked = changes.isPayMethodChecked || orgData.isPayMethodChecked;
const hasChanges = orgData && changes;
const isPayMethodCheckedChanged = hasChanges
- && orgData.isPayMethodChecked != isPayMethodChecked;
+ && orgData.isPayMethodChecked != isPayMethodChecked;
if (isNotFinancial && isPayMethodCheckedChanged)
throw new UserError('You can not modify is pay method checked');
@@ -114,7 +124,7 @@ module.exports = Self => {
const socialName = changes.name || orgData.name;
const hasChanges = orgData && changes;
const socialNameChanged = hasChanges
- && orgData.socialName != socialName;
+ && orgData.socialName != socialName;
if ((socialNameChanged) && !isAlpha(socialName))
throw new UserError('The social name has an invalid format');
diff --git a/modules/supplier/front/create/index.html b/modules/supplier/front/create/index.html
new file mode 100644
index 000000000..446a16cb6
--- /dev/null
+++ b/modules/supplier/front/create/index.html
@@ -0,0 +1,29 @@
+