diff --git a/loopback/locale/es.json b/loopback/locale/es.json index f75b1778e..f01da55ac 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -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" } \ No newline at end of file diff --git a/modules/supplier/back/model-config.json b/modules/supplier/back/model-config.json index 34d152bc6..62c580aca 100644 --- a/modules/supplier/back/model-config.json +++ b/modules/supplier/back/model-config.json @@ -10,5 +10,8 @@ }, "SupplierContact": { "dataSource": "vn" + }, + "SupplierAccount": { + "dataSource": "vn" } } diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js new file mode 100644 index 000000000..1853b1c9a --- /dev/null +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -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(); + }); + }); +}); diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json new file mode 100644 index 000000000..237934f8c --- /dev/null +++ b/modules/supplier/back/models/supplier-account.json @@ -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" + } + } +} \ No newline at end of file diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 37c94c266..73fd9d854 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -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; diff --git a/modules/supplier/front/billing-data/index.html b/modules/supplier/front/billing-data/index.html new file mode 100644 index 000000000..2cb3f7c4b --- /dev/null +++ b/modules/supplier/front/billing-data/index.html @@ -0,0 +1,64 @@ + + + + + + + +
+ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/supplier/front/billing-data/index.js b/modules/supplier/front/billing-data/index.js new file mode 100644 index 000000000..0c9cbb0dc --- /dev/null +++ b/modules/supplier/front/billing-data/index.js @@ -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: '<' + } +}); diff --git a/modules/supplier/front/billing-data/locale/es.yml b/modules/supplier/front/billing-data/locale/es.yml new file mode 100644 index 000000000..d84d37f3a --- /dev/null +++ b/modules/supplier/front/billing-data/locale/es.yml @@ -0,0 +1 @@ +Pay day: Dia de pago \ No newline at end of file diff --git a/modules/supplier/front/index.js b/modules/supplier/front/index.js index 8b4ac9ca2..22f402a0c 100644 --- a/modules/supplier/front/index.js +++ b/modules/supplier/front/index.js @@ -10,3 +10,4 @@ import './basic-data'; import './fiscal-data'; import './contact'; import './log'; +import './billing-data'; diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json index 10727fecf..31a358ef1 100644 --- a/modules/supplier/front/routes.json +++ b/modules/supplier/front/routes.json @@ -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" + } } ] } \ No newline at end of file