Exemplo n.º 1
0
    def clean(self):
        cleaned_data = super(CompanyCreateFromKRSForm, self).clean()
        krs = KrsClient()
        if cleaned_data['is_krs'] == '1':
            json = krs.query_podmiot(
                'conditions[krs_podmioty.krs]', cleaned_data['no'])
        else:
            json = krs.query_podmiot(
                'conditions[krs_podmioty.nip]', cleaned_data['no'])

        if json is None or json['Count'] == 0:
            raise forms.ValidationError(
                "Nie znaleziono firmy o danym numerze KRS/NIP", 'error')
        if json is None or json['Count'] > 1:
            raise forms.ValidationError(
                "Jest wiele firm o tym numerze KRS/NIP (!)", 'error')

        company = krs.json_to_company(json, 0)
        cleaned_data['company'] = company

        c = models.Company.objects.filter(nip=company['nip']).count()
        if c > 0:
            raise forms.ValidationError(
                u"Ta firma istnieje już w naszej bazie", 'error')

        return cleaned_data
Exemplo n.º 2
0
def update_company_from_krs(product, company):
    try:
        krs = KrsClient()
        if company.name:
            companies = krs.get_companies_by_name(company.name)
        elif company.nip:
            companies = krs.get_companies_by_nip(company.nip)
        else:
            return False
        if companies.__len__() == 1:
            company.official_name = companies[0]['nazwa']
            company.common_name = companies[0]['nazwa_skrocona']
            company.address = companies[0]['adres']
            company.nip = companies[0]['nip']
            company.plRegistered = 100
            company.sources = u"Dane z KRS|%s" % companies[0]['url']

            Company.save(company,
                         commit_desc="Dane firmy pobrane "
                         "automatycznie poprzez API "
                         "mojepanstwo.pl ({})".format(companies[0]['url']))

            shareholders = shareholders_to_str(krs, companies[0]['id'], '')
            if shareholders:
                create_bot_report(
                    product,
                    u'Wspólnicy spółki {}:\n{}'.format(company.name,
                                                       shareholders))
            return True

        elif companies.__len__() > 0:
            description = u'{} - ta firma może być jedną z następujących:\n\n' \
                .format(company.name)

            for i in range(0, min(companies.__len__(), 10)):
                description += \
                    (u'Nazwa: {}\n' +
                     u'Skrót: {}\n' +
                     u'NIP:   {}\n' +
                     u'Adres: \n{}\n' +
                     u'Url:   {}\n').format(companies[i]['nazwa'],
                                            companies[i]['nazwa_skrocona'],
                                            companies[i]['nip'],
                                            companies[i]['adres'],
                                            companies[i]['url'])
                shareholders = shareholders_to_str(krs, companies[i]['id'], '')
                if shareholders:
                    description += u'Wspólnicy:\n{}'.format(shareholders)
                description += '\n'

            create_bot_report(product, description)

    except (mojepanstwo_api.CompanyNotFound, mojepanstwo_api.ConnectionError,
            mojepanstwo_api.ApiError):
        pass

    return False
Exemplo n.º 3
0
def update_company_from_krs(product, company):
    try:
        krs = KrsClient()
        if company.name:
            companies = krs.get_companies_by_name(company.name)
        elif company.nip:
            companies = krs.get_companies_by_nip(company.nip)
        else:
            return False
        if companies.__len__() == 1:
            company.official_name = companies[0]['nazwa']
            company.common_name = companies[0]['nazwa_skrocona']
            company.address = companies[0]['adres']
            company.nip = companies[0]['nip']
            company.plRegistered = 100
            company.sources = u"Dane z KRS|%s" % companies[0]['url']

            Company.save(company, commit_desc="Dane firmy pobrane "
                                              "automatycznie poprzez API "
                                              "mojepanstwo.pl ({})"
                         .format(companies[0]['url']))

            shareholders = shareholders_to_str(krs, companies[0]['id'], '')
            if shareholders:
                create_bot_report(product, u'Wspólnicy spółki {}:\n{}'.
                                  format(company.name, shareholders))
            return True

        elif companies.__len__() > 0:
            description = u'{} - ta firma może być jedną z następujących:\n\n' \
                .format(company.name)

            for i in range(0, min(companies.__len__(), 10)):
                description += \
                    (u'Nazwa: {}\n' +
                     u'Skrót: {}\n' +
                     u'NIP:   {}\n' +
                     u'Adres: \n{}\n' +
                     u'Url:   {}\n').format(companies[i]['nazwa'],
                                            companies[i]['nazwa_skrocona'],
                                            companies[i]['nip'],
                                            companies[i]['adres'],
                                            companies[i]['url'])
                shareholders = shareholders_to_str(krs, companies[i]['id'], '')
                if shareholders:
                    description += u'Wspólnicy:\n{}'.format(shareholders)
                description += '\n'

            create_bot_report(product, description)

    except (mojepanstwo_api.CompanyNotFound, mojepanstwo_api.ConnectionError,
            mojepanstwo_api.ApiError):
        pass

    return False
# -*- coding: utf-8 -*-

from company.models import Company
from mojepanstwo_api import KrsClient
from pola import logic

# usage:
# export PYTHONIOENCODING=UTF-8
# python manage.py shell
# execfile('utils/test_mojepanstwo_api_v3.py')

companies = Company.objects.filter(name__isnull=False)

krs = KrsClient()

for company in companies:
    print company.name.encode('utf-8')

    companies = krs.get_companies_by_name(company.name)
    print companies
    if companies.__len__() == 1:
        print logic.shareholders_to_str(krs, companies[0]["id"], "---")

    print
    print