Postcode auto-fill fix
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-11-04 11:37:54 +01:00
parent 413283288f
commit fd05455027
5 changed files with 25 additions and 4 deletions

View File

@ -52,7 +52,7 @@ export default class Controller extends Section {
if (!this.address.provinceFk)
this.address.provinceFk = province.id;
if (postcodes.length === 1)
if (!this.address.postalCode && postcodes.length === 1)
this.address.postalCode = postcodes[0].code;
}

View File

@ -128,7 +128,7 @@ export default class Controller extends Section {
if (!this.client.countryFk)
this.client.countryFk = country.id;
if (postcodes.length === 1)
if (!this.client.postcode && postcodes.length === 1)
this.client.postcode = postcodes[0].code;
}

View File

@ -30,6 +30,27 @@ module.exports = Self => {
message: 'Invalid TIN'
});
Self.validatesLengthOf('postCode', {
allowNull: true,
allowBlank: true,
min: 3, max: 10
});
Self.validateAsync('postCode', hasValidPostcode, {
message: `The postcode doesn't exist. Please enter a correct one`
});
async function hasValidPostcode(err, done) {
if (!this.postcode)
return done();
const models = Self.app.models;
const postcode = await models.Postcode.findById(this.postcode);
if (!postcode) err();
done();
}
async function tinIsValid(err, done) {
const filter = {
fields: ['code'],

View File

@ -59,7 +59,7 @@
<vn-horizontal>
<vn-textfield
vn-one
label="IBAN"
label="Account"
ng-model="$ctrl.supplier.account"
rule>
</vn-textfield>

View File

@ -38,7 +38,7 @@ export default class Controller extends Section {
if (!this.supplier.countryFk)
this.supplier.countryFk = country.id;
if (postcodes.length === 1)
if (!this.supplier.postCode && postcodes.length === 1)
this.supplier.postCode = postcodes[0].code;
}