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: