Пример #1
0
 def get_number_segments_display(self):
     """
     returns string for date=today and all securities showing number segments
     """
     text = ""
     for security in self.company.security_set.filter(track_numbers=True):
         text += "{}: {} ".format(
             security.get_title_display(),
             human_readable_segments(self.current_segments(security)))
     return text
Пример #2
0
def captable_csv(request, company_id):
    """ returns csv with active shareholders """

    # perm check
    if not Operator.objects.filter(
        user=request.user, company__id=company_id
    ).exists():
        return HttpResponseForbidden()

    company = get_object_or_404(Company, id=company_id)
    track_numbers_secs = company.security_set.filter(track_numbers=True)

    # Create the HttpResponse object with the appropriate CSV header.
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = (
        u'attachment; '
        u'filename="{}_captable_{}.csv"'.format(
            time.strftime("%Y-%m-%d"), slugify(company.name)
        ))

    writer = csv.writer(response)

    header = [
        _(u'shareholder number'), _(u'last name'), _(u'first name'),
        _(u'email'), _(u'share count'), _(u'votes share percent'),
        _(u'language ISO'), _('language full')]

    if track_numbers_secs.exists():
        header.append(_('Share IDs'))

    writer.writerow(header)

    for shareholder in company.get_active_shareholders():
        row = [
            shareholder.number,
            shareholder.user.last_name,
            shareholder.user.first_name,
            shareholder.user.email,
            shareholder.share_count(),
            shareholder.share_percent() or '--',
            shareholder.user.userprofile.language,
            shareholder.user.userprofile.get_language_display(),
        ]
        if track_numbers_secs.exists():
            text = ""
            for sec in track_numbers_secs:
                text += "{}: {} ".format(
                    sec.get_title_display(),
                    human_readable_segments(shareholder.current_segments(sec) or
                                            _('None'))
                )
            row.append(text)
        writer.writerow([unicode(s).encode("utf-8") for s in row])

    return response
Пример #3
0
def _collect_csv_data(shareholder, date):
    rows = []
    for security in shareholder.company.security_set.all():
        if shareholder.share_count(date=date, security=security):

            row = [
                shareholder.number,
                shareholder.user.userprofile.get_legal_type_display(),
                list(set([s.get_registration_type_display() for s
                          in shareholder.buyer.all()])),
                shareholder.user.userprofile.company_department,
                shareholder.user.userprofile.title,
                shareholder.user.userprofile.salutation,
                shareholder.get_full_name(),
                shareholder.user.userprofile.get_address(skip_city=True),
                shareholder.user.userprofile.postal_code,
                shareholder.user.userprofile.country,
                shareholder.user.userprofile.city,
                shareholder.user.userprofile.birthday,
                shareholder.get_mailing_type_display(),
                shareholder.user.userprofile.nationality,
                security,
                security.cusip,
                security.face_value,
                shareholder.get_certificate_ids(security=security),
                shareholder.get_stock_book_ids(security=security),
                shareholder.get_depot_types(security=security),
                shareholder.user.email,
                shareholder.share_count(security=security, date=date),
                float(shareholder.share_percent(
                    security=security, date=date)) * 100,
                shareholder.vote_percent(security=security, date=date),
                shareholder.cumulated_face_value(security=security, date=date),
                shareholder.is_management,
                shareholder.user.userprofile.language,
                shareholder.user.userprofile.get_language_display(),
            ]
            # remove any kind of empty data and replace by empty string. make
            # all utf8
            row = [to_string_or_empty(val) for val in row]

            # handle track numbers
            if security.track_numbers:
                segments = human_readable_segments(
                    shareholder.current_segments(security)) or _('None')
                text = "{}: {} ".format(
                    security.get_title_display(),
                    segments
                )
                row.append(text)
            rows.append(row)
    return rows
