Changes
This commit is contained in:
parent
0b532880c0
commit
5cbd8d632d
|
@ -2179,6 +2179,7 @@ INSERT INTO `vn`.`rate`(`dated`, `warehouseFk`, `rate0`, `rate1`, `rate2`, `rate
|
|||
VALUES
|
||||
(DATE_ADD(CURDATE(), INTERVAL -1 YEAR), 1, 10, 15, 20, 25),
|
||||
(CURDATE(), 1, 12, 17, 22, 27);
|
||||
|
||||
INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk)
|
||||
VALUES
|
||||
(1, '07546501420', 67, 671, CURDATE(), 1761, 1, 1),
|
||||
|
|
|
@ -43,7 +43,7 @@ module.exports = Self => {
|
|||
|
||||
const entry = await models.Entry.findById(id);
|
||||
await entry.updateAttributes({
|
||||
observation: args.notes
|
||||
observation: args.observation
|
||||
});
|
||||
|
||||
const buys = [];
|
||||
|
@ -63,7 +63,7 @@ module.exports = Self => {
|
|||
const createdBuys = await models.Buy.create(buys);
|
||||
const buyIds = createdBuys.map(buy => buy.id);
|
||||
|
||||
/* let stmts = [];
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc');
|
||||
|
@ -77,6 +77,6 @@ module.exports = Self => {
|
|||
stmts.push('CALL buy_recalcPrices()');
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
await conn.executeStmt(sql); */
|
||||
await conn.executeStmt(sql);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -7,53 +7,13 @@
|
|||
name="form"
|
||||
ng-submit="$ctrl.onSubmit()"
|
||||
class="vn-ma-md">
|
||||
<div class="vn-w-md">
|
||||
<div class="vn-w-lg">
|
||||
<vn-card class="vn-pa-lg">
|
||||
<!-- <vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
vn-focus
|
||||
label="Reference"
|
||||
ng-model="$ctrl.dms.reference"
|
||||
rule>
|
||||
</vn-textfield>
|
||||
<vn-autocomplete vn-one
|
||||
label="Company"
|
||||
ng-model="$ctrl.dms.companyId"
|
||||
url="Companies"
|
||||
show-field="code"
|
||||
value-field="id">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete vn-one
|
||||
label="Warehouse"
|
||||
ng-model="$ctrl.dms.warehouseId"
|
||||
url="Warehouses"
|
||||
show-field="name"
|
||||
value-field="id">
|
||||
</vn-autocomplete>
|
||||
<vn-autocomplete vn-one
|
||||
label="Type"
|
||||
ng-model="$ctrl.dms.dmsTypeId"
|
||||
url="DmsTypes"
|
||||
show-field="name"
|
||||
value-field="id">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-textarea
|
||||
vn-one
|
||||
label="Description"
|
||||
ng-model="$ctrl.dms.description"
|
||||
rule>
|
||||
</vn-textarea>
|
||||
</vn-horizontal> -->
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
label="Invoice"
|
||||
ng-model="$ctrl.import.invoice">
|
||||
ng-model="$ctrl.import.ref">
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
|
@ -84,7 +44,7 @@
|
|||
<table class="vn-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th translate center>Item ID</th>
|
||||
<th translate expand>Item</th>
|
||||
<th translate expand>Description</th>
|
||||
<th translate center>Size</th>
|
||||
<th translate center>Packing</th>
|
||||
|
@ -96,7 +56,7 @@
|
|||
</thead>
|
||||
<tbody ng-repeat="buy in $ctrl.import.buys">
|
||||
<tr>
|
||||
<td title="{{::buy.itemFk}}">
|
||||
<td title="{{::buy.itemFk}}" expand>
|
||||
<vn-autocomplete
|
||||
class="dense"
|
||||
vn-focus
|
||||
|
@ -143,7 +103,7 @@
|
|||
</vn-card>
|
||||
<vn-button-bar>
|
||||
<vn-submit
|
||||
label="Upload">
|
||||
label="Import">
|
||||
</vn-submit>
|
||||
<vn-button
|
||||
class="cancel"
|
||||
|
|
|
@ -23,13 +23,10 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
fillData(raw) {
|
||||
this.import.file = raw;
|
||||
|
||||
const data = JSON.parse(raw);
|
||||
const [invoice] = data.invoices;
|
||||
|
||||
this.$.$applyAsync(() => {
|
||||
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 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;
|
||||
});
|
||||
// this.import.buys = buys;
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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('<vn-entry-buy-import-buys></vn-entry-latest-buys')($rootScope);
|
||||
controller = $componentController('vnEntryBuyImport', {$element});
|
||||
controller.entry = {
|
||||
id: 1
|
||||
};
|
||||
}));
|
||||
|
||||
describe('fillData()', () => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,2 @@
|
|||
#Ordenar alfabeticamente
|
||||
reference: Referencia
|
Loading…
Reference in New Issue