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
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:
commit
2aceff56f3
|
@ -9,7 +9,7 @@ describe('Entry import, create and edit buys path', () => {
|
|||
browser = await getBrowser();
|
||||
page = browser.page;
|
||||
await page.loginAndModule('buyer', 'entry');
|
||||
await page.accessToSearchResult('1');
|
||||
await page.accessToSearchResult('3');
|
||||
});
|
||||
|
||||
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() => {
|
||||
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() => {
|
||||
|
@ -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.observation, '729-6340 2846');
|
||||
|
||||
await page.autocompleteSearch(selectors.entryBuys.firstImportedItem, 'Ranged Reinforced weapon pistol 9mm');
|
||||
const itemName = 'Melee Reinforced weapon heavy shield 1x0.5m';
|
||||
await page.autocompleteSearch(selectors.entryBuys.secondImportedItem, itemName);
|
||||
await page.autocompleteSearch(selectors.entryBuys.thirdImportedItem, 'Container medical box 1m');
|
||||
await page.autocompleteSearch(selectors.entryBuys.fourthImportedItem, 'Container ammo box 1m');
|
||||
await page.autocompleteSearch(selectors.entryBuys.firstImportedItem, 'Ranged weapon longbow 2m');
|
||||
await page.autocompleteSearch(selectors.entryBuys.secondImportedItem, 'Ranged weapon longbow 2m');
|
||||
await page.autocompleteSearch(selectors.entryBuys.thirdImportedItem, 'Ranged weapon sniper rifle 300mm');
|
||||
await page.autocompleteSearch(selectors.entryBuys.fourthImportedItem, 'Melee weapon heavy shield 1x0.5m');
|
||||
|
||||
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() => {
|
||||
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() => {
|
||||
|
|
|
@ -218,5 +218,6 @@
|
|||
"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",
|
||||
"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"
|
||||
}
|
|
@ -52,23 +52,59 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
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({
|
||||
observation: args.observation,
|
||||
ref: args.ref
|
||||
}, 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 = [];
|
||||
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({
|
||||
entryFk: entry.id,
|
||||
itemFk: buy.itemFk,
|
||||
stickers: 1,
|
||||
quantity: 1,
|
||||
stickers: stickers,
|
||||
quantity: quantity,
|
||||
packing: buy.packing,
|
||||
grouping: buy.grouping,
|
||||
buyingValue: buy.buyingValue,
|
||||
packageFk: buy.packageFk
|
||||
packageFk: buy.packageFk,
|
||||
groupingMode: lastBuy.groupingMode,
|
||||
weight: lastBuy.weight
|
||||
});
|
||||
|
||||
await models.ItemMatchProperties.upsert({
|
||||
|
@ -79,6 +115,8 @@ module.exports = Self => {
|
|||
}, myOptions);
|
||||
}
|
||||
|
||||
if (!buys.length) return;
|
||||
|
||||
const createdBuys = await models.Buy.create(buys, myOptions);
|
||||
const buyIds = createdBuys.map(buy => buy.id);
|
||||
|
||||
|
|
|
@ -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];
|
||||
};
|
||||
};
|
|
@ -3,9 +3,7 @@ const LoopBackContext = require('loopback-context');
|
|||
|
||||
describe('entry import()', () => {
|
||||
const buyerId = 35;
|
||||
const companyId = 442;
|
||||
const travelId = 1;
|
||||
const supplierId = 1;
|
||||
const entryId = 3;
|
||||
const activeCtx = {
|
||||
accessToken: {userId: buyerId},
|
||||
};
|
||||
|
@ -51,25 +49,17 @@ describe('entry import()', () => {
|
|||
const tx = await models.Entry.beginTransaction({});
|
||||
try {
|
||||
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({
|
||||
where: {entryFk: newEntry.id}
|
||||
where: {entryFk: entryId}
|
||||
}, options);
|
||||
|
||||
expect(updatedEntry.observation).toEqual(expectedObservation);
|
||||
expect(updatedEntry.ref).toEqual(expectedRef);
|
||||
expect(entryBuys.length).toEqual(2);
|
||||
expect(entryBuys.length).toEqual(4);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -5,4 +5,5 @@ module.exports = Self => {
|
|||
require('../methods/entry/addBuy')(Self);
|
||||
require('../methods/entry/importBuys')(Self);
|
||||
require('../methods/entry/importBuysPreview')(Self);
|
||||
require('../methods/entry/lastItemBuys')(Self);
|
||||
};
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
<vn-autocomplete
|
||||
class="dense"
|
||||
vn-focus
|
||||
url="Items/withName"
|
||||
url="Entries/{{$ctrl.$params.id}}/lastItemBuys"
|
||||
ng-model="buy.itemFk"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
|
@ -119,15 +119,18 @@
|
|||
<vn-textfield
|
||||
label="Name"
|
||||
ng-model="$ctrl.itemFilterParams.name"
|
||||
ng-keydown="$ctrl.onKeyPress($event)"
|
||||
vn-focus>
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
label="Size"
|
||||
ng-model="$ctrl.itemFilterParams.size">
|
||||
ng-model="$ctrl.itemFilterParams.size"
|
||||
ng-keydown="$ctrl.onKeyPress($event)">
|
||||
</vn-textfield>
|
||||
<vn-autocomplete
|
||||
label="Producer"
|
||||
ng-model="$ctrl.itemFilterParams.producerFk"
|
||||
ng-keydown="$ctrl.onKeyPress($event)"
|
||||
url="Producers"
|
||||
show-field="name"
|
||||
value-field="id">
|
||||
|
@ -135,6 +138,7 @@
|
|||
<vn-autocomplete
|
||||
label="Type"
|
||||
ng-model="$ctrl.itemFilterParams.typeFk"
|
||||
ng-keydown="$ctrl.onKeyPress($event)"
|
||||
url="ItemTypes"
|
||||
show-field="name"
|
||||
value-field="id">
|
||||
|
@ -142,6 +146,7 @@
|
|||
<vn-autocomplete
|
||||
label="Color"
|
||||
ng-model="$ctrl.itemFilterParams.inkFk"
|
||||
ng-keydown="$ctrl.onKeyPress($event)"
|
||||
url="Inks"
|
||||
show-field="name"
|
||||
value-field="id">
|
||||
|
@ -155,7 +160,7 @@
|
|||
</vn-horizontal>
|
||||
<vn-crud-model
|
||||
vn-id="itemsModel"
|
||||
url="Items/withName"
|
||||
url="Entries/{{$ctrl.$params.id}}/lastItemBuys"
|
||||
filter="$ctrl.itemFilter"
|
||||
data="items"
|
||||
limit="10">
|
||||
|
@ -186,8 +191,8 @@
|
|||
</vn-td>
|
||||
<vn-td expand>{{::item.name}}</vn-td>
|
||||
<vn-td number>{{::item.size}}</vn-td>
|
||||
<vn-td expand>{{::item.producer.name}}</vn-td>
|
||||
<vn-td>{{::item.ink.name}}</vn-td>
|
||||
<vn-td expand>{{::item.producerName}}</vn-td>
|
||||
<vn-td>{{::item.inkName}}</vn-td>
|
||||
</a>
|
||||
</vn-tbody>
|
||||
</vn-table>
|
||||
|
|
|
@ -141,6 +141,11 @@ class Controller extends Section {
|
|||
filter.where = where;
|
||||
this.$.itemsModel.applyFilter(filter);
|
||||
}
|
||||
|
||||
onKeyPress($event) {
|
||||
if ($event.key === 'Enter')
|
||||
this.filter();
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope'];
|
||||
|
|
|
@ -27,4 +27,5 @@ Confirm: Confirmar
|
|||
Real hour: Hora real
|
||||
T. Hour: Hora T.
|
||||
Theoretical hour: Hora Teórica
|
||||
Go to the order: Ir al pedido
|
||||
Go to the order: Ir al pedido
|
||||
Basket: Cesta
|
|
@ -7,7 +7,7 @@
|
|||
<vn-icon-button icon="launch"></vn-icon-button>
|
||||
</a>
|
||||
<span>
|
||||
Ticket #{{$ctrl.summary.id}} - {{$ctrl.summary.client.name}}
|
||||
<span translate>Basket</span> #{{$ctrl.summary.id}} - {{$ctrl.summary.client.name}}
|
||||
({{$ctrl.summary.client.salesPersonFk}})
|
||||
</span>
|
||||
<vn-button
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
on-change="$ctrl.changeState(value)">
|
||||
</vn-button-menu>
|
||||
<vn-ticket-descriptor-menu
|
||||
ng-if="!$ctrl.isTicketModule"
|
||||
ng-if="!$ctrl.isOnTicketCard"
|
||||
ticket-id="$ctrl.summary.id"
|
||||
parent-reload="$ctrl.reload()"
|
||||
/>
|
||||
|
|
|
@ -41,9 +41,9 @@ class Controller extends Summary {
|
|||
});
|
||||
}
|
||||
|
||||
get isTicketModule() {
|
||||
const path = this.$state.getCurrentPath()[1];
|
||||
return path.state.name === 'ticket';
|
||||
get isOnTicketCard() {
|
||||
const currentState = this.$state.current.name;
|
||||
return currentState.startsWith('ticket.card');
|
||||
}
|
||||
|
||||
get isEditable() {
|
||||
|
|
|
@ -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>)
|
||||
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"
|
||||
title="Google Play" target="_blank" style="color: #8dba25">Android</a> (<a
|
||||
href="https://www.youtube.com/watch?v=gGfEtFm8qkw" target="_blank" style="color:
|
||||
#8dba25"><strong>Ver tutorial de uso</strong></a>), son'
|
||||
title="Google Play" target="_blank" style="color: #8dba25">Android</a>, son'
|
||||
clientId: Identificador de cliente
|
||||
user: Usuario
|
||||
password: Contraseña
|
||||
|
|
Loading…
Reference in New Issue