Пример #4
0
 def is_transfer_option_with_segments_shown(self, **kwargs):
     buyer = kwargs.get('buyer')
     ot = buyer.option_buyer.latest('id')
     s1 = u"{} {}".format(buyer.user.first_name, buyer.user.last_name)
     s2 = u"{} (#{})".format(ot.count,
                             human_readable_segments(ot.number_segments))
     for table in self.driver.find_elements_by_class_name('table'):
         tr = table.find_element_by_xpath('//tr[./td="{}"]'.format(s1))
         buyer_td = tr.find_element_by_class_name('buyer')
         count_td = tr.find_element_by_class_name('count')
         if s1 == buyer_td.text and s2 == count_td.text:
             return True
     return False
Пример #5
0
    def _enrich_security_objects(self):
        """ add more attributes to objects for plain display """
        shareholder = self.get_object()
        securities = shareholder.company.security_set.all()

        # hack security props for shareholder spec data
        for sec in securities:
            if sec.track_numbers:
                if shareholder.current_segments(sec):
                    sec.segments = human_readable_segments(
                        shareholder.current_segments(sec))
            sec.count = shareholder.share_count(security=sec) or 0
            sec.options_count = shareholder.options_count(security=sec) or 0
        return {'securities': securities}
Пример #6
0
def shareholder(request, shareholder_id):
    template = loader.get_template('shareholder.html')
    shareholder = get_object_or_404(Shareholder, id=int(shareholder_id))
    securities = shareholder.company.security_set.all()

    # hack security props for shareholder spec data
    for sec in securities:
        if sec.track_numbers:
            if shareholder.current_segments(sec):
                sec.segments = human_readable_segments(
                    shareholder.current_segments(sec))
        sec.count = shareholder.share_count(security=sec) or 0
    context = RequestContext(request, {
                             'shareholder': shareholder,
                             'securities': securities})
    return HttpResponse(template.render(context))
Пример #7
0
    def is_transfer_option_with_segments_shown(self, **kwargs):
        buyer = kwargs.get('buyer')
        ot = buyer.option_buyer.latest('id')
        s1 = buyer.get_full_name()
        for table in self.driver.find_elements_by_class_name('table'):
            trs = table.find_elements_by_class_name("optiontransaction")
            for tr in trs:
                buyer_td = tr.find_element_by_class_name('buyer-name')
                count_td = tr.find_element_by_class_name('count')
                if (s1 == buyer_td.text and str(ot.count) in count_td.text
                        and human_readable_segments(
                            ot.number_segments) in count_td.text):
                    return True
                print s1, buyer_td.text, count_td.text

        return False
Пример #8
0
    def test_create_capital_increase_numbered_shares(self):
        """
        position serializer handling numbered shares while doing a capital
        increase
        """
        def serialize(segments):
            operator = OperatorGenerator().generate()
            company = operator.company
            securities = TwoInitialSecuritiesGenerator().generate(
                company=company)
            security = securities[1]
            security.track_numbers = True
            security.save()
            position = PositionGenerator().generate(company=company,
                                                    number_segments=segments,
                                                    save=False,
                                                    security=security,
                                                    count=8)

            url = reverse('position-detail', kwargs={'pk': position.id})
            request = self.factory.get(url)
            request.user = operator.user
            request.session = {'company_pk': company.pk}

            # prepare data
            position.seller = None
            position.buyer = None
            position.depot_bank = BankGenerator().generate()
            # get test data dict
            data = PositionSerializer(position, context={
                'request': request
            }).data
            # clear bad datetimedata
            data['bought_at'] = '2014-01-01T10:00'
            del data['seller'], data['buyer']
            # feed data into serializer
            return PositionSerializer(data=data, context={'request': request})

        segments = [1, 3, 4, u'6-9', 33]
        serializer = serialize(human_readable_segments(segments))
        serializer.is_valid()
        position = serializer.create(serializer.validated_data)
        self.assertEqual([1, u'3-4', u'6-9', 33],
                         position.security.number_segments)
        self.assertEqual(position.registration_type, '1')
        self.assertEqual(position.depot_bank, Bank.objects.first())