Merge pull request '4616-ticket.sale_mana' (!1088) from 4616-ticket.sale_mana into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1088 Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
commit
c01b1c06a7
|
@ -18,9 +18,12 @@ describe('ticket componentUpdate()', () => {
|
|||
beforeAll(async() => {
|
||||
const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}});
|
||||
deliveryComponentId = deliveryComponenet.id;
|
||||
componentOfSaleSeven = `SELECT value FROM vn.saleComponent WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`;
|
||||
componentOfSaleEight = `SELECT value FROM vn.saleComponent WHERE saleFk = 8 AND componentFk = ${deliveryComponentId}`;
|
||||
|
||||
componentOfSaleSeven = `SELECT value
|
||||
FROM vn.saleComponent
|
||||
WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`;
|
||||
componentOfSaleEight = `SELECT value
|
||||
FROM vn.saleComponent
|
||||
WHERE saleFk = 8 AND componentFk = ${deliveryComponentId}`;
|
||||
[componentValue] = await models.SaleComponent.rawSql(componentOfSaleSeven);
|
||||
firstvalueBeforeChange = componentValue.value;
|
||||
|
||||
|
|
|
@ -115,14 +115,38 @@ module.exports = Self => {
|
|||
for (let sale of sales) {
|
||||
const oldDiscount = sale.discount;
|
||||
const value = ((-sale.price * newDiscount) / 100);
|
||||
const newComponent = models.SaleComponent.upsert({
|
||||
saleFk: sale.id,
|
||||
value: value,
|
||||
componentFk: componentId}, myOptions);
|
||||
|
||||
const manaComponent = await models.Component.findOne({
|
||||
where: {code: 'mana'}
|
||||
}, myOptions);
|
||||
|
||||
const manaClaimComponent = await models.Component.findOne({
|
||||
where: {code: 'manaClaim'}
|
||||
}, myOptions);
|
||||
|
||||
const [oldComponent] = await models.SaleComponent.find({
|
||||
where: {
|
||||
and: [
|
||||
{saleFk: sale.id},
|
||||
{componentFk: {inq: [manaComponent.id, manaClaimComponent.id]}}
|
||||
]
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
let deletedComponent;
|
||||
if (oldComponent) {
|
||||
const filter = {
|
||||
saleFk: sale.id,
|
||||
componentFk: oldComponent.componentFk
|
||||
};
|
||||
deletedComponent = await models.SaleComponent.destroyAll(filter, myOptions);
|
||||
}
|
||||
|
||||
const newComponent = await createSaleComponent(sale.id, value, componentId, myOptions);
|
||||
|
||||
const updatedSale = sale.updateAttribute('discount', newDiscount, myOptions);
|
||||
|
||||
promises.push(newComponent, updatedSale);
|
||||
promises.push(newComponent, updatedSale, deletedComponent);
|
||||
|
||||
const change = `${oldDiscount}% ➔ *${newDiscount}%*`;
|
||||
changesMade += `\r\n-${sale.itemFk}: ${sale.concept} (${sale.quantity}) ${change}`;
|
||||
|
@ -165,4 +189,14 @@ module.exports = Self => {
|
|||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
async function createSaleComponent(saleId, value, componentId, myOptions) {
|
||||
const models = Self.app.models;
|
||||
|
||||
return models.SaleComponent.create({
|
||||
saleFk: saleId,
|
||||
value: value,
|
||||
componentFk: componentId
|
||||
}, myOptions);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -300,7 +300,7 @@
|
|||
ng-model="$ctrl.manaCode">
|
||||
</vn-radio>
|
||||
</vn-vertical>
|
||||
<div class="simulator">
|
||||
<div class="simulator" ng-show="$ctrl.edit.sale">
|
||||
<p class="simulatorTitle" translate>New price</p>
|
||||
<p>
|
||||
<strong>{{$ctrl.getNewPrice() | currency: 'EUR': 2}}</strong>
|
||||
|
@ -321,32 +321,6 @@
|
|||
</div>
|
||||
</vn-popover>
|
||||
|
||||
<!-- Multiple discount dialog -->
|
||||
<vn-dialog vn-id="editDiscountDialog"
|
||||
on-open="$ctrl.getMana()"
|
||||
message="Edit discount">
|
||||
<tpl-body>
|
||||
<vn-spinner class="vn-pa-xs"
|
||||
ng-if="$ctrl.edit.mana == null"
|
||||
enable="true">
|
||||
</vn-spinner>
|
||||
<div ng-if="$ctrl.edit.mana != null">
|
||||
<div class="vn-pa-md">
|
||||
<vn-input-number vn-focus
|
||||
label="Discount"
|
||||
ng-model="$ctrl.edit.discount"
|
||||
on-change="$ctrl.changeMultipleDiscount()"
|
||||
clear-disabled="true"
|
||||
suffix="%">
|
||||
</vn-input-number>
|
||||
</div>
|
||||
<section class="header vn-pa-md">
|
||||
<span>Mana: <strong>{{::$ctrl.edit.mana | currency: 'EUR': 0}}</strong></span>
|
||||
</section>
|
||||
</div>
|
||||
</tpl-body>
|
||||
</vn-dialog>
|
||||
|
||||
<!-- Transfer Popover -->
|
||||
<vn-popover vn-id="transfer">
|
||||
<div class="vn-pa-lg transfer">
|
||||
|
@ -490,7 +464,7 @@
|
|||
</vn-item>
|
||||
<vn-item translate
|
||||
name="discount"
|
||||
ng-click="$ctrl.showEditDiscountDialog($event)">
|
||||
ng-click="$ctrl.showEditDiscountPopover($event, sale)">
|
||||
Update discount
|
||||
</vn-item>
|
||||
<vn-item translate
|
||||
|
|
|
@ -243,26 +243,21 @@ class Controller extends Section {
|
|||
|
||||
showEditDiscountPopover(event, sale) {
|
||||
if (this.isLocked) return;
|
||||
|
||||
this.edit = {
|
||||
discount: sale.discount,
|
||||
sale: sale
|
||||
};
|
||||
if (sale) {
|
||||
this.edit = {
|
||||
discount: sale.discount,
|
||||
sale: sale
|
||||
};
|
||||
} else {
|
||||
this.edit = {
|
||||
discount: null,
|
||||
sales: this.selectedValidSales()
|
||||
};
|
||||
}
|
||||
|
||||
this.$.editDiscount.show(event);
|
||||
}
|
||||
|
||||
showEditDiscountDialog(event) {
|
||||
if (this.isLocked) return;
|
||||
|
||||
this.edit = {
|
||||
discount: null,
|
||||
sales: this.selectedValidSales()
|
||||
};
|
||||
|
||||
this.$.editDiscountDialog.show(event);
|
||||
}
|
||||
|
||||
changeDiscount() {
|
||||
const sale = this.edit.sale;
|
||||
const newDiscount = this.edit.discount;
|
||||
|
@ -278,11 +273,10 @@ class Controller extends Section {
|
|||
const hasChanges = sales.some(sale => {
|
||||
return sale.discount != newDiscount;
|
||||
});
|
||||
|
||||
if (newDiscount != null && hasChanges)
|
||||
this.updateDiscount(sales);
|
||||
|
||||
this.$.editDiscountDialog.hide();
|
||||
this.$.editDiscount.hide();
|
||||
}
|
||||
|
||||
updateDiscount(sales) {
|
||||
|
@ -303,7 +297,7 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
getNewPrice() {
|
||||
if (this.edit) {
|
||||
if (this.edit.sale) {
|
||||
const sale = this.edit.sale;
|
||||
let newDiscount = sale.discount;
|
||||
let newPrice = this.edit.price || sale.price;
|
||||
|
@ -505,7 +499,8 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
save() {
|
||||
this.changeDiscount();
|
||||
if (this.edit.sale) this.changeDiscount();
|
||||
if (this.edit.sales) this.changeMultipleDiscount();
|
||||
}
|
||||
|
||||
cancel() {
|
||||
|
|
|
@ -393,7 +393,7 @@ describe('Ticket', () => {
|
|||
secondSelectedSale.checked = true;
|
||||
|
||||
const expectedSales = [firstSelectedSale, secondSelectedSale];
|
||||
controller.$.editDiscountDialog = {hide: jest.fn()};
|
||||
controller.$.editDiscount = {hide: jest.fn()};
|
||||
controller.edit = {
|
||||
discount: 10,
|
||||
sales: expectedSales
|
||||
|
@ -402,7 +402,7 @@ describe('Ticket', () => {
|
|||
controller.changeMultipleDiscount();
|
||||
|
||||
expect(controller.updateDiscount).toHaveBeenCalledWith(expectedSales);
|
||||
expect(controller.$.editDiscountDialog.hide).toHaveBeenCalledWith();
|
||||
expect(controller.$.editDiscount.hide).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('should not call to the updateDiscount() method and then to the editDiscountDialog hide() method', () => {
|
||||
|
@ -417,7 +417,7 @@ describe('Ticket', () => {
|
|||
secondSelectedSale.discount = 10;
|
||||
|
||||
const expectedSales = [firstSelectedSale, secondSelectedSale];
|
||||
controller.$.editDiscountDialog = {hide: jest.fn()};
|
||||
controller.$.editDiscount = {hide: jest.fn()};
|
||||
controller.edit = {
|
||||
discount: 10,
|
||||
sales: expectedSales
|
||||
|
@ -426,7 +426,7 @@ describe('Ticket', () => {
|
|||
controller.changeMultipleDiscount();
|
||||
|
||||
expect(controller.updateDiscount).not.toHaveBeenCalledWith(expectedSales);
|
||||
expect(controller.$.editDiscountDialog.hide).toHaveBeenCalledWith();
|
||||
expect(controller.$.editDiscount.hide).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue