Include regular price changes, for current price history dialog

This commit is contained in:
Lance Edgar 2020-01-21 11:41:37 -06:00
parent 09e18b064d
commit 842882e766

View file

@ -1231,6 +1231,33 @@ class ProductsView(MasterView):
}) })
last_price = version.price 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() final_history = OrderedDict()
for hist in sorted(history, key=lambda h: h['changed'], reverse=True): for hist in sorted(history, key=lambda h: h['changed'], reverse=True):
if hist['transaction_id'] not in final_history: if hist['transaction_id'] not in final_history: