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
|
# Other secrets
|
||||||
try:
|
try:
|
||||||
from .secret import (
|
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:
|
except ImportError:
|
||||||
raise RuntimeError("Secrets missing")
|
raise RuntimeError("Secrets missing")
|
||||||
|
@ -187,13 +188,15 @@ CACHES = {
|
||||||
|
|
||||||
# Channels settings (use db #0 of redis)
|
# Channels settings (use db #0 of redis)
|
||||||
|
|
||||||
CHANNEL_REDIS_URL = REDIS_BASE_URL + "/0"
|
|
||||||
|
|
||||||
CHANNEL_LAYERS = {
|
CHANNEL_LAYERS = {
|
||||||
"default": {
|
"default": {
|
||||||
"BACKEND": "asgi_redis.RedisChannelLayer",
|
"BACKEND": "asgi_redis.RedisChannelLayer",
|
||||||
"CONFIG": {
|
"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",
|
"ROUTING": "cof.routing.channel_routing",
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
SECRET_KEY = 'q()(zn4m63i%5cp4)f+ww4-28_w+ly3q9=6imw2ciu&_(5_4ah'
|
SECRET_KEY = 'q()(zn4m63i%5cp4)f+ww4-28_w+ly3q9=6imw2ciu&_(5_4ah'
|
||||||
RECAPTCHA_PUBLIC_KEY = "DUMMY"
|
RECAPTCHA_PUBLIC_KEY = "DUMMY"
|
||||||
RECAPTCHA_PRIVATE_KEY = "DUMMY"
|
RECAPTCHA_PRIVATE_KEY = "DUMMY"
|
||||||
|
REDIS_PASSWD = "dummy"
|
||||||
|
REDIS_PORT = 6379
|
||||||
|
REDIS_DB = 0
|
||||||
|
REDIS_HOST = "127.0.0.1"
|
||||||
ADMINS = None
|
ADMINS = None
|
||||||
|
|
|
@ -1946,6 +1946,7 @@ class OrderRead(DetailView):
|
||||||
context['mail'] = mail
|
context['mail'] = mail
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
@teamkfet_required
|
@teamkfet_required
|
||||||
def order_to_inventory(request, pk):
|
def order_to_inventory(request, pk):
|
||||||
order = get_object_or_404(Order, pk=pk)
|
order = get_object_or_404(Order, pk=pk)
|
||||||
|
@ -1953,28 +1954,36 @@ def order_to_inventory(request, pk):
|
||||||
if hasattr(order, 'inventory'):
|
if hasattr(order, 'inventory'):
|
||||||
raise Http404
|
raise Http404
|
||||||
|
|
||||||
articles = (Article.objects
|
supplier_prefetch = Prefetch(
|
||||||
.filter(orders=order.pk)
|
'article__supplierarticle_set',
|
||||||
.select_related('category')
|
queryset=(
|
||||||
.prefetch_related(Prefetch('orderarticle_set',
|
SupplierArticle.objects
|
||||||
queryset = OrderArticle.objects.filter(order=order),
|
.filter(supplier=order.supplier)
|
||||||
to_attr = 'order'))
|
.order_by('-at')
|
||||||
.prefetch_related(Prefetch('supplierarticle_set',
|
),
|
||||||
queryset = (SupplierArticle.objects
|
to_attr='supplier',
|
||||||
.filter(supplier=order.supplier)
|
)
|
||||||
.order_by('-at')),
|
|
||||||
to_attr = 'supplier'))
|
order_articles = (
|
||||||
.order_by('category__name', 'name'))
|
OrderArticle.objects
|
||||||
|
.filter(order=order.pk)
|
||||||
|
.select_related('article', 'article__category')
|
||||||
|
.prefetch_related(
|
||||||
|
supplier_prefetch,
|
||||||
|
)
|
||||||
|
.order_by('article__category__name', 'article__name')
|
||||||
|
)
|
||||||
|
|
||||||
initial = []
|
initial = []
|
||||||
for article in articles:
|
for order_article in order_articles:
|
||||||
|
article = order_article.article
|
||||||
initial.append({
|
initial.append({
|
||||||
'article': article.pk,
|
'article': article.pk,
|
||||||
'name': article.name,
|
'name': article.name,
|
||||||
'category': article.category_id,
|
'category': article.category_id,
|
||||||
'category__name': article.category.name,
|
'category__name': article.category.name,
|
||||||
'quantity_ordered': article.order[0].quantity_ordered,
|
'quantity_ordered': order_article.quantity_ordered,
|
||||||
'quantity_received': article.order[0].quantity_ordered,
|
'quantity_received': order_article.quantity_ordered,
|
||||||
'price_HT': article.supplier[0].price_HT,
|
'price_HT': article.supplier[0].price_HT,
|
||||||
'TVA': article.supplier[0].TVA,
|
'TVA': article.supplier[0].TVA,
|
||||||
'rights': article.supplier[0].rights,
|
'rights': article.supplier[0].rights,
|
||||||
|
@ -1989,31 +1998,50 @@ def order_to_inventory(request, pk):
|
||||||
messages.error(request, 'Permission refusée')
|
messages.error(request, 'Permission refusée')
|
||||||
elif formset.is_valid():
|
elif formset.is_valid():
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
inventory = Inventory()
|
inventory = Inventory.objects.create(
|
||||||
inventory.order = order
|
order=order, by=request.user.profile.account_kfet,
|
||||||
inventory.by = request.user.profile.account_kfet
|
)
|
||||||
inventory.save()
|
new_supplierarticle = []
|
||||||
|
new_inventoryarticle = []
|
||||||
for form in formset:
|
for form in formset:
|
||||||
q_received = form.cleaned_data['quantity_received']
|
q_received = form.cleaned_data['quantity_received']
|
||||||
article = form.cleaned_data['article']
|
article = form.cleaned_data['article']
|
||||||
SupplierArticle.objects.create(
|
|
||||||
supplier = order.supplier,
|
price_HT = form.cleaned_data['price_HT']
|
||||||
article = article,
|
TVA = form.cleaned_data['TVA']
|
||||||
price_HT = form.cleaned_data['price_HT'],
|
rights = form.cleaned_data['rights']
|
||||||
TVA = form.cleaned_data['TVA'],
|
|
||||||
rights = form.cleaned_data['rights'])
|
if any((form.initial['price_HT'] != price_HT,
|
||||||
(OrderArticle.objects
|
form.initial['TVA'] != TVA,
|
||||||
.filter(order=order, article=article)
|
form.initial['rights'] != rights)):
|
||||||
.update(quantity_received = q_received))
|
new_supplierarticle.append(
|
||||||
InventoryArticle.objects.create(
|
SupplierArticle(
|
||||||
inventory = inventory,
|
supplier=order.supplier,
|
||||||
article = article,
|
article=article,
|
||||||
stock_old = article.stock,
|
price_HT=price_HT,
|
||||||
stock_new = article.stock + q_received)
|
TVA=TVA,
|
||||||
|
rights=rights,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(
|
||||||
|
OrderArticle.objects
|
||||||
|
.filter(order=order, article=article)
|
||||||
|
.update(quantity_received=q_received)
|
||||||
|
)
|
||||||
|
new_inventoryarticle.append(
|
||||||
|
InventoryArticle(
|
||||||
|
inventory=inventory,
|
||||||
|
article=article,
|
||||||
|
stock_old=article.stock,
|
||||||
|
stock_new=article.stock + q_received,
|
||||||
|
)
|
||||||
|
)
|
||||||
article.stock += q_received
|
article.stock += q_received
|
||||||
if q_received > 0:
|
if q_received > 0:
|
||||||
article.is_sold = True
|
article.is_sold = True
|
||||||
article.save()
|
article.save()
|
||||||
|
SupplierArticle.objects.bulk_create(new_supplierarticle)
|
||||||
|
InventoryArticle.objects.bulk_create(new_inventoryarticle)
|
||||||
messages.success(request, "C'est tout bon !")
|
messages.success(request, "C'est tout bon !")
|
||||||
return redirect('kfet.order')
|
return redirect('kfet.order')
|
||||||
else:
|
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 "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'"
|
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
|
# Installation et configuration d'Apache
|
||||||
apt-get install -y apache2
|
apt-get install -y apache2
|
||||||
a2enmod proxy proxy_http proxy_wstunnel headers
|
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 -U pip
|
||||||
sudo -H -u ubuntu ~ubuntu/venv/bin/pip install -r requirements.txt -r requirements-devel.txt
|
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
|
# 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
|
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
|
# Installation du cron pour les mails de rappels
|
||||||
|
|
Loading…
Reference in a new issue