コード例 #1
0
def order_description_view(request, permanence_id):
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, may_order=True).order_by('?').first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence = Permanence.objects.filter(id=permanence_id).order_by('?').first()
    permanence_ok_or_404(permanence)
    is_basket = request.GET.get('is_basket', EMPTY_STRING)
    is_like = request.GET.get('is_like', EMPTY_STRING)
    if permanence.contract is not None:
        all_dates = permanence.contract.all_dates
        len_all_dates = len(all_dates)
        if len_all_dates < 2:
            date_id = 'all'
        else:
            date_id = sint(request.GET.get('date'), -1)
            if date_id < 0 or date_id >= len_all_dates:
                date_id = 'all'
    else:
        all_dates = []
        date_id = 'all'
    producer_id = request.GET.get('producer', 'all')
    department_id = request.GET.get('department', 'all')
    box_id = request.GET.get('box', 'all')
    if box_id != 'all':
        is_box = True
        # Do not display "all department" as selected
        department_id = None
    else:
        is_box = False
    q = request.GET.get('q', None)

    template_name = get_repanier_template_name("order_description.html")
    return render(
        request, template_name,
        {
            'is_like': is_like,
            'is_basket': is_basket,
            'is_box': is_box,
            'q': q,
            'all_dates': all_dates,

            'date_id': date_id,
            'producer_id': producer_id,
            'department_id': department_id,
            'box_id': box_id,
            'permanence_id': permanence_id,
            'may_order': True,

            'permanence': permanence,

            'is_description_view': 'active'
        }
    )
コード例 #2
0
 def get(self, request, *args, **kwargs):
     self.first_page = kwargs.get('page', True)
     permanence_id = sint(kwargs.get('permanence_id', 0))
     self.permanence = Permanence.objects.filter(id=permanence_id).only(
         "id", "status", "permanence_date", "with_delivery_point",
         "contract").order_by('?').first()
     permanence_ok_or_404(self.permanence)
     self.user = request.user
     self.is_basket = self.request.GET.get('is_basket', False)
     self.is_like = self.request.GET.get('is_like', False)
     if self.permanence.contract is not None and self.permanence.contract.permanences_dates is not None:
         self.all_dates = sorted(
             self.permanence.contract.permanences_dates.split(
                 settings.DJANGO_SETTINGS_DATES_SEPARATOR))
         len_all_dates = len(self.all_dates)
         if len_all_dates < 2:
             self.date_id = 'all'
         else:
             date_id = sint(self.request.GET.get('date'), -1)
             if date_id < 0 or date_id >= len_all_dates:
                 self.date_id = 'all'
             else:
                 self.date_id = date_id
                 self.date_selected = self.all_dates[date_id]
     customer_may_order = Customer.objects.filter(
         user_id=self.user.id, is_active=True).order_by('?').exists()
     if self.user.is_anonymous or not customer_may_order:
         self.is_anonymous = True
         self.may_order = False
     else:
         self.is_anonymous = False
         customer = self.user.customer
         self.may_order = customer.may_order if customer is not None else False
     self.q = self.request.GET.get('q', None)
     if not self.q:
         self.producer_id = self.request.GET.get('producer', 'all')
         if self.producer_id != 'all':
             self.producer_id = sint(self.producer_id)
         self.department_id = self.request.GET.get('department', 'all')
         if self.department_id != 'all':
             self.department_id = sint(self.department_id)
         self.box_id = self.request.GET.get('box', 'all')
         if self.box_id != 'all':
             self.box_id = sint(self.box_id)
             self.is_box = True
             # Do not display "all department" as selected
             self.department_id = None
     if len(request.GET) == 0:
         # This to let display a communication into a popup when the user is on the first order screen
         self.communication = True
     else:
         self.communication = False
     return super(OrderView, self).get(request, *args, **kwargs)
コード例 #3
0
def customer_product_description_ajax(request):
    if request.is_ajax():
        offer_item_id = sint(request.GET.get('offer_item', 0))
        offer_item = get_object_or_404(OfferItem, id=offer_item_id)
        permanence = offer_item.permanence
        permanence_ok_or_404(permanence)
        if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
            html = render_to_string(
                template_order_product_description,
                {'offer': offer_item, 'MEDIA_URL': settings.MEDIA_URL}
            )
            return JsonResponse({"#orderModal": mark_safe(html)})
    raise Http404
コード例 #4
0
def customer_product_description_ajax(request):
    if request.is_ajax():
        offer_item_id = sint(request.GET.get('offer_item', 0))
        offer_item = get_object_or_404(OfferItem, id=offer_item_id)
        permanence = offer_item.permanence
        permanence_ok_or_404(permanence)
        if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
            html = render_to_string(template_order_product_description, {
                'offer': offer_item,
                'MEDIA_URL': settings.MEDIA_URL
            })
            return JsonResponse({"#orderModal": mark_safe(html)})
    raise Http404
コード例 #5
0
ファイル: order_class.py プロジェクト: pcolmant/repanier
 def get(self, request, *args, **kwargs):
     self.first_page = kwargs.get('page', True)
     permanence_id = sint(kwargs.get('permanence_id', 0))
     self.permanence = Permanence.objects.filter(id=permanence_id).only(
         "id", "status", "permanence_date", "with_delivery_point", "contract"
     ).order_by('?').first()
     permanence_ok_or_404(self.permanence)
     self.user = request.user
     self.is_basket = self.request.GET.get('is_basket', False)
     self.is_like = self.request.GET.get('is_like', False)
     if self.permanence.contract is not None and self.permanence.contract.permanences_dates is not None:
         self.all_dates = sorted(
             self.permanence.contract.permanences_dates.split(settings.DJANGO_SETTINGS_DATES_SEPARATOR))
         len_all_dates = len(self.all_dates)
         if len_all_dates < 2:
             self.date_id = 'all'
         else:
             date_id = sint(self.request.GET.get('date'), -1)
             if date_id < 0 or date_id >= len_all_dates:
                 self.date_id = 'all'
             else:
                 self.date_id = date_id
                 self.date_selected = self.all_dates[date_id]
     customer_may_order = Customer.objects.filter(user_id=self.user.id, is_active=True).order_by('?').exists()
     if self.user.is_anonymous or not customer_may_order:
         self.is_anonymous = True
         self.may_order = False
     else:
         self.is_anonymous = False
         customer = self.user.customer
         self.may_order = customer.may_order if customer is not None else False
     self.q = self.request.GET.get('q', None)
     if not self.q:
         self.producer_id = self.request.GET.get('producer', 'all')
         if self.producer_id != 'all':
             self.producer_id = sint(self.producer_id)
         self.department_id = self.request.GET.get('department', 'all')
         if self.department_id != 'all':
             self.department_id = sint(self.department_id)
         self.box_id = self.request.GET.get('box', 'all')
         if self.box_id != 'all':
             self.box_id = sint(self.box_id)
             self.is_box = True
             # Do not display "all department" as selected
             self.department_id = None
     if len(request.GET) == 0:
         # This to let display a communication into a popup when the user is on the first order screen
         self.communication = True
     else:
         self.communication = False
     return super(OrderView, self).get(request, *args, **kwargs)
コード例 #6
0
 def dispatch(self, request, *args, **kwargs):
     permanence_id = sint(kwargs.get('permanence_id', 0))
     self.permanence = Permanence.objects.filter(id=permanence_id).only("id", "status", "permanence_date",
                                                                        "with_delivery_point").order_by('?').first()
     permanence_ok_or_404(self.permanence)
     self.user = request.user
     self.basket = kwargs.get('basket', False)
     if not self.basket:
         self.like = kwargs.get('like', False)
     else:
         # Not both favorite and basket
         self.like = False
     if self.permanence.with_delivery_point:
         self.delivery_id = sint(kwargs.get('delivery_id', 0))
     if self.user.is_anonymous() or self.user.is_staff:
         self.is_anonymous = True
         self.may_order = False
         self.q = None
     else:
         self.is_anonymous = False
         customer = self.user.customer
         self.may_order = customer.may_order if customer is not None else False
         self.q = self.request.GET.get('q', None)
         if self.q == EMPTY_STRING:
             self.q = None
     self.producer_id = self.request.GET.get('producer', 'all')
     if self.producer_id != 'all':
         self.producer_id = sint(self.producer_id)
     self.departementforcustomer_id = self.request.GET.get('departementforcustomer', 'all')
     if self.departementforcustomer_id != 'all':
         self.departementforcustomer_id = sint(self.departementforcustomer_id)
     self.box_id = self.request.GET.get('box', 'all')
     if self.box_id != 'all':
         self.box_id = sint(self.box_id)
         self.is_box = True
         # Do not display "all department" as selected
         self.departementforcustomer_id = None
     else:
         self.is_box = False
     if self.producer_id == 'all' and self.departementforcustomer_id == 'all' \
             and not self.basket and 'page' not in request.GET \
             and self.q is None:
         # This to let display a communication into a popup when the user is on the first order screen
         self.communication = True
     else:
         self.communication = False
     return super(OrderView, self).dispatch(request, *args, **kwargs)
コード例 #7
0
    def get(self, request, *args, **kwargs):
        self.first_page = kwargs.get("page", True)
        permanence_id = sint(kwargs.get("permanence_id", 0))
        self.permanence = (
            Permanence.objects.filter(id=permanence_id)
            .only("id", "status", "permanence_date", "with_delivery_point")
            .order_by("?")
            .first()
        )
        permanence_ok_or_404(self.permanence)
        self.user = request.user
        self.is_basket = self.request.GET.get("is_basket", False)
        self.is_like = self.request.GET.get("is_like", False)
        customer_may_order = (
            Customer.objects.filter(user_id=self.user.id, is_active=True)
            .order_by("?")
            .exists()
        )
        if self.user.is_anonymous or not customer_may_order:
            self.is_anonymous = True
            self.may_order = False
        else:
            self.is_anonymous = False
            customer = self.user.customer
            self.may_order = customer.may_order if customer is not None else False
        self.q = self.request.GET.get("q", None)
        if not self.q:
            self.producer_id = self.request.GET.get("producer", "all")
            if self.producer_id != "all":
                self.producer_id = sint(self.producer_id)
            self.department_id = self.request.GET.get("department", "all")
            if self.department_id != "all":
                self.department_id = sint(self.department_id)
            self.box_id = self.request.GET.get("box", "all")
            if self.box_id != "all":
                self.box_id = sint(self.box_id)
                self.is_box = True
                # Do not display "all department" as selected
                self.department_id = None
        if len(request.GET) == 0:
            # This to let display a communication into a popup when the user is on the first order screen
            self.communication = True
        else:
            self.communication = False

        return super(OrderView, self).get(request, *args, **kwargs)
コード例 #8
0
ファイル: order_class.py プロジェクト: CenaZ/repanier
 def get(self, request, *args, **kwargs):
     self.first_page = kwargs.get('page', True)
     permanence_id = sint(kwargs.get('permanence_id', 0))
     self.permanence = Permanence.objects.filter(id=permanence_id).only(
         "id", "status", "permanence_date",
         "with_delivery_point").order_by('?').first()
     permanence_ok_or_404(self.permanence)
     self.user = request.user
     self.is_basket = self.request.GET.get('is_basket', False)
     self.is_like = self.request.GET.get('is_like', False)
     customer_may_order = Customer.objects.filter(
         user_id=self.user.id, is_active=True).order_by('?').exists()
     if self.user.is_anonymous or not customer_may_order:
         self.is_anonymous = True
         self.may_order = False
     else:
         self.is_anonymous = False
         customer = self.user.customer
         self.may_order = customer.may_order if customer is not None else False
     self.q = self.request.GET.get('q', None)
     self.producer_id = self.request.GET.get('producer', 'all')
     if self.producer_id != 'all':
         self.producer_id = sint(self.producer_id)
     self.departementforcustomer_id = self.request.GET.get(
         'departementforcustomer', 'all')
     if self.departementforcustomer_id != 'all':
         self.departementforcustomer_id = sint(
             self.departementforcustomer_id)
     self.box_id = self.request.GET.get('box', 'all')
     if self.box_id != 'all':
         self.box_id = sint(self.box_id)
         self.is_box = True
         # Do not display "all department" as selected
         self.departementforcustomer_id = None
     else:
         self.is_box = False
     if self.producer_id == 'all' and self.departementforcustomer_id == 'all' \
             and not self.is_basket and 'page' not in request.GET \
             and self.q is None:
         # This to let display a communication into a popup when the user is on the first order screen
         self.communication = True
     else:
         self.communication = False
     return super(OrderView, self).get(request, *args, **kwargs)
コード例 #9
0
def btn_confirm_order_ajax(request):
    if not request.is_ajax():
        raise Http404
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, may_order=True).order_by('?').first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence_id = sint(request.GET.get('permanence', 0))
    permanence = Permanence.objects.filter(id=permanence_id).order_by('?').first()
    permanence_ok_or_404(permanence)
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence_id,
        customer_id=customer.id,
        is_order_confirm_send=False,
        is_group=False,
    ).order_by('?').first()
    if customer_invoice is None:
        raise Http404
    filename = "{}-{}.xlsx".format(
        _("Order"),
        permanence
    )
    export_order_2_1_customer(customer, filename, permanence)
    customer_invoice.confirm_order()
    customer_invoice.save()
    json_dict = my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax())
    if customer_invoice.delivery is not None:
        status = customer_invoice.delivery.status
    else:
        status = customer_invoice.status
    basket_message = get_html_basket_message(
        customer,
        permanence,
        status
    )
    json_dict.update(customer_invoice.get_html_my_order_confirmation(
        permanence=permanence,
        is_basket=True,
        basket_message=basket_message
    ))
    return JsonResponse(json_dict)
コード例 #10
0
def customer_product_description_ajax(request):
    if request.is_ajax():
        offer_item_id = sint(request.GET.get("offer_item", 0))
        offer_item = get_object_or_404(OfferItem, id=offer_item_id)
        permanence = offer_item.permanence
        permanence_ok_or_404(permanence)
        if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
            try:
                result = offer_item.cache_part_e
                result = html_box_content(offer_item, request.user, result)

                if result is None or result == EMPTY_STRING:
                    result = "%s" % _("There is no more product's information")
            except TranslationDoesNotExist:
                result = "%s" % _("There is no more product's information")
        else:
            result = "%s" % _("There is no more product's information")
        return HttpResponse(result)
    raise Http404
コード例 #11
0
def order_description_view(request, permanence_id):
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, may_order=True).first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence = Permanence.objects.filter(id=permanence_id).first()
    permanence_ok_or_404(permanence)
    is_basket = request.GET.get('is_basket', EMPTY_STRING)
    is_like = request.GET.get('is_like', EMPTY_STRING)
    producer_id = request.GET.get('producer', 'all')
    department_id = request.GET.get('department', 'all')
    box_id = request.GET.get('box', 'all')
    if box_id != 'all':
        is_box = True
        # Do not display "all department" as selected
        department_id = None
    else:
        is_box = False
    q = request.GET.get('q', None)

    template_name = get_repanier_template_name("order_description.html")
    return render(
        request, template_name,
        {
            'is_like': is_like,
            'is_basket': is_basket,
            'is_box': is_box,
            'q': q,
            'producer_id': producer_id,
            'department_id': department_id,
            'box_id': box_id,
            'permanence_id': permanence_id,
            'may_order': True,

            'permanence': permanence,

            'is_description_view': 'active'
        }
    )
コード例 #12
0
def customer_product_description_ajax(request):
    if request.is_ajax():
        offer_item_id = sint(request.GET.get('offer_item', 0))
        offer_item = get_object_or_404(OfferItem, id=offer_item_id)
        permanence = offer_item.permanence
        permanence_ok_or_404(permanence)
        if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
            offer_item.long_name = offer_item.product.long_name
            result = html_box_content(
                offer_item, request.user,
                render_to_string('repanier/cache_part_e.html', {
                    'offer': offer_item,
                    'MEDIA_URL': settings.MEDIA_URL
                }))

            if result is None or result == EMPTY_STRING:
                result = "%s" % _("There is no more product's information")
        else:
            result = "%s" % _("There is no more product's information")
        return HttpResponse(result)
    raise Http404
コード例 #13
0
def btn_confirm_order_ajax(request):
    if not request.is_ajax():
        raise Http404
    user = request.user
    customer = Customer.objects.filter(user_id=user.id, may_order=True).first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence_id = sint(request.GET.get('permanence', 0))
    permanence = Permanence.objects.filter(id=permanence_id).first()
    permanence_ok_or_404(permanence)
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence_id,
        customer_id=customer.id,
        is_order_confirm_send=False,
        is_group=False,
    ).first()
    if customer_invoice is None:
        raise Http404
    filename = "{}-{}.xlsx".format(_("Order"), permanence)
    export_order_2_1_customer(customer, filename, permanence)
    customer_invoice.confirm_order()
    customer_invoice.save()
    json_dict = my_basket(customer_invoice.is_order_confirm_send,
                          customer_invoice.get_total_price_with_tax())
    if customer_invoice.delivery is not None:
        status = customer_invoice.delivery.status
    else:
        status = customer_invoice.status
    basket_message = get_html_basket_message(customer, permanence, status)
    json_dict.update(
        customer_invoice.get_html_my_order_confirmation(
            permanence=permanence,
            is_basket=True,
            basket_message=basket_message))
    return JsonResponse(json_dict)
コード例 #14
0
ファイル: order_init_ajax.py プロジェクト: pcolmant/repanier
def order_init_ajax(request):
    if not request.is_ajax():
        raise Http404
    permanence_id = sint(request.GET.get('pe', 0))
    permanence = Permanence.objects.filter(id=permanence_id).order_by('?').first()
    permanence_ok_or_404(permanence)
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, may_order=True
    ).only(
        "id", "vat_id", "short_basket_name", "email2", "delivery_point",
        "balance", "date_balance", "may_order"
    ).order_by('?').first()
    if customer is None:
        raise Http404
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence.id,
        customer_id=customer.id
    ).order_by('?').first()
    if customer_invoice is None:
        customer_invoice = CustomerInvoice.objects.create(
            permanence_id=permanence.id,
            customer_id=customer.id,
            status=permanence.status,
            customer_charged_id=customer.id,
        )
        customer_invoice.set_order_delivery(delivery=None)
        customer_invoice.calculate_order_price()
        customer_invoice.save()

    if customer_invoice is None:
        raise Http404

    basket = sboolean(request.GET.get('ba', False))

    if customer_invoice.delivery is not None:
        status = customer_invoice.delivery.status
    else:
        status = customer_invoice.status
    if status <= PERMANENCE_OPENED:
        basket_message = get_html_basket_message(customer, permanence, status)
    else:
        if customer_invoice.delivery is not None:
            basket_message = EMPTY_STRING
        else:
            basket_message = "{}".format(
                _('The orders are closed.')
            )
    if settings.REPANIER_SETTINGS_TEMPLATE == "bs3":
        json_dict = customer_invoice.get_html_my_order_confirmation(
            permanence=permanence,
            is_basket=basket,
            basket_message=basket_message
        )
    else:
        json_dict = {}
    if customer.may_order:
        if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM:
            for producer_invoice in ProducerInvoice.objects.filter(
                    permanence_id=permanence.id
            ).only(
                "total_price_with_tax", "status"
            ).order_by('?'):
                json_dict.update(producer_invoice.get_order_json())
        communication = sboolean(request.GET.get('co', False))
        if communication:
            now = timezone.now()
            permanence_boards = PermanenceBoard.objects.filter(
                customer_id=customer.id,
                permanence_date__gte=now,
                permanence__status__lte=PERMANENCE_WAIT_FOR_INVOICED
            ).order_by("permanence_date")[:2]
            from repanier.apps import REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION
            if REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION > DECIMAL_ZERO or len(permanence_boards) > 0:
                if len(permanence_boards) == 0:
                    count_activity = PermanenceBoard.objects.filter(
                        customer_id=customer.id, permanence_date__lt=now,
                        permanence_date__gte=now - datetime.timedelta(
                            days=float(REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION) * 7
                        )
                    ).count()
                else:
                    count_activity = None
                template_name = get_repanier_template_name("communication_permanence_board.html")
                html = render_to_string(
                    template_name,
                    {'permanence_boards': permanence_boards, 'count_activity': count_activity}
                )
                json_dict["#communicationModal"] = mark_safe(html)
    json_dict.update(my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax()))
    return JsonResponse(json_dict)
コード例 #15
0
ファイル: order_init_ajax.py プロジェクト: comdragon/repanier
def order_init_ajax(request):
    if not request.is_ajax():
        raise Http404
    permanence_id = sint(request.GET.get('pe', 0))
    permanence = Permanence.objects.filter(
        id=permanence_id).order_by('?').first()
    permanence_ok_or_404(permanence)
    user = request.user
    customer = Customer.objects.filter(user_id=user.id, may_order=True).only(
        "id", "vat_id", "short_basket_name", "email2", "delivery_point",
        "balance", "date_balance", "may_order").order_by('?').first()
    if customer is None:
        raise Http404
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence.id,
        customer_id=customer.id).order_by('?').first()
    if customer_invoice is None:
        customer_invoice = CustomerInvoice.objects.create(
            permanence_id=permanence.id,
            customer_id=customer.id,
            status=permanence.status,
            customer_charged_id=customer.id,
        )
        customer_invoice.set_delivery(delivery=None)
        customer_invoice.save()

    if customer_invoice is None:
        raise Http404

    basket = sboolean(request.GET.get('ba', False))

    if customer_invoice.delivery is not None:
        status = customer_invoice.delivery.status
    else:
        status = customer_invoice.status
    if status <= PERMANENCE_OPENED:
        basket_message = get_html_basket_message(customer, permanence, status)
    else:
        if customer_invoice.delivery is not None:
            basket_message = EMPTY_STRING
        else:
            basket_message = "{}".format(_('The orders are closed.'))
    json_dict = customer_invoice.get_html_my_order_confirmation(
        permanence=permanence, is_basket=basket, basket_message=basket_message)
    if customer.may_order:
        if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM:
            for producer_invoice in ProducerInvoice.objects.filter(
                    permanence_id=permanence.id).only("total_price_with_tax",
                                                      "status").order_by('?'):
                json_dict.update(producer_invoice.get_order_json())
        communication = sboolean(request.GET.get('co', False))
        if communication:
            now = timezone.now()
            permanence_boards = PermanenceBoard.objects.filter(
                customer_id=customer.id,
                permanence_date__gte=now,
                permanence__status__lte=PERMANENCE_WAIT_FOR_INVOICED).order_by(
                    "permanence_date")[:2]
            from repanier.apps import REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION
            if REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION > DECIMAL_ZERO or len(
                    permanence_boards) > 0:
                if len(permanence_boards) == 0:
                    count_activity = PermanenceBoard.objects.filter(
                        customer_id=customer.id,
                        permanence_date__lt=now,
                        permanence_date__gte=now -
                        datetime.timedelta(days=float(
                            REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION) *
                                           7)).count()
                else:
                    count_activity = None
                html = render_to_string(
                    'repanier/communication_permanence_board.html', {
                        'permanence_boards': permanence_boards,
                        'count_activity': count_activity
                    })
                json_dict["#communicationModal"] = mark_safe(html)
    json_dict.update(
        my_basket(customer_invoice.is_order_confirm_send,
                  customer_invoice.get_total_price_with_tax()))
    return JsonResponse(json_dict)
コード例 #16
0
def order_filter_view(request, permanence_id):
    permanence = Permanence.objects.filter(
        id=permanence_id).order_by('?').first()
    permanence_ok_or_404(permanence)
    if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM:
        producer_set = Producer.objects.filter(permanence=permanence_id).only(
            "id", "short_profile_name")
    else:
        producer_set = None
    is_basket = request.GET.get('is_basket', EMPTY_STRING)
    is_like = request.GET.get('is_like', EMPTY_STRING)
    if permanence.contract is not None:
        all_dates = permanence.contract.all_dates
        len_all_dates = len(all_dates)
        if len_all_dates < 2:
            date_id = 'all'
        else:
            date_id = sint(request.GET.get('date'), -1)
            if date_id < 0 or date_id >= len_all_dates:
                date_id = 'all'
    else:
        all_dates = []
        date_id = 'all'
    producer_id = request.GET.get('producer', 'all')
    department_id = request.GET.get('department', 'all')
    box_id = request.GET.get('box', 'all')
    if box_id != 'all':
        is_box = True
        # Do not display "all department" as selected
        department_id = None
    else:
        is_box = False
    q = request.GET.get('q', None)
    department_set = LUT_DepartmentForCustomer.objects.filter(
        offeritem__permanence_id=permanence_id,
        offeritem__is_active=True,
        offeritem__is_box=False) \
        .order_by("tree_id", "lft") \
        .distinct("id", "tree_id", "lft")
    if producer_id != 'all':
        department_set = department_set.filter(
            offeritem__producer_id=producer_id)
    return render(
        request, "repanier/order_filter.html", {
            'is_like':
            is_like,
            'is_basket':
            is_basket,
            'is_box':
            is_box,
            'q':
            q,
            'all_dates':
            all_dates,
            'date_id':
            date_id,
            'producer_set':
            producer_set,
            'producer_id':
            producer_id,
            'department_set':
            department_set,
            'department_id':
            department_id,
            'box_set':
            OfferItemWoReceiver.objects.filter(
                permanence_id=permanence_id,
                is_box=True,
                is_active=True,
                may_order=True,
                translations__language_code=translation.get_language()).
            order_by(
                'customer_unit_price',
                'unit_deposit',
                'translations__long_name',
            ),
            'box_id':
            box_id,
            'permanence_id':
            permanence_id,
            'may_order':
            True
        })
コード例 #17
0
def order_filter_view(request, permanence_id):
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, may_order=True).order_by('?').first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence = Permanence.objects.filter(id=permanence_id).order_by('?').first()
    permanence_ok_or_404(permanence)
    is_basket = request.GET.get('is_basket', EMPTY_STRING)
    is_like = request.GET.get('is_like', EMPTY_STRING)
    producer_id = request.GET.get('producer', 'all')
    department_id = request.GET.get('department', 'all')
    box_id = request.GET.get('box', 'all')
    if box_id != 'all':
        is_box = True
        # Do not display "all department" as selected
        department_id = None
    else:
        is_box = False
    q = request.GET.get('q', None)

    if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM:
        producer_set = Producer.objects.filter(permanence=permanence_id).only("id", "short_profile_name")
    else:
        producer_set = None

    department_set = LUT_DepartmentForCustomer.objects.filter(
        offeritem__permanence_id=permanence_id,
        offeritem__is_active=True,
        offeritem__is_box=False
    ).order_by(
        "tree_id", "lft"
    ).distinct(
        "id", "tree_id", "lft"
    )
    if producer_id != 'all':
        department_set = department_set.filter(
            offeritem__producer_id=producer_id
        )

    box_set = OfferItemWoReceiver.objects.filter(
        permanence_id=permanence_id,
        is_box=True,
        is_active=True,
        may_order=True,
        translations__language_code=translation.get_language()
    ).order_by(
        'customer_unit_price',
        'unit_deposit',
        'translations__long_name',
    )

    template_name = get_repanier_template_name("order_filter.html")
    return render(
        request, template_name,
        {
            'is_like': is_like,
            'is_basket': is_basket,
            'is_box': is_box,
            'q': q,
            'producer_id': producer_id,
            'department_id': department_id,
            'box_id': box_id,
            'permanence_id': permanence_id,
            'may_order': True,

            'producer_set': producer_set,
            'department_set': department_set,
            'box_set': box_set,

            'is_filter_view': 'active'

        }
    )
コード例 #18
0
def order_init_ajax(request):
    if not request.is_ajax():
        raise Http404
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, is_active=True
    ).only(
        "id", "vat_id", "short_basket_name", "email2", "delivery_point",
        "balance", "date_balance", "may_order"
    ).order_by('?').first()
    if customer is None:
        raise Http404

    permanence_id = sint(request.GET.get('pe', 0))
    permanence = Permanence.objects.filter(id=permanence_id).order_by('?').first()
    permanence_ok_or_404(permanence)
    to_json = []
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence.id,
        customer_id=customer.id
    ).order_by('?').first()
    if customer_invoice is None:
        customer_invoice = CustomerInvoice.objects.create(
            permanence_id=permanence.id,
            customer_id=customer.id,
            status=permanence.status,
            customer_charged_id=customer.id,
        )
        customer_invoice.set_delivery(delivery=None)
        customer_invoice.save()

    if customer_invoice is None:
        raise Http404

    basket = sboolean(request.GET.get('ba', False))
    from repanier.apps import REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM, \
        REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION
    if customer_invoice.delivery is not None:
        status = customer_invoice.delivery.status
    else:
        status = customer_invoice.status
    if status <= PERMANENCE_OPENED:
        basket_message = calc_basket_message(customer, permanence, status)
    else:
        if customer_invoice.delivery is not None:
            basket_message = EMPTY_STRING
        else:
            basket_message = "%s" % (
                _('The orders are closed.'),
            )
    customer_invoice.my_order_confirmation(
        permanence=permanence,
        is_basket=basket,
        basket_message=basket_message,
        to_json=to_json
    )
    if customer.may_order:
        if REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM:
            for producer_invoice in ProducerInvoice.objects.filter(
                permanence_id=permanence.id
            ).only(
                "total_price_with_tax", "status"
            ).order_by('?'):
                producer_invoice.get_order_json(to_json)
        communication = sboolean(request.GET.get('co', False))
        if communication \
                and customer_invoice.total_price_with_tax == DECIMAL_ZERO \
                and not customer_invoice.is_order_confirm_send:
            now = timezone.now()
            permanence_boards = PermanenceBoard.objects.filter(
                customer_id=customer.id,
                permanence_date__gte=now,
                permanence__status__lte=PERMANENCE_WAIT_FOR_INVOICED
            ).order_by("permanence_date")[:2]
            is_staff = Staff.objects.filter(
                customer_responsible_id=customer.id
            ).order_by('?').exists()
            if (not is_staff and REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION > DECIMAL_ZERO) \
                    or len(permanence_boards) > 0:
                if len(permanence_boards) == 0:
                    count_activity = PermanenceBoard.objects.filter(
                        customer_id=customer.id, permanence_date__lt=now,
                        permanence_date__gte=now - datetime.timedelta(
                            days=float(REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION) * 7
                        )
                    ).count()
                else:
                    count_activity = None
                html = render_to_string(
                    'repanier/communication_permanence_board.html',
                    {'permanence_boards': permanence_boards, 'count_activity': count_activity})
                option_dict = {'id': "#communication", 'html': html}
                to_json.append(option_dict)
    my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax(), to_json)
    return HttpResponse(json.dumps(to_json, cls=DjangoJSONEncoder), content_type="application/json")