Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2279-save_button_if_new_data
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-12-16 11:36:21 +01:00
commit ec7ad986ac
10 changed files with 218 additions and 1 deletions

View File

@ -160,5 +160,6 @@
"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",
"ASSIGN_ZONE_FIRST": "Asigna una zona primero"
"ASSIGN_ZONE_FIRST": "Asigna una zona primero",
"You can not select this payment method without a registered bankery account": "No se puede utilizar este método de pago si no has registrado una cuenta bancaria"
}

View File

@ -10,5 +10,8 @@
},
"SupplierContact": {
"dataSource": "vn"
},
"SupplierAccount": {
"dataSource": "vn"
}
}

View File

@ -0,0 +1,48 @@
const app = require('vn-loopback/server/server');
describe('loopback model address', () => {
let supplierOne;
let supplierTwo;
beforeAll(async done => {
supplierOne = await app.models.Supplier.findById(1);
supplierTwo = await app.models.Supplier.findById(442);
done();
});
afterAll(async done => {
await supplierOne.updateAttribute('payMethodFk', supplierOne.payMethodFk);
await supplierTwo.updateAttribute('payMethodFk', supplierTwo.payMethodFk);
done();
});
describe('payMethodFk', () => {
it('should throw an error when attempting to set an invalid payMethod id in the supplier', async() => {
let error;
const expectedError = 'You can not select this payment method without a registered bankery account';
const supplier = await app.models.Supplier.findById(1);
await supplier.updateAttribute('payMethodFk', 4)
.catch(e => {
error = e;
expect(error.message).toContain(expectedError);
});
expect(error).toBeDefined();
});
it('should not throw if the payMethod id is valid', async() => {
let error;
const supplier = await app.models.Supplier.findById(442);
await supplier.updateAttribute('payMethodFk', 4)
.catch(e => {
error = e;
});
expect(error).toBeDefined();
});
});
});

View File

@ -0,0 +1,50 @@
{
"name": "SupplierAccount",
"base": "VnModel",
"options": {
"mysql": {
"table": "supplierAccount"
}
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"supplierFk": {
"type": "Number"
},
"iban": {
"type": "String"
},
"office": {
"type": "String"
},
"DC": {
"type": "String"
},
"number": {
"type": "String"
},
"description": {
"type": "String"
},
"bicSufix": {
"type": "String"
},
"bankEntityFk": {
"type": "Number"
},
"bankFk": {
"type": "Number"
}
},
"relations": {
"supplier": {
"type": "belongsTo",
"model": "Supplier",
"foreignKey": "supplierFk"
}
}
}

View File

@ -70,6 +70,21 @@ module.exports = Self => {
return regexp.test(value);
}
Self.validateAsync('payMethodFk', hasSupplierAccount, {
message: 'You can not select this payment method without a registered bankery account'
});
async function hasSupplierAccount(err, done) {
const payMethod = await Self.app.models.PayMethod.findById(this.payMethodFk);
const supplierAccount = await Self.app.models.SupplierAccount.findOne({where: {supplierFk: this.id}});
const hasIban = supplierAccount && supplierAccount.iban;
if (payMethod && payMethod.ibanRequired && !hasIban)
err();
done();
}
Self.observe('before save', async function(ctx) {
let changes = ctx.data || ctx.instance;
let orgData = ctx.currentInstance;

View File

@ -0,0 +1,64 @@
<mg-ajax path="Suppliers/{{patch.params.id}}" options="vnPatch"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.supplier"
form="form"
save="patch">
</vn-watcher>
<vn-crud-model
auto-load="true"
url="PayMethods"
data="paymethods">
</vn-crud-model>
<vn-crud-model
auto-load="true"
url="PayDems"
data="paydems">
</vn-crud-model>
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-horizontal>
<vn-autocomplete
vn-one
label="Billing data"
vn-acl="salesAssistant"
ng-model="$ctrl.supplier.payMethodFk"
data="paymethods"
fields="['ibanRequired']"
initial-data="$ctrl.supplier.payMethod">
</vn-autocomplete>
<vn-autocomplete
vn-one
label="Payment deadline"
vn-acl="salesAssistant"
ng-model="$ctrl.supplier.payDemFk"
data="paydems"
fields="['id', 'payDem']"
show-field="payDem"
initial-data="$ctrl.supplier.payDem">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-input-number
vn-one
min="0"
step="1"
label="Pay day"
ng-model="$ctrl.supplier.payDay"
vn-focus
rule>
</vn-input-number>
</vn-horizontal>
<vn-button-bar>
<vn-submit
label="Save"
ng-if="watcher.dataChanged()"
vn-acl="salesAssistant">
</vn-submit>
<vn-button
label="Undo changes"
ng-if="watcher.dataChanged()"
ng-click="watcher.loadOriginalData()">
</vn-button>
</vn-button-bar>
</form>

View File

@ -0,0 +1,24 @@
import ngModule from '../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
get supplier() {
return this._supplier;
}
set supplier(value) {
this._supplier = value;
}
onSubmit() {
return this.$.watcher.submit();
}
}
ngModule.vnComponent('vnSupplierBillingData', {
template: require('./index.html'),
controller: Controller,
bindings: {
supplier: '<'
}
});

View File

@ -0,0 +1 @@
Pay day: Dia de pago

View File

@ -10,3 +10,4 @@ import './basic-data';
import './fiscal-data';
import './contact';
import './log';
import './billing-data';

View File

@ -11,6 +11,7 @@
"card": [
{"state": "supplier.card.basicData", "icon": "settings"},
{"state": "supplier.card.fiscalData", "icon": "account_balance"},
{"state": "supplier.card.billingData", "icon": "icon-payment"},
{"state": "supplier.card.contact", "icon": "contact_phone"},
{"state": "supplier.card.log", "icon": "history"}
]
@ -75,6 +76,15 @@
"params": {
"supplier": "$ctrl.supplier"
}
},
{
"url": "/billing-data",
"state": "supplier.card.billingData",
"component": "vn-supplier-billing-data",
"description": "Billing data",
"params": {
"supplier": "$ctrl.supplier"
}
}
]
}