diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 33eecc627..64da72607 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -894,6 +894,7 @@ export default { header: 'vn-entry-summary > vn-card > h5', reference: 'vn-entry-summary vn-label-value[label="Reference"]', confirmed: 'vn-entry-summary vn-check[label="Confirmed"]', + anyBuyLine: 'vn-entry-summary tr.dark-row' }, entryDescriptor: { agency: 'vn-entry-descriptor div.body vn-label-value:nth-child(1) span', diff --git a/e2e/paths/12-entry/01_summary.spec.js b/e2e/paths/12-entry/01_summary.spec.js index e57654f94..a6ac8dab1 100644 --- a/e2e/paths/12-entry/01_summary.spec.js +++ b/e2e/paths/12-entry/01_summary.spec.js @@ -9,7 +9,7 @@ describe('Entry summary path', () => { browser = await getBrowser(); page = browser.page; await page.loginAndModule('buyer', 'entry'); - await page.waitToClick('vn-entry-index vn-tbody > a:nth-child(2)'); + await page.accessToSearchResult('4'); }); afterAll(async() => { @@ -30,7 +30,7 @@ describe('Entry summary path', () => { it('should display some entry details like the reference', async() => { const result = await page.waitToGetProperty(selectors.entrySummary.reference, 'innerText'); - expect(result).toContain('Movement 2'); + expect(result).toContain('Movement 4'); }); it('should display other entry details like the confirmed', async() => { @@ -38,4 +38,10 @@ describe('Entry summary path', () => { expect(result).toContain('unchecked'); }); + + it('should display all buys for the entry', async() => { + const result = await page.countElement(selectors.entrySummary.anyBuyLine); + + expect(result).toEqual(4); + }); }); diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js new file mode 100644 index 000000000..1b05ec483 --- /dev/null +++ b/modules/entry/back/methods/entry/getBuys.js @@ -0,0 +1,74 @@ +module.exports = Self => { + Self.remoteMethod('getBuys', { + description: 'Returns buys for one entry', + accessType: 'READ', + accepts: { + arg: 'id', + type: 'number', + required: true, + description: 'The entry id', + http: {source: 'path'} + }, + returns: { + type: ['Object'], + root: true + }, + http: { + path: `/:id/getBuys`, + verb: 'GET' + } + }); + + Self.getBuys = async id => { + let filter = { + where: {entryFk: id}, + fields: [ + 'id', + 'itemFk', + 'stickers', + 'packing', + 'grouping', + 'quantity', + 'packageFk', + 'weight', + 'buyingValue', + 'price2', + 'price3' + ], + include: { + relation: 'item', + scope: { + fields: [ + 'id', + 'typeFk', + 'name', + 'size', + 'minPrice', + 'tag5', + 'value5', + 'tag6', + 'value6', + 'tag7', + 'value7', + 'tag8', + 'value8', + 'tag9', + 'value9', + 'tag10', + 'value10', + 'groupingMode' + ], + include: { + relation: 'itemType', + scope: { + fields: ['code', 'description'] + } + } + } + } + }; + + let buys = await Self.app.models.Buy.find(filter); + return buys; + }; +}; diff --git a/modules/entry/back/methods/entry/specs/getBuys.spec.js b/modules/entry/back/methods/entry/specs/getBuys.spec.js new file mode 100644 index 000000000..b660ab2ad --- /dev/null +++ b/modules/entry/back/methods/entry/specs/getBuys.spec.js @@ -0,0 +1,14 @@ +const app = require('vn-loopback/server/server'); + +describe('entry getBuys()', () => { + const entryId = 4; + it('should get the buys and items of an entry', async() => { + const result = await app.models.Entry.getBuys(entryId); + + const length = result.length; + const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; + + expect(result.length).toEqual(4); + expect(anyResult.item).toBeDefined(); + }); +}); diff --git a/modules/entry/back/models/buy.json b/modules/entry/back/models/buy.json index 1f3f1b862..56f1eef4f 100644 --- a/modules/entry/back/models/buy.json +++ b/modules/entry/back/models/buy.json @@ -31,6 +31,12 @@ "grouping": { "type": "number" }, + "stickers": { + "type": "number" + }, + "packageFk": { + "type": "number" + }, "groupingMode": { "type": "number" }, @@ -56,6 +62,12 @@ "model": "Entry", "foreignKey": "entryFk", "required": true + }, + "item": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "itemFk", + "required": true } } } \ No newline at end of file diff --git a/modules/entry/back/models/entry.js b/modules/entry/back/models/entry.js index 713154d1b..94dbe787d 100644 --- a/modules/entry/back/models/entry.js +++ b/modules/entry/back/models/entry.js @@ -1,4 +1,5 @@ module.exports = Self => { require('../methods/entry/filter')(Self); require('../methods/entry/getEntry')(Self); + require('../methods/entry/getBuys')(Self); }; diff --git a/modules/entry/front/summary/index.html b/modules/entry/front/summary/index.html index af9eae30c..9151558f2 100644 --- a/modules/entry/front/summary/index.html +++ b/modules/entry/front/summary/index.html @@ -19,8 +19,12 @@ - + + + {{$ctrl.entryData.travel.agency.name}} + @@ -65,4 +69,89 @@ + + +

Buys

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
QuantityStickersPackageWeightPackingGroupingBuying valueImportGrouping pricePacking price
{{::line.quantity}}{{::line.stickers | dashIfEmpty}}{{::line.packageFk | dashIfEmpty}}{{::line.weight}} + + {{::line.packing | dashIfEmpty}} + + + + {{::line.grouping | dashIfEmpty}} + + + {{::line.buyingValue | currency: 'EUR':2}}{{::line.quantity * line.buyingValue | currency: 'EUR':2}}{{::line.price2 | currency: 'EUR':2}}{{::line.price3 | currency: 'EUR':2}}
+ + {{::line.item.itemType.code}} + + + + {{::line.item.id | zeroFill:6}} + + + + {{::line.item.size}} + + + + {{::line.item.minPrice | currency: 'EUR':2}} + + + + +
+
+
+ + + + + diff --git a/modules/entry/front/summary/index.js b/modules/entry/front/summary/index.js index f0b4c62b3..2a3dfe37b 100644 --- a/modules/entry/front/summary/index.js +++ b/modules/entry/front/summary/index.js @@ -10,15 +10,23 @@ class Controller extends Section { set entry(value) { this._entry = value; - if (value && value.id) + if (value && value.id) { this.getEntryData(); + this.getBuys(); + } } getEntryData() { - return this.$http.get(`/api/Entries/${this.entry.id}/getEntry`).then(response => { + return this.$http.get(`Entries/${this.entry.id}/getEntry`).then(response => { this.entryData = response.data; }); } + + getBuys() { + return this.$http.get(`Entries/${this.entry.id}/getBuys`).then(response => { + this.buys = response.data; + }); + } } ngModule.vnComponent('vnEntrySummary', { diff --git a/modules/entry/front/summary/index.spec.js b/modules/entry/front/summary/index.spec.js index a2d25d0d6..396e92b01 100644 --- a/modules/entry/front/summary/index.spec.js +++ b/modules/entry/front/summary/index.spec.js @@ -38,7 +38,7 @@ describe('component vnEntrySummary', () => { it('should perform a get and then store data on the controller', () => { controller._entry = {id: 999}; - const query = `/api/Entries/${controller._entry.id}/getEntry`; + const query = `Entries/${controller._entry.id}/getEntry`; $httpBackend.expectGET(query).respond('I am the entryData'); controller.getEntryData(); $httpBackend.flush(); @@ -46,4 +46,20 @@ describe('component vnEntrySummary', () => { expect(controller.entryData).toEqual('I am the entryData'); }); }); + + describe('getBuys()', () => { + it('should perform a get asking for the buys of an entry', () => { + controller._entry = {id: 999}; + + const thatQuery = `Entries/${controller._entry.id}/getEntry`; + const query = `Entries/${controller._entry.id}/getBuys`; + + $httpBackend.whenGET(thatQuery).respond('My Entries'); + $httpBackend.expectGET(query).respond('Some buys'); + controller.getBuys(); + $httpBackend.flush(); + + expect(controller.buys).toEqual('Some buys'); + }); + }); }); diff --git a/modules/entry/front/summary/locale/es.yml b/modules/entry/front/summary/locale/es.yml index 1673d6a17..6f442b2c8 100644 --- a/modules/entry/front/summary/locale/es.yml +++ b/modules/entry/front/summary/locale/es.yml @@ -1,3 +1,8 @@ Inventory: Inventario Virtual: Redada -Entry: Entrada \ No newline at end of file +Entry: Entrada +Stickers: Etiquetas +Item size: Tamaño +Item type: Tipo +Minimum price: Precio mínimo +Buys: Compras diff --git a/modules/entry/front/summary/style.scss b/modules/entry/front/summary/style.scss index 1374d2ec7..27d361056 100644 --- a/modules/entry/front/summary/style.scss +++ b/modules/entry/front/summary/style.scss @@ -3,4 +3,18 @@ vn-entry-summary .summary { max-width: $width-lg; -} \ No newline at end of file + + .dark-row { + background-color: lighten($color-marginal, 10%); + } + + tbody { + border: 2px solid $color-marginal; + } + + tr { + margin-bottom: 10px; + } +} + +$color-font-link-medium: lighten($color-font-link, 20%) \ No newline at end of file