Requested changes

This commit is contained in:
Joan Sanchez 2021-03-12 08:17:56 +01:00
parent e29dd4db42
commit be37334f49
7 changed files with 30 additions and 17 deletions

View File

@ -13,7 +13,7 @@
</section>
<input
type="file"
accept="{{$ctrl.acceptTypes}}"
accept="{{$ctrl.accept}}"
style="display: none;">
</input>
</div>

View File

@ -69,7 +69,7 @@ module.exports = Self => {
packing: buy.packing,
grouping: buy.grouping,
buyingValue: buy.buyingValue,
packageFk: 1
packageFk: buy.packageFk
});
}

View File

@ -71,8 +71,6 @@ describe('entry import()', () => {
expect(entryBuys.length).toEqual(2);
// Restores
await newEntry.destroy(options);
await tx.rollback();
});
});

View File

@ -2,6 +2,7 @@ const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('entry importBuysPreview()', () => {
const entryId = 1;
beforeAll(async done => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
@ -30,7 +31,7 @@ describe('entry importBuysPreview()', () => {
}
];
const result = await app.models.Entry.importBuysPreview(1, buys);
const result = await app.models.Entry.importBuysPreview(entryId, buys);
const randomIndex = Math.floor(Math.random() * result.length);
const buy = result[randomIndex];

View File

@ -75,13 +75,13 @@
<td title="{{::buy.description}}" expand>{{::buy.description | dashIfEmpty}}</td>
<td center title="{{::buy.size}}">{{::buy.size | dashIfEmpty}}</td>
<td center>
<vn-chip translate-attr="line.groupingMode == 2 ? {title: 'Minimun amount'} : {title: 'Packing'}" ng-class="{'message': line.groupingMode == 2}">
<span translate>{{::buy.packing | dashIfEmpty}}</span>
<vn-chip>
<span>{{::buy.packing | dashIfEmpty}}</span>
</vn-chip>
</td>
<td center>
<vn-chip translate-attr="line.groupingMode == 1 ? {title: 'Minimun amount'} : {title: 'Grouping'}" ng-class="{'message': line.groupingMode == 1}">
<span translate>{{::buy.grouping | dashIfEmpty}}</span>
<vn-chip>
<span>{{::buy.grouping | dashIfEmpty}}</span>
</vn-chip>
</vn-td>
<td>{{::buy.buyingValue | currency: 'EUR':2}}</td>
@ -108,7 +108,8 @@
<vn-button
class="cancel"
label="Cancel"
ui-sref="entry.card.buy.index"></vn-button>
ui-sref="entry.card.buy.index">
</vn-button>
</vn-button>
</vn-button-bar>
</div>

View File

@ -62,11 +62,23 @@ class Controller extends Section {
}
onSubmit() {
const params = this.import;
const query = `Entries/${this.entry.id}/importBuys`;
return this.$http.post(query, params)
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
.then(() => this.$state.go('entry.card.buy.index'));
try {
const params = this.import;
const hasAnyEmptyRow = params.buys.some(buy => {
return buy.itemFk == null;
});
if (hasAnyEmptyRow)
throw new Error(`Some of the imported buys doesn't have an item`);
const query = `Entries/${this.entry.id}/importBuys`;
return this.$http.post(query, params)
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
.then(() => this.$state.go('entry.card.buy.index'));
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
}
itemSearchFunc($search) {

View File

@ -1,4 +1,5 @@
reference: Referencia
Observation: Observación
Box: Embalage
Box: Embalaje
Import buys: Importar compras
Some of the imported buys doesn't have an item: Algunas de las compras importadas no tienen un artículo