Commit c4be8a86 authored by Patrick's avatar Patrick

Display new products to customers

parent 634a42f5
......@@ -127,22 +127,13 @@ def send_open_order(permanence_id):
)
for o in qs
),)
two_weeks_ago = timezone.now().date() - datetime.timedelta(days=14)
qs = qs.filter(product__is_updated_on__gte=two_weeks_ago)
offer_recent_detail = '<ul>%s</ul>' % ("".join('<li>%s, %s, %s</li>' % (
o.get_long_name(box_unicode=EMPTY_STRING),
o.producer.short_profile_name,
o.email_offer_price_with_vat,
)
for o in qs
),)
template = Template(offer_customer_mail)
context = TemplateContext({
'permanence_link' : mark_safe('<a href="http://%s%s">%s</a>' % (
settings.ALLOWED_HOSTS[0], reverse('order_view', args=(permanence.id,)), permanence)),
'offer_description': mark_safe(offer_description),
'offer_detail' : mark_safe(offer_detail),
'offer_recent_detail' : mark_safe(offer_recent_detail),
'offer_recent_detail' : mark_safe(permanence.get_new_products),
'offer_producer' : offer_producer,
'signature' : mark_safe(
'%s<br/>%s<br/>%s' % (signature, sender_function, REPANIER_SETTINGS_GROUP_NAME))
......
......@@ -119,13 +119,11 @@ class Configuration(TranslatableModel):
"""
Bonjour,<br />
<br />
Les commandes de la {{ permanence_link }} sont maintenant ouvertes.<br />
Les commandes de la {{ permanence_link }} sont maintenant ouvertes auprès de : {{ offer_producer }}.<br />
{% if offer_description %}{{ offer_description }}<br />
{% endif %} Les commandes sont ouvertes auprès de : {{ offer_producer }}.<br />
<br />
Les produits suivants sont en offre :<br />
{{ offer_detail }}<br />
{{ offer_recent_detail }}<br />
{% endif %}
{% if offer_recent_detail %}<br />Nouveauté(s) :<br />
{{ offer_recent_detail }}{% endif %}<br />
<br />
{{ signature }}
""",
......
......@@ -6,10 +6,11 @@ import datetime
from django.conf import settings
from django.core import urlresolvers
from django.core.cache import cache
from django.db import models, transaction
from django.db import models
from django.db.models import F, Sum
from django.utils import timezone, translation
from django.utils.encoding import python_2_unicode_compatible
from django.utils.functional import cached_property
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from djangocms_text_ckeditor.fields import HTMLField
......@@ -446,9 +447,7 @@ class Permanence(TranslatableModel):
else:
self.save(update_fields=['status', 'is_updated_on', 'highest_status'])
if new_status == PERMANENCE_WAIT_FOR_OPEN:
for a_producer in producer.Producer.objects.filter(
permanence=self.id
).only('id').order_by('?'):
for a_producer in self.producers.all():
# Create ProducerInvoice to be able to close those producer on demand
if not invoice.ProducerInvoice.objects.filter(
permanence_id=self.id,
......@@ -574,8 +573,8 @@ class Permanence(TranslatableModel):
except TranslationDoesNotExist:
pass
translation.activate(cur_language)
for producer in self.producers.all():
new_permanence.producers.add(producer)
for a_producer in self.producers.all():
new_permanence.producers.add(a_producer)
return creation_counter
def duplicate_short_name(self, new_permanence, cur_language):
......@@ -761,6 +760,60 @@ class Permanence(TranslatableModel):
self.total_purchase_vat += customer_vat
self.total_selling_vat += customer_vat
@cached_property
def get_new_products(self):
assert self.status < PERMANENCE_SEND
result = []
for a_producer in self.producers.all():
current_products = list(offeritem.OfferItem.objects.filter(
is_active=True,
may_order=True,
order_unit__lt=PRODUCT_ORDER_UNIT_DEPOSIT, # Don't display technical products.
permanence_id=self.id,
producer=a_producer
).values_list(
'product', flat=True
).order_by('?'))
six_months_ago = timezone.now().date() - datetime.timedelta(days=6*30)
previous_permanence = Permanence.objects.filter(
status__gte=PERMANENCE_SEND,
producers=a_producer,
permanence_date__gte=six_months_ago
).order_by(
"-permanence_date",
"status"
).first()
if previous_permanence is not None:
previous_products = list(offeritem.OfferItem.objects.filter(
is_active=True,
may_order=True,
order_unit__lt=PRODUCT_ORDER_UNIT_DEPOSIT, # Don't display technical products.
permanence_id=previous_permanence.id,
producer=a_producer
).values_list(
'product', flat=True
).order_by('?'))
new_products = [item for item in current_products if item not in previous_products]
else:
new_products = current_products
qs = offeritem.OfferItem.objects.filter(
permanence_id=self.id,
product__in=new_products,
translations__language_code=translation.get_language()
).order_by(
"translations__order_sort_order"
)
for o in qs:
result.append('<li>%s, %s, %s</li>' % (
o.get_long_name(box_unicode=EMPTY_STRING),
o.producer.short_profile_name,
o.email_offer_price_with_vat,
))
if result:
return '<ul>%s</ul>' % "".join(result)
return EMPTY_STRING
def get_full_status_display(self):
need_to_refresh_status = self.status in [
PERMANENCE_WAIT_FOR_PRE_OPEN,
......
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