refs #5540 country.code
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Carlos Satorres 2023-04-13 08:30:33 +02:00
parent 747efc4342
commit ad267c933c
2 changed files with 13 additions and 4 deletions

View File

@ -1,3 +1,5 @@
UPDATE vn.supplier
SET nif = SUBSTRING(nif, IF(ASCII(SUBSTRING(nif, 1, 1)) BETWEEN 65 AND 90 AND ASCII(SUBSTRING(nif, 2, 1)) BETWEEN 65 AND 90, 3, 1), LENGTH(nif))
WHERE isVies = 1 AND nif REGEXP '^[a-zA-Z]{2}';
UPDATE vn.supplier s
JOIN vn.country c ON c.id = s.countryFk
SET s.nif = MID(REPLACE(s.nif, ' ', ''), 3, LENGTH(REPLACE(s.nif, ' ', '')) - 1)
WHERE s.isVies = TRUE
AND c.code = LEFT(REPLACE(s.nif, ' ', ''), 2);

View File

@ -77,7 +77,14 @@ module.exports = Self => {
message: 'The first two values are letters'});
async function nifInvalid(err, done) {
if (this.isVies && /^[a-zA-Z]{2}/.test(this.nif))
const filter = {
fields: ['code'],
where: {id: this.countryFk}
};
const countryCode = this.nif.toUpperCase().substring(0, 2);
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code : null;
if (this.isVies && countryCode == code)
err();
done();
}