Added back unit test plus fixes
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
31205f4556
commit
2a2e276c6b
|
@ -83,6 +83,9 @@ export default class Field extends FormInput {
|
||||||
this._required = value;
|
this._required = value;
|
||||||
let required = this.element.querySelector('.required');
|
let required = this.element.querySelector('.required');
|
||||||
display(required, this._required);
|
display(required, this._required);
|
||||||
|
|
||||||
|
this.$.$applyAsync(() =>
|
||||||
|
this.input.setAttribute('required', value));
|
||||||
}
|
}
|
||||||
|
|
||||||
get required() {
|
get required() {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
</section>
|
</section>
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
accept="{{$ctrl.accept}}"
|
accept="{{$ctrl.acceptTypes}}"
|
||||||
style="display: none;">
|
style="display: none;">
|
||||||
</input>
|
</input>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -78,6 +78,16 @@ export default class InputFile extends Field {
|
||||||
$event: $event
|
$event: $event
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get accept() {
|
||||||
|
return this._accept;
|
||||||
|
}
|
||||||
|
|
||||||
|
set accept(value) {
|
||||||
|
this._accept = value;
|
||||||
|
this.$.$applyAsync(() =>
|
||||||
|
this.input.setAttribute('accept', value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnInputFile', {
|
ngModule.vnComponent('vnInputFile', {
|
||||||
|
|
|
@ -36,15 +36,23 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.import = async(ctx, id) => {
|
Self.import = async(ctx, id, options) => {
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
const entry = await models.Entry.findById(id);
|
let tx;
|
||||||
|
if (!options.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
options.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const entry = await models.Entry.findById(id, null, options);
|
||||||
await entry.updateAttributes({
|
await entry.updateAttributes({
|
||||||
observation: args.observation
|
observation: args.observation,
|
||||||
});
|
ref: args.ref
|
||||||
|
}, options);
|
||||||
|
|
||||||
const buys = [];
|
const buys = [];
|
||||||
for (let buy of args.buys) {
|
for (let buy of args.buys) {
|
||||||
|
@ -60,7 +68,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const createdBuys = await models.Buy.create(buys);
|
const createdBuys = await models.Buy.create(buys, options);
|
||||||
const buyIds = createdBuys.map(buy => buy.id);
|
const buyIds = createdBuys.map(buy => buy.id);
|
||||||
|
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
|
@ -77,6 +85,11 @@ module.exports = Self => {
|
||||||
stmts.push('CALL buy_recalcPrices()');
|
stmts.push('CALL buy_recalcPrices()');
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
await conn.executeStmt(sql);
|
await conn.executeStmt(sql, options);
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
const app = require('vn-loopback/server/server');
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
|
describe('entry import()', () => {
|
||||||
|
let newEntry;
|
||||||
|
const buyerId = 35;
|
||||||
|
const companyId = 442;
|
||||||
|
const travelId = 1;
|
||||||
|
const supplierId = 1;
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: buyerId},
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeAll(async done => {
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should import the buy rows', async() => {
|
||||||
|
const ctx = {
|
||||||
|
req: activeCtx,
|
||||||
|
args: {
|
||||||
|
observation: '123456',
|
||||||
|
ref: '1, 2',
|
||||||
|
buys: [
|
||||||
|
{
|
||||||
|
itemFk: 1,
|
||||||
|
buyingValue: 5.77,
|
||||||
|
description: 'Bow',
|
||||||
|
grouping: 1,
|
||||||
|
packing: 1,
|
||||||
|
size: 1,
|
||||||
|
volume: 1200
|
||||||
|
},
|
||||||
|
{
|
||||||
|
itemFk: 4,
|
||||||
|
buyingValue: 2.16,
|
||||||
|
description: 'Arrow',
|
||||||
|
grouping: 1,
|
||||||
|
packing: 1,
|
||||||
|
size: 25,
|
||||||
|
volume: 1125
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const tx = await app.models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
newEntry = await app.models.Entry.create({
|
||||||
|
dated: new Date(),
|
||||||
|
supplierFk: supplierId,
|
||||||
|
travelFk: travelId,
|
||||||
|
companyFk: companyId,
|
||||||
|
observation: 'The entry',
|
||||||
|
ref: 'Entry ref'
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
await app.models.Entry.import(ctx, newEntry.id, options);
|
||||||
|
|
||||||
|
const updatedEntry = await app.models.Entry.findById(newEntry.id, null, options);
|
||||||
|
const entryBuys = await app.models.Buy.find({
|
||||||
|
where: {entryFk: newEntry.id}
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
expect(updatedEntry.observation).toEqual('123456');
|
||||||
|
expect(updatedEntry.ref).toEqual('1, 2');
|
||||||
|
expect(entryBuys.length).toEqual(2);
|
||||||
|
|
||||||
|
// Restores
|
||||||
|
await newEntry.destroy(options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
});
|
||||||
|
});
|
|
@ -10,7 +10,7 @@
|
||||||
<div class="vn-w-lg">
|
<div class="vn-w-lg">
|
||||||
<vn-card class="vn-pa-lg">
|
<vn-card class="vn-pa-lg">
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield
|
<vn-textfield vn-focus
|
||||||
vn-one
|
vn-one
|
||||||
label="Reference"
|
label="Reference"
|
||||||
ng-model="$ctrl.import.ref">
|
ng-model="$ctrl.import.ref">
|
||||||
|
@ -29,22 +29,22 @@
|
||||||
label="File"
|
label="File"
|
||||||
ng-model="$ctrl.import.file"
|
ng-model="$ctrl.import.file"
|
||||||
on-change="$ctrl.onFileChange($event)"
|
on-change="$ctrl.onFileChange($event)"
|
||||||
required="true"
|
accept="application/json"
|
||||||
multiple="true">
|
required="true">
|
||||||
<append>
|
<append>
|
||||||
<vn-icon vn-none
|
<vn-icon vn-none
|
||||||
color-marginal
|
color-marginal
|
||||||
title="{{$ctrl.contentTypesInfo}}"
|
title="{{'JSON files only' | translate}}"
|
||||||
icon="info">
|
icon="info">
|
||||||
</vn-icon>
|
</vn-icon>
|
||||||
</append>
|
</append>
|
||||||
</vn-input-file>
|
</vn-input-file>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal ng-show="$ctrl.import.buys.length > 0">
|
||||||
<table class="vn-table">
|
<table class="vn-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th translate expand>Item</th>
|
<th translate>Item</th>
|
||||||
<th translate expand>Description</th>
|
<th translate expand>Description</th>
|
||||||
<th translate center>Size</th>
|
<th translate center>Size</th>
|
||||||
<th translate center>Packing</th>
|
<th translate center>Packing</th>
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody ng-repeat="buy in $ctrl.import.buys">
|
<tbody ng-repeat="buy in $ctrl.import.buys">
|
||||||
<tr>
|
<tr>
|
||||||
<td title="{{::buy.itemFk}}" expand>
|
<td title="{{::buy.itemFk}}">
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
class="dense"
|
class="dense"
|
||||||
vn-focus
|
vn-focus
|
||||||
|
@ -103,7 +103,7 @@
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-button-bar>
|
<vn-button-bar>
|
||||||
<vn-submit
|
<vn-submit
|
||||||
label="Import">
|
label="Import buys">
|
||||||
</vn-submit>
|
</vn-submit>
|
||||||
<vn-button
|
<vn-button
|
||||||
class="cancel"
|
class="cancel"
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
#Ordenar alfabeticamente
|
|
||||||
reference: Referencia
|
|
|
@ -1,7 +1,5 @@
|
||||||
vn-ticket-request {
|
vn-entry-buy-import {
|
||||||
.vn-textfield {
|
.vn-table > tbody td:nth-child(1) {
|
||||||
margin: 0!important;
|
width: 250px
|
||||||
max-width: 100px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
reference: Referencia
|
||||||
|
Observation: Observación
|
||||||
|
Box: Embalage
|
||||||
|
Import buys: Importar compras
|
Loading…
Reference in New Issue