From 842882e766c7a99d88dc46bcc22a80f195869902 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 21 Jan 2020 11:41:37 -0600 Subject: [PATCH] Include regular price changes, for current price history dialog --- tailbone/views/products.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tailbone/views/products.py b/tailbone/views/products.py index 14e17247..1d611400 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -1231,6 +1231,33 @@ class ProductsView(MasterView): }) last_price = version.price + # next we find all relevant *Regular* ProductPriceVersion records + versions = self.Session.query(ProductPriceVersion)\ + .join(Transaction, + Transaction.id == ProductPriceVersion.transaction_id)\ + .filter(ProductPriceVersion.product_uuid == product.uuid)\ + .filter(ProductPriceVersion.type == self.enum.PRICE_TYPE_REGULAR)\ + .order_by(Transaction.issued_at, + Transaction.id)\ + .all() + + last_price = None + for version in versions: + # only include this version if it was "regular" at the time + if version.uuid == version.product.regular_price_uuid: + if version.price != last_price: + changed = version.transaction.issued_at + price = version.price + history.append({ + 'transaction_id': version.transaction.id, + 'price': version.price, + 'price_type': self.enum.PRICE_TYPE[version.type], + 'since': humanize.naturaltime(now - changed), + 'changed': changed, + 'changed_by': version.transaction.user, + }) + last_price = version.price + final_history = OrderedDict() for hist in sorted(history, key=lambda h: h['changed'], reverse=True): if hist['transaction_id'] not in final_history: