Commit 3617245b authored by Patrick's avatar Patrick
Browse files

Perf concern. Less work on web server, more work on customer browser.

parent a71a5280
...@@ -70,8 +70,8 @@ ...@@ -70,8 +70,8 @@
<span id="prepared_amount">{{ prepared_amount }}</span> &euro; <span <span id="prepared_amount">{{ prepared_amount }}</span> &euro; <span
class="glyphicon glyphicon-shopping-cart"></span></a></b> class="glyphicon glyphicon-shopping-cart"></span></a></b>
</li> </li>
<li>
{% if producer_set.count > 1 %} {% if producer_set.count > 1 %}
<li>
<a href="?" <a href="?"
{% if producer_id == "all" and offeritem_id != "purchased" %}class="bs-docs-sidebar-active"{% endif %}>{% trans "All producers" %}</a> {% if producer_id == "all" and offeritem_id != "purchased" %}class="bs-docs-sidebar-active"{% endif %}>{% trans "All producers" %}</a>
<ul class="nav nav-stacked"> <ul class="nav nav-stacked">
...@@ -81,24 +81,26 @@ ...@@ -81,24 +81,26 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</li>
{% endif %} {% endif %}
</li>
{% if departementforcustomer_set.count > 1 %} {% if departementforcustomer_set.count > 1 %}
<li> <li>
<b><a href="?" <b><a href="{% url "order_view" permanence.id %}"
{% if departementforcustomer_id == "all" and offeritem_id != "purchased" %}class="bs-docs-sidebar-active"{% endif %}>{% trans "All departments" %}</a></b> {% if departementforcustomer_id == "all" and offeritem_id != "purchased" %}class="bs-docs-sidebar-active"{% endif %}>{% trans "All departments" %}</a></b>
<ul class="nav nav-stacked"> <ul class="nav nav-stacked">
{% for departementforcustomer in departementforcustomer_set %} {% for departementforcustomer in departementforcustomer_set %}
{% ifchanged departementforcustomer.parent %} {% ifchanged departementforcustomer.parent %}
{# {% if not forloop.first and departementforcustomer.parent.level == 0 %}</ul>{% endif %}#}
{% if departementforcustomer.parent.level == 0 %}</ul>{% endif %} {% if departementforcustomer.parent.level == 0 %}</ul>{% endif %}
<li><b><a href="?departementforcustomer={{ departementforcustomer.parent.id|stringformat:"d" }}" <li><b><a href="{% url "order_view" permanence.id %}?departementforcustomer={{ departementforcustomer.parent.id|stringformat:"d" }}"
{% if departementforcustomer.parent.id == departementforcustomer_id|add:0 %}class="bs-docs-sidebar-active"{% endif %}>{{ departementforcustomer.parent.short_name }}</a> {% if departementforcustomer.parent.id == departementforcustomer_id|add:0 %}class="bs-docs-sidebar-active"{% endif %}>{{ departementforcustomer.parent.short_name }}</a>
</b></li> </b></li>
{% if departementforcustomer.parent.level == 0 %}<ul class="nav nav-stacked">{% endif %} {% if departementforcustomer.parent.level == 0 %}<ul class="nav nav-stacked">{% endif %}
{% endifchanged %} {% endifchanged %}
<li><a href="?departementforcustomer={{ departementforcustomer.id|stringformat:"d" }}" <li><a href="{% url "order_view" permanence.id %}?departementforcustomer={{ departementforcustomer.id|stringformat:"d" }}"
{% if departementforcustomer.id == departementforcustomer_id|add:0 %}class="bs-docs-sidebar-active"{% endif %}>{{ departementforcustomer.short_name }}</a> {% if departementforcustomer.id == departementforcustomer_id|add:0 %}class="bs-docs-sidebar-active"{% endif %}>{{ departementforcustomer.short_name }}</a>
</li> </li>
{# {% if forloop.last %}</ul>{% endif %}#}
{% endfor %} {% endfor %}
</ul> </ul>
</li> </li>
...@@ -133,12 +135,11 @@ ...@@ -133,12 +135,11 @@
{% else %} {% else %}
<h3>{% trans "No offer found" %}</h3> <h3>{% trans "No offer found" %}</h3>
{% endif %} {% endif %}
</div>
</div>
{% else %} {% else %}
<h3>{% trans "You are not allowed to order products" %}</h3> <h3>{% trans "You are not allowed to order products" %}</h3>
{% endif %} {% endif %}
</div>
</div>
</div>
{# Order Modal starts#} {# Order Modal starts#}
<div id="orderModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="orderModalLabel" <div id="orderModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="orderModalLabel"
aria-hidden="true"> aria-hidden="true">
...@@ -184,6 +185,7 @@ ...@@ -184,6 +185,7 @@
</div> </div>
{# Other qty modal ends#} {# Other qty modal ends#}
</div> </div>
</div>
{% endblock %} {% endblock %}
{% block footer %} {% block footer %}
<div class="visible-xs"> <div class="visible-xs">
...@@ -206,7 +208,7 @@ ...@@ -206,7 +208,7 @@
<div class="btn-group"> <div class="btn-group">
<div class="btn-group"> <div class="btn-group">
{% if page_obj.has_previous %} {% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}&amp;producer={{ producer_id }}&amp;departementforcustomer={{ departementforcustomer_id }}" <a href="?page={{ page_obj.previous_page_number }}&amp;producer={{ producer_id }}&amp;departementforcustomer={{ departementforcustomer_id }}&amp;offeritem={{ offeritem_id }}"
class="btn btn-success btn-disabled btn-xs"><span class="glyphicon glyphicon-arrow-left"></span></a> class="btn btn-success btn-disabled btn-xs"><span class="glyphicon glyphicon-arrow-left"></span></a>
{% else %} {% else %}
<a href="#" class="btn btn-disabled btn-xs"></a> <a href="#" class="btn btn-disabled btn-xs"></a>
...@@ -216,7 +218,7 @@ ...@@ -216,7 +218,7 @@
class="btn btn-disabled btn-xs">{% trans "Page " %} {{ page_obj.number }} {% trans "of" %} {{ page_obj.paginator.num_pages }}</a> class="btn btn-disabled btn-xs">{% trans "Page " %} {{ page_obj.number }} {% trans "of" %} {{ page_obj.paginator.num_pages }}</a>
{% endif %} {% endif %}
{% if page_obj.has_next %} {% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}&amp;producer={{ producer_id }}&amp;departementforcustomer={{ departementforcustomer_id }}" <a href="?page={{ page_obj.next_page_number }}&amp;producer={{ producer_id }}&amp;departementforcustomer={{ departementforcustomer_id }}&amp;offeritem={{ offeritem_id }}"
class="btn btn-success btn-disabled btn-xs"><span class="glyphicon glyphicon-arrow-right"></span></a> class="btn btn-success btn-disabled btn-xs"><span class="glyphicon glyphicon-arrow-right"></span></a>
{% else %} {% else %}
<a href="#" class="btn btn-disabled btn-xs"></a> <a href="#" class="btn btn-disabled btn-xs"></a>
...@@ -224,7 +226,6 @@ ...@@ -224,7 +226,6 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
</div>
{% addtoblock "lastjs" %} {% addtoblock "lastjs" %}
<script type="text/javascript"> <script type="text/javascript">
var previously_edited_offer_item = null; var previously_edited_offer_item = null;
...@@ -259,22 +260,22 @@ ...@@ -259,22 +260,22 @@
} }
} }
$(document).ready(function () { $(document).ready(function () {
{% if offeritem_list %} {% if offeritem_list %}
{% for offer in offeritem_list %} {% for offer in offeritem_list %}
var lien = '{% url 'ajax_order_init' %}?offer_item=' + {{ offer.id|stringformat:"d" }}; var lien = '{% url 'ajax_order_init' %}?offer_item=' + {{ offer.id|stringformat:"d" }};
$.ajax({ $.ajax({
url: lien, url: lien,
cache: false, cache: false,
async: true, async: true,
success: function (result) { success: function (result) {
$("#offer_item{{ offer.id|stringformat:"d" }}").html(result); $("#offer_item{{ offer.id|stringformat:"d" }}").html(result);
}, },
error: function (result) { error: function (result) {
$("#offer_item{{ offer.id|stringformat:"d" }}").html('<option value="0" selected>{% trans "Retry3" %}</option>'); $("#offer_item{{ offer.id|stringformat:"d" }}").html('<option value="0" selected>{% trans "Retry3" %}</option>');
} }
}); });
{% endfor %} {% endfor %}
{% endif %} {% endif %}
lien = '{% url 'order_name' %}'; lien = '{% url 'order_name' %}';
$.ajax({ $.ajax({
url: lien, url: lien,
......
...@@ -9,7 +9,7 @@ from views import PermanenceView ...@@ -9,7 +9,7 @@ from views import PermanenceView
urlpatterns = patterns('', urlpatterns = patterns('',
url(r'^contact/$', views.contact_form, name='contact_form'), url(r'^contact/$', views.contact_form, name='contact_form'),
url(r'^order/(\w+)/$', cache_page(60*60)(login_required(OrderView.as_view())), name='order_view'), url(r'^order/(\w+)/$', cache_page(2*24*60*60)(login_required(OrderView.as_view())), name='order_view'),
url(r'^basket/(\w+)/$', login_required(OrderViewWithoutCache.as_view()), name='basket_view'), url(r'^basket/(\w+)/$', login_required(OrderViewWithoutCache.as_view()), name='basket_view'),
url(r'^order-name/$', views.order_name_ajax, name='order_name'), url(r'^order-name/$', views.order_name_ajax, name='order_name'),
url(r'^basket-amount/$', views.basket_amount_ajax, name='basket_amount'), url(r'^basket-amount/$', views.basket_amount_ajax, name='basket_amount'),
......
...@@ -18,6 +18,7 @@ from repanier.models import Staff ...@@ -18,6 +18,7 @@ from repanier.models import Staff
from repanier.tools import get_producer_unit from repanier.tools import get_producer_unit
from repanier.tools import get_customer_unit from repanier.tools import get_customer_unit
from repanier.tools import get_preparator_unit from repanier.tools import get_preparator_unit
from repanier.tools import get_display
def export(permanence, wb=None): def export(permanence, wb=None):
...@@ -143,85 +144,13 @@ def export(permanence, wb=None): ...@@ -143,85 +144,13 @@ def export(permanence, wb=None):
if row_num > 0: if row_num > 0:
ws.column_dimensions[get_column_letter(1)].width = 120 ws.column_dimensions[get_column_letter(1)].width = 120
if PERMANENCE_WAIT_FOR_SEND <= permanence.status <= PERMANENCE_SEND: # if PERMANENCE_WAIT_FOR_SEND <= permanence.status <= PERMANENCE_SEND:
if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
# Basket check list, by customer # Basket check list, by customer
ws = wb.create_sheet() ws = export_customer(permanence, wb=wb)
worksheet_setup_portait_a4(ws, unicode(_('Customer check')), unicode(permanence))
row_num = 0
department_for_customer_save = None
customer_save = None
purchase_set = Purchase.objects.filter(
permanence_id=permanence.id, producer__isnull=False,
product__translations__language_code=translation.get_language(),
product__department_for_customer__translations__language_code=translation.get_language()
).order_by(
"customer__short_basket_name",
"product__placement",
"producer__short_profile_name",
"product__department_for_customer__translations__short_name",
"product__translations__long_name"
)
for purchase in purchase_set:
qty = purchase.quantity if permanence.status < PERMANENCE_WAIT_FOR_SEND else purchase.quantity_send_to_producer
if qty != 0 or purchase.order_unit == PRODUCT_ORDER_UNIT_DEPOSIT:
unit = get_customer_unit(order_unit=purchase.order_unit, qty=qty)
row = [
(unicode(_("Placement")), 15,
purchase.product.get_placement_display() if purchase.product is not None else "",
NumberFormat.FORMAT_TEXT),
(unicode(_("Producer")), 15, purchase.producer.short_profile_name, NumberFormat.FORMAT_TEXT),
(unicode(_("Product")), 60, purchase.long_name, NumberFormat.FORMAT_TEXT),
(unicode(_("Quantity")), 10, qty, '#,##0.???'),
(unicode(_("Unit")), 12, unit, NumberFormat.FORMAT_TEXT),
(unicode(_("Basket")), 20, purchase.customer.short_basket_name, NumberFormat.FORMAT_TEXT),
]
if row_num == 0:
worksheet_set_header(ws, row_num, row)
row_num += 1
if customer_save != purchase.customer.id or department_for_customer_save != purchase.department_for_customer:
if customer_save != purchase.customer.id:
# Add an empty line for the scissors.
row_num += 1
c = ws.cell(row=row_num, column=2)
c.style.borders.bottom.border_style = Border.BORDER_THIN
c.style.alignment.horizontal = 'right'
c.style.font.italic = True
department_for_customer_save = purchase.department_for_customer
if department_for_customer_save is not None:
c.value = department_for_customer_save.short_name
else:
c.value = ""
if customer_save != purchase.customer.id:
for col_num in xrange(len(row)):
c = ws.cell(row=row_num, column=col_num)
c.style.borders.top.border_style = Border.BORDER_THIN
if col_num == 5:
c.value = purchase.customer.short_basket_name
c.style.font.bold = True
# Force the display of the department for next customer
customer_save = purchase.customer.id
else:
c = ws.cell(row=row_num, column=5)
c.value = purchase.customer.short_basket_name
row_num += 1
for col_num in xrange(len(row)):
c = ws.cell(row=row_num, column=col_num)
c.value = row[col_num][ROW_VALUE]
c.style.number_format.format_code = row[col_num][ROW_FORMAT]
c.style.borders.bottom.border_style = Border.BORDER_HAIR
row_num += 1 if PERMANENCE_WAIT_FOR_SEND <= permanence.status <= PERMANENCE_SEND:
# if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
# Preparation list # Preparation list
ws = None ws = None
row_num = 0 row_num = 0
...@@ -386,12 +315,11 @@ def export(permanence, wb=None): ...@@ -386,12 +315,11 @@ def export(permanence, wb=None):
c.value = previous_product_qty_sum c.value = previous_product_qty_sum
c.style.number_format.format_code = '#,##0.???' c.style.number_format.format_code = '#,##0.???'
# if PERMANENCE_WAIT_FOR_SEND <= permanence.status <= PERMANENCE_SEND: # if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND: # # Order adressed to our producers,
# Order adressed to our producers, # producer_set = Producer.objects.filter(permanence=permanence).order_by("short_profile_name")
producer_set = Producer.objects.filter(permanence=permanence).order_by("short_profile_name") # for producer in producer_set:
for producer in producer_set: # export_producer(permanence=permanence, producer=producer, wb=wb)
export_producer(permanence=permanence, producer=producer, wb=wb)
return wb return wb
...@@ -721,7 +649,7 @@ def export_producer(permanence, producer, wb=None): ...@@ -721,7 +649,7 @@ def export_producer(permanence, producer, wb=None):
return wb return wb
def export_customer(permanence, customer, wb=None): def export_customer(permanence, customer=None, wb=None):
if wb is None: if wb is None:
wb = Workbook() wb = Workbook()
ws = wb.get_active_sheet() ws = wb.get_active_sheet()
...@@ -730,60 +658,144 @@ def export_customer(permanence, customer, wb=None): ...@@ -730,60 +658,144 @@ def export_customer(permanence, customer, wb=None):
worksheet_setup_landscape_a4(ws, unicode(_('Customer check')), unicode(permanence)) worksheet_setup_landscape_a4(ws, unicode(_('Customer check')), unicode(permanence))
row_num = 0 row_num = 0
department_for_customer_save = None
purchase_set = Purchase.objects.filter(
permanence_id=permanence.id, customer_id=customer.id, producer__isnull=False).order_by(
"product__placement",
"producer__short_profile_name",
"department_for_customer",
"long_name"
)
customer_save = None customer_save = None
if customer is not None:
purchase_set = Purchase.objects.filter(
permanence_id=permanence.id, customer_id=customer.id, producer__isnull=False,
product__translations__language_code=translation.get_language()
).order_by(
"product__placement",
"product__department_for_customer__tree_id",
"product__department_for_customer__lft",
"producer__short_profile_name",
"product__translations__long_name"
)
else:
purchase_set = Purchase.objects.filter(
permanence_id=permanence.id, producer__isnull=False,
product__translations__language_code=translation.get_language()
).order_by(
"customer__short_basket_name",
"product__placement",
"product__department_for_customer__tree_id",
"product__department_for_customer__lft",
"producer__short_profile_name",
"product__translations__long_name"
)
hide_column_placement = True
placement_save = None
row_start_sum = None
for purchase in purchase_set: for purchase in purchase_set:
qty = purchase.quantity if permanence.status < PERMANENCE_WAIT_FOR_SEND else purchase.quantity_send_to_producer qty = purchase.quantity if permanence.status < PERMANENCE_WAIT_FOR_SEND else purchase.quantity_send_to_producer
if qty != 0 or purchase.order_unit == PRODUCT_ORDER_UNIT_DEPOSIT: if qty != 0 or purchase.order_unit == PRODUCT_ORDER_UNIT_DEPOSIT:
unit = get_customer_unit(order_unit=purchase.order_unit, qty=qty)
if placement_save is not None:
if placement_save != purchase.product.placement:
hide_column_placement = False
placement_save = purchase.product.placement
# unit = get_customer_unit(order_unit=purchase.order_unit, qty=qty)
if purchase.invoiced_price_with_compensation:
a_price = purchase.product.unit_price_with_compensation
else:
a_price = purchase.product.unit_price_with_vat
qty_display, price_display, price = get_display(
qty,
purchase.product.order_average_weight,
purchase.product.order_unit,
a_price
)
row = [ row = [
(unicode(_("Placement")), 15, (unicode(_("Placement")), 15,
purchase.product.get_placement_display() if purchase.product is not None else "", NumberFormat.FORMAT_TEXT, purchase.product.get_placement_display() if purchase.product is not None else "",
False), NumberFormat.FORMAT_TEXT),
(unicode(_("Producer")), 15, purchase.producer.short_profile_name, NumberFormat.FORMAT_TEXT, False), (unicode(_("Producer")), 15, purchase.producer.short_profile_name, NumberFormat.FORMAT_TEXT),
(unicode(_("Department")), 15, (unicode(_("Product")), 60, purchase.long_name, NumberFormat.FORMAT_TEXT),
purchase.department_for_customer.short_name if purchase.department_for_customer is not None else "N/A", (unicode(_("Quantity")), 20, qty_display, NumberFormat.FORMAT_TEXT),
NumberFormat.FORMAT_TEXT, False), (unicode(_("Unit Price")), 10, a_price,
(unicode(_("Product")), 60, purchase.long_name, NumberFormat.FORMAT_TEXT, False), u'_ € * #,##0.00_ ;_ € * -#,##0.00_ ;_ € * "-"??_ ;_ @_ '),
(unicode(_("Basket")), 20, purchase.customer.short_basket_name, NumberFormat.FORMAT_TEXT, False), (unicode(_("deposit")), 10, purchase.unit_deposit,
(unicode(_("Quantity")), 10, qty, '#,##0.???', False), u'_ € * #,##0.00_ ;_ € * -#,##0.00_ ;_ € * "-"??_ ;_ @_ '),
(unicode(_("Unit")), 10, unit, NumberFormat.FORMAT_TEXT, (unicode(_("Total invoiced price, deposit included")), 10, qty * purchase.unit_deposit + price,
True if purchase.wrapped else False), u'_ € * #,##0.00_ ;_ € * -#,##0.00_ ;_ € * "-"??_ ;_ @_ '),
# (unicode(_("Quantity")), 10, qty, '#,##0.???'),
# (unicode(_("Unit")), 12, unit, NumberFormat.FORMAT_TEXT),
(unicode(_("Basket")), 20, purchase.customer.short_basket_name, NumberFormat.FORMAT_TEXT),
] ]
if row_num == 0: if row_num == 0:
worksheet_set_header(ws, row_num, row) worksheet_set_header(ws, row_num, row)
row_num += 1 row_num += 1
if customer_save != purchase.customer.id or department_for_customer_save != purchase.department_for_customer:
if customer_save != purchase.customer.id:
if row_start_sum is not None:
c = ws.cell(row=row_num, column=5)
c.value = unicode(_("Total Price"))
c.style.number_format.format_code = NumberFormat.FORMAT_TEXT
c.style.font.bold = True
c = ws.cell(row=row_num, column=6)
formula = 'SUM(G%s:G%s)' % (row_start_sum + 3, row_num)
c.value = '=' + formula
c.style.number_format.format_code = u'_ € * #,##0.00_ ;_ € * -#,##0.00_ ;_ € * "-"??_ ;_ @_ '
c.style.font.bold = True
row_start_sum = row_num
# Add an empty line for the scissors.
if customer_save is not None:
row_num += 2
c = ws.cell(row=row_num, column=2)
c.style.borders.bottom.border_style = Border.BORDER_THIN
c.style.alignment.horizontal = 'right'
c.style.font.italic = True
department_for_customer_save = purchase.department_for_customer
if department_for_customer_save is not None:
c.value = department_for_customer_save.short_name
else:
c.value = ""
if customer_save != purchase.customer.id:
for col_num in xrange(len(row)):
c = ws.cell(row=row_num, column=col_num)
c.style.borders.top.border_style = Border.BORDER_THIN
if col_num == 7:
c.value = purchase.customer.short_basket_name
c.style.font.bold = True
# Force the display of the department for next customer
customer_save = purchase.customer.id
else:
c = ws.cell(row=row_num, column=7)
c.value = purchase.customer.short_basket_name
row_num += 1
for col_num in xrange(len(row)): for col_num in xrange(len(row)):
c = ws.cell(row=row_num, column=col_num) c = ws.cell(row=row_num, column=col_num)
c.value = row[col_num][ROW_VALUE] c.value = row[col_num][ROW_VALUE]
c.style.number_format.format_code = row[col_num][ROW_FORMAT] c.style.number_format.format_code = row[col_num][ROW_FORMAT]
if row[col_num][ROW_BOX]: c.style.borders.bottom.border_style = Border.BORDER_HAIR
c.style.borders.top.border_style = Border.BORDER_THIN
c.style.borders.bottom.border_style = Border.BORDER_THIN
c.style.borders.left.border_style = Border.BORDER_THIN
c.style.borders.right.border_style = Border.BORDER_THIN
else:
c.style.borders.bottom.border_style = Border.BORDER_HAIR
if customer_save != purchase.customer.id:
# Display the customer in bold when changing
if col_num == 4:
c.style.font.bold = True
c.style.borders.top.border_style = Border.BORDER_THIN
if customer_save != purchase.customer.id:
customer_save = purchase.customer.id
row_num += 1 row_num += 1
return wb
if row_start_sum is not None:
c = ws.cell(row=row_num, column=5)
c.value = unicode(_("Total Price"))
c.style.number_format.format_code = NumberFormat.FORMAT_TEXT
c.style.font.bold = True
c = ws.cell(row=row_num, column=6)
formula = 'SUM(G%s:G%s)' % (row_start_sum + 3, row_num)
c.value = '=' + formula
c.style.number_format.format_code = u'_ € * #,##0.00_ ;_ € * -#,##0.00_ ;_ € * "-"??_ ;_ @_ '
c.style.font.bold = True
if hide_column_placement:
ws.column_dimensions[get_column_letter(1)].visible = False
if customer is None:
return wb
return ws
def admin_export(request, queryset): def admin_export(request, queryset):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment