From a7b1f6981fca41338f6bb70fc62cf2bfc93f408c Mon Sep 17 00:00:00 2001 From: phzhik Date: Sun, 15 Oct 2023 10:45:43 +0400 Subject: [PATCH] + Recursive search of suitable commission price & delivery price --- store/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/store/models.py b/store/models.py index df2b7bd..4970ac3 100644 --- a/store/models.py +++ b/store/models.py @@ -85,10 +85,17 @@ class Category(MPTTModel): @property def delivery_price(self): if not self.delivery_price_CN_RU and self.parent_id: - return self.parent.delivery_price_CN_RU + return self.parent.delivery_price else: return self.delivery_price_CN_RU + @property + def commission_price(self): + if not self.commission and self.parent_id: + return self.parent.commission_price + else: + return self.commission + class UserQuerySet(models.QuerySet): pass @@ -474,7 +481,7 @@ class Checklist(models.Model): if self.category_id: # Add commission of bottom-most category - category_commission = getattr(self.category, 'commission', 0) + category_commission = getattr(self.category, 'commission_price', 0) commission = max(commission, category_commission * self.price_rub / 100) return commission