#4988 - new-module-agency #2303

Merged
pablone merged 17 commits from 4988-new-module-agency into dev 2024-04-26 07:06:56 +00:00
11 changed files with 164 additions and 1 deletions

View File

@ -180,5 +180,11 @@
}, },
"ProductionConfig": { "ProductionConfig": {
"dataSource": "vn" "dataSource": "vn"
},
"AgencyLog": {
"dataSource": "vn"
},
"AgencyWorkCenter": {
"dataSource": "vn"
} }
} }

View File

@ -0,0 +1,9 @@
{
"name": "AgencyLog",
"base": "Log",
"options": {
"mysql": {
"table": "agencyLog"
}
}
}

View File

@ -0,0 +1,8 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.rewriteDbError(function(err) {
if (err.code === 'ER_DUP_ENTRY')
return new UserError(`This workCenter is already assigned to this agency`);
return err;
});
};

View File

@ -0,0 +1,41 @@
{
"name": "AgencyWorkCenter",
"base": "VnModel",
"options": {
"mysql": {
"table": "agencyWorkCenter"
}
},
"properties": {
"id": {
"id": true,
"type": "number",
"forceId": false
},
"agencyFk": {
"type": "number",
"required": false
},
"workCenterFk": {
"type": "number",
"required": false
}
},
"relations": {
"agency": {
"type": "belongsTo",
"model": "WorkCenter",
"foreignKey": "agencyFk"
},
"workCenter": {
"type": "belongsTo",
"model": "WorkCenter",
"foreignKey": "workCenterFk"
}
},
"scope": {
"include":{
"relation": "workCenter"
}
}
}

View File

@ -3788,3 +3788,6 @@ INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk)
INSERT INTO vn.workerTeam(id, team, workerFk) INSERT INTO vn.workerTeam(id, team, workerFk)
VALUES VALUES
(8, 1, 19); (8, 1, 19);
INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, street, geoFk, deliveryManAdjustment)
VALUES(100, 'workCenterOne', 1, NULL, 1, 'gotham', NULL, NULL);

View File

@ -0,0 +1,8 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`agency_beforeInsert`
BEFORE INSERT ON `agency`
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();
END$$
DELIMITER ;

View File

@ -0,0 +1,24 @@
-- vn.agencyLog definition
ALTER TABLE vn.agency ADD IF NOT EXISTS editorFk int(10) unsigned DEFAULT NULL NULL;
ALTER TABLE vn.agency ADD CONSTRAINT agency_user_FK FOREIGN KEY (editorFk) REFERENCES `account`.`user`(id);
CREATE TABLE IF NOT EXISTS `vn`.`agencyLog` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`originFk` smallint(5) unsigned DEFAULT NULL,
`userFk` int(10) unsigned DEFAULT NULL,
`action` set('insert','update','delete','select') NOT NULL,
`creationDate` timestamp NULL DEFAULT current_timestamp(),
`description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
`changedModel` enum('agency','agencyMode') NOT NULL DEFAULT 'agency',
`oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)),
`newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)),
`changedModelId` int(11) NOT NULL,
`changedModelValue` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `logAgencyUserFk` (`userFk`),
KEY `agencyLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`),
KEY `agencyLog_originFk` (`originFk`,`creationDate`),
CONSTRAINT `agencyOriginFk` FOREIGN KEY (`originFk`) REFERENCES `agency` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `agencyUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;

View File

@ -0,0 +1,18 @@
CREATE TABLE IF NOT EXISTS `vn`.`agencyWorkCenter` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`agencyFk` smallint(5) unsigned NOT NULL,
`workCenterFk` int(11) NOT NULL,
`editorFk` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `agencyWorkCenter_unique` (`agencyFk`,`workCenterFk`),
KEY `agencyWorkCenter_workCenter_FK` (`workCenterFk`),
KEY `agencyWorkCenter_user_FK` (`editorFk`),
CONSTRAINT `agencyWorkCenter_agency_FK` FOREIGN KEY (`agencyFk`) REFERENCES `agency` (`id`) ON DELETE CASCADE,
CONSTRAINT `agencyWorkCenter_user_FK` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `agencyWorkCenter_workCenter_FK` FOREIGN KEY (`workCenterFk`) REFERENCES `workCenter` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='refs #4988';
INSERT INTO vn.agencyWorkCenter (agencyFk, workCenterFk)
SELECT id, workCenterFk
FROM vn.agency
WHERE workCenterFk IS NOT NULL;

View File

@ -0,0 +1,19 @@
-- Place your SQL code here
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('AgencyLog','*','READ','ALLOW','ROLE','employee');
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('AgencyWorkCenter','*','READ','ALLOW','ROLE','employee');
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES('AgencyMode', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES('Agency', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Agency','*','WRITE','ALLOW','ROLE','deliveryAssistant');
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('AgencyWorkCenter','*','WRITE','ALLOW','ROLE','deliveryAssistant');

View File

@ -354,6 +354,7 @@
"They're not your subordinate": "No es tu subordinado/a.", "They're not your subordinate": "No es tu subordinado/a.",
"No results found": "No se han encontrado resultados", "No results found": "No se han encontrado resultados",
"InvoiceIn is already booked": "La factura recibida está contabilizada", "InvoiceIn is already booked": "La factura recibida está contabilizada",
"This workCenter is already assigned to this agency": "Este centro de trabajo ya está asignado a esta agencia",
"Select ticket or client": "Elija un ticket o un client", "Select ticket or client": "Elija un ticket o un client",
"It was not able to create the invoice": "No se pudo crear la factura" "It was not able to create the invoice": "No se pudo crear la factura"
} }

View File

@ -15,6 +15,22 @@
"name": { "name": {
"type": "string", "type": "string",
"required": false "required": false
},
"warehouseFk": {
"type": "number",
"required": false
},
"isOwn": {
"type": "boolean",
"required": false
},
"workCenterFk": {
"type": "number",
"required": false
},
"isAnyVolumeAllowed": {
"type": "boolean",
"required": false
} }
}, },
"relations": { "relations": {
@ -22,6 +38,16 @@
"type": "hasOne", "type": "hasOne",
"model": "SupplierAgencyTerm", "model": "SupplierAgencyTerm",
"foreignKey": "agencyFk" "foreignKey": "agencyFk"
} },
"warehouse": {
"type": "belongsTo",
"model": "Warehouse",
"foreignKey": "warehouseFk"
},
"workCenter": {
"type": "belongsTo",
"model": "WorkCenter",
"foreignKey": "workCenterFk"
}
} }
} }