Merge pull request #7425 from G-Chubinidze/gc_SCI_10533

Enable adding negative numbers for Stock [SCI-10533]
This commit is contained in:
aignatov-bio 2024-05-09 10:56:40 +02:00 committed by GitHub
commit 6f66abb3e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -46,6 +46,7 @@
:label="i18n.t('repository_stock_values.manage_modal.amount')"
:required="true"
:min="0"
:negativeNumbersEnabled="this.operation == 'set'"
:error="errors.amount"
/>
</div>
@ -252,7 +253,6 @@ export default {
const newErrors = {};
if (!this.unit) { newErrors.unit = I18n.t('repository_stock_values.manage_modal.unit_error'); }
if (!this.amount) { newErrors.amount = I18n.t('repository_stock_values.manage_modal.amount_error'); }
if (this.amount && this.amount < 0) { newErrors.amount = I18n.t('repository_stock_values.manage_modal.negative_error'); }
if (this.reminderEnabled && !this.lowStockTreshold) { newErrors.tresholdAmount = I18n.t('repository_stock_values.manage_modal.amount_error'); }
if (this.comment && this.comment.length > 255) { newErrors.comment = I18n.t('repository_stock_values.manage_modal.comment_limit'); }
this.errors = newErrors;

View file

@ -38,7 +38,8 @@ export default {
error: { type: String, required: false },
min: { type: [String, Number] },
max: { type: [String, Number] },
blockInvalidInput: { type: Boolean, default: true }
blockInvalidInput: { type: Boolean, default: true },
negativeNumbersEnabled: {type: Boolean, required: false }
},
data() {
return {
@ -56,6 +57,13 @@ export default {
},
computed: {
pattern() {
if (this.negativeNumbersEnabled) {
if (this.type === 'number' && this.decimals) {
return `-?[0-9]+([\\.]-?[0-9]{0,${this.decimals}})?`;
} else if (this.type === 'number') {
return '-?[0-9]+';
}
}
if (this.type === 'number' && this.decimals) {
return `[0-9]+([\\.][0-9]{0,${this.decimals}})?`;
} else if (this.type === 'number') {