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> </section>
<input <input
type="file" type="file"
accept="{{$ctrl.acceptTypes}}" accept="{{$ctrl.accept}}"
style="display: none;"> style="display: none;">
</input> </input>
</div> </div>

View File

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

View File

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

View File

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

View File

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

View File

@ -62,11 +62,23 @@ class Controller extends Section {
} }
onSubmit() { onSubmit() {
const params = this.import; try {
const query = `Entries/${this.entry.id}/importBuys`; const params = this.import;
return this.$http.post(query, params) const hasAnyEmptyRow = params.buys.some(buy => {
.then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) return buy.itemFk == null;
.then(() => this.$state.go('entry.card.buy.index')); });
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) { itemSearchFunc($search) {

View File

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