Merge pull request 'Import entry buys from lastest buy' (#861) from 3258-import_buys into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #861
Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
Carlos Jimenez Ruiz 2022-02-01 12:12:18 +00:00
commit 2aceff56f3
14 changed files with 197 additions and 42 deletions

View File

@ -9,7 +9,7 @@ describe('Entry import, create and edit buys path', () => {
browser = await getBrowser(); browser = await getBrowser();
page = browser.page; page = browser.page;
await page.loginAndModule('buyer', 'entry'); await page.loginAndModule('buyer', 'entry');
await page.accessToSearchResult('1'); await page.accessToSearchResult('3');
}); });
afterAll(async() => { afterAll(async() => {
@ -19,7 +19,7 @@ describe('Entry import, create and edit buys path', () => {
it('should count the summary buys and find there only one at this point', async() => { it('should count the summary buys and find there only one at this point', async() => {
const buysCount = await page.countElement(selectors.entrySummary.anyBuyLine); const buysCount = await page.countElement(selectors.entrySummary.anyBuyLine);
expect(buysCount).toEqual(1); expect(buysCount).toEqual(2);
}); });
it('should navigate to the buy section and then click the import button opening the import form', async() => { it('should navigate to the buy section and then click the import button opening the import form', async() => {
@ -41,11 +41,10 @@ describe('Entry import, create and edit buys path', () => {
await page.waitForTextInField(selectors.entryBuys.ref, '200573095, 200573106, 200573117, 200573506'); await page.waitForTextInField(selectors.entryBuys.ref, '200573095, 200573106, 200573117, 200573506');
await page.waitForTextInField(selectors.entryBuys.observation, '729-6340 2846'); await page.waitForTextInField(selectors.entryBuys.observation, '729-6340 2846');
await page.autocompleteSearch(selectors.entryBuys.firstImportedItem, 'Ranged Reinforced weapon pistol 9mm'); await page.autocompleteSearch(selectors.entryBuys.firstImportedItem, 'Ranged weapon longbow 2m');
const itemName = 'Melee Reinforced weapon heavy shield 1x0.5m'; await page.autocompleteSearch(selectors.entryBuys.secondImportedItem, 'Ranged weapon longbow 2m');
await page.autocompleteSearch(selectors.entryBuys.secondImportedItem, itemName); await page.autocompleteSearch(selectors.entryBuys.thirdImportedItem, 'Ranged weapon sniper rifle 300mm');
await page.autocompleteSearch(selectors.entryBuys.thirdImportedItem, 'Container medical box 1m'); await page.autocompleteSearch(selectors.entryBuys.fourthImportedItem, 'Melee weapon heavy shield 1x0.5m');
await page.autocompleteSearch(selectors.entryBuys.fourthImportedItem, 'Container ammo box 1m');
await page.waitToClick(selectors.entryBuys.importBuysButton); await page.waitToClick(selectors.entryBuys.importBuysButton);
@ -57,7 +56,7 @@ describe('Entry import, create and edit buys path', () => {
}); });
it('should count the buys to find 4 buys have been added', async() => { it('should count the buys to find 4 buys have been added', async() => {
await page.waitForNumberOfElements(selectors.entryBuys.anyBuyLine, 5); await page.waitForNumberOfElements(selectors.entryBuys.anyBuyLine, 6);
}); });
it('should delete the four buys that were just added', async() => { it('should delete the four buys that were just added', async() => {

View File

@ -218,5 +218,6 @@
"The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día", "The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día",
"You can not modify is pay method checked": "No se puede modificar el campo método de pago validado", "You can not modify is pay method checked": "No se puede modificar el campo método de pago validado",
"Can't transfer claimed sales": "No puedes transferir lineas reclamadas", "Can't transfer claimed sales": "No puedes transferir lineas reclamadas",
"You don't have privileges to create pay back": "No tienes permisos para crear un abono" "You don't have privileges to create pay back": "No tienes permisos para crear un abono",
"The item is required": "El artículo es requerido"
} }

View File

@ -52,23 +52,59 @@ module.exports = Self => {
} }
try { try {
const entry = await models.Entry.findById(id, null, myOptions); const entry = await models.Entry.findById(id, {
include: [{
relation: 'travel',
scope: {
fields: ['warehouseInFk', 'landed'],
}
}]
}, myOptions);
await entry.updateAttributes({ await entry.updateAttributes({
observation: args.observation, observation: args.observation,
ref: args.ref ref: args.ref
}, myOptions); }, myOptions);
const travel = entry.travel();
await Self.rawSql('CALL buyUltimate(?, ?)', [
travel.warehouseInFk,
travel.landed
], myOptions);
const buyUltimate = await Self.rawSql(`
SELECT *
FROM tmp.buyUltimate
WHERE warehouseFk = ?
`, [travel.warehouseInFk], myOptions);
const lastItemBuys = new Map();
for (const buy of buyUltimate)
lastItemBuys.set(buy.itemFk, buy);
const buys = []; const buys = [];
for (let buy of args.buys) { for (let buy of args.buys) {
if (!buy.itemFk)
throw new Error('The item is required');
const lastItemBuy = lastItemBuys.get(buy.itemFk);
if (!lastItemBuy) continue;
const lastBuy = await models.Buy.findById(lastItemBuy.buyFk, null, myOptions);
const stickers = 1;
const quantity = (stickers * buy.packing);
buys.push({ buys.push({
entryFk: entry.id, entryFk: entry.id,
itemFk: buy.itemFk, itemFk: buy.itemFk,
stickers: 1, stickers: stickers,
quantity: 1, quantity: quantity,
packing: buy.packing, packing: buy.packing,
grouping: buy.grouping, grouping: buy.grouping,
buyingValue: buy.buyingValue, buyingValue: buy.buyingValue,
packageFk: buy.packageFk packageFk: buy.packageFk,
groupingMode: lastBuy.groupingMode,
weight: lastBuy.weight
}); });
await models.ItemMatchProperties.upsert({ await models.ItemMatchProperties.upsert({
@ -79,6 +115,8 @@ module.exports = Self => {
}, myOptions); }, myOptions);
} }
if (!buys.length) return;
const createdBuys = await models.Buy.create(buys, myOptions); const createdBuys = await models.Buy.create(buys, myOptions);
const buyIds = createdBuys.map(buy => buy.id); const buyIds = createdBuys.map(buy => buy.id);

View File

@ -0,0 +1,91 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethod('lastItemBuys', {
description: 'Returns a list of items from last buys',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'origin itemId',
http: {source: 'path'}
},
{
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: `/:id/lastItemBuys`,
verb: 'GET'
}
});
Self.lastItemBuys = async(id, filter, options) => {
const conn = Self.dataSource.connector;
const models = Self.app.models;
const where = {isActive: true};
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
filter = mergeFilters(filter, {where});
const entry = await models.Entry.findById(id, {
include: [{
relation: 'travel',
scope: {
fields: ['warehouseInFk', 'landed'],
}
}]
}, myOptions);
const travel = entry.travel();
const stmts = [];
let stmt;
stmt = new ParameterizedSQL(`CALL buyUltimate(?, ?)`, [
travel.warehouseInFk,
travel.landed
]);
stmts.push(stmt);
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.item');
stmt = new ParameterizedSQL(
`CREATE TEMPORARY TABLE tmp.item
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT
i.*,
p.name AS producerName,
nk.name AS inkName
FROM item i
JOIN producer p ON p.id = i.producerFk
JOIN ink nk ON nk.id = i.inkFk
JOIN tmp.buyUltimate bu ON i.id = bu.itemFk
AND bu.warehouseFk = ?
`, [travel.warehouseInFk]);
stmts.push(stmt);
stmt = new ParameterizedSQL('SELECT * FROM tmp.item');
stmt.merge(conn.makeSuffix(filter));
const itemsIndex = stmts.push(stmt) - 1;
stmts.push('DROP TEMPORARY TABLE tmp.item');
const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql, myOptions);
return result[itemsIndex];
};
};

View File

@ -3,9 +3,7 @@ const LoopBackContext = require('loopback-context');
describe('entry import()', () => { describe('entry import()', () => {
const buyerId = 35; const buyerId = 35;
const companyId = 442; const entryId = 3;
const travelId = 1;
const supplierId = 1;
const activeCtx = { const activeCtx = {
accessToken: {userId: buyerId}, accessToken: {userId: buyerId},
}; };
@ -51,25 +49,17 @@ describe('entry import()', () => {
const tx = await models.Entry.beginTransaction({}); const tx = await models.Entry.beginTransaction({});
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const newEntry = await models.Entry.create({
dated: new Date(),
supplierFk: supplierId,
travelFk: travelId,
companyFk: companyId,
observation: 'The entry',
ref: 'Entry ref'
}, options);
await models.Entry.importBuys(ctx, newEntry.id, options); await models.Entry.importBuys(ctx, entryId, options);
const updatedEntry = await models.Entry.findById(newEntry.id, null, options); const updatedEntry = await models.Entry.findById(entryId, null, options);
const entryBuys = await models.Buy.find({ const entryBuys = await models.Buy.find({
where: {entryFk: newEntry.id} where: {entryFk: entryId}
}, options); }, options);
expect(updatedEntry.observation).toEqual(expectedObservation); expect(updatedEntry.observation).toEqual(expectedObservation);
expect(updatedEntry.ref).toEqual(expectedRef); expect(updatedEntry.ref).toEqual(expectedRef);
expect(entryBuys.length).toEqual(2); expect(entryBuys.length).toEqual(4);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {

View File

@ -0,0 +1,26 @@
const models = require('vn-loopback/server/server').models;
describe('Entry lastItemBuys()', () => {
const entryId = 3;
it('should return the items that have been bought', async() => {
const filter = {where: {}};
const result = await models.Entry.lastItemBuys(entryId, filter);
expect(result.length).toBeGreaterThan(1);
});
it('should return the items matching color "brown"', async() => {
const brownInkCode = 'BRW';
const filter = {where: {inkFk: brownInkCode}};
const result = await models.Entry.lastItemBuys(entryId, filter);
expect(result.length).toEqual(2);
});
it('should return the items with a name containing "Ranged"', async() => {
const filter = {where: {name: {like: '%Ranged%'}}};
const result = await models.Entry.lastItemBuys(entryId, filter);
expect(result.length).toEqual(3);
});
});

View File

@ -5,4 +5,5 @@ module.exports = Self => {
require('../methods/entry/addBuy')(Self); require('../methods/entry/addBuy')(Self);
require('../methods/entry/importBuys')(Self); require('../methods/entry/importBuys')(Self);
require('../methods/entry/importBuysPreview')(Self); require('../methods/entry/importBuysPreview')(Self);
require('../methods/entry/lastItemBuys')(Self);
}; };

View File

@ -59,7 +59,7 @@
<vn-autocomplete <vn-autocomplete
class="dense" class="dense"
vn-focus vn-focus
url="Items/withName" url="Entries/{{$ctrl.$params.id}}/lastItemBuys"
ng-model="buy.itemFk" ng-model="buy.itemFk"
show-field="name" show-field="name"
value-field="id" value-field="id"
@ -119,15 +119,18 @@
<vn-textfield <vn-textfield
label="Name" label="Name"
ng-model="$ctrl.itemFilterParams.name" ng-model="$ctrl.itemFilterParams.name"
ng-keydown="$ctrl.onKeyPress($event)"
vn-focus> vn-focus>
</vn-textfield> </vn-textfield>
<vn-textfield <vn-textfield
label="Size" label="Size"
ng-model="$ctrl.itemFilterParams.size"> ng-model="$ctrl.itemFilterParams.size"
ng-keydown="$ctrl.onKeyPress($event)">
</vn-textfield> </vn-textfield>
<vn-autocomplete <vn-autocomplete
label="Producer" label="Producer"
ng-model="$ctrl.itemFilterParams.producerFk" ng-model="$ctrl.itemFilterParams.producerFk"
ng-keydown="$ctrl.onKeyPress($event)"
url="Producers" url="Producers"
show-field="name" show-field="name"
value-field="id"> value-field="id">
@ -135,6 +138,7 @@
<vn-autocomplete <vn-autocomplete
label="Type" label="Type"
ng-model="$ctrl.itemFilterParams.typeFk" ng-model="$ctrl.itemFilterParams.typeFk"
ng-keydown="$ctrl.onKeyPress($event)"
url="ItemTypes" url="ItemTypes"
show-field="name" show-field="name"
value-field="id"> value-field="id">
@ -142,6 +146,7 @@
<vn-autocomplete <vn-autocomplete
label="Color" label="Color"
ng-model="$ctrl.itemFilterParams.inkFk" ng-model="$ctrl.itemFilterParams.inkFk"
ng-keydown="$ctrl.onKeyPress($event)"
url="Inks" url="Inks"
show-field="name" show-field="name"
value-field="id"> value-field="id">
@ -155,7 +160,7 @@
</vn-horizontal> </vn-horizontal>
<vn-crud-model <vn-crud-model
vn-id="itemsModel" vn-id="itemsModel"
url="Items/withName" url="Entries/{{$ctrl.$params.id}}/lastItemBuys"
filter="$ctrl.itemFilter" filter="$ctrl.itemFilter"
data="items" data="items"
limit="10"> limit="10">
@ -186,8 +191,8 @@
</vn-td> </vn-td>
<vn-td expand>{{::item.name}}</vn-td> <vn-td expand>{{::item.name}}</vn-td>
<vn-td number>{{::item.size}}</vn-td> <vn-td number>{{::item.size}}</vn-td>
<vn-td expand>{{::item.producer.name}}</vn-td> <vn-td expand>{{::item.producerName}}</vn-td>
<vn-td>{{::item.ink.name}}</vn-td> <vn-td>{{::item.inkName}}</vn-td>
</a> </a>
</vn-tbody> </vn-tbody>
</vn-table> </vn-table>

View File

@ -141,6 +141,11 @@ class Controller extends Section {
filter.where = where; filter.where = where;
this.$.itemsModel.applyFilter(filter); this.$.itemsModel.applyFilter(filter);
} }
onKeyPress($event) {
if ($event.key === 'Enter')
this.filter();
}
} }
Controller.$inject = ['$element', '$scope']; Controller.$inject = ['$element', '$scope'];

View File

@ -28,3 +28,4 @@ Real hour: Hora real
T. Hour: Hora T. T. Hour: Hora T.
Theoretical hour: Hora Teórica Theoretical hour: Hora Teórica
Go to the order: Ir al pedido Go to the order: Ir al pedido
Basket: Cesta

View File

@ -7,7 +7,7 @@
<vn-icon-button icon="launch"></vn-icon-button> <vn-icon-button icon="launch"></vn-icon-button>
</a> </a>
<span> <span>
Ticket #{{$ctrl.summary.id}} - {{$ctrl.summary.client.name}} <span translate>Basket</span> #{{$ctrl.summary.id}} - {{$ctrl.summary.client.name}}
({{$ctrl.summary.client.salesPersonFk}}) ({{$ctrl.summary.client.salesPersonFk}})
</span> </span>
<vn-button <vn-button

View File

@ -20,7 +20,7 @@
on-change="$ctrl.changeState(value)"> on-change="$ctrl.changeState(value)">
</vn-button-menu> </vn-button-menu>
<vn-ticket-descriptor-menu <vn-ticket-descriptor-menu
ng-if="!$ctrl.isTicketModule" ng-if="!$ctrl.isOnTicketCard"
ticket-id="$ctrl.summary.id" ticket-id="$ctrl.summary.id"
parent-reload="$ctrl.reload()" parent-reload="$ctrl.reload()"
/> />

View File

@ -41,9 +41,9 @@ class Controller extends Summary {
}); });
} }
get isTicketModule() { get isOnTicketCard() {
const path = this.$state.getCurrentPath()[1]; const currentState = this.$state.current.name;
return path.state.name === 'ticket'; return currentState.startsWith('ticket.card');
} }
get isEditable() { get isEditable() {

View File

@ -5,9 +5,7 @@ clientData: 'Tus datos para poder comprar en la web de Verdnatura (<a href="http
title="Visitar Verdnatura" target="_blank" style="color: #8dba25">https://www.verdnatura.es</a>) title="Visitar Verdnatura" target="_blank" style="color: #8dba25">https://www.verdnatura.es</a>)
o en nuestras aplicaciones para <a href="https://goo.gl/3hC2mG" title="App Store" o en nuestras aplicaciones para <a href="https://goo.gl/3hC2mG" title="App Store"
target="_blank" style="color: #8dba25">iOS</a> y <a href="https://goo.gl/8obvLc" target="_blank" style="color: #8dba25">iOS</a> y <a href="https://goo.gl/8obvLc"
title="Google Play" target="_blank" style="color: #8dba25">Android</a> (<a title="Google Play" target="_blank" style="color: #8dba25">Android</a>, son'
href="https://www.youtube.com/watch?v=gGfEtFm8qkw" target="_blank" style="color:
#8dba25"><strong>Ver tutorial de uso</strong></a>), son'
clientId: Identificador de cliente clientId: Identificador de cliente
user: Usuario user: Usuario
password: Contraseña password: Contraseña