Item tax form and service

This commit is contained in:
Juan Ferrer Toribio 2018-02-23 13:04:44 +01:00
parent 0c1fa49708
commit cfc4b01fb0
11 changed files with 164 additions and 3 deletions

View File

@ -39,14 +39,14 @@ describe('Component vnDialog', () => {
describe('fireResponse()', () => {
it(`should call onResponse()`, () => {
let resposneRes;
let responseRes;
controller.onResponse = response => {
resposneRes = response;
responseRes = response;
return false;
};
let responseRet = controller.fireResponse('answer');
expect(resposneRes).toEqual({response: 'answer'});
expect(responseRes).toEqual({response: 'answer'});
expect(responseRet).toEqual(false);
});
});

View File

@ -52,6 +52,15 @@
},
"acl": ["buyer"]
},
{
"url" : "/tax",
"state": "item.card.tax",
"component": "vn-item-tax",
"menu": {
"description": "Tax",
"icon": "folder"
}
},
{
"url" : "/history",
"state": "item.card.history",

View File

@ -8,6 +8,7 @@ import './card/item-card';
import './descriptor/item-descriptor';
import './data/item-data';
import './tags/item-tags';
import './tax/item-tax';
import './history/item-history';
import './niche/item-niche';
import './botanical/item-botanical';

View File

@ -11,6 +11,7 @@ Basic data: Datos básicos
History: Historial
Item history: Historial del artículo
Item tags: Tags del artículo
Tax: IVA
Niche: Nicho
Picture: Foto
Barcode: Código barras

View File

@ -0,0 +1,24 @@
<form name="form" ng-submit="$ctrl.submit()">
<vn-card>
<vn-vertical pad-large>
<vn-title>Item tax</vn-title>
<vn-horizontal ng-repeat="tax in $ctrl.taxes track by $index">
<vn-textfield vn-one
label="Country"
model="tax.country.country"
disabled="true">
</vn-textfield>
<vn-autocomplete vn-one
label="Class"
field="tax.taxClassFk"
data="$ctrl.classes"
value-field="id"
show-field="description">
</vn-autocomplete>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -0,0 +1,43 @@
import ngModule from '../module';
export default class Controller {
constructor($stateParams, $http) {
this.$http = $http;
this.$stateParams = $stateParams;
let filter = {
fields: ['id', 'countryFk', 'taxClassFk'],
include: [{
relation: 'country',
scope: {fields: ['country']}
}]
};
let urlFilter = encodeURIComponent(JSON.stringify(filter));
let url = `/item/api/Items/${$stateParams.id}/taxes?filter=${urlFilter}`;
$http.get(url).then(json => {
this.taxes = json.data;
});
$http.get(`/item/api/TaxClasses`).then(json => {
this.classes = json.data;
});
}
submit() {
let data = [];
for (let tax of this.taxes)
data.push({id: tax.id, taxClassFk: tax.taxClassFk});
let url = `/item/api/Items/${this.$stateParams.id}/updateTaxes`;
this.$http.post(url, data);
}
}
Controller.$inject = ['$stateParams', '$http'];
ngModule.component('vnItemTax', {
template: require('./item-tax.html'),
controller: Controller,
bindings: {
item: '<'
}
});

View File

@ -0,0 +1,38 @@
module.exports = Self => {
Self.remoteMethod('updateTaxes', {
description: 'Updates the item taxes',
accessType: 'WRITE',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The item id',
http: {source: 'path'}
}, {
arg: 'niches',
type: ['object'],
required: true,
description: 'The list of taxes to update',
http: {source: 'body'}
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:id/updateTaxes`,
verb: 'post'
}
});
Self.updateTaxes = async (id, taxes) => {
let promises = [];
for (let tax of taxes)
promises.push(Self.app.models.ItemTaxCountry.updateAll(
{id: tax.id},
{taxClassFk: tax.taxClassFk}
));
await Promise.all(promises);
return true;
};
};

View File

@ -0,0 +1,36 @@
{
"name": "ItemTaxCountry",
"base": "VnModel",
"options": {
"mysql": {
"table": "itemTaxCountry"
}
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"effectived": {
"type": "Boolean"
}
},
"relations": {
"item": {
"type": "belongsTo",
"model": "Item",
"foreignKey": "itemFk"
},
"country": {
"type": "belongsTo",
"model": "Country",
"foreignKey": "countryFk"
},
"taxClass": {
"type": "belongsTo",
"model": "TaxClass",
"foreignKey": "taxClassFk"
}
}
}

View File

@ -1,6 +1,7 @@
module.exports = function(Self) {
require('../methods/item/filter.js')(Self);
require('../methods/item/clone.js')(Self);
require('../methods/item/updateTaxes.js')(Self);
Self.validatesPresenceOf('name', {message: 'Cannot be blank'});
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});

View File

@ -85,6 +85,11 @@
"model": "ItemBarcode",
"foreignKey": "itemFk"
},
"taxes": {
"type": "hasMany",
"model": "ItemTaxCountry",
"foreignKey": "itemFk"
},
"itemNiche": {
"type": "hasMany",
"model": "ItemNiche",

View File

@ -50,6 +50,9 @@
"ItemPlacement": {
"dataSource": "vn"
},
"ItemTaxCountry": {
"dataSource": "vn"
},
"Warehouse": {
"dataSource": "vn"
},