From 981bbc04113aab33cd7e06adf5e84a28d9c65536 Mon Sep 17 00:00:00 2001 From: Karthikeyan Date: Tue, 27 Feb 2024 18:21:59 +0530 Subject: [PATCH] [Karthi] | BAH-3589 | Refactor. Validation has been Added (#63) --- bahmni_purchase/models/price_markup_table.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bahmni_purchase/models/price_markup_table.py b/bahmni_purchase/models/price_markup_table.py index b8839ad..c46e07a 100644 --- a/bahmni_purchase/models/price_markup_table.py +++ b/bahmni_purchase/models/price_markup_table.py @@ -10,15 +10,21 @@ class PriceMarkupTable(models.Model): higher_price = fields.Float(string="Maximum Cost", default=1) markup_percentage = fields.Float(string="Markup Percentage", default=1) - @api.constrains('lower_price', 'higher_price') - def _check_fields_values(self): - if self.lower_price > self.higher_price: + @api.constrains('lower_price', 'higher_price','markup_percentage') + def _check_fields_values(self): + if self.lower_price < 0 or self.higher_price < 0 or self.markup_percentage < 0: + raise ValidationError('Negative values are not allowed for Minimum Cost, Maximum Cost and Markup Percentage.') + + if self.markup_percentage > 100: + raise ValidationError('Markup percentage should not exceed 100%. Please enter a valid markup percentage.') + + if self.lower_price >= self.higher_price: raise ValidationError('Minimum cost should not be greater than maximum cost.') # Add any other conditions you need to check for data in self.env['price.markup.table'].search([]): - if data.lower_price < self.lower_price < data.higher_price and data.id != self.id: + if data.lower_price <= self.lower_price < data.higher_price and data.id != self.id: raise ValidationError('Your minimum cost is available within the range of minimum cost and maximum cost of previous records.') - if data.lower_price < self.higher_price < data.higher_price and data.id != self.id: + if data.lower_price <= self.higher_price < data.higher_price and data.id != self.id: raise ValidationError('Your maximum cost is available within the range of minimum cost and maximum cost of previous records.')