def delete_if_unconfirmed(self, permanence): if not self.is_order_confirm_send: from repanier.email.email_order import export_order_2_1_customer from repanier.models.purchase import Purchase 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.objects.filter( customer_invoice_id=self.id, is_box_content=False, ).order_by('?') for a_purchase in purchase_qs.select_related("customer"): create_or_update_one_cart_item( customer=a_purchase.customer, offer_item_id=a_purchase.offer_item_id, q_order=DECIMAL_ZERO, batch_job=True, comment=_("Cancelled qty : %s") % number_format(a_purchase.quantity_ordered, 4) )
def cancel_if_unconfirmed(self, permanence): if settings.REPANIER_SETTINGS_CUSTOMER_MUST_CONFIRM_ORDER \ and not self.is_order_confirm_send \ and self.has_purchase: from repanier.email.email_order import export_order_2_1_customer from repanier.models.purchase import Purchase filename = "{0}-{1}.xlsx".format(_("Canceled order"), permanence) export_order_2_1_customer(self.customer, filename, permanence, cancel_order=True) purchase_qs = Purchase.objects.filter( customer_invoice_id=self.id, is_box_content=False, ).order_by('?') for a_purchase in purchase_qs.select_related("customer"): create_or_update_one_cart_item( customer=a_purchase.customer, offer_item_id=a_purchase.offer_item_id, q_order=DECIMAL_ZERO, batch_job=True, comment=_("Qty not confirmed : {}").format( number_format(a_purchase.quantity_ordered, 4)))
def cancel_if_unconfirmed(self, permanence): if settings.REPANIER_SETTINGS_CUSTOMER_MUST_CONFIRM_ORDER \ and not self.is_order_confirm_send \ and self.has_purchase: from repanier.email.email_order import export_order_2_1_customer from repanier.models.purchase import PurchaseWoReceiver filename = "{}-{}.xlsx".format( _("Canceled order"), permanence ) export_order_2_1_customer( self.customer, filename, permanence, cancel_order=True ) purchase_qs = PurchaseWoReceiver.objects.filter( customer_invoice_id=self.id, is_box_content=False, ).order_by('?') for a_purchase in purchase_qs.select_related("customer"): create_or_update_one_cart_item( customer=a_purchase.customer, offer_item_id=a_purchase.offer_item_id, q_order=DECIMAL_ZERO, batch_job=True, comment=_("Qty not confirmed : {}").format(number_format(a_purchase.quantity_ordered, 4)) )
def 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 offer_item_id = sint(request.GET.get('offer_item', 0)) value_id = sint(request.GET.get('value', 0)) is_basket = sboolean(request.GET.get('is_basket', False)) qs = CustomerInvoice.objects.filter( permanence__offeritem=offer_item_id, customer_id=customer.id, status=PERMANENCE_OPENED).order_by('?') json_dict = {} if qs.exists(): qs = ProducerInvoice.objects.filter( permanence__offeritem=offer_item_id, producer__offeritem=offer_item_id, status=PERMANENCE_OPENED ).order_by('?') if qs.exists(): purchase, updated = create_or_update_one_cart_item( customer=customer, offer_item_id=offer_item_id, value_id=value_id, batch_job=False, comment=EMPTY_STRING ) offer_item = OfferItemWoReceiver.objects.filter( id=offer_item_id ).order_by('?').first() if purchase is None: json_dict["#offer_item{}".format(offer_item.id)] = get_html_selected_value(offer_item, DECIMAL_ZERO, is_open=True) else: json_dict["#offer_item{}".format(offer_item.id)] = get_html_selected_value(offer_item, purchase.quantity_ordered, is_open=True) if updated and offer_item.is_box: # update the content for content in BoxContent.objects.filter( box=offer_item.product_id ).only( "product_id" ).order_by('?'): box_offer_item = OfferItemWoReceiver.objects.filter( product_id=content.product_id, permanence_id=offer_item.permanence_id ).order_by('?').first() if box_offer_item is not None: # Select one purchase purchase = PurchaseWoReceiver.objects.filter( customer_id=customer.id, offer_item_id=box_offer_item.id, is_box_content=False ).order_by('?').only('quantity_ordered').first() if purchase is not None: json_dict["#offer_item{}".format(box_offer_item.id)] = get_html_selected_value( box_offer_item, purchase.quantity_ordered, is_open=True ) box_purchase = PurchaseWoReceiver.objects.filter( customer_id=customer.id, offer_item_id=box_offer_item.id, is_box_content=True ).order_by('?').only('quantity_ordered').first() if box_purchase is not None: json_dict["#box_offer_item{}".format(box_offer_item.id)] = get_html_selected_box_value( box_offer_item, box_purchase.quantity_ordered ) if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM: producer_invoice = ProducerInvoice.objects.filter( producer_id=offer_item.producer_id, permanence_id=offer_item.permanence_id ).only("total_price_with_tax").order_by('?').first() json_dict.update(producer_invoice.get_order_json()) customer_invoice = CustomerInvoice.objects.filter( permanence_id=offer_item.permanence_id, customer_id=customer.id ).order_by('?').first() invoice_confirm_status_is_changed = customer_invoice.cancel_confirm_order() if settings.REPANIER_SETTINGS_CUSTOMER_MUST_CONFIRM_ORDER and invoice_confirm_status_is_changed: template_name = get_repanier_template_name("communication_confirm_order.html") html = render_to_string(template_name) json_dict["#communicationModal"] = mark_safe(html) customer_invoice.save() json_dict.update( my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax())) permanence = Permanence.objects.filter( id=offer_item.permanence_id ).order_by('?').first() if is_basket: basket_message = get_html_basket_message(customer, permanence, PERMANENCE_OPENED) else: basket_message = EMPTY_STRING json_dict.update(customer_invoice.get_html_my_order_confirmation( permanence=permanence, is_basket=is_basket, basket_message=basket_message )) return JsonResponse(json_dict)
def order_ajax(request): if not request.is_ajax(): raise Http404 user = request.user customer = Customer.objects.filter(user_id=user.id, is_active=True, may_order=True).order_by('?').first() if customer is None: raise Http404 offer_item_id = sint(request.GET.get('offer_item', 0)) value_id = sint(request.GET.get('value', 0)) is_basket = sboolean(request.GET.get('is_basket', False)) qs = CustomerInvoice.objects.filter(permanence__offeritem=offer_item_id, customer_id=customer.id, status=PERMANENCE_OPENED).order_by('?') to_json = [] if qs.exists(): qs = ProducerInvoice.objects.filter( permanence__offeritem=offer_item_id, producer__offeritem=offer_item_id, status=PERMANENCE_OPENED).order_by('?') if qs.exists(): from repanier.apps import REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS, \ REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM purchase, updated = create_or_update_one_cart_item( customer=customer, offer_item_id=offer_item_id, value_id=value_id, is_basket=is_basket, batch_job=False) offer_item = OfferItemWoReceiver.objects.filter( id=offer_item_id).order_by('?').first() if purchase is None: if offer_item.is_box: sold_out = _("Sold out") option_dict = { 'id': "#offer_item%d" % offer_item.id, 'html': '<option value="0" selected>%s</option>' % sold_out } else: option_dict = display_selected_value(offer_item, DECIMAL_ZERO, is_open=True) to_json.append(option_dict) else: if offer_item is not None: option_dict = display_selected_value( offer_item, purchase.quantity_ordered, is_open=True) to_json.append(option_dict) if updated and offer_item.is_box: # update the content for content in BoxContent.objects.filter( box=offer_item.product_id).only("product_id").order_by( '?'): box_offer_item = OfferItem.objects.filter( product_id=content.product_id, permanence_id=offer_item.permanence_id).order_by( '?').first() if box_offer_item is not None: # Select one purchase purchase = PurchaseWoReceiver.objects.filter( customer_id=customer.id, offer_item_id=box_offer_item.id, is_box_content=False).order_by('?').only( 'quantity_ordered').first() if purchase is not None: option_dict = display_selected_value( box_offer_item, purchase.quantity_ordered, is_open=True) to_json.append(option_dict) box_purchase = PurchaseWoReceiver.objects.filter( customer_id=customer.id, offer_item_id=box_offer_item.id, is_box_content=True).order_by('?').only( 'quantity_ordered').first() if box_purchase is not None: option_dict = display_selected_box_value( box_offer_item, box_purchase.quantity_ordered) to_json.append(option_dict) if REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM: producer_invoice = ProducerInvoice.objects.filter( producer_id=offer_item.producer_id, permanence_id=offer_item.permanence_id).only( "total_price_with_tax").order_by('?').first() producer_invoice.get_order_json(to_json) customer_invoice = CustomerInvoice.objects.filter( permanence_id=offer_item.permanence_id, customer_id=customer.id).order_by('?').first() status_changed = customer_invoice.cancel_confirm_order() if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS and status_changed: html = render_to_string( 'repanier/communication_confirm_order.html') option_dict = {'id': "#communication", 'html': html} to_json.append(option_dict) customer_invoice.save() my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax(), to_json) permanence = Permanence.objects.filter( id=offer_item.permanence_id).order_by('?').first() if is_basket: basket_message = calc_basket_message(customer, permanence, PERMANENCE_OPENED) else: basket_message = EMPTY_STRING customer_invoice.my_order_confirmation( permanence=permanence, is_basket=is_basket, basket_message=basket_message, to_json=to_json) return HttpResponse(json.dumps(to_json, cls=DjangoJSONEncoder), content_type="application/json")
def order_ajax(request): """ Add a selected offer item to a customer order (i.e. update the customer's invoice and the producer's invoice) """ 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 offer_item_id = sint(request.GET.get('offer_item', 0)) value_id = sint(request.GET.get('value', 0)) is_basket = sboolean(request.GET.get('is_basket', False)) qs = CustomerInvoice.objects.filter( permanence__offeritem=offer_item_id, customer_id=customer.id, status=PERMANENCE_OPENED) json_dict = {} if qs.exists(): qs = ProducerInvoice.objects.filter( permanence__offeritem=offer_item_id, producer__offeritem=offer_item_id, status=PERMANENCE_OPENED ) if qs.exists(): purchase, updated = create_or_update_one_cart_item( customer=customer, offer_item_id=offer_item_id, value_id=value_id, batch_job=False, comment=EMPTY_STRING ) offer_item = OfferItemWoReceiver.objects.filter( id=offer_item_id ).first() if purchase is None: json_dict["#offer_item{}".format(offer_item.id)] = get_html_selected_value(offer_item, DECIMAL_ZERO, is_open=True) else: json_dict["#offer_item{}".format(offer_item.id)] = get_html_selected_value(offer_item, purchase.quantity_ordered, is_open=True) if updated and offer_item.is_box: # update the content for content in BoxContent.objects.filter( box=offer_item.product_id ).only( "product_id" ): box_offer_item = OfferItemWoReceiver.objects.filter( product_id=content.product_id, permanence_id=offer_item.permanence_id ).first() if box_offer_item is not None: # Select one purchase purchase = PurchaseWoReceiver.objects.filter( customer_id=customer.id, offer_item_id=box_offer_item.id, is_box_content=False ).only('quantity_ordered').first() if purchase is not None: json_dict["#offer_item{}".format(box_offer_item.id)] = get_html_selected_value( box_offer_item, purchase.quantity_ordered, is_open=True ) box_purchase = PurchaseWoReceiver.objects.filter( customer_id=customer.id, offer_item_id=box_offer_item.id, is_box_content=True ).only('quantity_ordered').first() if box_purchase is not None: json_dict["#box_offer_item{}".format(box_offer_item.id)] = get_html_selected_box_value( box_offer_item, box_purchase.quantity_ordered ) if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM: producer_invoice = ProducerInvoice.objects.filter( producer_id=offer_item.producer_id, permanence_id=offer_item.permanence_id ).only("total_price_with_tax").first() json_dict.update(producer_invoice.get_order_json()) customer_invoice = CustomerInvoice.objects.filter( permanence_id=offer_item.permanence_id, customer_id=customer.id ).first() invoice_confirm_status_is_changed = customer_invoice.cancel_confirm_order() if invoice_confirm_status_is_changed: if settings.REPANIER_SETTINGS_CUSTOMER_MUST_CONFIRM_ORDER: template_name = get_repanier_template_name("communication_confirm_order.html") html = render_to_string(template_name) json_dict["#communicationModal"] = mark_safe(html) customer_invoice.save() json_dict.update( my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax())) permanence = Permanence.objects.filter( id=offer_item.permanence_id ).first() if is_basket: basket_message = get_html_basket_message(customer, permanence, PERMANENCE_OPENED) else: basket_message = EMPTY_STRING json_dict.update(customer_invoice.get_html_my_order_confirmation( permanence=permanence, is_basket=is_basket, basket_message=basket_message )) return JsonResponse(json_dict)