Exemple #1
0
def render_vested_shares_pdf(company_id, report_id, user_id=None, ordering=None,
                             notify=False, track_downloads=False):
    # prepare
    started_at = timezone.now()
    if user_id:
        user = User.objects.get(pk=user_id)
    company = Company.objects.get(pk=company_id)
    report = _get_report(report_id)
    ordering = _parse_ordering(ordering)
    filename = _get_filename(report, company)

    # render
    context = _get_vested_shares_pdf_context(company, date=report.report_at)
    content = render_to_pdf(
        'reports/table_report.pdf.html', context)

    # post process
    _add_file_to_report(filename, report, content)
    _summarize_report(report, started_at)

    if notify and user_id:
        _send_notify(user, filename, subject=_('Your pdf vested shares file'),
                     body=_('Your file is attached to this email'),
                     file_desc=_('PDF vested shares'),
                     url=url_with_domain(report.get_absolute_url()))

    if not track_downloads:
        report.downloaded_at = timezone.now()
        report.save()
Exemple #2
0
def render_address_data_xls(company_id, report_id, user_id=None, ordering=None,
                            notify=False, track_downloads=False):
    # prepare
    if user_id:
        user = User.objects.get(pk=user_id)
    company = Company.objects.get(pk=company_id)
    report = _get_report(report_id)
    filename = _get_filename(report, company)
    started_at = timezone.now()

    _rows = _get_contacts(company)

    rows = []
    for row in _rows:
        rows.append([to_string_or_empty(s) for s in row])

    save_to_excel_file(filename, rows, CONTACTS_HEADER)

    # post process
    _add_file_to_report(filename, report)
    _summarize_report(report, started_at)

    if notify and user_id:
        _send_notify(user, filename, subject=_('Your xls contacts file'),
                     body=_('Your file is attached to this email'),
                     file_desc=_('XLS Shareholder Address Data'),
                     url=url_with_domain(report.get_absolute_url()))

    if not track_downloads:
        report.downloaded_at = timezone.now()
        report.save()

    os.remove(filename)  # del tmp file
Exemple #3
0
def render_captable_xls(company_id, report_id, user_id=None, ordering=None,
                        notify=False, track_downloads=False):
    # prepare
    started_at = timezone.now()
    if user_id:
        user = User.objects.get(pk=user_id)
    company = Company.objects.get(pk=company_id)
    report = _get_report(report_id)
    ordering = _parse_ordering(ordering)
    filename = _get_filename(report, company)
    track_numbers_secs = company.security_set.filter(track_numbers=True)

    header = deepcopy(CSV_HEADER)
    has_track_numbers = track_numbers_secs.exists()
    if has_track_numbers:
        header.append(_('Share IDs'))

    def to_unicode(iterable):
        return [unicode(s).encode("utf-8") for s in iterable]

    # removed share percent due to heavy sql impact. killed perf for higher
    # shareholder count
    # for each active shareholder
    queryset = company.get_active_shareholders(date=report.report_at)
    queryset = _order_queryset(queryset, ordering)
    rows = []
    for shareholder in queryset:
        if shareholder.share_count(date=report.report_at):
            rows.extend(_collect_csv_data(shareholder, report.report_at))
        else:
            continue

    # money_format
    formats = {'22': 'percent_format', '23': 'percent_format',
               '24': 'money_format'}
    save_to_excel_file(filename, rows, header, formats)

    # post process
    _add_file_to_report(filename, report)
    _summarize_report(report, started_at)

    if notify and user_id:
        _send_notify(user, filename, subject=_('Your xls captable file'),
                     body=_('Your file is attached to this email'),
                     file_desc=_('XLS Captable/Active Shareholders'),
                     url=url_with_domain(report.get_absolute_url()))

    if not track_downloads:
        report.downloaded_at = timezone.now()
        report.save()

    os.remove(filename)  # del tmp file
