mirror of https://github.com/nanoy42/coope
10 changed files with 161 additions and 30 deletions
@ -0,0 +1,53 @@ |
|||
# Generated by Django 2.1 on 2019-08-27 19:19 |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
def update(apps, schema_editor): |
|||
Product = apps.get_model('gestion', 'Product') |
|||
for product in Product.objects.all(): |
|||
product.stock = product.stockBar |
|||
product.save() |
|||
|
|||
def reverse(apps, schema_editor): |
|||
Product = apps.get_model('gestion', 'Product') |
|||
for product in Product.objects.all(): |
|||
product.stockBar = product.stock |
|||
product.save() |
|||
|
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('gestion', '0011_auto_20190623_1640'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='historicalproduct', |
|||
name='stock', |
|||
field=models.IntegerField(default=0, verbose_name='Stock'), |
|||
), |
|||
migrations.AddField( |
|||
model_name='product', |
|||
name='stock', |
|||
field=models.IntegerField(default=0, verbose_name='Stock'), |
|||
), |
|||
migrations.RunPython(update, reverse), |
|||
migrations.RemoveField( |
|||
model_name='historicalproduct', |
|||
name='stockBar', |
|||
), |
|||
migrations.RemoveField( |
|||
model_name='historicalproduct', |
|||
name='stockHold', |
|||
), |
|||
migrations.RemoveField( |
|||
model_name='product', |
|||
name='stockBar', |
|||
), |
|||
migrations.RemoveField( |
|||
model_name='product', |
|||
name='stockHold', |
|||
), |
|||
] |
|||
@ -0,0 +1,41 @@ |
|||
{% extends 'base.html' %} |
|||
{% load static %} |
|||
{% block entete %}Gestion des produits{% endblock %} |
|||
{% block navbar%} |
|||
<ul> |
|||
{% for category in categories %} |
|||
<li><a href="#{{category}}">Stocks {{category}}</a></li> |
|||
{% endfor %} |
|||
</ul> |
|||
{% endblock %} |
|||
{% block content %} |
|||
{% for category in categories %} |
|||
<section id="{{category}}" class="main"> |
|||
<header class="major"> |
|||
<h2>Stocks {{category}}</h2> |
|||
</header> |
|||
<div class="table-wrapper"> |
|||
<table> |
|||
<thead> |
|||
<tr> |
|||
<th>Nom</th> |
|||
<th>Stock</th> |
|||
<th>Mettre à jour</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
{% for product in category.active_products %} |
|||
<tr id="tr-{{product.pk}}"> |
|||
<td><a href="{% url 'gestion:productProfile' product.pk %}">{{ product.name }}</a></td> |
|||
<td id="stock-{{product.pk}}">{{ product.stock }}</td> |
|||
<td><button class="update-stock" data-pk="{{product.pk}}" data-stock="{{product.stock}}" ><i class="fa fa-marker"></i></button></td> |
|||
</tr> |
|||
{% endfor %} |
|||
</tbody> |
|||
</table> |
|||
</div> |
|||
</section> |
|||
{% endfor %} |
|||
<script src="{% static 'jquery.js' %}"></script> |
|||
<script src="{% static 'stocks.js' %}"></script> |
|||
{% endblock %} |
|||
@ -0,0 +1,16 @@ |
|||
$(document).ready(function(){ |
|||
$(".update-stock").click(function(){ |
|||
var pk = $(this).attr('data-pk'); |
|||
var current_value = $(this).attr('data-stock'); |
|||
var ok = false; |
|||
while(!ok){ |
|||
var new_stock = prompt("Nouveau stock ? (entier attendu)", current_value); |
|||
ok = new_stock == null || !(isNaN(parseInt(new_stock))); |
|||
} |
|||
if(new_stock != null){ |
|||
$.get("/gestion/updateStock/" + pk, {"stock": new_stock}, function(data){ |
|||
$("#stock-"+pk).html(new_stock); |
|||
}); |
|||
} |
|||
}); |
|||
}); |
|||
Loading…
Reference in new issue