summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlxf <sng@luxagraf.net>2022-01-06 11:09:04 -0500
committerlxf <sng@luxagraf.net>2022-01-06 11:09:04 -0500
commit96232c02fe68f7f8c1213ce3e81c9c594ac4e9e5 (patch)
treedb8fd24fd10236c6c59ba20871e5774e755da434
parent1b74c74fb154385d861d8a74feca75826d1c8a4b (diff)
trad: fixed a bug in pl when saving
-rw-r--r--app/trading/models.py4
-rw-r--r--app/trading/views.py2
2 files changed, 4 insertions, 2 deletions
diff --git a/app/trading/models.py b/app/trading/models.py
index 10aaaf4..faac7ba 100644
--- a/app/trading/models.py
+++ b/app/trading/models.py
@@ -391,6 +391,7 @@ class LuxOptionPurchase(models.Model):
def get_contract_count(self):
return self.luxoptioncontract_set.count()
+ @property
def profit_loss(self):
total = 0
for option in self.luxoptioncontract_set.all():
@@ -428,7 +429,8 @@ class LuxOptionPurchase(models.Model):
def save(self, *args, **kwargs):
if self.status == 1 and not self.close_date:
self.close_date = timezone.now()
- if self.status == 1 and not self.pl:
+ if self.status == 1:
+ print("updating pl")
self.pl = self.profit_loss
super(LuxOptionPurchase, self).save()
diff --git a/app/trading/views.py b/app/trading/views.py
index 982fb8f..3bb64cf 100644
--- a/app/trading/views.py
+++ b/app/trading/views.py
@@ -25,7 +25,7 @@ class LuxTradeListView(PaginatedListView):
context['options_monthly_pl'] = LuxOptionPurchase.stats.get_month_pl()
context['options_year_pl'] = LuxOptionPurchase.stats.get_year_pl()
context['month'] = datetime.now().strftime('%h')
- context['luxoptions_purchases'] = LuxOptionPurchase.objects.filter(status=0)
+ context['luxoptions_purchases'] = LuxOptionPurchase.objects.all()
return context
def get_queryset(self):