Improve support for stock providers

This commit is contained in:
s3lph 2021-04-07 01:25:45 +02:00
parent 119ed38f28
commit 361144815e
3 changed files with 10 additions and 9 deletions

View file

@ -25,11 +25,11 @@ def buy():
if 'pid' in request.params:
pid = int(str(request.params.pid))
product = db.get_product(pid)
if c.get_dispenser().dispense(product, 1):
# Create a consumption entry for the (user, product) combination
db.increment_consumption(user, product)
stock_provider = c.get_stock_provider()
if stock_provider.needs_update():
stock_provider.update_stock(product, -1)
c.get_dispenser().dispense(product, 1)
# Redirect to the main page (where this request should have come from)
redirect('/')

View file

@ -1,5 +1,5 @@
Package: matemat
Version: 0.2.4
Version: 0.2.6
Maintainer: s3lph <account-gitlab-ideynizv@kernelpanic.lol>
Section: web
Priority: optional

View file

@ -34,8 +34,9 @@
</span><br/>
<div class="imgcontainer">
<img src="/static/upload/thumbnails/products/{{ product.id }}.png" alt="Picture of {{ product.name }}"/>
{% if product.stockable %}
<span class="thumblist-stock">{{ stock.get_stock(product) }}</span>
{% set pstock = stock.get_stock(product) %}
{% if pstock is not none %}
<span class="thumblist-stock">{{ pstock }}</span>
{% endif %}
</div>
</a>