Added section
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
ea6fc0fb04
commit
245b32a47f
|
@ -56,6 +56,9 @@
|
|||
"Sip": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"SageWithholding": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"UserConfigView": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"name": "SageWithholding",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "sage.TiposRetencion"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
"id": true,
|
||||
"description": "Identifier",
|
||||
"mysql": {
|
||||
"columnName": "CodigoRetencion"
|
||||
}
|
||||
},
|
||||
"withholding": {
|
||||
"type": "string",
|
||||
"mysql": {
|
||||
"columnName": "Retencion"
|
||||
}
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "READ",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -604,6 +604,24 @@ INSERT INTO `TiposTransacciones` VALUES (1,'Rég.general/Oper.interiores bienes
|
|||
UNLOCK TABLES;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `TiposRetencion`
|
||||
--
|
||||
|
||||
LOCK TABLES `TiposRetencion` WRITE;
|
||||
/*!40000 ALTER TABLE `TiposRetencion` DISABLE KEYS */;
|
||||
INSERT INTO `TiposRetencion` (`CodigoRetencion`, `Retencion`, `PorcentajeRetencion`, `CuentaCargo`, `CuentaAbono`, `ClaveIrpf`, `CuentaCargoANT_`, `CuentaAbonoANT_`, `IdTipoRetencion`) VALUES
|
||||
(1, 'RETENCION ESTIMACION OBJETIVA', '1.0000000000', '4730000000', '4751000000', NULL, NULL, NULL, '03811652-0F3A-44A1-AE1C-B19624525D7F'),
|
||||
(2, 'ACTIVIDADES AGRICOLAS O GANADERAS', '2.0000000000', '4730000000', '4751000000', NULL, NULL, NULL, 'F3F91EF3-FED6-444D-B03C-75B639D13FB4'),
|
||||
(9, 'ACTIVIDADES PROFESIONALES 2 PRIMEROS AÑOS', '9.0000000000', '4730000000', '4751000000', NULL, NULL, NULL, '73F95642-E951-4C91-970A-60C503A4792B'),
|
||||
(15, 'ACTIVIDADES PROFESIONALES', '15.0000000000', '4730000000', '4751000000', '6', NULL, NULL, 'F6BDE0EE-3B01-4023-8FFF-A73AE9AC50D7'),
|
||||
(19, 'ARRENDAMIENTO Y SUBARRENDAMIENTO', '19.0000000000', '4730000000', '4751000000', '8', NULL, NULL, '09B033AE-16E5-4057-8D4A-A7710C8A4FB9');
|
||||
/*!40000 ALTER TABLE `TiposRetencion` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
|
|
|
@ -1208,11 +1208,11 @@ INSERT INTO `vn`.`annualAverageInvoiced`(`clientFk`, `invoiced`)
|
|||
(104, 500),
|
||||
(105, 5000);
|
||||
|
||||
INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`,`isFarmer`,`retAccount`,`commission`, `created`, `postcodeFk`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `payDay`)
|
||||
INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`,`isFarmer`,`retAccount`,`commission`, `created`, `postcodeFk`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `payDay`, `taxTypeSageFk`, `withholdingSageFk`, `transactionTypeSageFk`)
|
||||
VALUES
|
||||
(1, 'Plants SL', 'Plants nick', 4000000001, 1, '06089160W', 0, NULL, 0, CURDATE(), 1111, 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 15),
|
||||
(2, 'Flower King', 'The king', 4000000002, 1, 'B22222222', 0, NULL, 0, CURDATE(), 2222, 1, 'supplier address 2', 'LONDON', 2, 45671, 1, 2, 10),
|
||||
(442, 'Verdnatura Levante SL', 'Verdnatura', 4000000442, 1, 'C33333333', 0, NULL, 0, CURDATE(), 3333, 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 15);
|
||||
(1, 'Plants SL', 'Plants nick', 4000000001, 1, '06089160W', 0, NULL, 0, CURDATE(), 1111, 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 15, 4, 1, 1),
|
||||
(2, 'Flower King', 'The king', 4000000002, 1, 'B22222222', 0, NULL, 0, CURDATE(), 2222, 1, 'supplier address 2', 'LONDON', 2, 45671, 1, 2, 10, 5, 2, 2),
|
||||
(442, 'Verdnatura Levante SL', 'Verdnatura', 4000000442, 1, 'C33333333', 0, NULL, 0, CURDATE(), 3333, 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 15, 6, 9, 3);
|
||||
|
||||
INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_refresh`, `expires`, `created`, `connection_id`)
|
||||
VALUES
|
||||
|
|
|
@ -7,7 +7,7 @@ describe('Supplier getSummary()', () => {
|
|||
expect(supplier.id).toEqual(1);
|
||||
expect(supplier.name).toEqual('Plants SL');
|
||||
expect(supplier.nif).toEqual('06089160W');
|
||||
expect(supplier.account).toEqual(4000000001);
|
||||
expect(supplier.account).toEqual('4000000001');
|
||||
expect(supplier.payDay).toEqual(15);
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('Supplier updateFiscalData', () => {
|
||||
const supplierId = 1;
|
||||
const administrativeId = 5;
|
||||
const employeeId = 1;
|
||||
const defaultData = {
|
||||
name: 'Plants SL',
|
||||
nif: '06089160W',
|
||||
account: '4000000001',
|
||||
sageTaxTypeFk: 4,
|
||||
sageWithholdingFk: 1,
|
||||
sageTransactionTypeFk: 1,
|
||||
postCode: '15214',
|
||||
city: 'PONTEVEDRA',
|
||||
provinceFk: 1,
|
||||
countryFk: 1,
|
||||
};
|
||||
|
||||
it('should return an error if the user is not administrative', async() => {
|
||||
const ctx = {req: {accessToken: {userId: employeeId}}};
|
||||
ctx.args = {};
|
||||
|
||||
let error;
|
||||
await app.models.Supplier.updateFiscalData(ctx, supplierId)
|
||||
.catch(e => {
|
||||
error = e;
|
||||
});
|
||||
|
||||
expect(error.message).toBeDefined();
|
||||
});
|
||||
|
||||
it('should check that the supplier fiscal data is untainted', async() => {
|
||||
const supplier = await app.models.Supplier.findById(supplierId);
|
||||
|
||||
expect(supplier.name).toEqual(defaultData.name);
|
||||
expect(supplier.nif).toEqual(defaultData.nif);
|
||||
expect(supplier.account).toEqual(defaultData.account);
|
||||
expect(supplier.sageTaxTypeFk).toEqual(defaultData.sageTaxTypeFk);
|
||||
expect(supplier.sageWithholdingFk).toEqual(defaultData.sageWithholdingFk);
|
||||
expect(supplier.sageTransactionTypeFk).toEqual(defaultData.sageTransactionTypeFk);
|
||||
expect(supplier.postCode).toEqual(defaultData.postCode);
|
||||
expect(supplier.city).toEqual(defaultData.city);
|
||||
expect(supplier.provinceFk).toEqual(defaultData.provinceFk);
|
||||
expect(supplier.countryFk).toEqual(defaultData.countryFk);
|
||||
});
|
||||
|
||||
it('should update the supplier fiscal data and return the count if changes made', async() => {
|
||||
const ctx = {req: {accessToken: {userId: administrativeId}}};
|
||||
ctx.args = {
|
||||
name: 'Weapon Dealer',
|
||||
nif: 'B11111111',
|
||||
account: '4000000005',
|
||||
sageTaxTypeFk: 5,
|
||||
sageWithholdingFk: 2,
|
||||
sageTransactionTypeFk: 2,
|
||||
postCode: '46460',
|
||||
city: 'VALENCIA',
|
||||
provinceFk: 2,
|
||||
countryFk: 2,
|
||||
};
|
||||
|
||||
const result = await app.models.Supplier.updateFiscalData(ctx, supplierId);
|
||||
|
||||
expect(result.name).toEqual('Weapon Dealer');
|
||||
expect(result.nif).toEqual('B11111111');
|
||||
expect(result.account).toEqual('4000000005');
|
||||
expect(result.sageTaxTypeFk).toEqual(5);
|
||||
expect(result.sageWithholdingFk).toEqual(2);
|
||||
expect(result.sageTransactionTypeFk).toEqual(2);
|
||||
expect(result.postCode).toEqual('46460');
|
||||
expect(result.city).toEqual('VALENCIA');
|
||||
expect(result.provinceFk).toEqual(2);
|
||||
expect(result.countryFk).toEqual(2);
|
||||
|
||||
// Restores
|
||||
ctx.args = defaultData;
|
||||
await app.models.Supplier.updateFiscalData(ctx, supplierId);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,78 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('updateFiscalData', {
|
||||
description: 'Updates fiscal data of a supplier',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'ctx',
|
||||
type: 'Object',
|
||||
http: {source: 'context'}
|
||||
},
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'Number',
|
||||
description: 'The supplier id',
|
||||
http: {source: 'path'}
|
||||
},
|
||||
{
|
||||
arg: 'name',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'nif',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'account',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'sageTaxTypeFk',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'sageWithholdingFk',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'sageTransactionTypeFk',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'postCode',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'city',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
arg: 'provinceFk',
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'countryFk',
|
||||
type: 'number'
|
||||
}],
|
||||
returns: {
|
||||
arg: 'res',
|
||||
type: 'string',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/updateFiscalData`,
|
||||
verb: 'PATCH'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateFiscalData = async(ctx, supplierId) => {
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
const supplier = await models.Supplier.findById(supplierId);
|
||||
|
||||
// Remove unwanted properties
|
||||
delete args.ctx;
|
||||
delete args.id;
|
||||
|
||||
return supplier.updateAttributes(args);
|
||||
};
|
||||
};
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/supplier/filter')(Self);
|
||||
require('../methods/supplier/getSummary')(Self);
|
||||
require('../methods/supplier/updateFiscalData')(Self);
|
||||
};
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
"type": "String"
|
||||
},
|
||||
"account": {
|
||||
"type": "Number"
|
||||
"type": "String"
|
||||
},
|
||||
"countryFk": {
|
||||
"type": "Number"
|
||||
|
@ -61,7 +61,7 @@
|
|||
"type": "Number"
|
||||
},
|
||||
"postCode": {
|
||||
"type": "Number"
|
||||
"type": "String"
|
||||
},
|
||||
"payMethodFk": {
|
||||
"type": "Number"
|
||||
|
@ -74,7 +74,25 @@
|
|||
},
|
||||
"nickname": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
"sageTaxTypeFk": {
|
||||
"type": "number",
|
||||
"mysql": {
|
||||
"columnName": "taxTypeSageFk"
|
||||
}
|
||||
},
|
||||
"sageTransactionTypeFk": {
|
||||
"type": "number",
|
||||
"mysql": {
|
||||
"columnName": "transactionTypeSageFk"
|
||||
}
|
||||
},
|
||||
"sageWithholdingFk": {
|
||||
"type": "number",
|
||||
"mysql": {
|
||||
"columnName": "withholdingSageFk"
|
||||
}
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
"payMethod": {
|
||||
|
|
|
@ -0,0 +1,177 @@
|
|||
<mg-ajax path="Suppliers/{{patch.params.id}}/updateFiscalData" options="vnPatch"></mg-ajax>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
data="$ctrl.supplier"
|
||||
id-field="id"
|
||||
form="form"
|
||||
save="patch">
|
||||
</vn-watcher>
|
||||
<vn-crud-model
|
||||
auto-load="true"
|
||||
url="Provinces/location"
|
||||
data="provincesLocation"
|
||||
order="name">
|
||||
</vn-crud-model>
|
||||
<vn-crud-model
|
||||
auto-load="true"
|
||||
url="Countries"
|
||||
data="countries"
|
||||
order="country">
|
||||
</vn-crud-model>
|
||||
<vn-crud-model
|
||||
auto-load="true"
|
||||
url="SageTaxTypes"
|
||||
data="sageTaxTypes"
|
||||
order="vat">
|
||||
</vn-crud-model>
|
||||
<vn-crud-model
|
||||
auto-load="true"
|
||||
url="SageTransactionTypes"
|
||||
data="sageTransactionTypes"
|
||||
order="transaction">
|
||||
</vn-crud-model>
|
||||
<vn-crud-model
|
||||
auto-load="true"
|
||||
url="SageWithholdings"
|
||||
data="sageWithholdings"
|
||||
order="withholding">
|
||||
</vn-crud-model>
|
||||
<form name="form" vn-http-submit="watcher.submit()" class="vn-w-md">
|
||||
<vn-card class="vn-pa-lg">
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-two
|
||||
vn-focus
|
||||
label="Social name"
|
||||
ng-model="$ctrl.supplier.name"
|
||||
rule
|
||||
info="You can use letters and spaces">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
label="Tax number"
|
||||
ng-model="$ctrl.supplier.nif"
|
||||
rule>
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
label="IBAN"
|
||||
ng-model="$ctrl.supplier.account"
|
||||
rule>
|
||||
</vn-textfield>
|
||||
<vn-autocomplete vn-one
|
||||
ng-model="$ctrl.supplier.sageTaxTypeFk"
|
||||
data="sageTaxTypes"
|
||||
show-field="vat"
|
||||
value-field="id"
|
||||
label="Sage tax type"
|
||||
rule>
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete vn-one
|
||||
ng-model="$ctrl.supplier.sageWithholdingFk"
|
||||
data="sageWithholdings"
|
||||
show-field="withholding"
|
||||
value-field="id"
|
||||
label="Sage withholding"
|
||||
rule>
|
||||
</vn-autocomplete>
|
||||
<vn-autocomplete vn-one
|
||||
ng-model="$ctrl.supplier.sageTransactionTypeFk"
|
||||
data="sageTransactionTypes"
|
||||
show-field="transaction"
|
||||
value-field="id"
|
||||
label="Sage transaction type"
|
||||
rule>
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-datalist vn-one
|
||||
label="Postcode"
|
||||
ng-model="$ctrl.supplier.postCode"
|
||||
selection="$ctrl.postcode"
|
||||
url="Postcodes/location"
|
||||
fields="['code','townFk']"
|
||||
order="code, townFk"
|
||||
value-field="code"
|
||||
show-field="code"
|
||||
rule>
|
||||
<tpl-item>
|
||||
{{code}} - {{town.name}} ({{town.province.name}},
|
||||
{{town.province.country.country}})
|
||||
</tpl-item>
|
||||
<append>
|
||||
<vn-icon-button
|
||||
icon="add_circle"
|
||||
vn-tooltip="New postcode"
|
||||
ng-click="postcode.open()"
|
||||
vn-acl="deliveryBoss"
|
||||
vn-acl-action="remove">
|
||||
</vn-icon-button>
|
||||
</append>
|
||||
</vn-datalist>
|
||||
<vn-datalist vn-id="town" vn-one
|
||||
label="City"
|
||||
ng-model="$ctrl.supplier.city"
|
||||
selection="$ctrl.town"
|
||||
url="Towns/location"
|
||||
fields="['id', 'name', 'provinceFk']"
|
||||
show-field="name"
|
||||
value-field="name">
|
||||
<tpl-item>
|
||||
{{name}}, {{province.name}}
|
||||
({{province.country.country}})
|
||||
</tpl-item>
|
||||
</vn-datalist>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal>
|
||||
<vn-autocomplete vn-id="province" vn-one
|
||||
label="Province"
|
||||
ng-model="$ctrl.supplier.provinceFk"
|
||||
selection="$ctrl.province"
|
||||
data="provincesLocation"
|
||||
fields="['id', 'name', 'countryFk']"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
rule>
|
||||
<tpl-item>{{name}} ({{country.country}})</tpl-item>
|
||||
</vn-autocomplete>
|
||||
<vn-autocomplete vn-id="country" vn-one
|
||||
ng-model="$ctrl.supplier.countryFk"
|
||||
data="countries"
|
||||
show-field="country"
|
||||
value-field="id"
|
||||
label="Country"
|
||||
rule>
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
<!--
|
||||
<vn-horizontal>
|
||||
<vn-check
|
||||
vn-one
|
||||
label="Is equalizated"
|
||||
ng-model="$ctrl.client.isEqualizated"
|
||||
info="In order to invoice, this field is not consulted, but the consignee's ET. When modifying this field if the invoice by address option is not checked, the change will be automatically propagated to all addresses, otherwise the user will be asked if he wants to propagate it or not."
|
||||
on-change="$ctrl.onChangeEqualizated(value)">
|
||||
</vn-check>
|
||||
<vn-check
|
||||
vn-one
|
||||
label="Verified data"
|
||||
ng-model="$ctrl.client.isTaxDataChecked"
|
||||
vn-acl="salesAssistant">
|
||||
</vn-check>
|
||||
</vn-horizontal> -->
|
||||
</vn-card>
|
||||
<vn-button-bar>
|
||||
<vn-submit label="Save"></vn-submit>
|
||||
<vn-button label="Undo changes" ng-if="$ctrl.$.form.$dirty" ng-click="watcher.loadOriginalData()"></vn-button>
|
||||
</vn-button-bar>
|
||||
</form>
|
||||
<!-- New postcode dialog -->
|
||||
<vn-geo-postcode
|
||||
vn-id="postcode"
|
||||
on-response="$ctrl.onResponse($response)">
|
||||
</vn-geo-postcode>
|
|
@ -0,0 +1,84 @@
|
|||
import ngModule from '../module';
|
||||
import Section from 'salix/components/section';
|
||||
|
||||
export default class Controller extends Section {
|
||||
get province() {
|
||||
return this._province;
|
||||
}
|
||||
|
||||
// Province auto complete
|
||||
set province(selection) {
|
||||
this._province = selection;
|
||||
|
||||
if (!selection) return;
|
||||
|
||||
const country = selection.country;
|
||||
|
||||
if (!this.supplier.countryFk)
|
||||
this.supplier.countryFk = country.id;
|
||||
}
|
||||
|
||||
get town() {
|
||||
return this._town;
|
||||
}
|
||||
|
||||
// Town auto complete
|
||||
set town(selection) {
|
||||
this._town = selection;
|
||||
|
||||
if (!selection) return;
|
||||
|
||||
const province = selection.province;
|
||||
const country = province.country;
|
||||
const postcodes = selection.postcodes;
|
||||
|
||||
if (!this.supplier.provinceFk)
|
||||
this.supplier.provinceFk = province.id;
|
||||
|
||||
if (!this.supplier.countryFk)
|
||||
this.supplier.countryFk = country.id;
|
||||
|
||||
if (postcodes.length === 1)
|
||||
this.supplier.postCode = postcodes[0].code;
|
||||
}
|
||||
|
||||
get postcode() {
|
||||
return this._postcode;
|
||||
}
|
||||
|
||||
// Postcode auto complete
|
||||
set postcode(selection) {
|
||||
const oldValue = this._postcode;
|
||||
this._postcode = selection;
|
||||
|
||||
if (!selection || !oldValue) return;
|
||||
|
||||
const town = selection.town;
|
||||
const province = town.province;
|
||||
const country = province.country;
|
||||
|
||||
if (!this.supplier.city)
|
||||
this.supplier.city = town.name;
|
||||
|
||||
if (!this.supplier.provinceFk)
|
||||
this.supplier.provinceFk = province.id;
|
||||
|
||||
if (!this.supplier.countryFk)
|
||||
this.supplier.countryFk = country.id;
|
||||
}
|
||||
|
||||
onResponse(response) {
|
||||
this.supplier.postCode = response.code;
|
||||
this.supplier.city = response.city;
|
||||
this.supplier.provinceFk = response.provinceFk;
|
||||
this.supplier.countryFk = response.countryFk;
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnSupplierFiscalData', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
supplier: '<'
|
||||
}
|
||||
});
|
|
@ -0,0 +1,215 @@
|
|||
import './index';
|
||||
import watcher from 'core/mocks/watcher';
|
||||
|
||||
describe('Supplier', () => {
|
||||
describe('Component vnSupplierFiscalData', () => {
|
||||
let $httpBackend;
|
||||
let $scope;
|
||||
let $element;
|
||||
let controller;
|
||||
|
||||
beforeEach(ngModule('supplier'));
|
||||
|
||||
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$scope = $rootScope.$new();
|
||||
$scope.watcher = watcher;
|
||||
$scope.watcher.orgData = {id: 101, isEqualizated: false, isTaxDataChecked: false};
|
||||
$element = angular.element('<vn-supplier-fiscal-data></supplier-fiscal-data>');
|
||||
controller = $componentController('vnClientFiscalData', {$element, $scope});
|
||||
controller.card = {reload: () => {}};
|
||||
controller.client = {
|
||||
id: 101,
|
||||
email: 'batman@gothamcity.com',
|
||||
phone: '1111111111',
|
||||
isEqualizated: false,
|
||||
isTaxDataChecked: false
|
||||
};
|
||||
|
||||
controller._province = {};
|
||||
controller._town = {};
|
||||
controller._postcode = {};
|
||||
}));
|
||||
|
||||
describe('onSubmit()', () => {
|
||||
it('should call the save() method directly', () => {
|
||||
jest.spyOn(controller, 'save');
|
||||
|
||||
controller.onSubmit();
|
||||
|
||||
expect(controller.save).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('should call the checkExistingClient() if the isTaxDataChecked property is checked', () => {
|
||||
jest.spyOn(controller, 'save');
|
||||
jest.spyOn(controller, 'checkExistingClient');
|
||||
|
||||
controller.client.isTaxDataChecked = true;
|
||||
controller.onSubmit();
|
||||
|
||||
expect(controller.save).not.toHaveBeenCalledWith();
|
||||
expect(controller.checkExistingClient).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkExistingClient()', () => {
|
||||
it(`should make a HTTP GET query filtering by email, phone and mobile`, () => {
|
||||
controller.client.mobile = 222222222;
|
||||
const filterObj = {
|
||||
where: {
|
||||
and: [
|
||||
{or: [
|
||||
{email: controller.client.email},
|
||||
{phone: controller.client.phone},
|
||||
{mobile: controller.client.mobile}
|
||||
]},
|
||||
{id: {neq: controller.client.id}}
|
||||
]
|
||||
}
|
||||
};
|
||||
const filter = encodeURIComponent(JSON.stringify(filterObj));
|
||||
$httpBackend.expect('GET', `Clients/findOne?filter=${filter}`).respond(404);
|
||||
controller.checkExistingClient();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it(`should show a save confirmation and then set the despiteOfClient property`, () => {
|
||||
controller.$.confirmDuplicatedClient = {show: () => {}};
|
||||
jest.spyOn(controller.$.confirmDuplicatedClient, 'show');
|
||||
|
||||
const filterObj = {
|
||||
where: {
|
||||
and: [
|
||||
{or: [{email: controller.client.email}, {phone: controller.client.phone}]},
|
||||
{id: {neq: controller.client.id}}
|
||||
]
|
||||
}
|
||||
};
|
||||
const expectedClient = {id: 102};
|
||||
const filter = encodeURIComponent(JSON.stringify(filterObj));
|
||||
$httpBackend.expect('GET', `Clients/findOne?filter=${filter}`).respond(expectedClient);
|
||||
controller.checkExistingClient();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$.confirmDuplicatedClient.show).toHaveBeenCalledWith();
|
||||
expect(controller.client.despiteOfClient).toEqual(102);
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkEtChanges()', () => {
|
||||
it(`should show a propagation confirmation if isEqualizated property is changed and invoice by address is checked`, () => {
|
||||
controller.$.propagateIsEqualizated = {show: () => {}};
|
||||
jest.spyOn(controller.$.propagateIsEqualizated, 'show');
|
||||
|
||||
const orgData = $scope.watcher.orgData;
|
||||
orgData.hasToInvoiceByAddress = true;
|
||||
controller.client.isEqualizated = true;
|
||||
|
||||
controller.checkEtChanges(orgData);
|
||||
|
||||
expect(controller.$.propagateIsEqualizated.show).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it(`should call to the onAcceptEt() method if isEqualizated property is changed and invoice by address isn't checked`, () => {
|
||||
jest.spyOn(controller, 'onAcceptEt');
|
||||
|
||||
const orgData = $scope.watcher.orgData;
|
||||
orgData.hasToInvoiceByAddress = false;
|
||||
controller.client.isEqualizated = true;
|
||||
|
||||
controller.checkEtChanges(orgData);
|
||||
|
||||
expect(controller.onAcceptEt).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('onAcceptEt()', () => {
|
||||
it('should request to patch the propagation of tax status', () => {
|
||||
controller.client = {id: 123, isEqualizated: false};
|
||||
$httpBackend.expectPATCH(`Clients/${controller.client.id}/addressesPropagateRe`, {isEqualizated: controller.client.isEqualizated}).respond('done');
|
||||
controller.onAcceptEt();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
|
||||
describe('province() setter', () => {
|
||||
it(`should set countryFk property`, () => {
|
||||
controller.client.countryFk = null;
|
||||
controller.province = {
|
||||
id: 1,
|
||||
name: 'New york',
|
||||
country: {
|
||||
id: 2,
|
||||
name: 'USA'
|
||||
}
|
||||
};
|
||||
|
||||
expect(controller.client.countryFk).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('town() setter', () => {
|
||||
it(`should set provinceFk property`, () => {
|
||||
controller.town = {
|
||||
provinceFk: 1,
|
||||
code: 46001,
|
||||
province: {
|
||||
id: 1,
|
||||
name: 'New york',
|
||||
country: {
|
||||
id: 2,
|
||||
name: 'USA'
|
||||
}
|
||||
},
|
||||
postcodes: []
|
||||
};
|
||||
|
||||
expect(controller.client.provinceFk).toEqual(1);
|
||||
});
|
||||
|
||||
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
|
||||
controller.town = {
|
||||
provinceFk: 1,
|
||||
code: 46001,
|
||||
province: {
|
||||
id: 1,
|
||||
name: 'New york',
|
||||
country: {
|
||||
id: 2,
|
||||
name: 'USA'
|
||||
}
|
||||
},
|
||||
postcodes: [{code: '46001'}]
|
||||
};
|
||||
|
||||
expect(controller.client.provinceFk).toEqual(1);
|
||||
expect(controller.client.postcode).toEqual('46001');
|
||||
});
|
||||
});
|
||||
|
||||
describe('postcode() setter', () => {
|
||||
it(`should set the town, provinceFk and contryFk properties`, () => {
|
||||
controller.postcode = {
|
||||
townFk: 1,
|
||||
code: 46001,
|
||||
town: {
|
||||
id: 1,
|
||||
name: 'New York',
|
||||
province: {
|
||||
id: 1,
|
||||
name: 'New york',
|
||||
country: {
|
||||
id: 2,
|
||||
name: 'USA'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
expect(controller.client.city).toEqual('New York');
|
||||
expect(controller.client.provinceFk).toEqual(1);
|
||||
expect(controller.client.countryFk).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
Sage tax type: Tipo de impuesto Sage
|
||||
Sage transaction type: Tipo de transacción Sage
|
||||
Sage withholding: Retención Sage
|
|
@ -6,3 +6,5 @@ import './search-panel';
|
|||
import './summary';
|
||||
import './card';
|
||||
import './descriptor';
|
||||
import './fiscal-data';
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
{"state": "supplier.index", "icon": "icon-supplier"}
|
||||
],
|
||||
"card": [
|
||||
{"state": "supplier.card.basicData", "icon": "settings"},
|
||||
{"state": "supplier.card.fiscalData", "icon": "account_balance"}
|
||||
]
|
||||
},
|
||||
"routes": [
|
||||
|
@ -36,6 +38,22 @@
|
|||
"params": {
|
||||
"supplier": "$ctrl.supplier"
|
||||
}
|
||||
}, {
|
||||
"url": "/basic-data",
|
||||
"state": "supplier.card.basicData",
|
||||
"component": "vn-supplier-basic-data",
|
||||
"description": "Basic data",
|
||||
"params": {
|
||||
"supplier": "$ctrl.supplier"
|
||||
}
|
||||
}, {
|
||||
"url": "/fiscal-data",
|
||||
"state": "supplier.card.fiscalData",
|
||||
"component": "vn-supplier-fiscal-data",
|
||||
"description": "Fiscal data",
|
||||
"params": {
|
||||
"supplier": "$ctrl.supplier"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue