def download_customer_invoice(request, customer_invoice_id): user = request.user if user.is_authenticated: if user.is_repanier_staff: customer_invoice = CustomerInvoice.objects.filter( id=customer_invoice_id, invoice_sort_order__isnull=False).order_by('?').first() else: customer_invoice = CustomerInvoice.objects.filter( customer__user_id=request.user.id, id=customer_invoice_id, invoice_sort_order__isnull=False).order_by('?').first() if customer_invoice is not None: # wb = export_purchase(permanence=customer_invoice.permanence, customer=customer_invoice.customer, wb=None) wb = export_invoice(permanence=customer_invoice.permanence, customer=customer_invoice.customer, sheet_name=customer_invoice.permanence, wb=None) response = HttpResponse( content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response[ 'Content-Disposition'] = "attachment; filename={0}-{1}.xlsx".format( _("Accounting report"), REPANIER_SETTINGS_GROUP_NAME) if wb is not None: wb.save(response) return response raise Http404
def preview_invoices(self, request, permanence_qs): valid_permanence_qs = permanence_qs.filter( status__in=[PERMANENCE_INVOICED, PERMANENCE_ARCHIVED]) wb = None first = True for permanence in valid_permanence_qs: if first: wb = export_bank(permanence=permanence, wb=wb, sheet_name=slugify(permanence)) wb = export_invoice(permanence=permanence, wb=wb, sheet_name=slugify(permanence)) if first: wb = export_permanence_stock(permanence=permanence, wb=wb, ws_customer_title=None) first = False if wb is not None: response = HttpResponse( content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response[ 'Content-Disposition'] = "attachment; filename={0}-{1}.xlsx".format( slugify(_("Accounting report")), repanier.apps.REPANIER_SETTINGS_GROUP_NAME) wb.save(response) return response user_message = _("No invoice available for %(permanence)s.") % { 'permanence': ', '.join("%s" % p for p in permanence_qs.all()) } user_message_level = messages.WARNING self.message_user(request, user_message, user_message_level) return
def preview_invoices(self, request, permanence_qs): valid_permanence_qs = permanence_qs.filter( status__in=[PERMANENCE_INVOICED, PERMANENCE_ARCHIVED] ) wb = None first = True for permanence in valid_permanence_qs: if first: wb = export_bank(permanence=permanence, wb=wb, sheet_name=permanence) wb = export_invoice(permanence=permanence, wb=wb, sheet_name=permanence) if first: wb = export_permanence_stock(permanence=permanence, wb=wb, ws_customer_title=None) first = False if wb is not None: response = HttpResponse( content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') response['Content-Disposition'] = "attachment; filename={0}-{1}.xlsx".format( _("Accounting report"), settings.REPANIER_SETTINGS_GROUP_NAME ) wb.save(response) return response user_message = _("No invoice available for %(permanence)s.") % { 'permanence': ', '.join("{}".format(p) for p in permanence_qs.all())} user_message_level = messages.WARNING self.message_user(request, user_message, user_message_level) return
def download_customer_invoice(request, customer_invoice_id): user = request.user if user.is_authenticated: if user.is_repanier_staff: customer_invoice = CustomerInvoice.objects.filter( id=customer_invoice_id, invoice_sort_order__isnull=False ).order_by('?').first() else: customer_invoice = CustomerInvoice.objects.filter( customer__user_id=request.user.id, id=customer_invoice_id, invoice_sort_order__isnull=False ).order_by('?').first() if customer_invoice is not None: # wb = export_purchase(permanence=customer_invoice.permanence, customer=customer_invoice.customer, wb=None) wb = export_invoice( permanence=customer_invoice.permanence, customer=customer_invoice.customer, sheet_name=customer_invoice.permanence, wb=None) response = HttpResponse( content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') response['Content-Disposition'] = "attachment; filename={0}-{1}.xlsx".format( _("Accounting report"), settings.REPANIER_SETTINGS_GROUP_NAME ) if wb is not None: wb.save(response) return response raise Http404
def action(modeladmin, request, customer_qs): # To the customer we speak of "invoice". # This is the detail of the invoice, i.e. sold products wb = None for customer in customer_qs: wb = export_invoice(year=year, customer=customer, wb=wb, sheet_name=slugify(customer)) if wb is not None: response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') response['Content-Disposition'] = "attachment; filename={0}-{1}.xlsx".format( "%s %s" % (_('Invoice'), year), repanier.apps.REPANIER_SETTINGS_GROUP_NAME ) wb.save(response) return response return
def action(modeladmin, request, producer_qs): # To the producer we speak of "payment". # This is the detail of the payment to the producer, i.e. received products wb = None for producer in producer_qs: wb = export_invoice(year=year, producer=producer, wb=wb, sheet_name=producer) if wb is not None: response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') response['Content-Disposition'] = "attachment; filename={0}-{1}.xlsx".format( "{} {}".format(_('Payment'), year), settings.REPANIER_SETTINGS_GROUP_NAME ) wb.save(response) return response return
def action(modeladmin, request, producer_qs): # To the producer we speak of "payment". # This is the detail of the payment to the producer, i.e. received products wb = None for producer in producer_qs: wb = export_invoice(year=year, producer=producer, wb=wb, sheet_name=producer) if wb is not None: response = HttpResponse( content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response[ 'Content-Disposition'] = "attachment; filename={0}-{1}.xlsx".format( "{} {}".format(_('Payment'), year), repanier.apps.REPANIER_SETTINGS_GROUP_NAME) wb.save(response) return response return
def action(modeladmin, request, customer_qs): # To the customer we speak of "invoice". # This is the detail of the invoice, i.e. sold products wb = None for customer in customer_qs: wb = export_invoice(year=year, customer=customer, wb=wb, sheet_name=customer) if wb is not None: response = HttpResponse( content_type= "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ) response[ "Content-Disposition"] = "attachment; filename={0}-{1}.xlsx".format( "{} {}".format(_("Invoice"), year), settings.REPANIER_SETTINGS_GROUP_NAME, ) wb.save(response) return response return
def accounting_report(self, request, permanence_id, permanence=None): wb = export_bank(permanence=permanence, wb=None, sheet_name=permanence) wb = export_invoice(permanence=permanence, wb=wb, sheet_name=permanence) wb = export_permanence_stock(permanence=permanence, wb=wb, ws_customer_title=None) if wb is not None: response = HttpResponse( content_type= "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ) response[ "Content-Disposition"] = "attachment; filename={0}-{1}.xlsx".format( _("Accounting report"), settings.REPANIER_SETTINGS_GROUP_NAME) wb.save(response) return response user_message = _("No invoice available for {permanence}.'.").format( permanence=permanence) user_message_level = messages.WARNING self.message_user(request, user_message, user_message_level) return HttpResponseRedirect(self.get_redirect_to_change_list_url())