feat: Create new Supplier
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
012cd68c89
commit
dc6c8f924d
|
@ -0,0 +1,2 @@
|
|||
INSERT INTO salix.ACL (model,property,accessType,principalId)
|
||||
VALUES ('Supplier','newSupplier','WRITE','administrative');
|
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE vn.supplier MODIFY COLUMN payMethodFk tinyint(3) unsigned DEFAULT NULL NULL;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------- */
|
||||
|
||||
ALTER TABLE vn.supplier MODIFY COLUMN supplierActivityFk varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL;
|
|
@ -1,28 +0,0 @@
|
|||
/* eslint-disable no-console */
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
let UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('new', {
|
||||
description: 'returns the created item',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'params',
|
||||
type: 'object',
|
||||
http: {source: 'body'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'number',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/new`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.new = async(params, options) => {
|
||||
console.log(params);
|
||||
console.log(options);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,50 @@
|
|||
/* eslint-disable no-console */
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('newSupplier', {
|
||||
description: 'returns the created item',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'params',
|
||||
type: 'object',
|
||||
http: {source: 'body'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'string',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/newSupplier`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.newSupplier = async(params, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
||||
params.payDemFk = 1;
|
||||
|
||||
console.log(params);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const supplier = await models.Supplier.create(params, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return {
|
||||
supplier
|
||||
};
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
if (tx) await tx.rollback();
|
||||
return params;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -10,7 +10,7 @@ module.exports = Self => {
|
|||
require('../methods/supplier/freeAgencies')(Self);
|
||||
require('../methods/supplier/campaignMetricsPdf')(Self);
|
||||
require('../methods/supplier/campaignMetricsEmail')(Self);
|
||||
require('../methods/supplier/new')(Self);
|
||||
require('../methods/supplier/newSupplier')(Self);
|
||||
|
||||
Self.validatesPresenceOf('name', {
|
||||
message: 'The social name cannot be empty'
|
||||
|
@ -58,6 +58,9 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
async function tinIsValid(err, done) {
|
||||
if (!this.countryFk)
|
||||
return done();
|
||||
|
||||
const filter = {
|
||||
fields: ['code'],
|
||||
where: {id: this.countryFk}
|
||||
|
@ -81,6 +84,7 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
async function hasSupplierAccount(err, done) {
|
||||
if (!this.payMethodFk) return 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;
|
||||
|
@ -93,6 +97,7 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
Self.observe('before save', async function(ctx) {
|
||||
if (ctx.isNewInstance) return;
|
||||
const loopbackContext = LoopBackContext.getCurrentContext();
|
||||
const changes = ctx.data || ctx.instance;
|
||||
const orgData = ctx.currentInstance;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
url="supplier/new"
|
||||
url="suppliers/newSupplier"
|
||||
data="$ctrl.supplier"
|
||||
insert-mode="true"
|
||||
form="form">
|
||||
|
|
|
@ -5,14 +5,22 @@ import Section from 'salix/components/section';
|
|||
class Controller extends Section {
|
||||
constructor($element, $) {
|
||||
super($element, $);
|
||||
console.log($);
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
this.$.watcher.submit().then(
|
||||
console.log('abc'),
|
||||
json => this.$state.go('item.card.basicData', {id: json.data.id})
|
||||
json => {
|
||||
console.log('abc');
|
||||
this.$state.go('item.card.basicData', {id: json.data.id});
|
||||
console.log('ctrl --> ', this.$.$ctrl);
|
||||
|
||||
redirect(this.$.$ctrl);
|
||||
|
||||
async function redirect(ctrl) {
|
||||
await new Promise(r => setTimeout(r, 100));
|
||||
window.location.href = `/#!/supplier/${ctrl.supplier.supplier.id}/fiscal-data`;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,12 +31,6 @@
|
|||
"component": "vn-supplier",
|
||||
"description": "Suppliers"
|
||||
},
|
||||
{
|
||||
"url": "/create",
|
||||
"state": "supplier.create",
|
||||
"component": "vn-supplier-create",
|
||||
"description": "New supplier"
|
||||
},
|
||||
{
|
||||
"url": "/index?q",
|
||||
"state": "supplier.index",
|
||||
|
@ -58,6 +52,12 @@
|
|||
"supplier": "$ctrl.supplier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"url": "/create",
|
||||
"state": "supplier.create",
|
||||
"component": "vn-supplier-create",
|
||||
"description": "New supplier"
|
||||
},
|
||||
{
|
||||
"url": "/basic-data",
|
||||
"state": "supplier.card.basicData",
|
||||
|
|
Loading…
Reference in New Issue