Commit ccf43cee authored by Patrick's avatar Patrick

Work and tests in progress

parent 2fa467a8
...@@ -57,7 +57,8 @@ class ConfigurationAdmin(TranslatableAdmin): ...@@ -57,7 +57,8 @@ class ConfigurationAdmin(TranslatableAdmin):
'customers_must_confirm_orders', 'customers_must_confirm_orders',
('bank_account', 'max_week_wo_participation'), ('bank_account', 'max_week_wo_participation'),
('membership_fee', 'membership_fee_duration'), ('membership_fee', 'membership_fee_duration'),
'how_to_register'), 'notification_is_public',
'notification'),
}), }),
] ]
if Producer.objects.filter(producer_pre_opening=True).order_by('?').only('id').exists(): if Producer.objects.filter(producer_pre_opening=True).order_by('?').only('id').exists():
...@@ -109,6 +110,7 @@ class ConfigurationAdmin(TranslatableAdmin): ...@@ -109,6 +110,7 @@ class ConfigurationAdmin(TranslatableAdmin):
'sms_gateway_mail', 'sms_gateway_mail',
'invoice', 'invoice',
('currency', 'vat_id'), ('currency', 'vat_id'),
'how_to_register'
), ),
}), }),
] ]
......
...@@ -431,11 +431,11 @@ class PermanenceInPreparationAdmin(TranslatableAdmin): ...@@ -431,11 +431,11 @@ class PermanenceInPreparationAdmin(TranslatableAdmin):
email_will_be_sent, email_will_be_sent_to = send_email_to_who( email_will_be_sent, email_will_be_sent_to = send_email_to_who(
repanier.apps.REPANIER_SETTINGS_SEND_OPENING_MAIL_TO_CUSTOMER repanier.apps.REPANIER_SETTINGS_SEND_OPENING_MAIL_TO_CUSTOMER
) )
if 'apply' in request.POST: if 'apply' in request.POST or 'apply-wo-mail' in request.POST:
form = OpenAndSendOfferForm(request.POST) form = OpenAndSendOfferForm(request.POST)
if form.is_valid(): if form.is_valid():
user_message, user_message_level = task_order.admin_open_and_send( user_message, user_message_level = task_order.admin_open_and_send(
request, permanence request, permanence, 'apply-wo-mail' in request.POST
) )
self.message_user(request, user_message, user_message_level) self.message_user(request, user_message, user_message_level)
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
......
...@@ -291,6 +291,7 @@ class OfferItemSendAdmin(admin.ModelAdmin): ...@@ -291,6 +291,7 @@ class OfferItemSendAdmin(admin.ModelAdmin):
@transaction.atomic @transaction.atomic
def save_related(self, request, form, formsets, change): def save_related(self, request, form, formsets, change):
getcontext().rounding = ROUND_HALF_UP
for formset in formsets: for formset in formsets:
# option.py -> construct_change_message doesn't test the presence of those array not created at form initialisation... # option.py -> construct_change_message doesn't test the presence of those array not created at form initialisation...
if not hasattr(formset, 'new_objects'): formset.new_objects = [] if not hasattr(formset, 'new_objects'): formset.new_objects = []
...@@ -380,6 +381,7 @@ class OfferItemSendAdmin(admin.ModelAdmin): ...@@ -380,6 +381,7 @@ class OfferItemSendAdmin(admin.ModelAdmin):
ratio = DECIMAL_ZERO ratio = DECIMAL_ZERO
else: else:
ratio = DECIMAL_ONE ratio = DECIMAL_ONE
# Rule of 3
if ratio != DECIMAL_ONE: if ratio != DECIMAL_ONE:
adjusted_invoice = DECIMAL_ZERO adjusted_invoice = DECIMAL_ZERO
i = 0 i = 0
......
This diff is collapsed.
...@@ -96,6 +96,7 @@ class Configuration(TranslatableModel): ...@@ -96,6 +96,7 @@ class Configuration(TranslatableModel):
help_text=_("This is the minimum order amount to avoid shipping cost."), help_text=_("This is the minimum order amount to avoid shipping cost."),
default=DECIMAL_ZERO, max_digits=5, decimal_places=2, default=DECIMAL_ZERO, max_digits=5, decimal_places=2,
validators=[MinValueValidator(0)]) validators=[MinValueValidator(0)])
notification_is_public = models.BooleanField(_("the notification is public"), default=False)
translations = TranslatedFields( translations = TranslatedFields(
group_label=models.CharField(_("group label"), group_label=models.CharField(_("group label"),
max_length=100, max_length=100,
...@@ -104,11 +105,13 @@ class Configuration(TranslatableModel): ...@@ -104,11 +105,13 @@ class Configuration(TranslatableModel):
how_to_register=HTMLField(_("how to register"), how_to_register=HTMLField(_("how to register"),
help_text=EMPTY_STRING, help_text=EMPTY_STRING,
configuration='CKEDITOR_SETTINGS_MODEL2', configuration='CKEDITOR_SETTINGS_MODEL2',
default= default=EMPTY_STRING,
""" blank=True),
Pour créer un compte et passer commande, veuillez contacter .... notification=HTMLField(_("notification"),
""", help_text=EMPTY_STRING,
blank=False), configuration='CKEDITOR_SETTINGS_MODEL2',
default=EMPTY_STRING,
blank=True),
offer_customer_mail=HTMLField(_("offer customer mail"), offer_customer_mail=HTMLField(_("offer customer mail"),
help_text=EMPTY_STRING, help_text=EMPTY_STRING,
configuration='CKEDITOR_SETTINGS_MODEL2', configuration='CKEDITOR_SETTINGS_MODEL2',
......
...@@ -8,6 +8,7 @@ from django.db import models ...@@ -8,6 +8,7 @@ from django.db import models
from django.db import transaction from django.db import transaction
from django.db.models import F, Sum from django.db.models import F, Sum
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from django.utils.formats import number_format
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -373,7 +374,8 @@ class CustomerInvoice(models.Model): ...@@ -373,7 +374,8 @@ class CustomerInvoice(models.Model):
customer=a_purchase.customer, customer=a_purchase.customer,
offer_item_id=a_purchase.offer_item_id, offer_item_id=a_purchase.offer_item_id,
q_order=DECIMAL_ZERO, q_order=DECIMAL_ZERO,
batch_job=True batch_job=True,
comment=_("Cancelled qty : %s") % number_format(purchase.quantity_ordered, 4)
) )
def __str__(self): def __str__(self):
......
...@@ -19,7 +19,7 @@ import repanier.apps ...@@ -19,7 +19,7 @@ import repanier.apps
from repanier.const import * from repanier.const import *
from repanier.fields.RepanierMoneyField import ModelMoneyField from repanier.fields.RepanierMoneyField import ModelMoneyField
from repanier.models.box import BoxContent from repanier.models.box import BoxContent
from repanier.tools import get_or_create_offer_item from repanier.tools import get_or_create_offer_item, cap
@python_2_unicode_compatible @python_2_unicode_compatible
...@@ -210,6 +210,13 @@ class Purchase(models.Model): ...@@ -210,6 +210,13 @@ class Purchase(models.Model):
else: else:
raise AttributeError raise AttributeError
def set_comment(self, comment):
if comment:
if self.comment:
self.comment = cap("%s, %s" % (self.comment, comment), 100)
else:
self.comment = cap(comment, 100)
@transaction.atomic @transaction.atomic
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if not self.pk: if not self.pk:
......
...@@ -15,7 +15,8 @@ from django.core.files.storage import default_storage ...@@ -15,7 +15,8 @@ from django.core.files.storage import default_storage
from django.conf import settings from django.conf import settings
from django.http import HttpResponse from django.http import HttpResponse
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import ugettext as _not_lazy # from django.utils.translation import ugettext as _not_lazy
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_protect from django.views.decorators.csrf import csrf_protect
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
from .forms import FileForm from .forms import FileForm
...@@ -29,13 +30,14 @@ def ajax_picture(request, upload_to=None, form_class=FileForm, size=SIZE_XS): ...@@ -29,13 +30,14 @@ def ajax_picture(request, upload_to=None, form_class=FileForm, size=SIZE_XS):
if form.is_valid(): if form.is_valid():
size = sint(size) size = sint(size)
if size not in [SIZE_XS, SIZE_S, SIZE_M, SIZE_L]: if size not in [SIZE_XS, SIZE_S, SIZE_M, SIZE_L]:
data = json.dumps({'error': _not_lazy('Wrong size.')}) msg = "%s" % _('Wrong picture size.')
data = json.dumps({'error': msg})
return HttpResponse(data, content_type="application/json", status=403) return HttpResponse(data, content_type="application/json", status=403)
disk = os.statvfs(settings.MEDIA_ROOT) disk = os.statvfs(settings.MEDIA_ROOT)
if disk.f_blocks > 0 and ((disk.f_bfree + 1.0) / disk.f_blocks) < 0.2: if disk.f_blocks > 0 and ((disk.f_bfree + 1.0) / disk.f_blocks) < 0.2:
data = json.dumps({'error': _not_lazy( msg = "%s" % _('Please, contact the administrator of the webserver : There is not enough disk space.')
'Please, contact the administrator of the webserver : There is not enough disk space.')}) data = json.dumps({'error': msg})
return HttpResponse(data, content_type="application/json", status=403) return HttpResponse(data, content_type="application/json", status=403)
file_ = form.cleaned_data['file'] file_ = form.cleaned_data['file']
...@@ -43,7 +45,8 @@ def ajax_picture(request, upload_to=None, form_class=FileForm, size=SIZE_XS): ...@@ -43,7 +45,8 @@ def ajax_picture(request, upload_to=None, form_class=FileForm, size=SIZE_XS):
'image/gif'] 'image/gif']
if file_.content_type not in image_types: if file_.content_type not in image_types:
data = json.dumps({'error': _not_lazy('The system does not recognize the format.')}) msg = "%s" % _('The system does not recognize the format.')
data = json.dumps({'error': msg})
return HttpResponse(data, content_type="application/json", status=403) return HttpResponse(data, content_type="application/json", status=403)
file_name, extension = os.path.splitext(file_.name) file_name, extension = os.path.splitext(file_.name)
...@@ -51,23 +54,27 @@ def ajax_picture(request, upload_to=None, form_class=FileForm, size=SIZE_XS): ...@@ -51,23 +54,27 @@ def ajax_picture(request, upload_to=None, form_class=FileForm, size=SIZE_XS):
name = os.path.join(upload_to or "tmp", safe_name) name = os.path.join(upload_to or "tmp", safe_name)
if default_storage.exists(name): if default_storage.exists(name):
msg = "%s" % _(
'A picture with the same file name already exist. This picture will not replace it.'
)
return HttpResponse( return HttpResponse(
json.dumps( json.dumps(
{'url' : default_storage.url(name), {'url' : default_storage.url(name),
'filename': name, 'filename': name,
'msg' : _not_lazy( 'msg' : msg
'An image with same file name already exist. Please, check the file name and rename it if necessary.')
} }
), content_type="application/json") ), content_type="application/json")
else: else:
image = Image.open(file_) image = Image.open(file_)
if image.size[0] > size or image.size[1] > size: if image.size[0] > size or image.size[1] > size:
return HttpResponse(json.dumps({'error': _not_lazy('Wrong size.')}), content_type="application/json", msg = "%s" % _('The file size is too big.')
return HttpResponse(json.dumps({'error': msg}), content_type="application/json",
status=403) status=403)
file_name = default_storage.save(name, image.fp)
file_name = default_storage.save(name, image.fp) url = default_storage.url(file_name)
url = default_storage.url(file_name) return HttpResponse(
json.dumps(
return HttpResponse(json.dumps({'url': url, 'filename': file_name}), content_type="application/json") {'url': url, 'filename': file_name}
), content_type="application/json")
return HttpResponse(status=403) return HttpResponse(status=403)
...@@ -177,7 +177,7 @@ def pre_open_order(permanence_id): ...@@ -177,7 +177,7 @@ def pre_open_order(permanence_id):
@transaction.atomic @transaction.atomic
def open_order(permanence_id): def open_order(permanence_id, do_not_send_any_mail=False):
permanence = common_to_pre_open_and_open(permanence_id) permanence = common_to_pre_open_and_open(permanence_id)
# 1 - Disallow access to the producer to his/her products no more into "pre order" status # 1 - Disallow access to the producer to his/her products no more into "pre order" status
for producer in Producer.objects.filter( for producer in Producer.objects.filter(
...@@ -203,7 +203,7 @@ def open_order(permanence_id): ...@@ -203,7 +203,7 @@ def open_order(permanence_id):
permanence.producers.add(offer_item.producer_id) permanence.producers.add(offer_item.producer_id)
try: try:
if repanier.apps.REPANIER_SETTINGS_SEND_OPENING_MAIL_TO_CUSTOMER: if repanier.apps.REPANIER_SETTINGS_SEND_OPENING_MAIL_TO_CUSTOMER and not do_not_send_any_mail:
email_offer.send_open_order(permanence_id) email_offer.send_open_order(permanence_id)
permanence.set_status(PERMANENCE_OPENED) permanence.set_status(PERMANENCE_OPENED)
except Exception as error_str: except Exception as error_str:
...@@ -247,7 +247,7 @@ def admin_undo_back_to_planned(request, permanence): ...@@ -247,7 +247,7 @@ def admin_undo_back_to_planned(request, permanence):
return user_message, user_message_level return user_message, user_message_level
def admin_open_and_send(request, permanence): def admin_open_and_send(request, permanence, do_not_send_any_mail=False):
producer_pre_opening = Producer.objects.filter( producer_pre_opening = Producer.objects.filter(
permanence__id=permanence.id, is_active=True, producer_pre_opening=True permanence__id=permanence.id, is_active=True, producer_pre_opening=True
).order_by('?') ).order_by('?')
...@@ -267,7 +267,7 @@ def admin_open_and_send(request, permanence): ...@@ -267,7 +267,7 @@ def admin_open_and_send(request, permanence):
else: else:
permanence.set_status(PERMANENCE_WAIT_FOR_OPEN) permanence.set_status(PERMANENCE_WAIT_FOR_OPEN)
# open_order(permanence.id) # open_order(permanence.id)
thread.start_new_thread(open_order, (permanence.id,)) thread.start_new_thread(open_order, (permanence.id, do_not_send_any_mail))
user_message = _("The offers are being generated.") user_message = _("The offers are being generated.")
user_message_level = messages.INFO user_message_level = messages.INFO
return user_message, user_message_level return user_message, user_message_level
......
...@@ -96,32 +96,22 @@ ...@@ -96,32 +96,22 @@
</div> </div>
<a name="content"></a><section> <a name="content"></a><section>
{% if current_page.is_home %} {% if current_page.is_home %}
<div class="container-info" id="containerInfo" style="display: none"> <div class="container-info" id="containerInfo" style="display: none"></div>
<div class="container"> {% addtoblock "lastjs" %}{% spaceless %}
<div class="row"> <script type="text/javascript">
<div class="col-md-12"> $(document).ready(function () {
<div class="panel panel-default" id="homeInfo"> lien = '{% url 'home_info' %}';
</div> $.ajax({
</div> url: lien,
</div> cache: false,
</div> async: false,
</div> success: function (result) {
{% addtoblock "lastjs" %}{% spaceless %} $("#containerInfo").html(result).show();
<script type="text/javascript"> }
$(document).ready(function () { });
lien = '{% url 'home_info' %}'; });
$.ajax({ </script>
url: lien, {% endspaceless %}{% endaddtoblock %}
cache: false,
async: false,
success: function (result) {
$("#homeInfo").html(result);
$("#containerInfo").show();
}
});
});
</script>
{% endspaceless %}{% endaddtoblock %}
{% endif %} {% endif %}
{% block base_content%}{% endblock %} {% block base_content%}{% endblock %}
</section> </section>
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
<div class="submit-row"> <div class="submit-row">
<button type="submit" name="cancel" value="cancel"><h6>{% trans "No, cancel the action" %}</h6></button> <button type="submit" name="cancel" value="cancel"><h6>{% trans "No, cancel the action" %}</h6></button>
<button type="submit" name="apply" value="apply" class="default"><h6>{% trans "Yes, I'm sure" %}</h6></button> <button type="submit" name="apply" value="apply" class="default"><h6>{% trans "Yes, I'm sure" %}</h6></button>
{% if email_will_be_sent %}
<button type="submit" name="apply-wo-mail" value="apply-wo-mail"><h6>{% trans "Yes, I'm sure but do not send any mail" %}</h6></button>
{% endif %}
</div> </div>
<fieldset class="module aligned "> <fieldset class="module aligned ">
<div class="submit-row"> <div class="submit-row">
......
...@@ -134,7 +134,7 @@ ...@@ -134,7 +134,7 @@
{% endif %} {% endif %}
{% if download_invoice %} {% if download_invoice %}
<a href="{% url 'download_customer_invoice' object.id %}" <a href="{% url 'download_customer_invoice' object.id %}"
class="btn btn-disabled"> {% trans "Download" %} <span class="glyphicon glyphicon glyphicon-save"></span> </a> class="btn btn-success btn-disabled"> {% trans "Download" %} <span class="glyphicon glyphicon glyphicon-save"></span> </a>
{% endif %} {% endif %}
{% if next_customer_invoice_id %} {% if next_customer_invoice_id %}
<a href="{% url 'customer_invoice_view' next_customer_invoice_id %}" <a href="{% url 'customer_invoice_view' next_customer_invoice_id %}"
......
{% extends 'cms_page.html' %} {% extends 'cms_page.html' %}
{% load cms_tags sekizai_tags i18n l10n thumbnail filer_tags filer_image_tags %} {% load cms_tags sekizai_tags i18n l10n thumbnail filer_tags filer_image_tags %}
{% block sub_content %} {% block sub_content %}
<div id="containerInfo" style="display: none"></div>
{% addtoblock "lastjs" %}{% spaceless %}
<script type="text/javascript">
$(document).ready(function () {
lien = '{% url 'order_info' %}';
$.ajax({
url: lien,
cache: false,
async: false,
success: function (result) {
$("#containerInfo").html(result).show();
}
});
});
</script>
{% endspaceless %}{% endaddtoblock %}
{% if is_anonymous %} {% if is_anonymous %}
<div class="row"> <div class="row">
<div class="panel-group"> <div class="panel-group">
...@@ -9,6 +25,7 @@ ...@@ -9,6 +25,7 @@
<div class="col-xs-3"> <div class="col-xs-3">
<a href="{% url "login_form" %}?next={% url 'order_delivery_view' permanence.id delivery_id %}" class="btn btn-default">{% trans "Login me" %}</a> <a href="{% url "login_form" %}?next={% url 'order_delivery_view' permanence.id delivery_id %}" class="btn btn-default">{% trans "Login me" %}</a>
</div> </div>
{% if how_to_register %}
<div class="col-xs-9"> <div class="col-xs-9">
<div class="accordion-toggle collapsed" data-toggle="collapse" data-target="#collapse"> <div class="accordion-toggle collapsed" data-toggle="collapse" data-target="#collapse">
<span class="btn btn-info">{% trans "Create an account" %}</span> <span class="btn btn-info">{% trans "Create an account" %}</span>
...@@ -17,6 +34,7 @@ ...@@ -17,6 +34,7 @@
{{ how_to_register }} {{ how_to_register }}
</div> </div>
</div> </div>
{% endif %}
</div> </div>
</div> </div>
</div> </div>
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
<input type="hidden" name="this_is_the_login_form" value="1" /> <input type="hidden" name="this_is_the_login_form" value="1" />
<input type="hidden" name="next" value="{{ next }}" /> <input type="hidden" name="next" value="{{ next }}" />
</div> </div>
{% if how_to_register %}
<p></p> <p></p>
<div class="form-group"> <div class="form-group">
<div class="accordion-toggle collapsed" data-toggle="collapse" data-target="#collapse"> <div class="accordion-toggle collapsed" data-toggle="collapse" data-target="#collapse">
...@@ -52,6 +53,7 @@ ...@@ -52,6 +53,7 @@
</div> </div>
</div> </div>
</div> </div>
{% endif %}
<div class="modal-footer"> <div class="modal-footer">
<div class="form-group"> <div class="form-group">
<button class="btn btn-default" type="submit">{% trans "Login" %}</button> <button class="btn btn-default" type="submit">{% trans "Login" %}</button>
......
...@@ -26,6 +26,7 @@ from django.utils.safestring import mark_safe ...@@ -26,6 +26,7 @@ from django.utils.safestring import mark_safe
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from parler.models import TranslationDoesNotExist from parler.models import TranslationDoesNotExist
from six import string_types
import models import models
from const import * from const import *
...@@ -312,7 +313,7 @@ def cap_to_bytes_length(unicode_text, byte_limit): ...@@ -312,7 +313,7 @@ def cap_to_bytes_length(unicode_text, byte_limit):
def cap(s, l): def cap(s, l):
if s is not None: if s is not None:
if not isinstance(s, basestring): if not isinstance(s, string_types):
s = str(s) s = str(s)
s = s if len(s) <= l else s[0:l - 4] + '...' s = s if len(s) <= l else s[0:l - 4] + '...'
return s return s
...@@ -787,21 +788,13 @@ def recalculate_order_amount(permanence_id, ...@@ -787,21 +788,13 @@ def recalculate_order_amount(permanence_id,
if offer_item.order_unit == PRODUCT_ORDER_UNIT_PC_KG: if offer_item.order_unit == PRODUCT_ORDER_UNIT_PC_KG:
purchase.quantity_invoiced = (purchase.quantity_ordered * offer_item.order_average_weight) \ purchase.quantity_invoiced = (purchase.quantity_ordered * offer_item.order_average_weight) \
.quantize(FOUR_DECIMALS) .quantize(FOUR_DECIMALS)
if offer_item.wrapped:
purchase.quantity_for_preparation_sort_order = DECIMAL_ZERO
else:
purchase.quantity_for_preparation_sort_order = purchase.quantity_ordered
elif offer_item.order_unit == PRODUCT_ORDER_UNIT_KG:
purchase.quantity_invoiced = purchase.quantity_ordered
if offer_item.wrapped:
purchase.quantity_for_preparation_sort_order = DECIMAL_ZERO
else:
purchase.quantity_for_preparation_sort_order = purchase.quantity_ordered
else: else:
purchase.quantity_invoiced = purchase.quantity_ordered purchase.quantity_invoiced = purchase.quantity_ordered
purchase.quantity_for_preparation_sort_order = DECIMAL_ZERO
purchase.save() purchase.save()
if send_to_producer:
reorder_purchases(permanence_id)
def display_selected_value(offer_item, quantity_ordered): def display_selected_value(offer_item, quantity_ordered):
if offer_item.may_order: if offer_item.may_order:
...@@ -967,7 +960,8 @@ def update_or_create_purchase(customer=None, offer_item_id=None, q_order=None, v ...@@ -967,7 +960,8 @@ def update_or_create_purchase(customer=None, offer_item_id=None, q_order=None, v
if quantity_ordered < DECIMAL_ZERO: if quantity_ordered < DECIMAL_ZERO:
quantity_ordered = DECIMAL_ZERO quantity_ordered = DECIMAL_ZERO
purchase, updated = create_or_update_one_purchase( purchase, updated = create_or_update_one_purchase(
customer.id, box_offer_item, q_order=quantity_ordered, batch_job=batch_job, is_box_content=True customer.id, box_offer_item, q_order=quantity_ordered,
batch_job=batch_job, is_box_content=True
) )
else: else:
updated = False updated = False
...@@ -1304,7 +1298,10 @@ def my_order_confirmation_email_send_to(customer): ...@@ -1304,7 +1298,10 @@ def my_order_confirmation_email_send_to(customer):
return msg_confirmation return msg_confirmation
def create_or_update_one_purchase(customer_id, offer_item, permanence_date=None, status=PERMANENCE_OPENED, q_order=None, batch_job=False, is_box_content=False): def create_or_update_one_purchase(
customer_id, offer_item,
permanence_date=None, status=PERMANENCE_OPENED, q_order=None,
batch_job=False, is_box_content=False, comment=EMPTY_STRING):
# The batch_job flag is used because we need to forbid # The batch_job flag is used because we need to forbid
# customers to add purchases during the close_orders_async or other batch_job process # customers to add purchases during the close_orders_async or other batch_job process
...@@ -1327,12 +1324,14 @@ def create_or_update_one_purchase(customer_id, offer_item, permanence_date=None, ...@@ -1327,12 +1324,14 @@ def create_or_update_one_purchase(customer_id, offer_item, permanence_date=None,
quantity_ordered=q_order if status < PERMANENCE_SEND else DECIMAL_ZERO, quantity_ordered=q_order if status < PERMANENCE_SEND else DECIMAL_ZERO,
quantity_invoiced=q_order if status >= PERMANENCE_SEND else DECIMAL_ZERO, quantity_invoiced=q_order if status >= PERMANENCE_SEND else DECIMAL_ZERO,
is_box_content=is_box_content, is_box_content=is_box_content,
status=status status=status,
comment=comment
) )
else: else:
purchase.set_comment(comment)
if status < PERMANENCE_SEND: if status < PERMANENCE_SEND:
if q_order == DECIMAL_ZERO: # if q_order == DECIMAL_ZERO:
purchase.comment = _("Cancelled qty : %s") % number_format(purchase.quantity_ordered, 4) # purchase.comment = _("Cancelled qty : %s") % number_format(purchase.quantity_ordered, 4)
purchase.quantity_ordered = q_order purchase.quantity_ordered = q_order
else: else:
purchase.quantity_invoiced = q_order purchase.quantity_invoiced = q_order
...@@ -1370,6 +1369,7 @@ def create_or_update_one_purchase(customer_id, offer_item, permanence_date=None, ...@@ -1370,6 +1369,7 @@ def create_or_update_one_purchase(customer_id, offer_item, permanence_date=None,
else: else:
q_alert = offer_item.customer_alert_order_quantity q_alert = offer_item.customer_alert_order_quantity
if purchase is not None: if purchase is not None:
purchase.set_comment(comment)
if q_order <= q_alert: if q_order <= q_alert:
if purchase.quantity_confirmed <= q_order: if purchase.quantity_confirmed <= q_order:
purchase.quantity_ordered = q_order purchase.quantity_ordered = q_order
...@@ -1392,14 +1392,14 @@ def create_or_update_one_purchase(customer_id, offer_item, permanence_date=None, ...@@ -1392,14 +1392,14 @@ def create_or_update_one_purchase(customer_id, offer_item, permanence_date=None,
quantity_ordered=q_order, quantity_ordered=q_order,
quantity_invoiced=DECIMAL_ZERO, quantity_invoiced=DECIMAL_ZERO,
is_box_content=is_box_content, is_box_content=is_box_content,
status=status status=status,
comment=comment
) )
return purchase, True return purchase, True
else: else:
return purchase, False return purchase, False
def clean_offer_item(permanence, queryset, reset_add_2_stock=False): def clean_offer_item(permanence, queryset, reset_add_2_stock=False):
if permanence.status > PERMANENCE_SEND: if permanence.status > PERMANENCE_SEND:
# The purchases are already invoiced. # The purchases are already invoiced.
...@@ -1488,6 +1488,22 @@ def clean_offer_item(permanence, queryset, reset_add_2_stock=False): ...@@ -1488,6 +1488,22 @@ def clean_offer_item(permanence, queryset, reset_add_2_stock=False):
translation.activate(cur_language) translation.activate(cur_language)
def reorder_purchases(permanence_id):
# Order the purchases such that lower quantity are before larger quantity
models.Purchase.objects.filter(
permanence_id=permanence_id
).update(
quantity_for_preparation_sort_order=DECIMAL_ZERO
)
models.Purchase.objects.filter(
permanence_id=permanence_id,
offer_item__wrapped=False,
offer_item__order_unit__in=[PRODUCT_ORDER_UNIT_KG, PRODUCT_ORDER_UNIT_PC_KG]
).update(
quantity_for_preparation_sort_order=F('quantity_invoiced')
)
def reorder_offer_items(permanence_id): def reorder_offer_items(permanence_id):
# calculate the sort order of the order display screen # calculate the sort order of the order display screen
cur_language = translation.get_language()