From 20ef2fe5fe3c04f3234f5bb7e33410151e26b375 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Tue, 6 Jan 2026 09:25:47 +0330 Subject: [PATCH] add rounding method for Toman price in ProductVariant model --- backend/product/models.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/product/models.py b/backend/product/models.py index 7265a04..149f3d4 100644 --- a/backend/product/models.py +++ b/backend/product/models.py @@ -446,6 +446,10 @@ class ProductVariant(DirtyFieldsMixin, models.Model): except Exception: return 0 + def round_toman(self, value): + """Round to nearest 1000 toman (e.g., 89123 -> 89000, 89500 -> 90000)""" + return round(value / 1000) * 1000 + def set_or_update_price(self, dollor_price=None): if not dollor_price: dollor_object, _ = DollorModel.objects.get_or_create( @@ -468,7 +472,8 @@ class ProductVariant(DirtyFieldsMixin, models.Model): # Always recalculate Toman price using stored dollar price and current rate if self.price_in_dollor: - toman_price = self.price_in_dollor * Decimal(str(dollor_price)) + # toman_price = self.price_in_dollor * Decimal(str(dollor_price)) + toman_price = Decimal(str(self.price_in_dollor)) * Decimal(str(dollor_price)) else: # Fallback if price_in_dollor is not set yet toman_price = self.input_price @@ -476,7 +481,7 @@ class ProductVariant(DirtyFieldsMixin, models.Model): toman_price = self.input_price self.price_in_dollor = None - self.price = max(int(toman_price), self.min_price) + self.price = max(self.round_toman(toman_price), self.min_price) def save(self, *args, **kwargs): self.set_or_update_price()