-
+ |
+ label="Import">
{
- this.import.invoice = invoice.id_invoice;
this.import.observation = invoice.tx_awb;
const boxes = invoice.boxes;
@@ -49,21 +46,27 @@ class Controller extends Section {
}
}
- const params = {buys};
- const query = `Entries/${this.entry.id}/importPreview`;
- this.$http.get(query, {params}).then(res => {
- this.import.buys = res.data;
- });
- // this.import.buys = buys;
+ const boxesId = boxes.map(box => box.id_box);
+ this.import.ref = boxesId.join(', ');
+
+ this.fetchBuys(buys);
+ });
+ }
+
+ fetchBuys(buys) {
+ const params = {buys};
+ const query = `Entries/${this.entry.id}/importPreview`;
+ this.$http.get(query, {params}).then(res => {
+ this.import.buys = res.data;
});
}
onSubmit() {
- const params = {buys: this.import.buys};
+ const params = this.import;
const query = `Entries/${this.entry.id}/import`;
- return this.$http.post(query, params).then(() => {
- this.vnApp.showSuccess(this.$t('Data saved!'));
- });
+ return this.$http.post(query, params)
+ .then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
+ .then(() => this.$state.go('entry.card.buy.index'));
}
itemSearchFunc($search) {
diff --git a/modules/entry/front/buy/import/index.spec.js b/modules/entry/front/buy/import/index.spec.js
new file mode 100644
index 0000000000..408fdab83f
--- /dev/null
+++ b/modules/entry/front/buy/import/index.spec.js
@@ -0,0 +1,128 @@
+import './index.js';
+
+describe('Entry', () => {
+ describe('Component vnEntryBuyImport', () => {
+ let controller;
+ let $httpParamSerializer;
+ let $httpBackend;
+
+ beforeEach(ngModule('entry'));
+
+ beforeEach(angular.mock.inject(($componentController, $compile, $rootScope, _$httpParamSerializer_, _$httpBackend_) => {
+ $httpBackend = _$httpBackend_;
+ $httpParamSerializer = _$httpParamSerializer_;
+ let $element = $compile(' {
+ it(`should call to the fillData() method`, () => {
+ controller.fetchBuys = jest.fn();
+
+ const rawData = `{
+ "invoices": [
+ {
+ "tx_awb": "123456",
+ "boxes": [
+ {
+ "id_box": 1,
+ "nu_length": 1,
+ "nu_width": 15,
+ "nu_height": 80,
+ "products": [
+ {
+ "nm_product": "Bow",
+ "nu_length": 1,
+ "nu_stems_bunch": 1,
+ "nu_bunches": 1,
+ "mny_rate_stem": 5.77
+ }
+
+ ]
+ },
+ {
+ "id_box": 2,
+ "nu_length": 25,
+ "nu_width": 1,
+ "nu_height": 45,
+ "products": [
+ {
+ "nm_product": "Arrow",
+ "nu_length": 25,
+ "nu_stems_bunch": 1,
+ "nu_bunches": 1,
+ "mny_rate_stem": 2.16
+ }
+ ]
+ }
+ ]
+ }
+ ]}`;
+ const expectedBuys = [
+ {'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200},
+ {'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125}
+ ];
+ controller.fillData(rawData);
+ controller.$.$apply();
+
+ const importData = controller.import;
+
+ expect(importData.observation).toEqual('123456');
+ expect(importData.ref).toEqual('1, 2');
+
+ expect(controller.fetchBuys).toHaveBeenCalledWith(expectedBuys);
+ });
+ });
+
+ describe('fetchBuys()', () => {
+ it(`should perform a query to fetch the buys data`, () => {
+ const buys = [
+ {'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200},
+ {'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125}
+ ];
+
+ const serializedParams = $httpParamSerializer({buys});
+ const query = `Entries/1/importPreview?${serializedParams}`;
+ $httpBackend.expectGET(query).respond(200, buys);
+ controller.fetchBuys(buys);
+ $httpBackend.flush();
+
+ const importData = controller.import;
+
+ expect(importData.buys.length).toEqual(2);
+ });
+ });
+
+ describe('onSubmit()', () => {
+ it(`should perform a query to update columns`, () => {
+ jest.spyOn(controller.vnApp, 'showSuccess');
+ jest.spyOn(controller.$state, 'go');
+
+ controller.import = {
+ observation: '123456',
+ ref: '1, 2',
+ buys: [
+ {'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200},
+ {'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125}
+ ]
+ };
+ const params = controller.import;
+
+ const query = `Entries/1/import`;
+ $httpBackend.expectPOST(query, params).respond(200, params.buys);
+ controller.onSubmit();
+ $httpBackend.flush();
+
+ const importData = controller.import;
+
+ expect(importData.buys.length).toEqual(2);
+
+ expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
+ expect(controller.$state.go).toHaveBeenCalledWith('foo.card.summary', {id: 1}, undefined);
+ });
+ });
+ });
+});
diff --git a/modules/entry/front/buy/import/locale/es.yml b/modules/entry/front/buy/import/locale/es.yml
new file mode 100644
index 0000000000..7962a2870a
--- /dev/null
+++ b/modules/entry/front/buy/import/locale/es.yml
@@ -0,0 +1,2 @@
+#Ordenar alfabeticamente
+reference: Referencia
\ No newline at end of file
|