This commit is contained in:
parent
cbaf6001a8
commit
6a753d26af
|
@ -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.';
|
||||
|
|
|
@ -112,13 +112,9 @@ module.exports = Self => {
|
|||
const hasChanges = orgData && changes;
|
||||
const isPayMethodCheckedChanged = hasChanges
|
||||
&& orgData.isPayMethodChecked != isPayMethodChecked;
|
||||
const isAccountChanged = hasChanges && orgData.account != changes.account;
|
||||
|
||||
if (!editPayMethodCheck && isPayMethodCheckedChanged)
|
||||
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) {
|
||||
|
@ -126,10 +122,11 @@ module.exports = Self => {
|
|||
const supplierId = ctx.instance.id;
|
||||
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(
|
||||
'account',
|
||||
supplierId.toString().padStart(10, '0')
|
||||
supplier.account + supplierId,
|
||||
ctx.options
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue