refs #6213 default account value
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Pablo Natek 2023-09-11 18:28:47 +02:00
parent cbaf6001a8
commit 6a753d26af
2 changed files with 10 additions and 7 deletions

View File

@ -1 +1,7 @@
ALTER TABLE vn.supplier ADD CONSTRAINT supplier_CHECK CHECK (LENGTH(account) = 10);
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

@ -112,13 +112,9 @@ module.exports = Self => {
const hasChanges = orgData && changes; const hasChanges = orgData && changes;
const isPayMethodCheckedChanged = hasChanges const isPayMethodCheckedChanged = hasChanges
&& orgData.isPayMethodChecked != isPayMethodChecked; && orgData.isPayMethodChecked != isPayMethodChecked;
const isAccountChanged = hasChanges && orgData.account != changes.account;
if (!editPayMethodCheck && isPayMethodCheckedChanged) if (!editPayMethodCheck && isPayMethodCheckedChanged)
throw new UserError('You can not modify is pay method checked'); throw new UserError('You can not modify is pay method checked');
if (isAccountChanged && !(changes.account.length === 10))
throw new UserError('The account size must be exactly 10 characters');
}); });
Self.observe('after save', async function(ctx) { Self.observe('after save', async function(ctx) {
@ -126,10 +122,11 @@ module.exports = Self => {
const supplierId = ctx.instance.id; const supplierId = ctx.instance.id;
const models = Self.app.models; const models = Self.app.models;
const supplier = await models.Supplier.findById(supplierId); const supplier = await models.Supplier.findById(supplierId, null, ctx.options);
await supplier.updateAttribute( await supplier.updateAttribute(
'account', 'account',
supplierId.toString().padStart(10, '0') supplier.account + supplierId,
ctx.options
); );
} }
}); });