Merge pull request '3811-ticket.sale_updatePrice' (!1099) from 3811-ticket.sale_updatePrice into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1099 Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
commit
abec6ae04d
|
@ -0,0 +1,3 @@
|
|||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES
|
||||
('Business', '*', '*', 'ALLOW', 'ROLE', 'hr');
|
|
@ -0,0 +1,3 @@
|
|||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES
|
||||
('Sale', 'usesMana', '*', 'ALLOW', 'ROLE', 'employee');
|
|
@ -8,6 +8,9 @@
|
|||
"BankEntity": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"Business": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"BusinessType": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "Business",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "business"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"id": true
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
"worker": {
|
||||
"type": "belongsTo",
|
||||
"model": "Worker",
|
||||
"foreignKey": "workerFk"
|
||||
},
|
||||
"department": {
|
||||
"type": "belongsTo",
|
||||
"model": "Department",
|
||||
"foreignKey": "departmentFk"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -79,10 +79,18 @@ describe('sale updatePrice()', () => {
|
|||
const price = 5.4;
|
||||
const originalSalesPersonMana = await models.WorkerMana.findById(18, null, options);
|
||||
const manaComponent = await models.Component.findOne({where: {code: 'mana'}}, options);
|
||||
const teamOne = 96;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
const business = await models.Business.findOne({where: {workerFk: userId}}, options);
|
||||
await business.updateAttribute('departmentFk', teamOne, options);
|
||||
|
||||
await models.Sale.updatePrice(ctx, saleId, price, options);
|
||||
const updatedSale = await models.Sale.findById(saleId, null, options);
|
||||
createdSaleComponent = await models.SaleComponent.findOne({where: {saleFk: saleId, componentFk: manaComponent.id}}, options);
|
||||
const createdSaleComponent = await models.SaleComponent.findOne({
|
||||
where: {
|
||||
saleFk: saleId, componentFk: manaComponent.id
|
||||
}}, options);
|
||||
|
||||
expect(updatedSale.price).toBe(price);
|
||||
expect(createdSaleComponent.value).toEqual(-2.04);
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('sale usesMana()', () => {
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 18}
|
||||
}
|
||||
};
|
||||
|
||||
it('should return that the worker uses mana', async() => {
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const teamOne = 96;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
const business = await models.Business.findOne({where: {workerFk: userId}}, options);
|
||||
await business.updateAttribute('departmentFk', teamOne, options);
|
||||
|
||||
const usesMana = await models.Sale.usesMana(ctx, options);
|
||||
|
||||
expect(usesMana).toBe(true);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should return that the worker not uses mana', async() => {
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const usesMana = await models.Sale.usesMana(ctx, options);
|
||||
|
||||
expect(usesMana).toBe(false);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -77,7 +77,8 @@ module.exports = Self => {
|
|||
|
||||
const oldPrice = sale.price;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const usesMana = await models.WorkerMana.findOne({where: {workerFk: userId}, fields: 'amount'}, myOptions);
|
||||
|
||||
const usesMana = await models.Sale.usesMana(ctx, myOptions);
|
||||
const componentCode = usesMana ? 'mana' : 'buyerDiscount';
|
||||
const discount = await models.Component.findOne({where: {code: componentCode}}, myOptions);
|
||||
const componentId = discount.id;
|
||||
|
@ -88,7 +89,6 @@ module.exports = Self => {
|
|||
saleFk: id
|
||||
};
|
||||
const saleComponent = await models.SaleComponent.findOne({where}, myOptions);
|
||||
|
||||
if (saleComponent) {
|
||||
await models.SaleComponent.updateAll(where, {
|
||||
value: saleComponent.value + componentValue
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('usesMana', {
|
||||
description: 'Returns if the worker uses mana',
|
||||
accessType: 'READ',
|
||||
accepts: [],
|
||||
returns: {
|
||||
type: 'boolean',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/usesMana`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.usesMana = async(ctx, options) => {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions);
|
||||
const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions);
|
||||
const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions);
|
||||
const usesMana = departments.find(department => department.id == workerDepartment.departmentFk);
|
||||
|
||||
return usesMana ? true : false;
|
||||
};
|
||||
};
|
|
@ -110,6 +110,11 @@ describe('sale updateDiscount()', () => {
|
|||
const componentId = manaDiscount.id;
|
||||
const manaCode = 'mana';
|
||||
|
||||
const teamOne = 96;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const business = await models.Business.findOne({where: {workerFk: userId}}, options);
|
||||
await business.updateAttribute('departmentFk', teamOne, options);
|
||||
|
||||
await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options);
|
||||
|
||||
const updatedSale = await models.Sale.findById(originalSaleId, null, options);
|
||||
|
@ -150,6 +155,11 @@ describe('sale updateDiscount()', () => {
|
|||
const componentId = manaDiscount.id;
|
||||
const manaCode = 'manaClaim';
|
||||
|
||||
const teamOne = 96;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const business = await models.Business.findOne({where: {workerFk: userId}}, options);
|
||||
await business.updateAttribute('departmentFk', teamOne, options);
|
||||
|
||||
await models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount, manaCode, options);
|
||||
|
||||
const updatedSale = await models.Sale.findById(originalSaleId, null, options);
|
||||
|
|
|
@ -98,12 +98,7 @@ module.exports = Self => {
|
|||
if (isLocked || (!hasAllowedRoles && alertLevel > 0))
|
||||
throw new UserError(`The sales of this ticket can't be modified`);
|
||||
|
||||
const usesMana = await models.WorkerMana.findOne({
|
||||
where: {
|
||||
workerFk: userId
|
||||
},
|
||||
fields: 'amount'}, myOptions);
|
||||
|
||||
const usesMana = await models.Sale.usesMana(ctx, myOptions);
|
||||
const componentCode = usesMana ? manaCode : 'buyerDiscount';
|
||||
const discountComponent = await models.Component.findOne({
|
||||
where: {code: componentCode}}, myOptions);
|
||||
|
|
|
@ -8,6 +8,7 @@ module.exports = Self => {
|
|||
require('../methods/sale/recalculatePrice')(Self);
|
||||
require('../methods/sale/refund')(Self);
|
||||
require('../methods/sale/canEdit')(Self);
|
||||
require('../methods/sale/usesMana')(Self);
|
||||
|
||||
Self.validatesPresenceOf('concept', {
|
||||
message: `Concept cannot be blank`
|
||||
|
|
|
@ -244,7 +244,7 @@
|
|||
</vn-spinner>
|
||||
<div ng-if="$ctrl.edit.mana != null">
|
||||
<section class="header vn-pa-md">
|
||||
<h5>MANÁ: {{::$ctrl.edit.mana | currency: 'EUR': 0}}</h5>
|
||||
<h5>Mana: {{::$ctrl.edit.mana | currency: 'EUR': 0}}</h5>
|
||||
</section>
|
||||
<div class="vn-pa-md">
|
||||
<vn-input-number
|
||||
|
@ -264,6 +264,16 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<vn-horizontal >
|
||||
<vn-button
|
||||
label="Cancel"
|
||||
ng-click="$ctrl.cancel()">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
label="Save"
|
||||
ng-click="$ctrl.save()">
|
||||
</vn-button>
|
||||
</vn-horizontal>
|
||||
</div>
|
||||
</vn-popover>
|
||||
|
||||
|
@ -278,7 +288,7 @@
|
|||
</vn-spinner>
|
||||
<div ng-if="$ctrl.edit.mana != null">
|
||||
<section class="header vn-pa-md">
|
||||
<h5>Mana: {{::$ctrl.edit.mana | currency: 'EUR':0}}</h5>
|
||||
<h5>Mana: {{::$ctrl.edit.mana | currency: 'EUR': 0}}</h5>
|
||||
</section>
|
||||
<div class="vn-pa-md">
|
||||
<vn-input-number
|
||||
|
@ -288,7 +298,7 @@
|
|||
clear-disabled="true"
|
||||
suffix="%">
|
||||
</vn-input-number>
|
||||
<vn-vertical ng-if="$ctrl.currentWorkerMana != 0">
|
||||
<vn-vertical ng-if="$ctrl.usesMana && $ctrl.currentWorkerMana != 0">
|
||||
<vn-radio
|
||||
label="Promotion mana"
|
||||
val="mana"
|
||||
|
|
|
@ -75,6 +75,7 @@ class Controller extends Section {
|
|||
this.$.editPricePopover.relocate();
|
||||
});
|
||||
});
|
||||
this.getUsesMana();
|
||||
this.getCurrentWorkerMana();
|
||||
}
|
||||
|
||||
|
@ -85,6 +86,13 @@ class Controller extends Section {
|
|||
});
|
||||
}
|
||||
|
||||
getUsesMana() {
|
||||
this.$http.get(`Sales/usesMana`)
|
||||
.then(res => {
|
||||
this.useMana = res.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns checked instances
|
||||
*
|
||||
|
|
|
@ -115,6 +115,7 @@ describe('Ticket', () => {
|
|||
const expectedAmount = 250;
|
||||
|
||||
$httpBackend.expect('GET', 'Tickets/1/getSalesPersonMana').respond(200, expectedAmount);
|
||||
$httpBackend.expect('GET', 'Sales/usesMana').respond(200);
|
||||
$httpBackend.expect('GET', 'WorkerManas/getCurrentWorkerMana').respond(200, expectedAmount);
|
||||
controller.getMana();
|
||||
$httpBackend.flush();
|
||||
|
|
Loading…
Reference in New Issue