minor changes
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
1835171fe8
commit
98a691c152
|
@ -65,7 +65,7 @@ module.exports = function(Self) {
|
|||
try {
|
||||
delete args.ctx; // Remove unwanted properties
|
||||
const newReceipt = await models.Receipt.create(args, myOptions);
|
||||
const originalClient = await models.Client.findById(args.clientFk, myOptions);
|
||||
const originalClient = await models.Client.findById(args.clientFk, null, myOptions);
|
||||
const bank = await models.Bank.findById(args.bankFk, null, myOptions);
|
||||
const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions);
|
||||
|
||||
|
|
|
@ -83,54 +83,41 @@ module.exports = function(Self) {
|
|||
Self.updateAddress = async(ctx, clientId, addressId, options) => {
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
const address = await models.Address.findOne({
|
||||
where: {
|
||||
id: addressId,
|
||||
clientFk: clientId
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
try {
|
||||
const address = await models.Address.findOne({
|
||||
where: {
|
||||
id: addressId,
|
||||
clientFk: clientId
|
||||
const provinceId = args.provinceFk || address.provinceFk;
|
||||
if (provinceId) {
|
||||
const province = await models.Province.findById(provinceId, {
|
||||
include: {
|
||||
relation: 'country'
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
const provinceId = args.provinceFk || address.provinceFk;
|
||||
if (provinceId) {
|
||||
const province = await models.Province.findById(provinceId, {
|
||||
include: {
|
||||
relation: 'country'
|
||||
}
|
||||
}, myOptions);
|
||||
const isUeeMember = province.country().isUeeMember;
|
||||
const incotermsId = args.incotermsFk || address.incotermsFk;
|
||||
|
||||
const isUeeMember = province.country().isUeeMember;
|
||||
const incotermsId = args.incotermsFk || address.incotermsFk;
|
||||
if (!isUeeMember && !incotermsId)
|
||||
throw new UserError(`Incoterms is required for a non UEE member`);
|
||||
|
||||
if (!isUeeMember && !incotermsId)
|
||||
throw new UserError(`Incoterms is required for a non UEE member`);
|
||||
|
||||
const customsAgentId = args.customsAgentFk || address.customsAgentFk;
|
||||
if (!isUeeMember && !customsAgentId)
|
||||
throw new UserError(`Customs agent is required for a non UEE member`);
|
||||
}
|
||||
|
||||
delete args.ctx; // Remove unwanted properties
|
||||
|
||||
const updatedAddress = await address.updateAttributes(ctx.args, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return updatedAddress;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
const customsAgentId = args.customsAgentFk || address.customsAgentFk;
|
||||
if (!isUeeMember && !customsAgentId)
|
||||
throw new UserError(`Customs agent is required for a non UEE member`);
|
||||
}
|
||||
|
||||
delete args.ctx; // Remove unwanted properties
|
||||
|
||||
const updatedAddress = await address.updateAttributes(ctx.args, myOptions);
|
||||
|
||||
return updatedAddress;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -72,8 +72,8 @@ module.exports = Self => {
|
|||
|
||||
try {
|
||||
delete args.ctx; // removed unwanted data
|
||||
const fixedPrice = await models.FixedPrice.upsert(args, options);
|
||||
const targetItem = await models.Item.findById(args.itemFk, null, options);
|
||||
const fixedPrice = await models.FixedPrice.upsert(args, myOptions);
|
||||
const targetItem = await models.Item.findById(args.itemFk, null, myOptions);
|
||||
|
||||
await targetItem.updateAttributes({
|
||||
minPrice: args.minPrice,
|
||||
|
|
|
@ -34,49 +34,36 @@ module.exports = Self => {
|
|||
Self.createIntrastat = async(id, intrastatId, description, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
const country = await models.Country.findOne({
|
||||
where: {code: 'ES'}
|
||||
}, myOptions);
|
||||
|
||||
try {
|
||||
const country = await models.Country.findOne({
|
||||
where: {code: 'ES'}
|
||||
}, myOptions);
|
||||
const itemTaxCountry = await models.ItemTaxCountry.findOne({
|
||||
where: {
|
||||
itemFk: id,
|
||||
countryFk: country.id
|
||||
},
|
||||
order: 'effectived DESC'
|
||||
}, myOptions);
|
||||
|
||||
const itemTaxCountry = await models.ItemTaxCountry.findOne({
|
||||
where: {
|
||||
itemFk: id,
|
||||
countryFk: country.id
|
||||
},
|
||||
order: 'effectived DESC'
|
||||
}, myOptions);
|
||||
const taxClassCode = await models.TaxClassCode.findOne({
|
||||
where: {
|
||||
taxClassFk: itemTaxCountry.taxClassFk
|
||||
},
|
||||
order: 'effectived DESC'
|
||||
}, myOptions);
|
||||
|
||||
const taxClassCode = await models.TaxClassCode.findOne({
|
||||
where: {
|
||||
taxClassFk: itemTaxCountry.taxClassFk
|
||||
},
|
||||
order: 'effectived DESC'
|
||||
}, myOptions);
|
||||
const intrastat = await models.Intrastat.create({
|
||||
id: intrastatId,
|
||||
description: description,
|
||||
taxClassFk: itemTaxCountry.taxClassFk,
|
||||
taxCodeFk: taxClassCode.taxCodeFk
|
||||
}, myOptions);
|
||||
|
||||
const intrastat = await models.Intrastat.create({
|
||||
id: intrastatId,
|
||||
description: description,
|
||||
taxClassFk: itemTaxCountry.taxClassFk,
|
||||
taxCodeFk: taxClassCode.taxCodeFk
|
||||
}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return intrastat;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
return intrastat;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue