From f26afa9a7b3766b9bcd4ed0a22dc1f1ef14a0196 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 13 Jul 2023 13:34:03 +0200 Subject: [PATCH] refs #5964 fix supply --- modules/supplier/back/models/supplier.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index e88fadc0b..f359d0580 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -68,9 +68,9 @@ module.exports = Self => { }; const country = await Self.app.models.Country.findOne(filter); const code = country ? country.code.toLowerCase() : null; - const countryCode = this.nif.toLowerCase().substring(0, 2); + const countryCode = this.nif?.toLowerCase().substring(0, 2); - if (!this.nif || !validateTin(this.nif, code) || (this.isVies && countryCode == code)) + if (!validateTin(this.nif, code) || (this.isVies && countryCode == code)) err(); done(); } @@ -122,7 +122,7 @@ module.exports = Self => { }); async function hasSupplierSameName(err, done) { - if (!this.name || !this.countryFk) done(); + if (!this.name || !this.countryFk) return done(); const supplier = await Self.app.models.Supplier.findOne( { where: {