Commit f7adcdf8 authored by Patrick's avatar Patrick
Browse files

More user friendly display of qty and price

parent 355bbbf3
......@@ -462,8 +462,8 @@ class ProductAdmin(TranslatableAdmin):
('is_into_offer', 'is_active', 'is_created_on', 'is_updated_on')
)
list_select_related = ('producer', 'department_for_customer')
list_per_page = 100
list_max_show_all = 100
list_per_page = 17
list_max_show_all = 17
filter_horizontal = ('production_mode',)
ordering = ('producer',
# 'department_for_customer',
......
......@@ -216,8 +216,8 @@ def close(permanence_id, current_site_name):
if permanence.has_translation(language[0]):
permanence.cache_part_d = ""
permanence.save()
if offer_item.has_translation(language[0]):
for offer_item in OfferItem.objects.filter(permanence_id=permanence_id).order_by():
for offer_item in OfferItem.objects.filter(permanence_id=permanence_id).order_by():
if offer_item.has_translation(language[0]):
offer_item.cache_part_a = ""
offer_item.cache_part_b = ""
offer_item.cache_part_c = ""
......@@ -228,7 +228,8 @@ def close(permanence_id, current_site_name):
recalculate_order_amount(permanence_id, send_to_producer=True)
email_order.send(permanence_id, current_site_name)
menu_pool.clear()
permanence.update(status=PERMANENCE_SEND)
permanence.status=PERMANENCE_SEND
permanence.save(update_fields=['status'])
def admin_close_and_send(request, queryset):
......
......@@ -120,9 +120,7 @@
</div>
<div class="col-sm-6 col-lg-3" data-id="{{ offer.id|stringformat:"d" }}" data-product="{{ offer.product.long_name }}">
<select name="offer_item{{ offer.id|stringformat:"d" }}" id="offer_item{{ offer.id|stringformat:"d" }}" onchange="order_ajax({{ offer.id|stringformat:"d" }})" class="form-control">
{# <option value="0" selected>---</option>#}
</select>
{# {% repanier_select_qty offer_item_id=offer.id %}#}
{% if user.customer.vat_id %}
{{ offer.cache_part_c | safe }}
{% else %}
......@@ -229,38 +227,33 @@
</div>
{% addtoblock "lastjs" %}
<script type="text/javascript">
var previously_edited_offer_item = null;
var previously_edited_offer_item_id = null;
function order_ajax(offer_item_id) {
var offer_item = $("#offer_item" + offer_item_id);
{# *** Need to save offer_item.val() for Firefox *** #}
var offer_item_val = $("option:selected", offer_item).val();
if (offer_item_val == 'other_qty') {
var getProductFromRow = offer_item.closest('div').data('product');
$('#otherQtyModalLabel').html(getProductFromRow);
$('#otherQtyModal').modal('show');
offer_item.val(offer_item.data('oldValue'));
} else {
var lien = '{% url 'order_form_ajax' %}?value=' + offer_item_val + "&offer_item=" + offer_item_id;
{# *** Bellow needed to avoid Firefox flashing the old/new selected value *** #}
// offer_item.val(offer_item_val);
$.ajax({
url: lien,
cache: false,
async: true,
async: false,
success: function (result) {
if (result.indexOf("ok") != 0) {
offer_item.val(offer_item.data('oldValue'));
offer_item.html('<option value="0" selected>{% trans "Retry1" %}</option>');
} else {
$('#prepared_amount').text(result.substring(2));
$('#prepared_amount_visible_xs').text(result.substring(2));
$('#my_basket').text(result.substring(2));
{# *** Need to restore offer_item.val() for Firefox *** #}
{# offer_item.val(offer_item_val);#}
offer_item.data('oldValue', offer_item_val);
}
},
error: function (result) {
offer_item.val(offer_item.data('oldValue'));
offer_item.html('<option value="0" selected>{% trans "Retry2" %}</option>');
}
});
}
......@@ -274,22 +267,20 @@
cache: false,
async: false,
success: function (result) {
$("#offer_item{{ offer.id|stringformat:"d" }}").append(result);
$("#offer_item{{ offer.id|stringformat:"d" }}").html(result);
},
error: function (result) {
$("#offer_item{{ offer.id|stringformat:"d" }}").append('<option value="0" selected>{% trans "Communication error" %}</option>');
$("#offer_item{{ offer.id|stringformat:"d" }}").html('<option value="0" selected>{% trans "Retry3" %}</option>');
}
});
{% endfor %}
{% endif %}
$("#li_my_basket").show();
$("select").mouseenter(function (event) {
var lien = "";
var offer_item = $(this);
var offer_item_val = $("option:selected", offer_item).val();
offer_item.data('oldValue', offer_item_val);
var offer_item_id = offer_item.closest('div').data('id');
var lien = '{% url 'ajax_order_select' %}?offer_item=' + offer_item_id;
lien = '{% url 'ajax_order_select' %}?offer_item=' + offer_item_id;
$.ajax({
url: lien,
cache: false,
......@@ -307,11 +298,9 @@
}
});
offer_item.html(selectOption);
offer_item.data('oldValue', selectVal);
// offer_item.val(selectVal);
},
error: function (result) {
offer_item.val(offer_item.data('oldValue'));
offer_item.html('<option value="0" selected>{% trans "Retry4" %}</option>');
}
});
});
......
......@@ -109,7 +109,7 @@ def get_preparator_unit(order_unit=PRODUCT_ORDER_UNIT_PC, qty=0):
return unit
def get_qty_display(qty=0, order_average_weight=0, order_unit=PRODUCT_ORDER_UNIT_PC, price=None):
def get_display(qty=0, order_average_weight=0, order_unit=PRODUCT_ORDER_UNIT_PC, price=None):
unit = unicode(_(' pieces'))
magnitude = 1
if order_unit == PRODUCT_ORDER_UNIT_KG:
......@@ -182,11 +182,14 @@ def get_qty_display(qty=0, order_average_weight=0, order_unit=PRODUCT_ORDER_UNIT
decimal = 1
elif qty * 100 == int(qty * 100):
decimal = 2
qty_display = number_format(qty, decimal) + unit
if price is not None:
display_price = " = " + number_format((price * qty).quantize(TWO_DECIMALS), 2) + "&nbsp;&euro;"
price = (price * qty).quantize(TWO_DECIMALS)
price_display = " = " + number_format(price, 2)
else:
display_price = ""
return number_format(qty, decimal) + unit + display_price
price = 0
price_display = ""
return qty_display, price_display, price
def get_user_order_amount(permanence, user=None):
......
......@@ -9,7 +9,7 @@ from views import PermanenceView
urlpatterns = patterns('',
url(r'^contact/$', views.contact_form, name='contact_form'),
url(r'^order/(\w+)/$', cache_page(24*60*60)(OrderView.as_view()), name='order_view'),
url(r'^order/(\w+)/$', cache_page(60*60)(OrderView.as_view()), name='order_view'),
url(r'^basket/(\w+)/$', login_required(OrderViewWithoutCache.as_view()), name='basket_view'),
url(r'^order-ajax/$', views.order_form_ajax, name='order_form_ajax'),
url(r'^ajax/order-init/$', views.ajax_order_init, name='ajax_order_init'),
......
......@@ -146,13 +146,14 @@ def ajax_order_init(request):
if q_order<=0:
result = '<option value="0" selected>---</option>'
else:
qty_display = get_qty_display(
qty_display, price_display, price = get_display(
q_order,
q_average_weight,
offer_item.product.order_unit,
a_price
)
result = '<option value="' + str(q_order) + '" selected>' + qty_display + '</option>'
result = '<option value="' + str(q_order) + '" selected>' + \
qty_display + price_display + '&nbsp;&euro;</option>'
# result += '</select>'
else:
result = "N/A4"
......@@ -236,13 +237,14 @@ def ajax_order_select(request):
selected = "selected"
if (offer_item.permanence.status == PERMANENCE_OPENED or
(PERMANENCE_SEND <= offer_item.permanence.status and selected == "selected")):
qty_display = get_qty_display(
qty_display, price_display, price = get_display(
q_valid,
q_average_weight,
offer_item.product.order_unit,
a_price
)
option_dict = {'value': str(q_select_id), 'selected': selected, 'label': qty_display}
option_dict = {'value': str(q_select_id), 'selected': selected,
'label': qty_display + price_display + '&nbsp;&euro;'}
to_json.append(option_dict)
if q_valid < q_step:
# 1; 2; 4; 6; 8 ... q_min = 1; q_step = 2
......@@ -257,13 +259,14 @@ def ajax_order_select(request):
# An custom order_qty > q_alert
q_select_id += 1
selected = "selected"
qty_display = get_qty_display(
qty_display, price_display, price = get_display(
q_order,
q_average_weight,
offer_item.product.order_unit,
a_price
)
option_dict = {'value': str(q_select_id), 'selected': selected, 'label': qty_display}
option_dict = {'value': str(q_select_id), 'selected': selected,
'label': qty_display + price_display + '&nbsp;&euro;'}
to_json.append(option_dict)
if offer_item.permanence.status == PERMANENCE_OPENED:
option_dict = {'value': 'other_qty', 'selected': '', 'label': unicode(_("Other qty"))}
......
......@@ -39,6 +39,8 @@ def export(permanence, wb=None):
(unicode(_("Product")), 60, product.long_name, NumberFormat.FORMAT_TEXT, False),
(unicode(_("Unit Price")), 10, product.original_unit_price,
u'_ € * #,##0.00_ ;_ € * -#,##0.00_ ;_ € * "-"??_ ;_ @_ ', False),
(unicode(_("deposit")), 10, product.unit_deposit,
u'_ € * #,##0.00_ ;_ € * -#,##0.00_ ;_ € * "-"??_ ;_ @_ ', False),
]
if row_num == 0:
......@@ -80,12 +82,14 @@ def export(permanence, wb=None):
while q_valid <= q_alert and q_counter <= 20:
q_counter += 1
c = ws.cell(row=row_num, column=col_num)
c.value = get_qty_display(
qty_display, price_display, price = get_display(
q_valid,
product.order_average_weight,
product.order_unit
product.order_unit,
product.unit_price_with_vat
)
ws.column_dimensions[get_column_letter(col_num + 1)].width = 15
c.value = qty_display + price_display + u" €"
ws.column_dimensions[get_column_letter(col_num + 1)].width = 20
c.style.number_format.format_code = NumberFormat.FORMAT_TEXT
col_num += 1
if q_valid < q_step:
......@@ -114,6 +118,8 @@ def export(permanence, wb=None):
(unicode(_("Product")), 60, offer_item.product.long_name, NumberFormat.FORMAT_TEXT, False),
(unicode(_("Unit Price")), 10, offer_item.product.original_unit_price,
u'_ € * #,##0.00_ ;_ € * -#,##0.00_ ;_ € * "-"??_ ;_ @_ ', False),
(unicode(_("deposit")), 10, offer_item.product.unit_deposit,
u'_ € * #,##0.00_ ;_ € * -#,##0.00_ ;_ € * "-"??_ ;_ @_ ', False),
]
if row_num == 0:
......@@ -155,12 +161,14 @@ def export(permanence, wb=None):
while q_valid <= q_alert and q_counter <= 20:
q_counter += 1
c = ws.cell(row=row_num, column=col_num)
c.value = get_qty_display(
qty_display, price_display, price = get_display(
q_valid,
offer_item.product.order_average_weight,
offer_item.product.order_unit
offer_item.product.order_unit,
offer_item.product.unit_price_with_vat
)
ws.column_dimensions[get_column_letter(col_num + 1)].width = 15
c.value = qty_display + price_display + u" €"
ws.column_dimensions[get_column_letter(col_num + 1)].width = 20
c.style.number_format.format_code = NumberFormat.FORMAT_TEXT
col_num += 1
if q_valid < q_step:
......
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