Commit 6a397bd1 authored by Patrick's avatar Patrick

The customer can now add an higher qty of any product to a confirmed invoice....

The customer can now add an higher qty of any product to a confirmed invoice. The invoice has to be confirmed again.
parent bbd72ed2
This diff is collapsed.
...@@ -6,9 +6,11 @@ import datetime ...@@ -6,9 +6,11 @@ import datetime
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
from django.db import models from django.db import models
from django.db import transaction from django.db import transaction
from django.db.models import F
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import purchase
from repanier.apps import REPANIER_SETTINGS_PERMANENCE_NAME from repanier.apps import REPANIER_SETTINGS_PERMANENCE_NAME
import producer import producer
from repanier.const import * from repanier.const import *
...@@ -187,6 +189,9 @@ class CustomerInvoice(models.Model): ...@@ -187,6 +189,9 @@ class CustomerInvoice(models.Model):
@transaction.atomic @transaction.atomic
def confirm_order(self): def confirm_order(self):
purchase.Purchase.objects.filter(
customer_invoice__id=self.id
).update(quantity_confirmed=F('quantity_ordered'))
getcontext().rounding = ROUND_HALF_UP getcontext().rounding = ROUND_HALF_UP
producer_invoice_buyinggroup = ProducerInvoice.objects.filter( producer_invoice_buyinggroup = ProducerInvoice.objects.filter(
producer__represent_this_buyinggroup=True, producer__represent_this_buyinggroup=True,
......
...@@ -59,6 +59,9 @@ class Purchase(models.Model): ...@@ -59,6 +59,9 @@ class Purchase(models.Model):
quantity_ordered = models.DecimalField( quantity_ordered = models.DecimalField(
_("quantity ordered"), _("quantity ordered"),
max_digits=9, decimal_places=4, default=DECIMAL_ZERO) max_digits=9, decimal_places=4, default=DECIMAL_ZERO)
quantity_confirmed = models.DecimalField(
_("quantity confirmed"),
max_digits=9, decimal_places=4, default=DECIMAL_ZERO)
# 0 if this is not a KG product -> the preparation list for this product will be produced by family # 0 if this is not a KG product -> the preparation list for this product will be produced by family
# qty if not -> the preparation list for this product will be produced by qty then by family # qty if not -> the preparation list for this product will be produced by qty then by family
quantity_for_preparation_sort_order = models.DecimalField( quantity_for_preparation_sort_order = models.DecimalField(
......
...@@ -1167,14 +1167,15 @@ def my_order_confirmation(permanence, customer_invoice, is_basket=False, ...@@ -1167,14 +1167,15 @@ def my_order_confirmation(permanence, customer_invoice, is_basket=False,
) )
else: else:
msg_delivery = EMPTY_STRING msg_delivery = EMPTY_STRING
msg_confirmation1 = EMPTY_STRING
if not is_basket and not apps.REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS: if not is_basket and not apps.REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS:
# or customer_invoice.total_price_with_tax.amount != DECIMAL_ZERO: # or customer_invoice.total_price_with_tax.amount != DECIMAL_ZERO:
# If apps.REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS is True, # If apps.REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS is True,
# then permanence.with_delivery_point is also True # then permanence.with_delivery_point is also True
msg_confirmation = msg_html = EMPTY_STRING msg_confirmation2 = msg_html = EMPTY_STRING
else: else:
if customer_invoice.is_order_confirm_send: if customer_invoice.is_order_confirm_send:
msg_confirmation = my_order_confirmation_email_send_to(customer_invoice.customer) msg_confirmation2 = my_order_confirmation_email_send_to(customer_invoice.customer)
msg_html = """ msg_html = """
<div class="row"> <div class="row">
<div class="panel panel-default"> <div class="panel panel-default">
...@@ -1186,35 +1187,38 @@ def my_order_confirmation(permanence, customer_invoice, is_basket=False, ...@@ -1186,35 +1187,38 @@ def my_order_confirmation(permanence, customer_invoice, is_basket=False,
</div> </div>
</div> </div>
</div> </div>
""" % (msg_delivery, msg_confirmation, basket_message) """ % (msg_delivery, msg_confirmation2, basket_message)
else: else:
msg_html = None msg_html = None
btn_disabled = EMPTY_STRING btn_disabled = EMPTY_STRING
msg_confirmation = EMPTY_STRING msg_confirmation2 = EMPTY_STRING
if apps.REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS: if apps.REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS:
if is_basket: if is_basket:
if customer_invoice.status == PERMANENCE_OPENED: if customer_invoice.status == PERMANENCE_OPENED:
if permanence.with_delivery_point and customer_invoice.delivery is None: if customer_invoice.delivery is None:
btn_disabled = "disabled" btn_disabled = "disabled"
msg_confirmation = '<span class="glyphicon glyphicon-floppy-disk"></span>&nbsp;&nbsp;%s' % _("Confirm this order and receive an email containing its summary.") msg_confirmation1 = '<font color="red">%s</font><br/>' % _("An unconfirmed order will be canceled.")
else: msg_confirmation2 = '<span class="glyphicon glyphicon-floppy-disk"></span>&nbsp;&nbsp;%s' % _("Confirm this order and receive an email containing its summary.")
elif permanence.with_delivery_point:
href = urlresolvers.reverse( href = urlresolvers.reverse(
'basket_view', args=(permanence.id,) 'basket_view', args=(permanence.id,)
) )
msg_confirmation = _("Verify my order content before validating it.") msg_confirmation1 = '<font color="red">%s</font><br/>' % _("An unconfirmed order will be canceled.")
msg_confirmation2 = _("Verify my order content before validating it.")
msg_html = """ msg_html = """
<div class="row"> <div class="row">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
%s %s
%s
<a href="%s" class="btn btn-info" %s>%s</a> <a href="%s" class="btn btn-info" %s>%s</a>
</div> </div>
</div> </div>
</div> </div>
""" % (msg_delivery, href, btn_disabled, msg_confirmation) """ % (msg_delivery, msg_confirmation1, href, btn_disabled, msg_confirmation2)
else: else:
if is_basket: if is_basket:
msg_confirmation = _("Receive an email containing this order summary.") msg_confirmation2 = _("Receive an email containing this order summary.")
elif permanence.with_delivery_point: elif permanence.with_delivery_point:
msg_html = """ msg_html = """
<div class="row"> <div class="row">
...@@ -1228,7 +1232,7 @@ def my_order_confirmation(permanence, customer_invoice, is_basket=False, ...@@ -1228,7 +1232,7 @@ def my_order_confirmation(permanence, customer_invoice, is_basket=False,
else: else:
msg_html = EMPTY_STRING msg_html = EMPTY_STRING
if msg_html is None: if msg_html is None:
if msg_confirmation == EMPTY_STRING: if msg_confirmation2 == EMPTY_STRING:
msg_html = """ msg_html = """
<div class="row"> <div class="row">
<div class="panel panel-default"> <div class="panel panel-default">
...@@ -1246,17 +1250,17 @@ def my_order_confirmation(permanence, customer_invoice, is_basket=False, ...@@ -1246,17 +1250,17 @@ def my_order_confirmation(permanence, customer_invoice, is_basket=False,
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
%s %s
%s
<button id="btn_confirm_order" class="btn btn-info" %s onclick="btn_receive_order_email();">%s</button> <button id="btn_confirm_order" class="btn btn-info" %s onclick="btn_receive_order_email();">%s</button>
<div class="clearfix"></div> <div class="clearfix"></div>
%s %s
</div> </div>
</div> </div>
</div> </div>
""" % (msg_delivery, btn_disabled, msg_confirmation, basket_message) """ % (msg_delivery, msg_confirmation1, btn_disabled, msg_confirmation2, basket_message)
if to_json is not None: if to_json is not None:
option_dict = {'id': "#span_btn_confirm_order", 'html': msg_html} option_dict = {'id': "#span_btn_confirm_order", 'html': msg_html}
to_json.append(option_dict) to_json.append(option_dict)
return msg_confirmation
def my_order_confirmation_email_send_to(customer): def my_order_confirmation_email_send_to(customer):
...@@ -1336,10 +1340,18 @@ def create_or_update_one_purchase(customer, offer_item, value_id, value, close_o ...@@ -1336,10 +1340,18 @@ def create_or_update_one_purchase(customer, offer_item, value_id, value, close_o
q_alert = offer_item.customer_alert_order_quantity q_alert = offer_item.customer_alert_order_quantity
if q_order <= q_alert: if q_order <= q_alert:
if purchase is not None: if purchase is not None:
if close_orders and value_id == DECIMAL_ZERO: if close_orders:
purchase.comment = _("Cancelled qty : %s") % number_format(purchase.quantity_ordered, 4) if value_id == DECIMAL_ZERO:
purchase.quantity_ordered = q_order purchase.comment = _("Cancelled qty : %s") % number_format(purchase.quantity_ordered, 4)
purchase.save() else:
purchase.quantity_ordered = q_order
purchase.save()
else:
if purchase.quantity_confirmed < q_order:
purchase.quantity_ordered = q_order
purchase.save()
else:
return purchase, False
else: else:
permanence = models.Permanence.objects.filter(id=offer_item.permanence_id) \ permanence = models.Permanence.objects.filter(id=offer_item.permanence_id) \
.only("permanence_date") \ .only("permanence_date") \
......
...@@ -34,9 +34,9 @@ def order_ajax(request): ...@@ -34,9 +34,9 @@ def order_ajax(request):
permanence__offeritem=offer_item_id, permanence__offeritem=offer_item_id,
customer_id=customer.id, customer_id=customer.id,
status=PERMANENCE_OPENED).order_by('?') status=PERMANENCE_OPENED).order_by('?')
from repanier.apps import REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS # from repanier.apps import REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS
if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS: # if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS:
qs = qs.filter(is_order_confirm_send=False) # qs = qs.filter(is_order_confirm_send=False)
result = None result = None
if qs.exists(): if qs.exists():
qs = ProducerInvoice.objects.filter( qs = ProducerInvoice.objects.filter(
......
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