Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2563-supplier_fiscalData
This commit is contained in:
commit
c826c1ccc1
|
@ -57,6 +57,8 @@ describe('Client lock verified data path', () => {
|
|||
});
|
||||
|
||||
it('should check the Verified data checkbox', async() => {
|
||||
await page.autocompleteSearch(selectors.clientFiscalData.sageTax, 'operaciones no sujetas');
|
||||
await page.autocompleteSearch(selectors.clientFiscalData.sageTransaction, 'regularización de inversiones');
|
||||
await page.waitToClick(selectors.clientFiscalData.verifiedDataCheckbox);
|
||||
await page.waitToClick(selectors.clientFiscalData.saveButton);
|
||||
await page.waitToClick(selectors.globalItems.acceptButton);
|
||||
|
|
|
@ -21,6 +21,7 @@ let buildDir = 'dist';
|
|||
|
||||
let backSources = [
|
||||
'!node_modules',
|
||||
'!loopback/locale/*.json',
|
||||
'loopback',
|
||||
'modules/*/back/**',
|
||||
'modules/*/back/*',
|
||||
|
|
|
@ -81,5 +81,6 @@
|
|||
"shipped": "Shipped",
|
||||
"landed": "Landed",
|
||||
"addressFk": "Address",
|
||||
"companyFk": "Company"
|
||||
"companyFk": "Company",
|
||||
"You need to fill sage information before you check verified data": "You need to fill sage information before you check verified data"
|
||||
}
|
|
@ -157,6 +157,5 @@
|
|||
"landed": "F. entrega",
|
||||
"addressFk": "Consignatario",
|
||||
"companyFk": "Empresa",
|
||||
"The social name cannot be empty": "La razón social no puede quedar en blanco",
|
||||
"The nif cannot be empty": "El NIF no puede quedar en blanco"
|
||||
"You need to fill sage information before you check verified data": "Debes rellenar la información de sage antes de marcar datos comprobados"
|
||||
}
|
|
@ -2,9 +2,11 @@ const app = require('vn-loopback/server/server');
|
|||
|
||||
describe('Client updateFiscalData', () => {
|
||||
const clientId = 101;
|
||||
const employeeId = 1;
|
||||
const salesAssistantId = 21;
|
||||
const administrativeId = 5;
|
||||
afterAll(async done => {
|
||||
const clientId = 101;
|
||||
const ctx = {req: {accessToken: {userId: 5}}};
|
||||
const ctx = {req: {accessToken: {userId: administrativeId}}};
|
||||
ctx.args = {postcode: 46460};
|
||||
|
||||
await app.models.Client.updateFiscalData(ctx, clientId);
|
||||
|
@ -12,8 +14,8 @@ describe('Client updateFiscalData', () => {
|
|||
done();
|
||||
});
|
||||
|
||||
it('should return an error if the user is not administrative and the isTaxDataChecked value is true', async() => {
|
||||
const ctx = {req: {accessToken: {userId: 1}}};
|
||||
it('should return an error if the user is not salesAssistant and the isTaxDataChecked value is true', async() => {
|
||||
const ctx = {req: {accessToken: {userId: employeeId}}};
|
||||
ctx.args = {};
|
||||
|
||||
let error;
|
||||
|
@ -22,11 +24,30 @@ describe('Client updateFiscalData', () => {
|
|||
error = e;
|
||||
});
|
||||
|
||||
expect(error.message).toBeDefined();
|
||||
expect(error.message).toEqual(`You can't make changes on a client with verified data`);
|
||||
});
|
||||
|
||||
it('should return an error if the salesAssistant did not fill the sage data before checking verified data', async() => {
|
||||
const client = await app.models.Client.findById(clientId);
|
||||
await client.updateAttribute('isTaxDataChecked', false);
|
||||
|
||||
const ctx = {req: {accessToken: {userId: salesAssistantId}}};
|
||||
ctx.args = {isTaxDataChecked: true};
|
||||
|
||||
let error;
|
||||
await app.models.Client.updateFiscalData(ctx, clientId)
|
||||
.catch(e => {
|
||||
error = e;
|
||||
});
|
||||
|
||||
expect(error.message).toEqual('You need to fill sage information before you check verified data');
|
||||
|
||||
// Restores
|
||||
await client.updateAttribute('isTaxDataChecked', true);
|
||||
});
|
||||
|
||||
it('should update the client fiscal data and return the count if changes made', async() => {
|
||||
const ctx = {req: {accessToken: {userId: 5}}};
|
||||
const ctx = {req: {accessToken: {userId: administrativeId}}};
|
||||
ctx.args = {postcode: 46680};
|
||||
|
||||
const client = await app.models.Client.findById(clientId);
|
||||
|
|
|
@ -45,15 +45,15 @@ module.exports = Self => {
|
|||
},
|
||||
{
|
||||
arg: 'sageTaxTypeFk',
|
||||
type: 'number'
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'sageTransactionTypeFk',
|
||||
type: 'number'
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'transferorFk',
|
||||
type: 'number'
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'hasToInvoiceByAddress',
|
||||
|
@ -118,6 +118,15 @@ module.exports = Self => {
|
|||
if (!isSalesAssistant && client.isTaxDataChecked)
|
||||
throw new UserError(`You can't make changes on a client with verified data`);
|
||||
|
||||
// Sage data validation
|
||||
const taxDataChecked = args.isTaxDataChecked;
|
||||
const sageTaxChecked = client.sageTaxTypeFk || args.sageTaxTypeFk;
|
||||
const sageTransactionChecked = client.sageTransactionTypeFk || args.sageTransactionTypeFk;
|
||||
const hasSageData = sageTaxChecked && sageTransactionChecked;
|
||||
|
||||
if (taxDataChecked && !hasSageData)
|
||||
throw new UserError(`You need to fill sage information before you check verified data`);
|
||||
|
||||
if (args.despiteOfClient) {
|
||||
const logRecord = {
|
||||
originFk: clientId,
|
||||
|
|
|
@ -188,7 +188,7 @@ module.exports = Self => {
|
|||
|
||||
// Validate socialName format
|
||||
const hasChanges = orgData && changes;
|
||||
const socialName = changes.socialName || orgData.socialName;
|
||||
const socialName = changes && changes.socialName || orgData && orgData.socialName;
|
||||
const isTaxDataChecked = hasChanges && (changes.isTaxDataChecked || orgData.isTaxDataChecked);
|
||||
|
||||
const socialNameChanged = hasChanges
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
label="Social name"
|
||||
ng-model="$ctrl.client.socialName"
|
||||
rule
|
||||
info="You can use letters and spaces">
|
||||
info="You can use letters and spaces"
|
||||
required="true">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
|
@ -63,6 +64,7 @@
|
|||
show-field="vat"
|
||||
value-field="id"
|
||||
label="Sage tax type"
|
||||
vn-acl="salesAssistant"
|
||||
rule>
|
||||
</vn-autocomplete>
|
||||
<vn-autocomplete vn-one
|
||||
|
@ -71,6 +73,7 @@
|
|||
show-field="transaction"
|
||||
value-field="id"
|
||||
label="Sage transaction type"
|
||||
vn-acl="salesAssistant"
|
||||
rule>
|
||||
</vn-autocomplete>
|
||||
<vn-autocomplete vn-one
|
||||
|
@ -82,6 +85,7 @@
|
|||
value-field="id"
|
||||
label="Previous client"
|
||||
info="In case of a company succession, specify the grantor company"
|
||||
vn-acl="salesAssistant"
|
||||
rule>
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
|
|
Loading…
Reference in New Issue