Item tax form and service
This commit is contained in:
parent
0c1fa49708
commit
cfc4b01fb0
|
@ -39,14 +39,14 @@ describe('Component vnDialog', () => {
|
||||||
|
|
||||||
describe('fireResponse()', () => {
|
describe('fireResponse()', () => {
|
||||||
it(`should call onResponse()`, () => {
|
it(`should call onResponse()`, () => {
|
||||||
let resposneRes;
|
let responseRes;
|
||||||
controller.onResponse = response => {
|
controller.onResponse = response => {
|
||||||
resposneRes = response;
|
responseRes = response;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let responseRet = controller.fireResponse('answer');
|
let responseRet = controller.fireResponse('answer');
|
||||||
|
|
||||||
expect(resposneRes).toEqual({response: 'answer'});
|
expect(responseRes).toEqual({response: 'answer'});
|
||||||
expect(responseRet).toEqual(false);
|
expect(responseRet).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -52,6 +52,15 @@
|
||||||
},
|
},
|
||||||
"acl": ["buyer"]
|
"acl": ["buyer"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"url" : "/tax",
|
||||||
|
"state": "item.card.tax",
|
||||||
|
"component": "vn-item-tax",
|
||||||
|
"menu": {
|
||||||
|
"description": "Tax",
|
||||||
|
"icon": "folder"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"url" : "/history",
|
"url" : "/history",
|
||||||
"state": "item.card.history",
|
"state": "item.card.history",
|
||||||
|
|
|
@ -8,6 +8,7 @@ import './card/item-card';
|
||||||
import './descriptor/item-descriptor';
|
import './descriptor/item-descriptor';
|
||||||
import './data/item-data';
|
import './data/item-data';
|
||||||
import './tags/item-tags';
|
import './tags/item-tags';
|
||||||
|
import './tax/item-tax';
|
||||||
import './history/item-history';
|
import './history/item-history';
|
||||||
import './niche/item-niche';
|
import './niche/item-niche';
|
||||||
import './botanical/item-botanical';
|
import './botanical/item-botanical';
|
||||||
|
|
|
@ -11,6 +11,7 @@ Basic data: Datos básicos
|
||||||
History: Historial
|
History: Historial
|
||||||
Item history: Historial del artículo
|
Item history: Historial del artículo
|
||||||
Item tags: Tags del artículo
|
Item tags: Tags del artículo
|
||||||
|
Tax: IVA
|
||||||
Niche: Nicho
|
Niche: Nicho
|
||||||
Picture: Foto
|
Picture: Foto
|
||||||
Barcode: Código barras
|
Barcode: Código barras
|
||||||
|
|
|
@ -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>
|
|
@ -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: '<'
|
||||||
|
}
|
||||||
|
});
|
|
@ -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;
|
||||||
|
};
|
||||||
|
};
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
module.exports = function(Self) {
|
module.exports = function(Self) {
|
||||||
require('../methods/item/filter.js')(Self);
|
require('../methods/item/filter.js')(Self);
|
||||||
require('../methods/item/clone.js')(Self);
|
require('../methods/item/clone.js')(Self);
|
||||||
|
require('../methods/item/updateTaxes.js')(Self);
|
||||||
|
|
||||||
Self.validatesPresenceOf('name', {message: 'Cannot be blank'});
|
Self.validatesPresenceOf('name', {message: 'Cannot be blank'});
|
||||||
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});
|
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});
|
||||||
|
|
|
@ -85,6 +85,11 @@
|
||||||
"model": "ItemBarcode",
|
"model": "ItemBarcode",
|
||||||
"foreignKey": "itemFk"
|
"foreignKey": "itemFk"
|
||||||
},
|
},
|
||||||
|
"taxes": {
|
||||||
|
"type": "hasMany",
|
||||||
|
"model": "ItemTaxCountry",
|
||||||
|
"foreignKey": "itemFk"
|
||||||
|
},
|
||||||
"itemNiche": {
|
"itemNiche": {
|
||||||
"type": "hasMany",
|
"type": "hasMany",
|
||||||
"model": "ItemNiche",
|
"model": "ItemNiche",
|
||||||
|
|
|
@ -50,6 +50,9 @@
|
||||||
"ItemPlacement": {
|
"ItemPlacement": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"ItemTaxCountry": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"Warehouse": {
|
"Warehouse": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue