Merge branch 'dev' into 3752-claim_action
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2022-05-10 11:47:14 +00:00
commit a47c0dbaea
19 changed files with 206 additions and 48 deletions

View File

@ -28,7 +28,7 @@ module.exports = Self => {
const args = ctx.args; const args = ctx.args;
const models = Self.app.models; const models = Self.app.models;
const sale = await models.Sale.findById(args.saleId,); const sale = await models.Sale.findById(args.saleId);
return await sale.updateAttribute('quantity', args.quantity); return await sale.updateAttribute('quantity', args.quantity);
}; };
}; };

View File

@ -1133,7 +1133,7 @@ export default {
entryLatestBuys: { entryLatestBuys: {
firstBuy: 'vn-entry-latest-buys tbody > tr:nth-child(1)', firstBuy: 'vn-entry-latest-buys tbody > tr:nth-child(1)',
allBuysCheckBox: 'vn-entry-latest-buys thead vn-check', allBuysCheckBox: 'vn-entry-latest-buys thead vn-check',
secondBuyCheckBox: 'vn-entry-latest-buys tbody tr:nth-child(2) vn-check[ng-model="buy.$checked"]', secondBuyCheckBox: 'vn-entry-latest-buys tbody tr:nth-child(2) vn-check[ng-model="buy.checked"]',
editBuysButton: 'vn-entry-latest-buys vn-button[icon="edit"]', editBuysButton: 'vn-entry-latest-buys vn-button[icon="edit"]',
fieldAutocomplete: 'vn-autocomplete[ng-model="$ctrl.editedColumn.field"]', fieldAutocomplete: 'vn-autocomplete[ng-model="$ctrl.editedColumn.field"]',
newValueInput: 'vn-textfield[ng-model="$ctrl.editedColumn.newValue"]', newValueInput: 'vn-textfield[ng-model="$ctrl.editedColumn.newValue"]',

View File

@ -0,0 +1 @@
SelectAllRows: Select the {{rows}} row(s)

View File

@ -0,0 +1,3 @@
SelectAllRows: Seleccionar las {{rows}} fila(s)
All: Se han seleccionado
row(s) have been selected.: fila(s).

View File

@ -2,4 +2,23 @@
ng-model="$ctrl.checked" ng-model="$ctrl.checked"
indeterminate="$ctrl.isIndeterminate" indeterminate="$ctrl.isIndeterminate"
translate-attr="{title: 'Check all'}"> translate-attr="{title: 'Check all'}">
</vn-check> </vn-check>
<vn-icon-button
class="vn-pl-none"
ng-if="$ctrl.checked && $ctrl.checkDummyEnabled"
icon="expand_more"
vn-popover="menu"
ng-click="$ctrl.countRows()">
</vn-icon-button>
<vn-menu vn-id="menu">
<vn-list>
<span translate>All</span>
<span class="bold">
{{$ctrl.rows}}
</span>
<span translate>row(s) have been selected.</span>
<span class="bold link" ng-click="$ctrl.checkDummy()">
{{$ctrl.allRowsText}}
</span>
</vn-list>
</vn-menu>

View File

@ -106,6 +106,9 @@ export default class MultiCheck extends FormInput {
this.toggle(); this.toggle();
this.emit('change', value); this.emit('change', value);
if (!value)
this.checkedDummyCount = null;
} }
/** /**
@ -132,12 +135,43 @@ export default class MultiCheck extends FormInput {
areAllUnchecked() { areAllUnchecked() {
if (!this.model || !this.model.data) return; if (!this.model || !this.model.data) return;
this.checkedDummyCount = null;
const data = this.model.data; const data = this.model.data;
return data.every(item => { return data.every(item => {
return item[this.checkField] === false; return item[this.checkField] === false;
}); });
} }
countRows() {
if (!this.model || !this.model.data) return;
const data = this.model.data;
const modelParams = this.model.userParams;
const params = {
filter: {
modelParams: modelParams,
limit: null
}
};
this.rows = data.length;
this.$http.get(this.model.url, {params})
.then(res => {
this.allRowsCount = res.data.length;
this.allRowsText = this.$t('SelectAllRows', {
rows: this.allRowsCount
});
});
}
checkDummy() {
if (this.checkedDummyCount)
return this.checkedDummyCount = null;
this.checkedDummyCount = this.allRowsCount;
}
/** /**
* Toggles checked property on * Toggles checked property on
* all instances * all instances
@ -158,7 +192,9 @@ ngModule.vnComponent('vnMultiCheck', {
checkField: '@?', checkField: '@?',
checkAll: '=?', checkAll: '=?',
checked: '=?', checked: '=?',
disabled: '<?' disabled: '<?',
checkDummyEnabled: '<?',
checkedDummyCount: '=?'
} }
}); });

View File

@ -4,10 +4,14 @@ import crudModel from 'core/mocks/crud-model';
describe('Component vnMultiCheck', () => { describe('Component vnMultiCheck', () => {
let controller; let controller;
let $element; let $element;
let $httpBackend;
let $httpParamSerializer;
beforeEach(ngModule('vnCore')); beforeEach(ngModule('vnCore'));
beforeEach(inject($componentController => { beforeEach(inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
$element = angular.element(`<div class="shown"></div>`); $element = angular.element(`<div class="shown"></div>`);
controller = $componentController('vnMultiCheck', {$element: $element}); controller = $componentController('vnMultiCheck', {$element: $element});
controller._model = crudModel; controller._model = crudModel;
@ -26,6 +30,14 @@ describe('Component vnMultiCheck', () => {
expect(controller._checked).toEqual(crudModel); expect(controller._checked).toEqual(crudModel);
expect(controller.toggle).toHaveBeenCalledWith(); expect(controller.toggle).toHaveBeenCalledWith();
}); });
it(`should set checkedDummyCount to null`, () => {
jest.spyOn(controller, 'toggle');
controller.checkedDummyCount = 12;
controller.checked = null;
expect(controller.checkedDummyCount).toBeNull();
});
}); });
describe('toggle()', () => { describe('toggle()', () => {
@ -132,4 +144,50 @@ describe('Component vnMultiCheck', () => {
expect(thirdRow.checked).toBeTruthy(); expect(thirdRow.checked).toBeTruthy();
}); });
}); });
describe('countRows()', () => {
it(`should count visible rows and all rows of model`, () => {
controller.model.url = 'modelUrl/filter';
const data = controller.model.data;
const filter = {
limit: null
};
const serializedParams = $httpParamSerializer({filter});
const response = [
{id: 1, name: 'My item 1'},
{id: 2, name: 'My item 2'},
{id: 3, name: 'My item 3'},
{id: 4, name: 'My item 4'},
{id: 5, name: 'My item 5'},
{id: 6, name: 'My item 6'}
];
controller.countRows();
$httpBackend.expectGET(`modelUrl/filter?${serializedParams}`).respond(response);
$httpBackend.flush();
expect(controller.rows).toEqual(data.length);
expect(controller.allRowsCount).toEqual(response.length);
expect(controller.allRowsCount).toBeGreaterThan(controller.rows);
});
});
describe('checkDummy()', () => {
const allRows = 1234;
it(`should set the checked dummy count to all rows count if there was no count yet`, () => {
controller.checkedDummyCount = null;
controller.allRowsCount = allRows;
controller.checkDummy();
expect(controller.checkedDummyCount).toEqual(controller.allRowsCount);
});
it(`should remove the dummy count if there was an existing one`, () => {
controller.checkedDummyCount = allRows;
controller.checkDummy();
expect(controller.checkedDummyCount).toBeNull();
});
});
}); });

View File

@ -1,5 +1,17 @@
@import "variables";
vn-multi-check { vn-multi-check {
.vn-check { .vn-check {
margin-bottom: 12px margin-bottom: 12px
} }
vn-list{
padding: 50px;
}
vn-menu{
padding: 50px;
}
}
.bold{
font-weight: bold;
} }

View File

@ -105,7 +105,7 @@
<div ng-transclude="btnFive"> <div ng-transclude="btnFive">
<vn-quick-link <vn-quick-link
ng-if="$ctrl.client.supplier.nif" ng-if="$ctrl.client.supplier.nif"
tooltip="Go to client" tooltip="Go to supplier"
state="['supplier.card.summary', {id: $ctrl.client.supplier.id}]" state="['supplier.card.summary', {id: $ctrl.client.supplier.id}]"
icon="icon-supplier"> icon="icon-supplier">
</vn-quick-link> </vn-quick-link>

View File

@ -3,5 +3,6 @@ View consumer report: Ver informe de consumo
From date: Fecha desde From date: Fecha desde
To date: Fecha hasta To date: Fecha hasta
Go to user: Ir al usuario Go to user: Ir al usuario
Go to supplier: Ir al proveedor
Client invoices list: Listado de facturas del cliente Client invoices list: Listado de facturas del cliente
Pay method: Forma de pago Pay method: Forma de pago

View File

@ -1,27 +1,32 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('editLatestBuys', { Self.remoteMethodCtx('editLatestBuys', {
description: 'Updates a column for one or more buys', description: 'Updates a column for one or more buys',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [{
arg: 'field', arg: 'field',
type: 'String', type: 'string',
required: true, required: true,
description: `the column to edit` description: `the column to edit`
}, },
{ {
arg: 'newValue', arg: 'newValue',
type: 'Any', type: 'any',
required: true, required: true,
description: `The new value to save` description: `The new value to save`
}, },
{ {
arg: 'lines', arg: 'lines',
type: ['Object'], type: ['object'],
required: true, required: true,
description: `the buys which will be modified` 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: { returns: {
type: 'Object', type: 'object',
root: true root: true
}, },
http: { http: {
@ -30,7 +35,7 @@ module.exports = Self => {
} }
}); });
Self.editLatestBuys = async(field, newValue, lines, options) => { Self.editLatestBuys = async(ctx, field, newValue, lines, filter, options) => {
let tx; let tx;
const myOptions = {}; const myOptions = {};
@ -64,17 +69,19 @@ module.exports = Self => {
const models = Self.app.models; const models = Self.app.models;
const model = models[modelName]; const model = models[modelName];
try { try {
const promises = []; const promises = [];
const value = {};
value[field] = newValue;
if (filter) {
ctx.args.filter = {where: filter, limit: null};
lines = await models.Buy.latestBuysFilter(ctx, null, myOptions);
}
const targets = lines.map(line => { const targets = lines.map(line => {
return line[identifier]; return line[identifier];
}); });
const value = {};
value[field] = newValue;
for (let target of targets) for (let target of targets)
promises.push(model.upsertWithWhere({id: target}, value, myOptions)); promises.push(model.upsertWithWhere({id: target}, value, myOptions));

View File

@ -86,7 +86,7 @@ module.exports = Self => {
} }
], ],
returns: { returns: {
type: ['Object'], type: ['object'],
root: true root: true
}, },
http: { http: {
@ -98,6 +98,9 @@ module.exports = Self => {
Self.latestBuysFilter = async(ctx, filter, options) => { Self.latestBuysFilter = async(ctx, filter, options) => {
const myOptions = {}; const myOptions = {};
if (filter && filter.modelParams)
ctx.args = filter.modelParams;
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);

View File

@ -6,7 +6,7 @@ describe('Buy editLatestsBuys()', () => {
const options = {transaction: tx}; const options = {transaction: tx};
try { try {
let ctx = { const ctx = {
args: { args: {
search: 'Ranged weapon longbow 2m' search: 'Ranged weapon longbow 2m'
} }
@ -18,7 +18,35 @@ describe('Buy editLatestsBuys()', () => {
const newValue = 99; const newValue = 99;
const lines = [{itemFk: original.itemFk, id: original.id}]; const lines = [{itemFk: original.itemFk, id: original.id}];
await models.Buy.editLatestBuys(field, newValue, lines, options); await models.Buy.editLatestBuys(ctx, field, newValue, lines, null, options);
const [result] = await models.Buy.latestBuysFilter(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.Buy.beginTransaction({});
const options = {transaction: tx};
try {
const filter = {typeFk: 1};
const ctx = {
args: {
filter: filter
}
};
const field = 'size';
const newValue = 88;
await models.Buy.editLatestBuys(ctx, field, newValue, null, filter, options);
const [result] = await models.Buy.latestBuysFilter(ctx, null, options); const [result] = await models.Buy.latestBuysFilter(ctx, null, options);

View File

@ -29,9 +29,11 @@
<tr> <tr>
<th shrink> <th shrink>
<vn-multi-check <vn-multi-check
checked="$ctrl.checkAll"
model="model" model="model"
check-field="$checked"> checked="$ctrl.checkAll"
check-field="checked"
check-dummy-enabled="true"
checked-dummy-count="$ctrl.checkedDummyCount">
</vn-multi-check> </vn-multi-check>
</th> </th>
<th translate>Picture</th> <th translate>Picture</th>
@ -126,7 +128,7 @@
}"> }">
<td> <td>
<vn-check <vn-check
ng-model="buy.$checked" ng-model="buy.checked"
vn-click-stop> vn-click-stop>
</vn-check> </vn-check>
</td> </td>

View File

@ -6,7 +6,7 @@ export default class Controller extends Section {
constructor($element, $) { constructor($element, $) {
super($element, $); super($element, $);
this.editedColumn; this.editedColumn;
this.$checkAll = false; this.checkAll = false;
this.smartTableOptions = { this.smartTableOptions = {
activeButtons: { activeButtons: {
@ -91,7 +91,7 @@ export default class Controller extends Section {
const buys = this.$.model.data || []; const buys = this.$.model.data || [];
const checkedBuys = []; const checkedBuys = [];
for (let buy of buys) { for (let buy of buys) {
if (buy.$checked) if (buy.checked)
checkedBuys.push(buy); checkedBuys.push(buy);
} }
@ -142,6 +142,9 @@ export default class Controller extends Section {
} }
get totalChecked() { get totalChecked() {
if (this.checkedDummyCount)
return this.checkedDummyCount;
return this.checked.length; return this.checked.length;
} }
@ -156,6 +159,9 @@ export default class Controller extends Section {
lines: rowsToEdit lines: rowsToEdit
}; };
if (this.checkedDummyCount && this.checkedDummyCount > 0)
data.filter = this.$.model.userParams;
return this.$http.post('Buys/editLatestBuys', data) return this.$http.post('Buys/editLatestBuys', data)
.then(() => { .then(() => {
this.uncheck(); this.uncheck();

View File

@ -31,10 +31,10 @@ describe('Entry', () => {
describe('get checked', () => { describe('get checked', () => {
it(`should return a set of checked lines`, () => { it(`should return a set of checked lines`, () => {
controller.$.model.data = [ controller.$.model.data = [
{$checked: true, id: 1}, {checked: true, id: 1},
{$checked: true, id: 2}, {checked: true, id: 2},
{$checked: true, id: 3}, {checked: true, id: 3},
{$checked: false, id: 4}, {checked: false, id: 4},
]; ];
let result = controller.checked; let result = controller.checked;

View File

@ -100,12 +100,7 @@ module.exports = Self => {
}, },
] ]
}; };
let supplier = await Self.app.models.Supplier.findOne(filter);
const farmerCode = 2; return Self.app.models.Supplier.findOne(filter);
if (supplier.sageWithholdingFk == farmerCode)
supplier.isFarmer = true;
return supplier;
}; };
}; };

View File

@ -25,12 +25,4 @@ describe('Supplier getSummary()', () => {
expect(payMethod.name).toEqual('PayMethod one'); expect(payMethod.name).toEqual('PayMethod one');
}); });
it(`should get if supplier is farmer by sageWithholdingFk`, async() => {
const supplier = await app.models.Supplier.findById(2);
const supplierSummary = await app.models.Supplier.getSummary(2);
expect(supplier.isFarmer).toBeUndefined();
expect(supplierSummary.isFarmer).toEqual(true);
});
}); });

View File

@ -83,11 +83,6 @@
label="Account" label="Account"
value="{{::$ctrl.summary.account}}"> value="{{::$ctrl.summary.account}}">
</vn-label-value> </vn-label-value>
<vn-check
label="Is Farmer"
ng-model="$ctrl.summary.isFarmer"
disabled="true">
</vn-check>
</vn-one> </vn-one>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>