5275-item.fixed-price_refactor #1426
|
@ -426,7 +426,8 @@ export default {
|
||||||
fourthStarted: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.started"]',
|
fourthStarted: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.started"]',
|
||||||
fourthEnded: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.ended"]',
|
fourthEnded: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.ended"]',
|
||||||
fourthDeleteIcon: 'vn-fixed-price tr:nth-child(5) > td:nth-child(9) > vn-icon-button[icon="delete"]',
|
fourthDeleteIcon: 'vn-fixed-price tr:nth-child(5) > td:nth-child(9) > vn-icon-button[icon="delete"]',
|
||||||
orderColumnId: 'vn-fixed-price th[field="itemFk"]'
|
orderColumnId: 'vn-fixed-price th[field="itemFk"]',
|
||||||
|
removeWarehouseFilter: 'vn-searchbar > form > vn-textfield > div.container > div.prepend > prepend > div > span:nth-child(1) > vn-icon > i'
|
||||||
},
|
},
|
||||||
itemCreateView: {
|
itemCreateView: {
|
||||||
temporalName: 'vn-item-create vn-textfield[ng-model="$ctrl.item.provisionalName"]',
|
temporalName: 'vn-item-create vn-textfield[ng-model="$ctrl.item.provisionalName"]',
|
||||||
|
|
|
@ -90,7 +90,7 @@ describe('SmartTable SearchBar integration', () => {
|
||||||
await page.waitToClick(selectors.itemFixedPrice.orderColumnId);
|
await page.waitToClick(selectors.itemFixedPrice.orderColumnId);
|
||||||
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
||||||
|
|
||||||
expect(result).toEqual('13');
|
expect(result).toEqual('3');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reload page and have same order', async() => {
|
it('should reload page and have same order', async() => {
|
||||||
|
@ -99,7 +99,7 @@ describe('SmartTable SearchBar integration', () => {
|
||||||
});
|
});
|
||||||
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
||||||
|
|
||||||
expect(result).toEqual('13');
|
expect(result).toEqual('3');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,8 +15,9 @@ describe('Item fixed prices path', () => {
|
||||||
await browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should click on the add new foxed price button', async() => {
|
it('should click on the add new fixed price button', async() => {
|
||||||
await page.doSearch();
|
await page.waitToClick(selectors.itemFixedPrice.removeWarehouseFilter);
|
||||||
|
await page.waitForSpinnerLoad();
|
||||||
await page.waitToClick(selectors.itemFixedPrice.add);
|
await page.waitToClick(selectors.itemFixedPrice.add);
|
||||||
await page.waitForSelector(selectors.itemFixedPrice.fourthFixedPrice);
|
await page.waitForSelector(selectors.itemFixedPrice.fourthFixedPrice);
|
||||||
});
|
});
|
||||||
|
@ -37,7 +38,8 @@ describe('Item fixed prices path', () => {
|
||||||
it('should reload the section and check the created price has the expected ID', async() => {
|
it('should reload the section and check the created price has the expected ID', async() => {
|
||||||
await page.accessToSection('item.index');
|
await page.accessToSection('item.index');
|
||||||
await page.accessToSection('item.fixedPrice');
|
await page.accessToSection('item.fixedPrice');
|
||||||
await page.doSearch();
|
await page.waitToClick(selectors.itemFixedPrice.removeWarehouseFilter);
|
||||||
|
await page.waitForSpinnerLoad();
|
||||||
|
|
||||||
const result = await page.waitToGetProperty(selectors.itemFixedPrice.fourthItemID, 'value');
|
const result = await page.waitToGetProperty(selectors.itemFixedPrice.fourthItemID, 'value');
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('editFixedPrice', {
|
||||||
|
description: 'Updates a column for one or more fixed price',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'field',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: `the column to edit`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'newValue',
|
||||||
|
type: 'any',
|
||||||
|
required: true,
|
||||||
|
description: `The new value to save`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'lines',
|
||||||
|
type: ['object'],
|
||||||
|
required: true,
|
||||||
|
description: `the buys which will be modified`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'filter',
|
||||||
|
type: 'object',
|
||||||
|
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string'
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/editFixedPrice`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.editFixedPrice = async(ctx, field, newValue, lines, filter, options) => {
|
||||||
|
let tx;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
let modelName;
|
||||||
|
let identifier;
|
||||||
|
|
||||||
|
switch (field) {
|
||||||
|
case 'hasMinPrice':
|
||||||
|
case 'minPrice':
|
||||||
|
modelName = 'Item';
|
||||||
|
identifier = 'itemFk';
|
||||||
|
break;
|
||||||
|
case 'rate2':
|
||||||
|
case 'rate3':
|
||||||
|
case 'started':
|
||||||
|
case 'ended':
|
||||||
|
case 'warehouseFk':
|
||||||
|
modelName = 'FixedPrice';
|
||||||
|
identifier = 'id';
|
||||||
|
}
|
||||||
|
|
||||||
|
const models = Self.app.models;
|
||||||
|
const model = models[modelName];
|
||||||
|
try {
|
||||||
|
const promises = [];
|
||||||
|
const value = {};
|
||||||
|
value[field] = newValue;
|
||||||
|
|
||||||
|
if (filter) {
|
||||||
|
filter = {where: filter};
|
||||||
|
lines = await models.FixedPrice.filter(ctx, filter, myOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
const targets = lines.map(line => {
|
||||||
|
return line[identifier];
|
||||||
|
});
|
||||||
|
for (let target of targets)
|
||||||
|
promises.push(model.upsertWithWhere({id: target}, value, myOptions));
|
||||||
|
|
||||||
|
const result = await Promise.all(promises);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -184,8 +184,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt.merge(conn.makeWhere(filter.where));
|
stmt.merge(conn.makeSuffix(filter));
|
||||||
stmt.merge(conn.makePagination(filter));
|
|
||||||
|
|
||||||
const fixedPriceIndex = stmts.push(stmt) - 1;
|
const fixedPriceIndex = stmts.push(stmt) - 1;
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('Item editFixedPrice()', () => {
|
||||||
|
it('should change the value of a given column for the selected buys', async() => {
|
||||||
|
const tx = await models.FixedPrice.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
|
args: {
|
||||||
|
search: '1'
|
||||||
|
},
|
||||||
|
req: {accessToken: {userId: 1}}
|
||||||
|
};
|
||||||
|
|
||||||
|
const [original] = await models.FixedPrice.filter(ctx, null, options);
|
||||||
|
|
||||||
|
const field = 'rate2';
|
||||||
|
const newValue = 99;
|
||||||
|
const lines = [{itemFk: original.itemFk, id: original.id}];
|
||||||
|
|
||||||
|
await models.FixedPrice.editFixedPrice(ctx, field, newValue, lines, null, options);
|
||||||
|
|
||||||
|
const [result] = await models.FixedPrice.filter(ctx, null, options);
|
||||||
|
|
||||||
|
expect(result[field]).toEqual(newValue);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should change the value of a given column for filter', async() => {
|
||||||
|
const tx = await models.FixedPrice.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const filter = {'it.categoryFk': 1};
|
||||||
|
const ctx = {
|
||||||
|
args: {
|
||||||
|
filter: filter
|
||||||
|
},
|
||||||
|
req: {accessToken: {userId: 1}}
|
||||||
|
};
|
||||||
|
|
||||||
|
const field = 'rate2';
|
||||||
|
const newValue = 88;
|
||||||
|
|
||||||
|
await models.FixedPrice.editFixedPrice(ctx, field, newValue, null, filter, options);
|
||||||
|
|
||||||
|
const [result] = await models.FixedPrice.filter(ctx, null, options);
|
||||||
|
|
||||||
|
expect(result[field]).toEqual(newValue);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -42,7 +42,7 @@ describe('upsertFixedPrice()', () => {
|
||||||
|
|
||||||
delete ctx.args.started;
|
delete ctx.args.started;
|
||||||
delete ctx.args.ended;
|
delete ctx.args.ended;
|
||||||
ctx.args.hasMinPrice = true;
|
ctx.args.hasMinPrice = false;
|
||||||
|
|
||||||
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ describe('upsertFixedPrice()', () => {
|
||||||
|
|
||||||
delete ctx.args.started;
|
delete ctx.args.started;
|
||||||
delete ctx.args.ended;
|
delete ctx.args.ended;
|
||||||
ctx.args.hasMinPrice = false;
|
ctx.args.hasMinPrice = true;
|
||||||
|
|
||||||
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ describe('upsertFixedPrice()', () => {
|
||||||
rate2: rate2,
|
rate2: rate2,
|
||||||
rate3: firstRate3,
|
rate3: firstRate3,
|
||||||
minPrice: 0,
|
minPrice: 0,
|
||||||
hasMinPrice: false
|
hasMinPrice: true
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// create new fixed price
|
// create new fixed price
|
||||||
|
|
|
@ -87,7 +87,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
await targetItem.updateAttributes({
|
await targetItem.updateAttributes({
|
||||||
minPrice: args.minPrice,
|
minPrice: args.minPrice,
|
||||||
hasMinPrice: args.minPrice ? true : false
|
hasMinPrice: args.hasMinPrice
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const itemFields = [
|
const itemFields = [
|
||||||
|
|
|
@ -2,4 +2,5 @@ module.exports = Self => {
|
||||||
require('../methods/fixed-price/filter')(Self);
|
require('../methods/fixed-price/filter')(Self);
|
||||||
require('../methods/fixed-price/upsertFixedPrice')(Self);
|
require('../methods/fixed-price/upsertFixedPrice')(Self);
|
||||||
require('../methods/fixed-price/getRate2')(Self);
|
require('../methods/fixed-price/getRate2')(Self);
|
||||||
|
require('../methods/fixed-price/editFixedPrice')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="FixedPrices/filter"
|
url="FixedPrices/filter"
|
||||||
|
user-params="::$ctrl.filterParams"
|
||||||
limit="20"
|
limit="20"
|
||||||
data="prices"
|
data="prices"
|
||||||
order="itemFk"
|
order="itemFk"
|
||||||
|
@ -17,6 +18,8 @@
|
||||||
auto-state="false"
|
auto-state="false"
|
||||||
panel="vn-fixed-price-search-panel"
|
panel="vn-fixed-price-search-panel"
|
||||||
info="Search prices by item ID or code"
|
info="Search prices by item ID or code"
|
||||||
|
suggested-filter="$ctrl.filterParams"
|
||||||
|
filter="$ctrl.filterParams"
|
||||||
placeholder="Search fixed prices"
|
placeholder="Search fixed prices"
|
||||||
model="model">
|
model="model">
|
||||||
</vn-searchbar>
|
</vn-searchbar>
|
||||||
|
@ -31,15 +34,21 @@
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th shrink>
|
||||||
|
<vn-multi-check
|
||||||
|
model="model"
|
||||||
|
checked="$ctrl.checkAll"
|
||||||
|
check-field="checked"
|
||||||
|
check-dummy-enabled="true"
|
||||||
|
checked-dummy-count="$ctrl.checkedDummyCount">
|
||||||
|
</vn-multi-check>
|
||||||
|
</th>
|
||||||
<th field="itemFk">
|
<th field="itemFk">
|
||||||
<span translate>Item ID</span>
|
<span translate>Item ID</span>
|
||||||
</th>
|
</th>
|
||||||
<th field="name">
|
<th field="name">
|
||||||
<span translate>Description</span>
|
<span translate>Description</span>
|
||||||
</th>
|
</th>
|
||||||
<th field="warehouseFk">
|
|
||||||
<span translate>Warehouse</span>
|
|
||||||
</th>
|
|
||||||
<th
|
<th
|
||||||
field="rate2">
|
field="rate2">
|
||||||
<span translate>Grouping price</span>
|
<span translate>Grouping price</span>
|
||||||
|
@ -57,13 +66,24 @@
|
||||||
<th field="ended">
|
<th field="ended">
|
||||||
<span translate>Ended</span>
|
<span translate>Ended</span>
|
||||||
</th>
|
</th>
|
||||||
|
<th field="warehouseFk">
|
||||||
|
<span translate>Warehouse</span>
|
||||||
|
</th>
|
||||||
<th shrink></th>
|
<th shrink></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr ng-repeat="price in prices">
|
<tr ng-repeat="price in prices">
|
||||||
|
<td>
|
||||||
|
<vn-check
|
||||||
|
ng-model="price.checked"
|
||||||
|
on-change="$ctrl.saveChecked(price.id)"
|
||||||
|
vn-click-stop>
|
||||||
|
</vn-check>
|
||||||
|
</td>
|
||||||
<td shrink-field>
|
<td shrink-field>
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
|
vn-id="itemFk"
|
||||||
class="dense"
|
class="dense"
|
||||||
url="Items/withName"
|
url="Items/withName"
|
||||||
ng-model="price.itemFk"
|
ng-model="price.itemFk"
|
||||||
|
@ -88,7 +108,7 @@
|
||||||
ng-if="price.itemFk"
|
ng-if="price.itemFk"
|
||||||
ng-click="itemDescriptor.show($event, price.itemFk)"
|
ng-click="itemDescriptor.show($event, price.itemFk)"
|
||||||
class="link">
|
class="link">
|
||||||
{{price.name}}
|
{{itemFk.selection.name}}
|
||||||
</span>
|
</span>
|
||||||
<vn-one ng-if="price.subName">
|
<vn-one ng-if="price.subName">
|
||||||
<h3 title="{{price.subName}}">{{price.subName}}</h3>
|
<h3 title="{{price.subName}}">{{price.subName}}</h3>
|
||||||
|
@ -100,18 +120,11 @@
|
||||||
tabindex="-1">
|
tabindex="-1">
|
||||||
</vn-fetched-tags>
|
</vn-fetched-tags>
|
||||||
</td>
|
</td>
|
||||||
<td shrink-field-expand>
|
|
||||||
<vn-autocomplete
|
|
||||||
vn-one
|
|
||||||
ng-model="price.warehouseFk"
|
|
||||||
data="warehouses"
|
|
||||||
on-change="$ctrl.upsertPrice(price)"
|
|
||||||
tabindex="2">
|
|
||||||
</vn-autocomplete>
|
|
||||||
</td>
|
|
||||||
<td shrink-field>
|
<td shrink-field>
|
||||||
<vn-td-editable number>
|
<vn-td-editable number>
|
||||||
<text>{{price.rate2 | currency: 'EUR':2}}</text>
|
<text>
|
||||||
|
<strong>{{price.rate2 | currency: 'EUR':2}}</strong>
|
||||||
|
</text>
|
||||||
<field>
|
<field>
|
||||||
<vn-input-number
|
<vn-input-number
|
||||||
class="dense"
|
class="dense"
|
||||||
|
@ -125,7 +138,9 @@
|
||||||
</td>
|
</td>
|
||||||
<td shrink-field>
|
<td shrink-field>
|
||||||
<vn-td-editable number>
|
<vn-td-editable number>
|
||||||
<text>{{price.rate3 | currency: 'EUR':2}}</text>
|
<text>
|
||||||
|
<strong>{{price.rate3 | currency: 'EUR':2}}</strong>
|
||||||
|
</text>
|
||||||
<field>
|
<field>
|
||||||
<vn-input-number
|
<vn-input-number
|
||||||
class="dense"
|
class="dense"
|
||||||
|
@ -140,28 +155,42 @@
|
||||||
<td shrink-field-expand class="minPrice">
|
<td shrink-field-expand class="minPrice">
|
||||||
<vn-check
|
<vn-check
|
||||||
vn-one
|
vn-one
|
||||||
ng-model="price.hasMinPrice">
|
ng-model="price.hasMinPrice"
|
||||||
|
on-change="$ctrl.upsertPrice(price)">
|
||||||
</vn-check>
|
</vn-check>
|
||||||
<vn-input-number
|
<vn-input-number
|
||||||
disabled="!price.hasMinPrice"
|
ng-class="{inactive: !price.hasMinPrice}"
|
||||||
ng-model="price.minPrice"
|
ng-model="price.minPrice"
|
||||||
on-change="$ctrl.upsertPrice(price)"
|
on-change="$ctrl.upsertPrice(price)"
|
||||||
step="0.01">
|
step="0.01">
|
||||||
</vn-input-number>
|
</vn-input-number>
|
||||||
</td>
|
</td>
|
||||||
<td shrink-date>
|
<td shrink-date>
|
||||||
<vn-date-picker
|
<vn-chip class="chip {{$ctrl.isBigger(price.started)}} transparent">
|
||||||
vn-one
|
<vn-date-picker
|
||||||
ng-model="price.started"
|
vn-one
|
||||||
on-change="$ctrl.upsertPrice(price)">
|
ng-model="price.started"
|
||||||
</vn-date-picker>
|
on-change="$ctrl.upsertPrice(price)">
|
||||||
|
</vn-date-picker>
|
||||||
|
</vn-chip>
|
||||||
</td>
|
</td>
|
||||||
<td shrink-date>
|
<td shrink-date>
|
||||||
<vn-date-picker
|
<vn-chip class="chip {{$ctrl.isLower(price.ended)}} transparent">
|
||||||
|
<vn-date-picker
|
||||||
|
vn-one
|
||||||
|
ng-model="price.ended"
|
||||||
|
on-change="$ctrl.upsertPrice(price)">
|
||||||
|
</vn-date-picker>
|
||||||
|
</vn-chip>
|
||||||
|
</td>
|
||||||
|
<td expand>
|
||||||
|
<vn-autocomplete
|
||||||
vn-one
|
vn-one
|
||||||
ng-model="price.ended"
|
ng-model="price.warehouseFk"
|
||||||
on-change="$ctrl.upsertPrice(price)">
|
data="warehouses"
|
||||||
</vn-date-picker>
|
on-change="$ctrl.upsertPrice(price)"
|
||||||
|
tabindex="2">
|
||||||
|
</vn-autocomplete>
|
||||||
</td>
|
</td>
|
||||||
<td shrink>
|
<td shrink>
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
|
@ -185,6 +214,69 @@
|
||||||
</smart-table>
|
</smart-table>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div fixed-bottom-right>
|
||||||
|
<vn-vertical style="align-items: center;">
|
||||||
|
<vn-button class="round sm vn-mb-sm"
|
||||||
|
icon="edit"
|
||||||
|
ng-show="$ctrl.totalChecked > 0"
|
||||||
|
ng-click="edit.show($event)"
|
||||||
|
vn-tooltip="Edit fixed price(s)"
|
||||||
|
tooltip-position="left">
|
||||||
|
</vn-button>
|
||||||
|
</vn-vertical>
|
||||||
|
</div>
|
||||||
|
<vn-dialog class="edit"
|
||||||
|
vn-id="edit"
|
||||||
|
on-accept="$ctrl.onEditAccept()"
|
||||||
|
on-close="$ctrl.editedColumn = null">
|
||||||
|
<tpl-body style="width: 400px;">
|
||||||
|
<span translate>Edit</span>
|
||||||
|
<span class="countLines">
|
||||||
|
{{::$ctrl.totalChecked}}
|
||||||
|
</span>
|
||||||
|
<span translate>buy(s)</span>
|
||||||
|
<vn-horizontal>
|
||||||
|
<vn-autocomplete
|
||||||
|
vn-one
|
||||||
|
ng-model="$ctrl.editedColumn.field"
|
||||||
|
data="$ctrl.columns"
|
||||||
|
value-field="field"
|
||||||
|
show-field="displayName"
|
||||||
|
label="Field to edit">
|
||||||
|
</vn-autocomplete>
|
||||||
|
<vn-input-number
|
||||||
|
vn-one
|
||||||
|
ng-if="$ctrl.editedColumn.field == 'rate2' || $ctrl.editedColumn.field == 'rate3' || $ctrl.editedColumn.field == 'minPrice'"
|
||||||
|
label="Value"
|
||||||
|
ng-model="$ctrl.editedColumn.newValue">
|
||||||
|
</vn-input-number>
|
||||||
|
<vn-check
|
||||||
|
vn-one
|
||||||
|
ng-if="$ctrl.editedColumn.field == 'hasMinPrice'"
|
||||||
|
ng-model="$ctrl.editedColumn.newValue">
|
||||||
|
</vn-check>
|
||||||
|
<vn-date-picker
|
||||||
|
vn-one
|
||||||
|
ng-if="$ctrl.editedColumn.field == 'started' || $ctrl.editedColumn.field == 'ended'"
|
||||||
|
label="Date"
|
||||||
|
ng-model="$ctrl.editedColumn.newValue">
|
||||||
|
</vn-date-picker>
|
||||||
|
<vn-autocomplete
|
||||||
|
vn-one
|
||||||
|
ng-if="$ctrl.editedColumn.field == 'warehouseFk'"
|
||||||
|
label="Warehouse"
|
||||||
|
ng-model="$ctrl.editedColumn.newValue"
|
||||||
|
data="warehouses">
|
||||||
|
</vn-autocomplete>
|
||||||
|
</vn-horizontal>
|
||||||
|
</tpl-body>
|
||||||
|
<tpl-buttons>
|
||||||
|
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||||
|
<button response="accept" translate>Save</button>
|
||||||
|
</tpl-buttons>
|
||||||
|
</vn-dialog>
|
||||||
|
|
||||||
<vn-item-descriptor-popover
|
<vn-item-descriptor-popover
|
||||||
vn-id="item-descriptor"
|
vn-id="item-descriptor"
|
||||||
warehouse-fk="$ctrl.vnConfig.warehouseFk">
|
warehouse-fk="$ctrl.vnConfig.warehouseFk">
|
||||||
|
|
|
@ -5,6 +5,9 @@ import './style.scss';
|
||||||
export default class Controller extends Section {
|
export default class Controller extends Section {
|
||||||
constructor($element, $) {
|
constructor($element, $) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
|
this.editedColumn;
|
||||||
|
this.checkAll = false;
|
||||||
|
this.checkedFixedPrices = [];
|
||||||
|
|
||||||
this.smartTableOptions = {
|
this.smartTableOptions = {
|
||||||
activeButtons: {
|
activeButtons: {
|
||||||
|
@ -30,13 +33,146 @@ export default class Controller extends Section {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.filterParams = {
|
||||||
|
warehouseFk: this.vnConfig.warehouseFk
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
getFilterParams() {
|
||||||
|
return {
|
||||||
|
warehouseFk: this.vnConfig.warehouseFk
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
get columns() {
|
||||||
|
if (this._columns) return this._columns;
|
||||||
|
|
||||||
|
this._columns = [
|
||||||
|
{field: 'rate2', displayName: this.$t('Grouping price')},
|
||||||
|
{field: 'rate3', displayName: this.$t('Packing price')},
|
||||||
|
{field: 'hasMinPrice', displayName: this.$t('Has min price')},
|
||||||
|
{field: 'minPrice', displayName: this.$t('Min price')},
|
||||||
|
{field: 'started', displayName: this.$t('Started')},
|
||||||
|
{field: 'ended', displayName: this.$t('Ended')},
|
||||||
|
{field: 'warehouseFk', displayName: this.$t('Warehouse')}
|
||||||
|
];
|
||||||
|
|
||||||
|
return this._columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
get checked() {
|
||||||
|
const fixedPrices = this.$.model.data || [];
|
||||||
|
const checkedBuys = [];
|
||||||
|
for (let fixedPrice of fixedPrices) {
|
||||||
|
if (fixedPrice.checked)
|
||||||
|
checkedBuys.push(fixedPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
return checkedBuys;
|
||||||
|
}
|
||||||
|
|
||||||
|
uncheck() {
|
||||||
|
this.checkAll = false;
|
||||||
|
this.checkedFixedPrices = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get totalChecked() {
|
||||||
|
if (this.checkedDummyCount)
|
||||||
|
return this.checkedDummyCount;
|
||||||
|
|
||||||
|
return this.checked.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
saveChecked(fixedPriceId) {
|
||||||
|
const index = this.checkedFixedPrices.indexOf(fixedPriceId);
|
||||||
|
if (index !== -1)
|
||||||
|
return this.checkedFixedPrices.splice(index, 1);
|
||||||
|
return this.checkedFixedPrices.push(fixedPriceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
reCheck() {
|
||||||
|
if (!this.$.model.data) return;
|
||||||
|
if (!this.checkedFixedPrices.length) return;
|
||||||
|
|
||||||
|
this.$.model.data.forEach(fixedPrice => {
|
||||||
|
if (this.checkedFixedPrices.includes(fixedPrice.id))
|
||||||
|
fixedPrice.checked = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onEditAccept() {
|
||||||
|
const rowsToEdit = [];
|
||||||
|
for (let row of this.checked)
|
||||||
|
rowsToEdit.push({id: row.id, itemFk: row.itemFk});
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
field: this.editedColumn.field,
|
||||||
|
newValue: this.editedColumn.newValue,
|
||||||
|
lines: rowsToEdit
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.checkedDummyCount && this.checkedDummyCount > 0) {
|
||||||
|
const params = {};
|
||||||
|
if (this.$.model.userParams) {
|
||||||
|
const userParams = this.$.model.userParams;
|
||||||
|
for (let param in userParams) {
|
||||||
|
let newParam = this.exprBuilder(param, userParams[param]);
|
||||||
|
if (!newParam)
|
||||||
|
newParam = {[param]: userParams[param]};
|
||||||
|
Object.assign(params, newParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.$.model.userFilter)
|
||||||
|
Object.assign(params, this.$.model.userFilter.where);
|
||||||
|
|
||||||
|
data.filter = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.$http.post('FixedPrices/editFixedPrice', data)
|
||||||
|
.then(() => {
|
||||||
|
this.uncheck();
|
||||||
|
this.$.model.refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
isBigger(date) {
|
||||||
|
let today = Date.vnNew();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
date = new Date(date);
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
const timeDifference = today - date;
|
||||||
|
if (timeDifference < 0) return 'warning';
|
||||||
|
}
|
||||||
|
|
||||||
|
isLower(date) {
|
||||||
|
let today = Date.vnNew();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
date = new Date(date);
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
const timeDifference = today - date;
|
||||||
|
if (timeDifference > 0) return 'warning';
|
||||||
}
|
}
|
||||||
|
|
||||||
add() {
|
add() {
|
||||||
if (!this.$.model.data || this.$.model.data.length == 0) {
|
if (!this.$.model.data || this.$.model.data.length == 0) {
|
||||||
this.$.model.data = [];
|
this.$.model.data = [];
|
||||||
this.$.model.proxiedData = [];
|
this.$.model.proxiedData = [];
|
||||||
this.$.model.insert({});
|
|
||||||
|
const today = Date.vnNew();
|
||||||
|
|
||||||
|
const millisecsInDay = 86400000;
|
||||||
|
const daysInWeek = 7;
|
||||||
|
const nextWeek = new Date(today.getTime() + daysInWeek * millisecsInDay);
|
||||||
|
|
||||||
|
this.$.model.insert({
|
||||||
|
started: today,
|
||||||
|
ended: nextWeek
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,10 +202,8 @@ export default class Controller extends Section {
|
||||||
if (resetMinPrice)
|
if (resetMinPrice)
|
||||||
delete price['minPrice'];
|
delete price['minPrice'];
|
||||||
|
|
||||||
price.hasMinPrice = price.minPrice ? true : false;
|
const requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3'];
|
||||||
|
for (const field of requiredFields)
|
||||||
let requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3'];
|
|
||||||
for (let field of requiredFields)
|
|
||||||
if (price[field] == undefined) return;
|
if (price[field] == undefined) return;
|
||||||
|
|
||||||
const query = 'FixedPrices/upsertFixedPrice';
|
const query = 'FixedPrices/upsertFixedPrice';
|
||||||
|
|
|
@ -12,8 +12,92 @@ describe('fixed price', () => {
|
||||||
const $scope = $rootScope.$new();
|
const $scope = $rootScope.$new();
|
||||||
const $element = angular.element('<vn-fixed-price></vn-fixed-price>');
|
const $element = angular.element('<vn-fixed-price></vn-fixed-price>');
|
||||||
controller = $componentController('vnFixedPrice', {$element, $scope});
|
controller = $componentController('vnFixedPrice', {$element, $scope});
|
||||||
|
controller.$ = {
|
||||||
|
model: {refresh: () => {}},
|
||||||
|
edit: {hide: () => {}}
|
||||||
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
describe('get columns', () => {
|
||||||
|
it(`should return a set of columns`, () => {
|
||||||
|
let result = controller.columns;
|
||||||
|
|
||||||
|
let length = result.length;
|
||||||
|
let anyColumn = Object.keys(result[Math.floor(Math.random() * Math.floor(length))]);
|
||||||
|
|
||||||
|
expect(anyColumn).toContain('field', 'displayName');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('get checked', () => {
|
||||||
|
it(`should return a set of checked lines`, () => {
|
||||||
|
controller.$.model.data = [
|
||||||
|
{checked: true, id: 1},
|
||||||
|
{checked: true, id: 2},
|
||||||
|
{checked: true, id: 3},
|
||||||
|
{checked: false, id: 4},
|
||||||
|
];
|
||||||
|
|
||||||
|
let result = controller.checked;
|
||||||
|
|
||||||
|
expect(result.length).toEqual(3);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('reCheck()', () => {
|
||||||
|
it(`should recheck buys`, () => {
|
||||||
|
controller.$.model.data = [
|
||||||
|
{checked: false, id: 1},
|
||||||
|
{checked: false, id: 2},
|
||||||
|
{checked: false, id: 3},
|
||||||
|
{checked: false, id: 4},
|
||||||
|
];
|
||||||
|
controller.checkedFixedPrices = [1, 2];
|
||||||
|
|
||||||
|
controller.reCheck();
|
||||||
|
|
||||||
|
expect(controller.$.model.data[0].checked).toEqual(true);
|
||||||
|
expect(controller.$.model.data[1].checked).toEqual(true);
|
||||||
|
expect(controller.$.model.data[2].checked).toEqual(false);
|
||||||
|
expect(controller.$.model.data[3].checked).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('saveChecked()', () => {
|
||||||
|
it(`should check buy`, () => {
|
||||||
|
const buyCheck = 3;
|
||||||
|
controller.checkedFixedPrices = [1, 2];
|
||||||
|
|
||||||
|
controller.saveChecked(buyCheck);
|
||||||
|
|
||||||
|
expect(controller.checkedFixedPrices[2]).toEqual(buyCheck);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should uncheck buy`, () => {
|
||||||
|
const buyUncheck = 3;
|
||||||
|
controller.checkedFixedPrices = [1, 2, 3];
|
||||||
|
|
||||||
|
controller.saveChecked(buyUncheck);
|
||||||
|
|
||||||
|
expect(controller.checkedFixedPrices[2]).toEqual(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onEditAccept()', () => {
|
||||||
|
it(`should perform a query to update columns`, () => {
|
||||||
|
controller.editedColumn = {field: 'my field', newValue: 'the new value'};
|
||||||
|
const query = 'FixedPrices/editFixedPrice';
|
||||||
|
|
||||||
|
$httpBackend.expectPOST(query).respond();
|
||||||
|
controller.onEditAccept();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
const result = controller.checked;
|
||||||
|
|
||||||
|
expect(result.length).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('upsertPrice()', () => {
|
describe('upsertPrice()', () => {
|
||||||
it('should do nothing if one or more required arguments are missing', () => {
|
it('should do nothing if one or more required arguments are missing', () => {
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
|
|
|
@ -3,3 +3,5 @@ Search prices by item ID or code: Buscar por ID de artículo o código
|
||||||
Search fixed prices: Buscar precios fijados
|
Search fixed prices: Buscar precios fijados
|
||||||
Add fixed price: Añadir precio fijado
|
Add fixed price: Añadir precio fijado
|
||||||
This row will be removed: Esta linea se eliminará
|
This row will be removed: Esta linea se eliminará
|
||||||
|
Edit fixed price(s): Editar precio(s) fijado(s)
|
||||||
|
Has min price: Tiene precio mínimo
|
||||||
|
|
|
@ -1,20 +1,46 @@
|
||||||
@import "variables";
|
@import "variables";
|
||||||
smart-table table{
|
vn-fixed-price{
|
||||||
[shrink-field]{
|
smart-table table{
|
||||||
width: 80px;
|
[shrink-field]{
|
||||||
max-width: 80px;
|
width: 80px;
|
||||||
|
max-width: 80px;
|
||||||
|
}
|
||||||
|
[shrink-field-expand]{
|
||||||
|
width: 150px;
|
||||||
|
max-width: 150px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[shrink-field-expand]{
|
|
||||||
width: 150px;
|
|
||||||
max-width: 150px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.minPrice {
|
.minPrice {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
vn-input-number {
|
vn-input-number {
|
||||||
width: 90px;
|
width: 90px;
|
||||||
max-width: 90px;
|
max-width: 90px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
smart-table table tbody > * > td .chip {
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
smart-table table tbody > * > td{
|
||||||
|
padding: 0px;
|
||||||
|
padding-left: 5px;
|
||||||
|
padding-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
smart-table table tbody > * > td .chip.warning {
|
||||||
|
color: $color-font-bg
|
||||||
|
}
|
||||||
|
|
||||||
|
.vn-field > .container > .infix > .control > input {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
vn-input-number.inactive{
|
||||||
|
input {
|
||||||
|
color: $color-font-light !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue