Skip to content

Commit

Permalink
#1281 add get_plan_revisions to Plan model
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsimpson committed Feb 18, 2024
1 parent 453d37d commit 70a996c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions subscribie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sqlalchemy import event
from sqlalchemy import Column
from sqlalchemy import Boolean
from sqlalchemy import text

from typing import Optional
from datetime import datetime
Expand Down Expand Up @@ -744,6 +745,23 @@ def getPrice(self, currency):
)
return sell_price, interval_amount

def get_plan_revisions(self):
textual_sql = text(f"""
WITH RECURSIVE RevisionChain AS
(SELECT id, created_at, uuid, title, parent_plan_revision_uuid
FROM plan WHERE uuid = '{self.uuid}'
UNION ALL
SELECT p.id, p.created_at, p.uuid, p.title, p.parent_plan_revision_uuid
FROM plan p
INNER JOIN RevisionChain rc
ON p.uuid = rc.parent_plan_revision_uuid
)
SELECT * FROM RevisionChain""")
textual_sql = textual_sql.columns(Plan.id, Plan.created_at, Plan.uuid, Plan.title, Plan.parent_plan_revision_uuid)
orm_sql = database.select(Plan).from_statement(textual_sql)
plan_decendants = database.session.execute(orm_sql).scalars().all()
return plan_decendants

def applyRules(self, rules=[], context={}):
"""Apply pricelist rules to a given plan
Expand Down

0 comments on commit 70a996c

Please sign in to comment.