Exemple #4
0
def render_vested_shares_xls(company_id, report_id, user_id=None, ordering=None,
                             notify=False, track_downloads=False):
    # prepare
    started_at = timezone.now()
    if user_id:
        user = User.objects.get(pk=user_id)
    company = Company.objects.get(pk=company_id)
    report = _get_report(report_id)
    ordering = _parse_ordering(ordering)
    filename = _get_filename(report, company)

    positions = Position.objects.filter(
        Q(buyer__company=company) | Q(seller__company=company),
        vesting_months__gt=0).distinct()
    ots = OptionTransaction.objects.filter(
        option_plan__company=company,
        vesting_months__gt=0).distinct()
    _rows = []
    _rows += [
        [p.buyer.get_full_name(), p.count, unicode(p.security),
         p.buyer.is_management, p.bought_at, p.vesting_months,
         p.vesting_expires_at, _('stock')
         ] for p in positions]
    _rows += [[ot.buyer.get_full_name(), ot.count,
              unicode(ot.option_plan.security),
              ot.buyer.is_management, ot.bought_at,
              ot.vesting_months, u'', _('certificate')] for ot in ots]

    rows = []
    for row in _rows:
        rows.append([to_string_or_empty(s) for s in row])

    save_to_excel_file(filename, rows, VESTED_SHARES_HEADER)

    # post process
    _add_file_to_report(filename, report)
    _summarize_report(report, started_at)

    if notify and user_id:
        _send_notify(user, filename, subject=_('Your xls vested shares file'),
                     body=_('Your file is attached to this email'),
                     file_desc=_('XLS Vested Shares'),
                     url=url_with_domain(report.get_absolute_url()))

    if not track_downloads:
        report.downloaded_at = timezone.now()
        report.save()

    os.remove(filename)  # del tmp file
Exemple #5
0
def render_assembly_participation_xls(company_id, report_id, user_id=None,
                                      ordering=None, notify=False,
                                      track_downloads=False):
    # prepare
    started_at = timezone.now()
    if user_id:
        user = User.objects.get(pk=user_id)
    company = Company.objects.get(pk=company_id)
    report = _get_report(report_id)
    ordering = u'number'
    filename = _get_filename(report, company)

    def to_unicode(iterable):
        return [unicode(s).encode("utf-8") for s in iterable]

    # for each active shareholder
    queryset = company.get_active_shareholders(date=report.report_at)
    queryset = _order_queryset(queryset, ordering)

    rows = []
    for shareholder in queryset:
        if shareholder.share_count(date=report.report_at):
            rows.extend(_collect_participation_csv_data(
                shareholder, report.report_at))
        else:
            continue

    # money_format
    formats = {'7': 'money_format'}
    save_to_excel_file(filename, rows, PARTICIPATION_HEADER, formats)

    # post process
    _add_file_to_report(filename, report)
    _summarize_report(report, started_at)

    if notify and user_id:
        _send_notify(user, filename,
                     subject=_('Your csv assembly participation file'),
                     body=_('Your file is attached to this email'),
                     file_desc=_('CSV Assembly Participation'),
                     url=url_with_domain(report.get_absolute_url()))

    if not track_downloads:
        report.downloaded_at = timezone.now()
        report.save()

    os.remove(filename)
Exemple #6
0
 def test_url_with_domain(self):
     """ returns url with domain for path without needing the request """
     self.assertEqual(url_with_domain('/some/path/'),
                      'https://example.com/some/path/')
Exemple #7
0
def render_certificates_xls(company_id, report_id, user_id=None, ordering=None,
                            notify=False, track_downloads=False):
    """
    return xls with list of printed certificates
    """
    # prepare
    started_at = timezone.now()
    if user_id:
        user = User.objects.get(pk=user_id)
    company = Company.objects.get(pk=company_id)
    report = _get_report(report_id)
    ordering = _parse_ordering(ordering)
    filename = _get_filename(report, company)

    ots = OptionTransaction.objects.filter(
        option_plan__company=company,
        printed_at__isnull=False,
        certificate_id__isnull=False,
        ).distinct()
    pos = Position.objects.filter(
        Q(buyer__company=company) | Q(seller__company=company),
        printed_at__isnull=False,
        certificate_id__isnull=False,
        ).distinct()
    # add option transactions
    _rows = []
    _rows += [
        [ot.buyer.get_full_name(),
         ot.count,
         unicode(ot.option_plan.security),
         ot.certificate_id,
         ot.printed_at, _('option')]
        for ot in ots]
    # add positions
    _rows += [
        [ot.buyer.get_full_name(),
         ot.count,
         unicode(ot.security),
         ot.certificate_id,
         ot.printed_at, _('stock')]
        for ot in pos]
    # render xls
    rows = []
    for row in _rows:
        rows.append([to_string_or_empty(s) for s in row])

    save_to_excel_file(filename, rows, CERTIFICATES_HEADER)

    # post process
    _add_file_to_report(filename, report)
    _summarize_report(report, started_at)

    if notify and user_id:
        _send_notify(user, filename, subject=_('Your xls certificates file'),
                     body=_('Your file is attached to this email'),
                     file_desc=_('XLS Certificates'),
                     url=url_with_domain(report.get_absolute_url()))

    if not track_downloads:
        report.downloaded_at = timezone.now()
        report.save()

    os.remove(filename)  # del tmp file