Merge pull request 'refs #6213 fixCreateError' (!1746) from 6213-supplierFixCreateErrors into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #1746
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Pablo Natek 2023-10-06 06:24:02 +00:00
commit 23019df6fb
6 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,6 @@
UPDATE `vn`.`supplier`
SET account = LPAD(id,10,'0')
WHERE account IS NULL;
ALTER TABLE `vn`.`supplier` ADD CONSTRAINT supplierAccountTooShort CHECK (LENGTH(account) = 10);
ALTER TABLE `vn`.`supplier` MODIFY COLUMN account varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT 4100000000 NOT NULL COMMENT 'Default accounting code for suppliers.';

View File

@ -216,6 +216,7 @@
"The worker has hours recorded that day": "El trabajador tiene horas fichadas ese día",
"The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día",
"You can not modify is pay method checked": "No se puede modificar el campo método de pago validado",
"The account size must be exactly 10 characters": "El tamaño de la cuenta debe ser exactamente de 10 caracteres",
"Can't transfer claimed sales": "No puedes transferir lineas reclamadas",
"You don't have privileges to create refund": "No tienes permisos para crear un abono",
"The item is required": "El artículo es requerido",

View File

@ -32,6 +32,7 @@ describe('Supplier newSupplier()', () => {
const result = await models.Supplier.newSupplier(ctx, options);
expect(result.name).toEqual('newSupplier');
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;

View File

@ -123,5 +123,21 @@ describe('loopback model Supplier', () => {
throw e;
}
});
it('should update the account attribute when a new supplier is created', async() => {
const tx = await models.Supplier.beginTransaction({});
const options = {transaction: tx};
try {
const newSupplier = await models.Supplier.create({name: 'Alfred Pennyworth'}, options);
const fetchedSupplier = await models.Supplier.findById(newSupplier.id, null, options);
expect(Number(fetchedSupplier.account)).toEqual(4100000000 + newSupplier.id);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});
});

View File

@ -117,6 +117,16 @@ module.exports = Self => {
throw new UserError('You can not modify is pay method checked');
});
Self.observe('after save', async function(ctx) {
if (ctx.instance && ctx.isNewInstance) {
const {id} = ctx.instance;
const {Supplier} = Self.app.models;
const supplier = await Supplier.findById(id, null, ctx.options);
await supplier?.updateAttribute('account', Number(supplier.account) + id, ctx.options);
}
});
Self.validateAsync('name', 'countryFk', hasSupplierSameName, {
message: 'A supplier with the same name already exists. Change the country.'
});

View File

@ -18,7 +18,6 @@
</vn-card>
<vn-button-bar>
<vn-submit
disabled="!watcher.dataChanged()"
label="Create">
</vn-submit>
<vn-button