Commit 3e7bdb2c authored by Patrick's avatar Patrick

Work in progress

parent d1bad61b
...@@ -3,12 +3,12 @@ from __future__ import unicode_literals ...@@ -3,12 +3,12 @@ from __future__ import unicode_literals
from django.conf import settings from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django.shortcuts import render
from django.utils import timezone
from django.core.checks import messages from django.core.checks import messages
from django.db.models import F, Q from django.db.models import F, Q
from django.http import HttpResponseRedirect, HttpResponse from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render
from django.template import Context as TemplateContext, Template from django.template import Context as TemplateContext, Template
from django.utils import timezone
from django.utils import translation from django.utils import translation
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.text import slugify from django.utils.text import slugify
......
...@@ -14,7 +14,7 @@ from repanier.models import Permanence, Configuration, CustomerInvoice ...@@ -14,7 +14,7 @@ from repanier.models import Permanence, Configuration, CustomerInvoice
from repanier.models import PermanenceBoard from repanier.models import PermanenceBoard
from repanier.models import Producer, ProducerInvoice from repanier.models import Producer, ProducerInvoice
from repanier.tools import * from repanier.tools import *
from repanier.xlsx.xlsx_order import generate_customer_xlsx from repanier.xlsx.xlsx_order import generate_customer_xlsx, generate_producer_xlsx
def email_order(permanence_id, all_producers=True, closed_deliveries_id=None, producers_id=None): def email_order(permanence_id, all_producers=True, closed_deliveries_id=None, producers_id=None):
...@@ -114,7 +114,7 @@ def email_order(permanence_id, all_producers=True, closed_deliveries_id=None, pr ...@@ -114,7 +114,7 @@ def email_order(permanence_id, all_producers=True, closed_deliveries_id=None, pr
producer_set = producer_set.filter(id__in=producers_id) producer_set = producer_set.filter(id__in=producers_id)
for producer in producer_set: for producer in producer_set:
long_profile_name = producer.long_profile_name if producer.long_profile_name is not None else producer.short_profile_name long_profile_name = producer.long_profile_name if producer.long_profile_name is not None else producer.short_profile_name
wb = xlsx_order.generate_producer_xlsx(permanence=permanence, producer=producer, wb=None) wb = generate_producer_xlsx(permanence=permanence, producer=producer, wb=None)
order_producer_mail = config.safe_translation_getter( order_producer_mail = config.safe_translation_getter(
'order_producer_mail', any_language=True, default=EMPTY_STRING 'order_producer_mail', any_language=True, default=EMPTY_STRING
......
...@@ -42,28 +42,8 @@ class Command(BaseCommand): ...@@ -42,28 +42,8 @@ class Command(BaseCommand):
id__in=recently_updated_customer_invoice_qs id__in=recently_updated_customer_invoice_qs
) )
for customer_invoice in customer_invoice_qs: for customer_invoice in customer_invoice_qs:
# TODO : Send Mail customer_invoice.delete_if_unconfirmed(permanence)
filename = "{0}-{1}.xlsx".format(
slugify(_("Canceled order")),
slugify(permanence)
)
sender_email, sender_function, signature, cc_email_staff = get_signature(
is_reply_to_order_email=True)
export_order_2_1_customer(
customer_invoice.customer, filename, permanence, sender_email,
sender_function, signature,
cancel_order=True
)
purchase_qs = Purchase.objects.filter(
customer_invoice_id=customer_invoice.id,
is_box_content=False
).order_by('?')
for purchase in purchase_qs.select_related("customer"):
update_or_create_purchase(
customer=purchase.customer,
offer_item_id=purchase.offer_item_id,
q_order=DECIMAL_ZERO,
batch_job=True
)
...@@ -8,13 +8,15 @@ from django.db import models ...@@ -8,13 +8,15 @@ 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.text import slugify
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import producer
import purchase import purchase
from repanier.apps import DJANGO_IS_MIGRATION_RUNNING from repanier.apps import DJANGO_IS_MIGRATION_RUNNING
import producer
from repanier.const import * from repanier.const import *
from repanier.fields.RepanierMoneyField import ModelMoneyField from repanier.fields.RepanierMoneyField import ModelMoneyField
from repanier.tools import update_or_create_purchase, get_signature
def permanence_verbose_name(): def permanence_verbose_name():
...@@ -347,6 +349,33 @@ class CustomerInvoice(models.Model): ...@@ -347,6 +349,33 @@ class CustomerInvoice(models.Model):
status=self.status status=self.status
) )
def delete_if_unconfirmed(self, permanence):
if not self.is_order_confirm_send:
from repanier.email.email_order import export_order_2_1_customer
filename = "{0}-{1}.xlsx".format(
slugify(_("Canceled order")),
slugify(permanence)
)
sender_email, sender_function, signature, cc_email_staff = get_signature(
is_reply_to_order_email=True)
export_order_2_1_customer(
self.customer, filename, permanence, sender_email,
sender_function, signature,
cancel_order=True
)
purchase_qs = purchase.Purchase.objects.filter(
customer_invoice_id=self.id,
is_box_content=False,
).order_by('?')
for a_purchase in purchase_qs.select_related("customer"):
update_or_create_purchase(
customer=a_purchase.customer,
offer_item_id=a_purchase.offer_item_id,
q_order=DECIMAL_ZERO,
batch_job=True
)
def __str__(self): def __str__(self):
return '%s, %s' % (self.customer, self.permanence) return '%s, %s' % (self.customer, self.permanence)
......
# -*- coding: utf-8 # -*- coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import copy
from django.conf import settings from django.conf import settings
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
from django.db import models from django.db import models
......
# -*- coding: utf-8 # -*- coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
# import copy
import django
from django.conf import settings from django.conf import settings
from django.core.mail import EmailMessage
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
......
...@@ -8,21 +8,18 @@ from django.contrib import messages ...@@ -8,21 +8,18 @@ from django.contrib import messages
from django.db import transaction from django.db import transaction
from django.utils import timezone from django.utils import timezone
from django.utils import translation from django.utils import translation
from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import repanier.apps import repanier.apps
from repanier.const import * from repanier.const import *
from repanier.email import email_offer from repanier.email import email_offer
from repanier.email import email_order from repanier.email import email_order
from repanier.email.email_order import export_order_2_1_customer
from repanier.models import Customer, BoxContent, DeliveryBoard, CustomerInvoice from repanier.models import Customer, BoxContent, DeliveryBoard, CustomerInvoice
from repanier.models import OfferItem from repanier.models import OfferItem
from repanier.models import Permanence from repanier.models import Permanence
from repanier.models import Producer, ProducerInvoice from repanier.models import Producer
from repanier.models import Product from repanier.models import Product
from repanier.models import Purchase from repanier.tools import clean_offer_item
from repanier.tools import clean_offer_item, update_or_create_purchase, get_signature
from repanier.tools import recalculate_order_amount, create_or_update_one_purchase, get_or_create_offer_item, \ from repanier.tools import recalculate_order_amount, create_or_update_one_purchase, get_or_create_offer_item, \
add_months, \ add_months, \
reorder_offer_items reorder_offer_items
...@@ -311,42 +308,19 @@ def automatically_closed(): ...@@ -311,42 +308,19 @@ def automatically_closed():
@transaction.atomic @transaction.atomic
def close_order_delivery(permanence, delivery, all_producers, producers_id=None): def close_order_delivery(permanence, delivery, all_producers, producers_id=None):
from repanier.apps import REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS
today = timezone.now().date() today = timezone.now().date()
getcontext().rounding = ROUND_HALF_UP getcontext().rounding = ROUND_HALF_UP
if repanier.apps.REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS: if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS:
purchase_qs = Purchase.objects.filter( # Cancel unconfirmed purchases whichever the producer is
customer_invoice_qs = CustomerInvoice.objects.filter(
permanence_id=permanence.id, permanence_id=permanence.id,
customer_invoice__delivery=delivery, delivery=delivery,
customer_invoice__is_order_confirm_send=False, is_order_confirm_send=False,
is_box_content=False total_price_with_tax__gt=DECIMAL_ZERO,
).exclude( )
quantity_ordered=DECIMAL_ZERO for customer_invoice in customer_invoice_qs:
).order_by('customer_invoice') customer_invoice.delete_if_unconfirmed(permanence)
if not all_producers:
# This may never be the but, but...
purchase_qs = purchase_qs.filter(producer_id__in=producers_id)
customer_invoice_id_save = -1
for purchase in purchase_qs.select_related("customer", "offer_item"):
if customer_invoice_id_save != purchase.customer_invoice_id:
customer_invoice_id_save =purchase.customer_invoice_id
# This order has been cancelled
# filename = force_filename("%s - %s.xlsx" % (_("Canceled order"), permanence))
filename = "{0}-{1}.xlsx".format(
slugify(_("Canceled order")),
slugify(permanence)
)
sender_email, sender_function, signature, cc_email_staff = get_signature(
is_reply_to_order_email=True)
export_order_2_1_customer(
purchase.customer, filename, permanence, sender_email,
sender_function, signature,
cancel_order=True)
update_or_create_purchase(
customer=purchase.customer,
offer_item_id=purchase.offer_item.id,
q_order=DECIMAL_ZERO,
batch_job=True
)
if all_producers: if all_producers:
# 1 - Do not round to multiple producer_order_by_quantity # 1 - Do not round to multiple producer_order_by_quantity
# 2 - Do not add Transport # 2 - Do not add Transport
...@@ -391,41 +365,19 @@ def close_order_delivery(permanence, delivery, all_producers, producers_id=None) ...@@ -391,41 +365,19 @@ def close_order_delivery(permanence, delivery, all_producers, producers_id=None)
@transaction.atomic @transaction.atomic
def close_order(permanence, all_producers, producers_id=None): def close_order(permanence, all_producers, producers_id=None):
from repanier.apps import REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS
getcontext().rounding = ROUND_HALF_UP getcontext().rounding = ROUND_HALF_UP
today = timezone.now().date() today = timezone.now().date()
if repanier.apps.REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS: if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS:
# 0 - Cancel unconfirmed purchases # Cancel unconfirmed purchases whichever the producer is
purchase_qs = Purchase.objects.filter( customer_invoice_qs = CustomerInvoice.objects.filter(
permanence_id=permanence.id, permanence_id=permanence.id,
customer_invoice__is_order_confirm_send=False, is_order_confirm_send=False,
is_box_content=False total_price_with_tax__gt=DECIMAL_ZERO,
).exclude( )
quantity_ordered=DECIMAL_ZERO for customer_invoice in customer_invoice_qs:
).order_by('customer_invoice') customer_invoice.delete_if_unconfirmed(permanence)
if not all_producers:
purchase_qs = purchase_qs.filter(producer_id__in=producers_id)
customer_invoice_id_save = -1
for purchase in purchase_qs.select_related("customer", "offer_item"):
if customer_invoice_id_save != purchase.customer_invoice_id:
customer_invoice_id_save = purchase.customer_invoice_id
# This order has been cancelled
filename = "{0}-{1}.xlsx".format(
slugify(_("Canceled order")),
slugify(permanence)
)
sender_email, sender_function, signature, cc_email_staff = get_signature(
is_reply_to_order_email=True)
export_order_2_1_customer(
purchase.customer, filename, permanence, sender_email,
sender_function, signature,
cancel_order=True)
update_or_create_purchase(
customer=purchase.customer,
offer_item_id=purchase.offer_item.id,
q_order=DECIMAL_ZERO,
batch_job=True
)
# 1 - Round to multiple producer_order_by_quantity # 1 - Round to multiple producer_order_by_quantity
offer_item_qs = OfferItem.objects.filter( offer_item_qs = OfferItem.objects.filter(
permanence_id=permanence.id, permanence_id=permanence.id,
......
...@@ -4,7 +4,6 @@ from __future__ import unicode_literals ...@@ -4,7 +4,6 @@ from __future__ import unicode_literals
import datetime import datetime
import json import json
from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder from django.core.serializers.json import DjangoJSONEncoder
from django.http import Http404 from django.http import Http404
from django.http import HttpResponse from django.http import HttpResponse
...@@ -16,7 +15,7 @@ from django.views.decorators.cache import never_cache ...@@ -16,7 +15,7 @@ from django.views.decorators.cache import never_cache
from django.views.decorators.http import require_GET from django.views.decorators.http import require_GET
from repanier.const import DECIMAL_ZERO, PERMANENCE_WAIT_FOR_INVOICED, PERMANENCE_OPENED, DECIMAL_ONE, \ from repanier.const import DECIMAL_ZERO, PERMANENCE_WAIT_FOR_INVOICED, PERMANENCE_OPENED, DECIMAL_ONE, \
PERMANENCE_CLOSED, REPANIER_MONEY_ZERO, EMPTY_STRING REPANIER_MONEY_ZERO, EMPTY_STRING
from repanier.models import Customer, Permanence, CustomerInvoice, PermanenceBoard, Staff, OfferItem, \ from repanier.models import Customer, Permanence, CustomerInvoice, PermanenceBoard, Staff, OfferItem, \
ProducerInvoice, Purchase ProducerInvoice, Purchase
from repanier.tools import sboolean, sint, display_selected_value, \ from repanier.tools import sboolean, sint, display_selected_value, \
...@@ -64,11 +63,8 @@ def order_init_ajax(request): ...@@ -64,11 +63,8 @@ def order_init_ajax(request):
raise Http404 raise Http404
my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax(), to_json) my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax(), to_json)
basket = sboolean(request.GET.get('ba', False)) basket = sboolean(request.GET.get('ba', False))
from repanier.apps import REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS, \ from repanier.apps import REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM, \
REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM, \
REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION
# if basket or (REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS
# and customer_invoice.is_order_confirm_send):
if customer_invoice.delivery is not None: if customer_invoice.delivery is not None:
status = customer_invoice.delivery.status status = customer_invoice.delivery.status
else: else:
...@@ -89,14 +85,6 @@ def order_init_ajax(request): ...@@ -89,14 +85,6 @@ def order_init_ajax(request):
basket_message=basket_message, basket_message=basket_message,
to_json=to_json to_json=to_json
) )
# else:
# if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS:
# my_order_confirmation(
# permanence=permanence,
# customer_invoice=customer_invoice,
# is_basket=basket,
# to_json=to_json
# )
if customer.may_order: if customer.may_order:
if REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM: if REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM:
for producer in permanence.producers.all(): for producer in permanence.producers.all():
......
# -*- coding: utf-8 # -*- coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from django.http import HttpResponse
from django.utils import translation from django.utils import translation
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from openpyxl.style import Fill from openpyxl.style import Fill
...@@ -27,6 +26,7 @@ def next_purchase(purchases): ...@@ -27,6 +26,7 @@ def next_purchase(purchases):
def export_abstract(permanence, deliveries_id=None, group=False, wb=None): def export_abstract(permanence, deliveries_id=None, group=False, wb=None):
if permanence is not None: if permanence is not None:
from repanier.apps import REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS
row_num = 1 row_num = 1
# Customer info # Customer info
Customer.objects.all().update(preparation_order=0) Customer.objects.all().update(preparation_order=0)
...@@ -54,9 +54,13 @@ def export_abstract(permanence, deliveries_id=None, group=False, wb=None): ...@@ -54,9 +54,13 @@ def export_abstract(permanence, deliveries_id=None, group=False, wb=None):
customer.preparation_order = preparation_order customer.preparation_order = preparation_order
customer.save(update_fields=['preparation_order']) customer.save(update_fields=['preparation_order'])
preparation_order += 1 preparation_order += 1
if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS and not invoice.is_order_confirm_send:
confirmed = _(" /!\ Unconfirmed")
else:
confirmed = EMPTY_STRING
row = [ row = [
"N/A", "N/A",
" %d - %s" % (customer.preparation_order, customer.long_basket_name), " %d - %s%s" % (customer.preparation_order, customer.long_basket_name, confirmed),
customer.phone1, customer.phone1,
customer.phone2, customer.phone2,
invoice.total_price_with_tax.amount, invoice.total_price_with_tax.amount,
...@@ -92,10 +96,13 @@ def export_abstract(permanence, deliveries_id=None, group=False, wb=None): ...@@ -92,10 +96,13 @@ def export_abstract(permanence, deliveries_id=None, group=False, wb=None):
customer.preparation_order = preparation_order customer.preparation_order = preparation_order
customer.save(update_fields=['preparation_order']) customer.save(update_fields=['preparation_order'])
preparation_order += 1 preparation_order += 1
if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS and not invoice.is_order_confirm_send:
confirmed = _(" /!\ Unconfirmed")
else:
confirmed = EMPTY_STRING
row = [ row = [
"%d - %s" % (delivery_ref, delivery.get_delivery_display()), "%d - %s" % (delivery_ref, delivery.get_delivery_display()),
" %d - %s" % (customer.preparation_order, customer.long_basket_name), " %d - %s%s" % (customer.preparation_order, customer.long_basket_name, confirmed),
customer.phone1, customer.phone1,
customer.phone2, customer.phone2,
invoice.total_price_with_tax.amount, invoice.total_price_with_tax.amount,
...@@ -139,9 +146,12 @@ def export_abstract(permanence, deliveries_id=None, group=False, wb=None): ...@@ -139,9 +146,12 @@ def export_abstract(permanence, deliveries_id=None, group=False, wb=None):
customer.preparation_order = preparation_order customer.preparation_order = preparation_order
customer.save(update_fields=['preparation_order']) customer.save(update_fields=['preparation_order'])
preparation_order += 1 preparation_order += 1
if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS and not invoice.is_order_confirm_send:
confirmed = _(" /!\ Unconfirmed")
else:
confirmed = EMPTY_STRING
row = [ row = [
"%d - %s" % (customer.preparation_order, customer.short_basket_name), "%d - %s%s" % (customer.preparation_order, customer.long_basket_name, confirmed),
customer.long_basket_name, customer.long_basket_name,
customer.phone1, customer.phone1,
customer.phone2, customer.phone2,
......
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