mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Update stock items quantity after shopping
This commit is contained in:
parent
0660ea5e64
commit
2f721592f1
3247
locale/fr/LC_MESSAGES/django.po
Normal file
3247
locale/fr/LC_MESSAGES/django.po
Normal file
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,14 @@ Shopping list for {{ stock }}
|
||||
{% endif %}
|
||||
<h3>{% trans s=stock %}Shopping lists history for {{ s }}{% endtrans %}</h3>
|
||||
|
||||
<p>
|
||||
{% trans %}Information :{% endtrans %}
|
||||
<br>
|
||||
{% trans %}Use the "update stock" action when you get back from shopping to add the effective quantity bought for each shopping list item.{% endtrans %}
|
||||
<br>
|
||||
{% trans %}For example, 3 Cheesburger (boxes) are aksing in the list, but there were only 2 so, 2 have to be added in the stock quantity.{% endtrans %}
|
||||
</p>
|
||||
|
||||
<h4>{% trans %}To do{% endtrans %}</h4>
|
||||
<table>
|
||||
<thead>
|
||||
@ -25,6 +33,9 @@ Shopping list for {{ stock }}
|
||||
<td>{{ s.date|localtime|date("Y-m-d H:i") }}</td>
|
||||
<td><a href="{{ url('stock:shoppinglist_items', stock_id=stock.id, shoppinglist_id=s.id)}}">{{ s.name }}</a></td>
|
||||
<td>{{ s.items_to_buy.count() }}</td>
|
||||
<td>
|
||||
<a href="{{ url('stock:update_after_shopping', stock_id=stock.id, shoppinglist_id=s.id)}}">{% trans %}Update stock{% endtrans %}</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{ url('stock:shoppinglist_set_done', stock_id=stock.id, shoppinglist_id=s.id)}}">{% trans %}Mark as done{% endtrans %}</a>
|
||||
</td>
|
||||
|
16
stock/templates/stock/update_after_shopping.jinja
Normal file
16
stock/templates/stock/update_after_shopping.jinja
Normal file
@ -0,0 +1,16 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans s = shoppinglist %}Update {{ s }}'s quantity after shopping{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>{% trans s = shoppinglist %}Update {{ s }}'s quantity after shopping{% endtrans %}</h3>
|
||||
<div>
|
||||
<form method="post" action="" class="inline" style="display:inline">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p() }}
|
||||
<p><input type="submit" value="{% trans %}Update stock quantities{% endtrans %}" /></p>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
@ -24,4 +24,6 @@ urlpatterns = [
|
||||
name='shoppinglist_set_done'),
|
||||
url(r'^(?P<stock_id>[0-9]+)/shoppingList/(?P<shoppinglist_id>[0-9]+)/setTodo$', StockShopppingListSetTodo.as_view(),
|
||||
name='shoppinglist_set_todo'),
|
||||
url(r'^(?P<stock_id>[0-9]+)/shoppingList/(?P<shoppinglist_id>[0-9]+)/updateStock$', StockUpdateAfterShopppingBaseFormView.as_view(),
|
||||
name='update_after_shopping'),
|
||||
]
|
||||
|
@ -218,15 +218,9 @@ class StockItemQuantityBaseFormView(CounterAdminTabsMixin, CanEditMixin, DetailV
|
||||
return super(StockItemQuantityBaseFormView, self).post(request, *args, **kwargs)
|
||||
|
||||
def form_valid(self, form):
|
||||
"""
|
||||
We handle here the redirection, passing the user id of the asked customer
|
||||
"""
|
||||
return super(StockItemQuantityBaseFormView, self).form_valid(form)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""
|
||||
We handle here the login form for the barman
|
||||
"""
|
||||
kwargs = super(StockItemQuantityBaseFormView, self).get_context_data(**kwargs)
|
||||
if 'form' not in kwargs.keys():
|
||||
kwargs['form'] = self.get_form()
|
||||
@ -297,3 +291,69 @@ class StockShopppingListSetTodo(CanEditMixin, DetailView):
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
return HttpResponseRedirect(reverse('stock:shoppinglist_list', args=self.args, kwargs={'stock_id':self.object.stock_owner.id}))
|
||||
|
||||
|
||||
class StockUpdateAfterShopppingForm(forms.BaseForm):
|
||||
def clean(self):
|
||||
with transaction.atomic():
|
||||
self.shoppinglist = ShoppingList.objects.filter(id=self.shoppinglist_id).first()
|
||||
for k,t in self.cleaned_data.items():
|
||||
item_id = int(k[5:])
|
||||
if int(t) > 0 :
|
||||
item = StockItem.objects.filter(id=item_id).first()
|
||||
item.effective_quantity += int(t)
|
||||
item.save()
|
||||
self.shoppinglist.todo = False
|
||||
self.shoppinglist.save()
|
||||
return self.cleaned_data
|
||||
|
||||
class StockUpdateAfterShopppingBaseFormView(CounterAdminTabsMixin, CanEditMixin, DetailView, BaseFormView):
|
||||
"""
|
||||
docstring for StockUpdateAfterShopppingBaseFormView
|
||||
"""
|
||||
model = ShoppingList
|
||||
template_name = "stock/update_after_shopping.jinja"
|
||||
pk_url_kwarg = "shoppinglist_id"
|
||||
current_tab = "stocks"
|
||||
|
||||
def get_form_class(self):
|
||||
fields = OrderedDict()
|
||||
kwargs = {}
|
||||
for t in ProductType.objects.order_by('name').all():
|
||||
for i in self.shoppinglist.items_to_buy.filter(type=t).order_by('name').all():
|
||||
field_name = "item-%s" % (str(i.id))
|
||||
fields[field_name] = forms.CharField(max_length=30, required=True, label=str(i),
|
||||
help_text=str(i.tobuy_quantity) + " asked")
|
||||
kwargs['shoppinglist_id'] = self.shoppinglist.id
|
||||
kwargs['base_fields'] = fields
|
||||
return type('StockUpdateAfterShopppingForm', (StockUpdateAfterShopppingForm,), kwargs)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.shoppinglist = ShoppingList.objects.filter(id=self.kwargs['shoppinglist_id']).first()
|
||||
return super(StockUpdateAfterShopppingBaseFormView, self).get(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""
|
||||
Handle the many possibilities of the post request
|
||||
"""
|
||||
self.object = self.get_object()
|
||||
self.shoppinglist = ShoppingList.objects.filter(id=self.kwargs['shoppinglist_id']).first()
|
||||
return super(StockUpdateAfterShopppingBaseFormView, self).post(request, *args, **kwargs)
|
||||
|
||||
def form_valid(self, form):
|
||||
"""
|
||||
We handle here the redirection
|
||||
"""
|
||||
return super(StockUpdateAfterShopppingBaseFormView, self).form_valid(form)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(StockUpdateAfterShopppingBaseFormView, self).get_context_data(**kwargs)
|
||||
if 'form' not in kwargs.keys():
|
||||
kwargs['form'] = self.get_form()
|
||||
kwargs['shoppinglist'] = self.shoppinglist
|
||||
kwargs['stock'] = self.shoppinglist.stock_owner
|
||||
return kwargs
|
||||
|
||||
def get_success_url(self):
|
||||
self.kwargs.pop('shoppinglist_id', None)
|
||||
return reverse_lazy('stock:shoppinglist_list', args=self.args, kwargs=self.kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user