This commit is contained in:
Joan Sanchez 2021-03-09 10:01:40 +01:00
parent 0b532880c0
commit 5cbd8d632d
6 changed files with 156 additions and 62 deletions

View File

@ -2179,6 +2179,7 @@ INSERT INTO `vn`.`rate`(`dated`, `warehouseFk`, `rate0`, `rate1`, `rate2`, `rate
VALUES VALUES
(DATE_ADD(CURDATE(), INTERVAL -1 YEAR), 1, 10, 15, 20, 25), (DATE_ADD(CURDATE(), INTERVAL -1 YEAR), 1, 10, 15, 20, 25),
(CURDATE(), 1, 12, 17, 22, 27); (CURDATE(), 1, 12, 17, 22, 27);
INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk) INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk)
VALUES VALUES
(1, '07546501420', 67, 671, CURDATE(), 1761, 1, 1), (1, '07546501420', 67, 671, CURDATE(), 1761, 1, 1),

View File

@ -43,7 +43,7 @@ module.exports = Self => {
const entry = await models.Entry.findById(id); const entry = await models.Entry.findById(id);
await entry.updateAttributes({ await entry.updateAttributes({
observation: args.notes observation: args.observation
}); });
const buys = []; const buys = [];
@ -63,7 +63,7 @@ module.exports = Self => {
const createdBuys = await models.Buy.create(buys); const createdBuys = await models.Buy.create(buys);
const buyIds = createdBuys.map(buy => buy.id); const buyIds = createdBuys.map(buy => buy.id);
/* let stmts = []; let stmts = [];
let stmt; let stmt;
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc'); stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc');
@ -77,6 +77,6 @@ module.exports = Self => {
stmts.push('CALL buy_recalcPrices()'); stmts.push('CALL buy_recalcPrices()');
const sql = ParameterizedSQL.join(stmts, ';'); const sql = ParameterizedSQL.join(stmts, ';');
await conn.executeStmt(sql); */ await conn.executeStmt(sql);
}; };
}; };

View File

@ -7,53 +7,13 @@
name="form" name="form"
ng-submit="$ctrl.onSubmit()" ng-submit="$ctrl.onSubmit()"
class="vn-ma-md"> class="vn-ma-md">
<div class="vn-w-md"> <div class="vn-w-lg">
<vn-card class="vn-pa-lg"> <vn-card class="vn-pa-lg">
<!-- <vn-horizontal> <vn-horizontal>
<vn-textfield <vn-textfield
vn-one vn-one
vn-focus
label="Reference" label="Reference"
ng-model="$ctrl.dms.reference" ng-model="$ctrl.import.ref">
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">
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
@ -84,7 +44,7 @@
<table class="vn-table"> <table class="vn-table">
<thead> <thead>
<tr> <tr>
<th translate center>Item ID</th> <th translate expand>Item</th>
<th translate expand>Description</th> <th translate expand>Description</th>
<th translate center>Size</th> <th translate center>Size</th>
<th translate center>Packing</th> <th translate center>Packing</th>
@ -96,7 +56,7 @@
</thead> </thead>
<tbody ng-repeat="buy in $ctrl.import.buys"> <tbody ng-repeat="buy in $ctrl.import.buys">
<tr> <tr>
<td title="{{::buy.itemFk}}"> <td title="{{::buy.itemFk}}" expand>
<vn-autocomplete <vn-autocomplete
class="dense" class="dense"
vn-focus vn-focus
@ -143,7 +103,7 @@
</vn-card> </vn-card>
<vn-button-bar> <vn-button-bar>
<vn-submit <vn-submit
label="Upload"> label="Import">
</vn-submit> </vn-submit>
<vn-button <vn-button
class="cancel" class="cancel"

View File

@ -23,13 +23,10 @@ class Controller extends Section {
} }
fillData(raw) { fillData(raw) {
this.import.file = raw;
const data = JSON.parse(raw); const data = JSON.parse(raw);
const [invoice] = data.invoices; const [invoice] = data.invoices;
this.$.$applyAsync(() => { this.$.$applyAsync(() => {
this.import.invoice = invoice.id_invoice;
this.import.observation = invoice.tx_awb; this.import.observation = invoice.tx_awb;
const boxes = invoice.boxes; const boxes = invoice.boxes;
@ -49,21 +46,27 @@ class Controller extends Section {
} }
} }
const params = {buys}; const boxesId = boxes.map(box => box.id_box);
const query = `Entries/${this.entry.id}/importPreview`; this.import.ref = boxesId.join(', ');
this.$http.get(query, {params}).then(res => {
this.import.buys = res.data; this.fetchBuys(buys);
}); });
// this.import.buys = 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() { onSubmit() {
const params = {buys: this.import.buys}; const params = this.import;
const query = `Entries/${this.entry.id}/import`; const query = `Entries/${this.entry.id}/import`;
return this.$http.post(query, params).then(() => { return this.$http.post(query, params)
this.vnApp.showSuccess(this.$t('Data saved!')); .then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
}); .then(() => this.$state.go('entry.card.buy.index'));
} }
itemSearchFunc($search) { itemSearchFunc($search) {

View File

@ -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);
});
});
});
});

View File

@ -0,0 +1,2 @@
#Ordenar alfabeticamente
reference: Referencia