diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index c4338a555..1e096b3c1 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2842,7 +2842,8 @@ INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `payMethodFk INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`) VALUES - (1, 12); + (1, 12), + (8, 10); INSERT INTO `vn`.`deviceProductionModels` (`code`) VALUES diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 138fa7100..abb62d492 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -294,6 +294,7 @@ "Invalid NIF for VIES": "Invalid NIF for VIES", "Ticket does not exist": "Este ticket no existe", "Ticket is already signed": "Este ticket ya ha sido firmado", + "You can only add negative amounts in refund tickets": "Solo se puede añadir cantidades negativas en tickets abono", "Fecha fuera de rango": "Fecha fuera de rango", "Error while generating PDF": "Error al generar PDF", "Error when sending mail to client": "Error al enviar el correo al cliente", diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 7b577fa98..697129df0 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -14,7 +14,7 @@ module.exports = Self => { Self.validatesPresenceOf('street', { message: 'Street cannot be empty' }); - + Self.validatesPresenceOf('city', { message: 'City cannot be empty' }); @@ -282,7 +282,7 @@ module.exports = Self => { await Self.changeCredit(ctx, finalState, changes); // Credit management changes - if (orgData?.rating != changes.rating || orgData?.recommendedCredit != changes.recommendedCredit) + if (changes?.rating || changes?.recommendedCredit) await Self.changeCreditManagement(ctx, finalState, changes); const oldInstance = {}; diff --git a/modules/ticket/back/methods/sale/specs/updateQuantity.spec.js b/modules/ticket/back/methods/sale/specs/updateQuantity.spec.js index 80adb0bd1..8064ea30b 100644 --- a/modules/ticket/back/methods/sale/specs/updateQuantity.spec.js +++ b/modules/ticket/back/methods/sale/specs/updateQuantity.spec.js @@ -110,4 +110,53 @@ describe('sale updateQuantity()', () => { throw e; } }); + + it('should throw an error if the quantity is negative and it is not a refund ticket', async() => { + const ctx = { + req: { + accessToken: {userId: 1}, + headers: {origin: 'localhost:5000'}, + __: () => {} + } + }; + const saleId = 17; + const newQuantity = -10; + + const tx = await models.Sale.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error).toEqual(new Error('You can only add negative amounts in refund tickets')); + }); + + it('should update a negative quantity when is a ticket refund', async() => { + const tx = await models.Sale.beginTransaction({}); + const saleId = 13; + const newQuantity = -10; + + try { + const options = {transaction: tx}; + + await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + + const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); + + expect(modifiedLine.quantity).toEqual(newQuantity); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/ticket/back/methods/sale/updateQuantity.js b/modules/ticket/back/methods/sale/updateQuantity.js index 421c74702..edbc34e42 100644 --- a/modules/ticket/back/methods/sale/updateQuantity.js +++ b/modules/ticket/back/methods/sale/updateQuantity.js @@ -68,6 +68,13 @@ module.exports = Self => { if (newQuantity > sale.quantity && !isRoleAdvanced) throw new UserError('The new quantity should be smaller than the old one'); + const ticketRefund = await models.TicketRefund.findOne({ + where: {refundTicketFk: sale.ticketFk}, + fields: ['id']} + , myOptions); + if (newQuantity < 0 && !ticketRefund) + throw new UserError('You can only add negative amounts in refund tickets'); + const oldQuantity = sale.quantity; const result = await sale.updateAttributes({quantity: newQuantity}, myOptions); diff --git a/modules/worker/front/calendar/index.html b/modules/worker/front/calendar/index.html index 29540081e..ace2f4e27 100644 --- a/modules/worker/front/calendar/index.html +++ b/modules/worker/front/calendar/index.html @@ -3,27 +3,35 @@ data="absenceTypes" auto-load="true"> -
- - - - - - +
+
+ + + + + + +
+
+
+ Autonomous worker
-
{{'Contract' | translate}} #{{$ctrl.businessId}}
+
{{'Contract' | translate}} #{{$ctrl.card.worker.hasWorkCenter}}
{{'Used' | translate}} {{$ctrl.contractHolidays.holidaysEnjoyed || 0}} {{'of' | translate}} {{$ctrl.contractHolidays.totalHolidays || 0}} {{'days' | translate}} @@ -63,7 +71,6 @@ ng-model="$ctrl.businessId" search-function="{businessFk: $search}" value-field="businessFk" - show-field="businessFk" order="businessFk DESC" limit="5"> @@ -103,3 +110,4 @@ message="This item will be deleted" question="Are you sure you want to continue?"> + diff --git a/modules/worker/front/calendar/index.js b/modules/worker/front/calendar/index.js index a52ecd7da..87e806cc3 100644 --- a/modules/worker/front/calendar/index.js +++ b/modules/worker/front/calendar/index.js @@ -64,8 +64,7 @@ class Controller extends Section { set worker(value) { this._worker = value; - - if (value) { + if (value && value.hasWorkCenter) { this.getIsSubordinate(); this.getActiveContract(); } diff --git a/modules/worker/front/calendar/index.spec.js b/modules/worker/front/calendar/index.spec.js index 586a7223d..4b78d883b 100644 --- a/modules/worker/front/calendar/index.spec.js +++ b/modules/worker/front/calendar/index.spec.js @@ -74,7 +74,7 @@ describe('Worker', () => { let yesterday = new Date(today.getTime()); yesterday.setDate(yesterday.getDate() - 1); - controller.worker = {id: 1107}; + controller.worker = {id: 1107, hasWorkCenter: true}; expect(controller.getIsSubordinate).toHaveBeenCalledWith(); expect(controller.getActiveContract).toHaveBeenCalledWith(); diff --git a/modules/worker/front/calendar/locale/es.yml b/modules/worker/front/calendar/locale/es.yml index bd75458aa..50bb4bb52 100644 --- a/modules/worker/front/calendar/locale/es.yml +++ b/modules/worker/front/calendar/locale/es.yml @@ -11,4 +11,5 @@ Choose an absence type from the right menu: Elige un tipo de ausencia desde el m To start adding absences, click an absence type from the right menu and then on the day you want to add an absence: Para empezar a añadir ausencias, haz clic en un tipo de ausencia desde el menu de la derecha y después en el día que quieres añadir la ausencia You can just add absences within the current year: Solo puedes añadir ausencias dentro del año actual Current day: Día actual -Paid holidays: Vacaciones pagadas \ No newline at end of file +Paid holidays: Vacaciones pagadas +Autonomous worker: Trabajador autónomo diff --git a/modules/worker/front/card/index.js b/modules/worker/front/card/index.js index 415b60787..e1eb97327 100644 --- a/modules/worker/front/card/index.js +++ b/modules/worker/front/card/index.js @@ -34,6 +34,10 @@ class Controller extends ModuleCard { this.$http.get(`Workers/${this.$params.id}`, {filter}) .then(res => this.worker = res.data); + this.$http.get(`Workers/${this.$params.id}/activeContract`) + .then(res => { + if (res.data) this.worker.hasWorkCenter = res.data.workCenterFk; + }); } } diff --git a/modules/worker/front/time-control/index.html b/modules/worker/front/time-control/index.html index 044ea4038..5f0855ee6 100644 --- a/modules/worker/front/time-control/index.html +++ b/modules/worker/front/time-control/index.html @@ -4,106 +4,114 @@ filter="::$ctrl.filter" data="$ctrl.hours"> - - - - - -
{{::$ctrl.weekdayNames[$index].name}}
-
- {{::weekday.dated | date: 'dd'}} - - {{::weekday.dated | date: 'MMMM'}} - -
- - - +
+ + + + + +
{{::$ctrl.weekdayNames[$index].name}}
- {{::weekday.event.name}} + {{::weekday.dated | date: 'dd'}} + + {{::weekday.dated | date: 'MMMM'}} +
- -
-
-
- - - -
- - - - - - - {{::hour.timed | date: 'HH:mm'}} + title="{{::weekday.event.name}}" + ng-class="{invisible: !weekday.event}"> + + +
+ {{::weekday.event.name}} +
-
-
-
-
- - - - {{$ctrl.formatHours(weekday.workedHours)}} h. - - - - - - - - - -
-
+ + + + + + +
+ + + + + + + + {{::hour.timed | date: 'HH:mm'}} + +
+
+
+
+ + + + {{$ctrl.formatHours(weekday.workedHours)}} h. + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + +
+
+ Autonomous worker +
diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 85ddcedfe..90ec33293 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -151,6 +151,7 @@ class Controller extends Section { } getAbsences() { + if (!this.worker.hasWorkerCenter) return; const fullYear = this.started.getFullYear(); let params = { workerFk: this.$params.id, diff --git a/modules/worker/front/time-control/index.spec.js b/modules/worker/front/time-control/index.spec.js index 94f9d3d48..0132f50fe 100644 --- a/modules/worker/front/time-control/index.spec.js +++ b/modules/worker/front/time-control/index.spec.js @@ -16,6 +16,10 @@ describe('Component vnWorkerTimeControl', () => { $scope = $rootScope.$new(); $element = angular.element(''); controller = $componentController('vnWorkerTimeControl', {$element, $scope}); + controller.worker = { + hasWorkerCenter: true + + }; })); describe('date() setter', () => {