Merge branch 'master' into aureplop/fix_cache
This commit is contained in:
commit
673dc0295d
4 changed files with 78 additions and 40 deletions
|
@ -42,7 +42,8 @@ REDIS_BASE_URL = "redis://" + REDIS_AUTH + REDIS_HOST + ":" + REDIS_PORT
|
|||
# Other secrets
|
||||
try:
|
||||
from .secret import (
|
||||
SECRET_KEY, RECAPTCHA_PUBLIC_KEY, RECAPTCHA_PRIVATE_KEY, ADMINS
|
||||
SECRET_KEY, RECAPTCHA_PUBLIC_KEY, RECAPTCHA_PRIVATE_KEY, ADMINS,
|
||||
REDIS_PASSWD, REDIS_DB, REDIS_HOST, REDIS_PORT
|
||||
)
|
||||
except ImportError:
|
||||
raise RuntimeError("Secrets missing")
|
||||
|
@ -187,13 +188,15 @@ CACHES = {
|
|||
|
||||
# Channels settings (use db #0 of redis)
|
||||
|
||||
CHANNEL_REDIS_URL = REDIS_BASE_URL + "/0"
|
||||
|
||||
CHANNEL_LAYERS = {
|
||||
"default": {
|
||||
"BACKEND": "asgi_redis.RedisChannelLayer",
|
||||
"CONFIG": {
|
||||
"hosts": [CHANNEL_REDIS_URL],
|
||||
"hosts": [(
|
||||
"redis://:{passwd}@{host}:{port}/{db}"
|
||||
.format(passwd=REDIS_PASSWD, host=REDIS_HOST,
|
||||
port=REDIS_PORT, db=REDIS_DB)
|
||||
)],
|
||||
},
|
||||
"ROUTING": "cof.routing.channel_routing",
|
||||
}
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
SECRET_KEY = 'q()(zn4m63i%5cp4)f+ww4-28_w+ly3q9=6imw2ciu&_(5_4ah'
|
||||
RECAPTCHA_PUBLIC_KEY = "DUMMY"
|
||||
RECAPTCHA_PRIVATE_KEY = "DUMMY"
|
||||
REDIS_PASSWD = "dummy"
|
||||
REDIS_PORT = 6379
|
||||
REDIS_DB = 0
|
||||
REDIS_HOST = "127.0.0.1"
|
||||
ADMINS = None
|
||||
|
|
|
@ -1946,6 +1946,7 @@ class OrderRead(DetailView):
|
|||
context['mail'] = mail
|
||||
return context
|
||||
|
||||
|
||||
@teamkfet_required
|
||||
def order_to_inventory(request, pk):
|
||||
order = get_object_or_404(Order, pk=pk)
|
||||
|
@ -1953,28 +1954,36 @@ def order_to_inventory(request, pk):
|
|||
if hasattr(order, 'inventory'):
|
||||
raise Http404
|
||||
|
||||
articles = (Article.objects
|
||||
.filter(orders=order.pk)
|
||||
.select_related('category')
|
||||
.prefetch_related(Prefetch('orderarticle_set',
|
||||
queryset = OrderArticle.objects.filter(order=order),
|
||||
to_attr = 'order'))
|
||||
.prefetch_related(Prefetch('supplierarticle_set',
|
||||
queryset = (SupplierArticle.objects
|
||||
supplier_prefetch = Prefetch(
|
||||
'article__supplierarticle_set',
|
||||
queryset=(
|
||||
SupplierArticle.objects
|
||||
.filter(supplier=order.supplier)
|
||||
.order_by('-at')),
|
||||
to_attr = 'supplier'))
|
||||
.order_by('category__name', 'name'))
|
||||
.order_by('-at')
|
||||
),
|
||||
to_attr='supplier',
|
||||
)
|
||||
|
||||
order_articles = (
|
||||
OrderArticle.objects
|
||||
.filter(order=order.pk)
|
||||
.select_related('article', 'article__category')
|
||||
.prefetch_related(
|
||||
supplier_prefetch,
|
||||
)
|
||||
.order_by('article__category__name', 'article__name')
|
||||
)
|
||||
|
||||
initial = []
|
||||
for article in articles:
|
||||
for order_article in order_articles:
|
||||
article = order_article.article
|
||||
initial.append({
|
||||
'article': article.pk,
|
||||
'name': article.name,
|
||||
'category': article.category_id,
|
||||
'category__name': article.category.name,
|
||||
'quantity_ordered': article.order[0].quantity_ordered,
|
||||
'quantity_received': article.order[0].quantity_ordered,
|
||||
'quantity_ordered': order_article.quantity_ordered,
|
||||
'quantity_received': order_article.quantity_ordered,
|
||||
'price_HT': article.supplier[0].price_HT,
|
||||
'TVA': article.supplier[0].TVA,
|
||||
'rights': article.supplier[0].rights,
|
||||
|
@ -1989,31 +1998,50 @@ def order_to_inventory(request, pk):
|
|||
messages.error(request, 'Permission refusée')
|
||||
elif formset.is_valid():
|
||||
with transaction.atomic():
|
||||
inventory = Inventory()
|
||||
inventory.order = order
|
||||
inventory.by = request.user.profile.account_kfet
|
||||
inventory.save()
|
||||
inventory = Inventory.objects.create(
|
||||
order=order, by=request.user.profile.account_kfet,
|
||||
)
|
||||
new_supplierarticle = []
|
||||
new_inventoryarticle = []
|
||||
for form in formset:
|
||||
q_received = form.cleaned_data['quantity_received']
|
||||
article = form.cleaned_data['article']
|
||||
SupplierArticle.objects.create(
|
||||
|
||||
price_HT = form.cleaned_data['price_HT']
|
||||
TVA = form.cleaned_data['TVA']
|
||||
rights = form.cleaned_data['rights']
|
||||
|
||||
if any((form.initial['price_HT'] != price_HT,
|
||||
form.initial['TVA'] != TVA,
|
||||
form.initial['rights'] != rights)):
|
||||
new_supplierarticle.append(
|
||||
SupplierArticle(
|
||||
supplier=order.supplier,
|
||||
article=article,
|
||||
price_HT = form.cleaned_data['price_HT'],
|
||||
TVA = form.cleaned_data['TVA'],
|
||||
rights = form.cleaned_data['rights'])
|
||||
(OrderArticle.objects
|
||||
price_HT=price_HT,
|
||||
TVA=TVA,
|
||||
rights=rights,
|
||||
)
|
||||
)
|
||||
(
|
||||
OrderArticle.objects
|
||||
.filter(order=order, article=article)
|
||||
.update(quantity_received = q_received))
|
||||
InventoryArticle.objects.create(
|
||||
.update(quantity_received=q_received)
|
||||
)
|
||||
new_inventoryarticle.append(
|
||||
InventoryArticle(
|
||||
inventory=inventory,
|
||||
article=article,
|
||||
stock_old=article.stock,
|
||||
stock_new = article.stock + q_received)
|
||||
stock_new=article.stock + q_received,
|
||||
)
|
||||
)
|
||||
article.stock += q_received
|
||||
if q_received > 0:
|
||||
article.is_sold = True
|
||||
article.save()
|
||||
SupplierArticle.objects.bulk_create(new_supplierarticle)
|
||||
InventoryArticle.objects.bulk_create(new_inventoryarticle)
|
||||
messages.success(request, "C'est tout bon !")
|
||||
return redirect('kfet.order')
|
||||
else:
|
||||
|
|
|
@ -23,6 +23,11 @@ apt-get install -y mysql-server
|
|||
mysql -uroot -p$DBPASSWD -e "CREATE DATABASE $DBNAME; GRANT ALL PRIVILEGES ON $DBNAME.* TO '$DBUSER'@'localhost' IDENTIFIED BY '$DBPASSWD'"
|
||||
mysql -uroot -p$DBPASSWD -e "GRANT ALL PRIVILEGES ON test_$DBNAME.* TO '$DBUSER'@'localhost'"
|
||||
|
||||
# Configuration de redis
|
||||
REDIS_PASSWD="dummy"
|
||||
redis-cli CONFIG SET requirepass $REDIS_PASSWD
|
||||
redis-cli -a $REDIS_PASSWD CONFIG REWRITE
|
||||
|
||||
# Installation et configuration d'Apache
|
||||
apt-get install -y apache2
|
||||
a2enmod proxy proxy_http proxy_wstunnel headers
|
||||
|
@ -61,10 +66,8 @@ sudo -H -u ubuntu python3 -m venv ~ubuntu/venv
|
|||
sudo -H -u ubuntu ~ubuntu/venv/bin/pip install -U pip
|
||||
sudo -H -u ubuntu ~ubuntu/venv/bin/pip install -r requirements.txt -r requirements-devel.txt
|
||||
|
||||
# Installation des secrets
|
||||
sudo -H -u ubuntu cp cof/settings/secret_example.py cof/settings/secret.py
|
||||
|
||||
# Préparation de Django
|
||||
if [ ! -f cof/settings/secret.py ]; then sudo -H -u ubuntu ln -s secret_example.py cof/settings/secret.py; fi
|
||||
sudo -H -u ubuntu DJANGO_SETTINGS_MODULE='cof.settings.dev' DBUSER=$DBUSER DBNAME=$DBNAME DBPASSWD=$DBPASSWD bash provisioning/prepare_django.sh
|
||||
|
||||
# Installation du cron pour les mails de rappels
|
||||
|
|
Loading…
Reference in a new issue