fix: getRate2
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
82bc7307f0
commit
320ceb3e2c
|
@ -72,4 +72,45 @@ describe('upsertFixedPrice()', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it(`should recalculate rate2 if change rate3`, async() => {
|
||||
const tx = await models.FixedPrice.beginTransaction({});
|
||||
|
||||
const tomorrow = new Date(now);
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
|
||||
const rate2 = 2;
|
||||
const firstRate3 = 1;
|
||||
const secondRate3 = 2;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const ctx = {args: {
|
||||
id: undefined,
|
||||
itemFk: 1,
|
||||
warehouseFk: 1,
|
||||
started: tomorrow,
|
||||
ended: tomorrow,
|
||||
rate2: rate2,
|
||||
rate3: firstRate3,
|
||||
minPrice: 0,
|
||||
hasMinPrice: false
|
||||
}};
|
||||
|
||||
// create new fixed price
|
||||
const newFixedPrice = await models.FixedPrice.upsertFixedPrice(ctx, options);
|
||||
|
||||
// change rate3 to same fixed price id
|
||||
ctx.args.id = newFixedPrice.id;
|
||||
ctx.args.rate3 = secondRate3;
|
||||
|
||||
const result = await models.FixedPrice.upsertFixedPrice(ctx, options);
|
||||
|
||||
expect(result.rate2).not.toEqual(rate2);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -72,6 +72,16 @@ module.exports = Self => {
|
|||
|
||||
try {
|
||||
delete args.ctx; // removed unwanted data
|
||||
|
||||
if (args.id) {
|
||||
const beforeFixedPrice = await models.FixedPrice.findById(args.id, {fields: ['rate3']}, myOptions);
|
||||
const [result] = await Self.rawSql(`SELECT vn.priceFixed_getRate2(?, ?) as rate2`,
|
||||
[args.id, args.rate3], myOptions);
|
||||
|
||||
if (beforeFixedPrice.rate3 != args.rate3 && result.rate2)
|
||||
args.rate2 = result.rate2;
|
||||
}
|
||||
|
||||
const fixedPrice = await models.FixedPrice.upsert(args, myOptions);
|
||||
const targetItem = await models.Item.findById(args.itemFk, null, myOptions);
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@
|
|||
class="dense"
|
||||
vn-focus
|
||||
ng-model="price.rate3"
|
||||
on-change="$ctrl.upsertPrice(price); $ctrl.recalculateRate2(price)"
|
||||
on-change="$ctrl.upsertPrice(price);"
|
||||
step="0.01"s>
|
||||
</vn-input-number>
|
||||
</field>
|
||||
|
|
|
@ -113,24 +113,6 @@ export default class Controller extends Section {
|
|||
return {[param]: value};
|
||||
}
|
||||
}
|
||||
|
||||
recalculateRate2(price) {
|
||||
if (!price.id || !price.rate3) return;
|
||||
|
||||
const query = 'FixedPrices/getRate2';
|
||||
const params = {
|
||||
fixedPriceId: price.id,
|
||||
rate3: price.rate3
|
||||
};
|
||||
this.$http.get(query, {params})
|
||||
.then(res => {
|
||||
const rate2 = res.data.rate2;
|
||||
if (rate2) {
|
||||
price.rate2 = rate2;
|
||||
this.upsertPrice(price);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnFixedPrice', {
|
||||
|
|
|
@ -85,25 +85,5 @@ describe('fixed price', () => {
|
|||
expect(controller.$.model.remove).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('recalculateRate2()', () => {
|
||||
it(`should rate2 recalculate`, () => {
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
const price = {
|
||||
id: 1,
|
||||
itemFk: 1,
|
||||
rate2: 2,
|
||||
rate3: 2
|
||||
};
|
||||
const response = {rate2: 1};
|
||||
controller.recalculateRate2(price);
|
||||
|
||||
const query = `FixedPrices/getRate2?fixedPriceId=${price.id}&rate3=${price.rate3}`;
|
||||
$httpBackend.expectGET(query).respond(response);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(price.rate2).toEqual(response.rate2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue