Example #1
0
def notify_manager_about_new_issue(issue: Issue):
    manager = issue.manager
    if manager is None:
        if issue.bg_sum > 1500000:
            manager = _get_default_manager()
        else:
            manager = _get_default_low_cost_manager()

    manager.email_user(subject='Новая заявка',
                       html_template_filename=
                       'mail/events_for_send_to_fo_manager/new_issue.html',
                       context=dict(
                           issue_number=issue.humanized_id,
                           issue_id=issue.id,
                           finance_product=issue.get_product().humanized_name,
                           issuer_short_name=issue.issuer_short_name))
Example #2
0
def notify_managers_issue_in_review(issue: Issue):
    """
    Заявка перешла в статус рассмотрение
    :param issue:
    """
    # клиент отправил заявку на рассмотрение, уведомить менеджера
    if issue.manager:
        issue.manager.email_user(
            subject="Заявка перешла в статус 'рассмотрение'",
            html_template_filename=
            'mail/events_for_send_to_user_manager/issue_in_review.html',
            context=dict(
                user_full_name=issue.user.__str__(),
                issue_id=issue.id,
                issue_number=issue.humanized_id,
                finance_product=issue.get_product().humanized_name,
                issuer_short_name=issue.issuer_short_name,
            ))
Example #3
0
def notify_manager_about_user_created_issue(issue: Issue):
    manager = issue.manager
    if manager is None:
        if issue.bg_sum > 1500000:
            manager = _get_default_manager()
        else:
            manager = _get_default_low_cost_manager()

    # клиент создал заявку, уведомить менеджера
    manager.email_user(
        subject="Новая заявка от клиента",
        html_template_filename=
        'mail/events_for_send_to_user_manager/user_created_new_issue.html',
        context=dict(
            user_full_name=issue.user.__str__(),
            new_issue_id=issue.id,
            new_issue_number=issue.humanized_id,
            finance_product=issue.get_product().humanized_name,
            issuer_short_name=issue.issuer_short_name,
        ))
Example #4
0
    def post(self, request, *args, **kwargs):

        if self.get_issue() and 'issue_registering' not in self.get_issue(
        ).editable_dashboard_views():
            return self.get(request, *args, **kwargs)

        base_form = IssueRegisteringForm(request.POST)
        if base_form.is_valid():
            # todo go to next stage if we can
            need_to_notify_for_issue_create = False
            if not self.get_issue():
                issuer = self.create_issuer(
                    user_owner=request.user,
                    inn=request.POST.get('issuer_inn'),
                    kpp=request.POST.get('issuer_kpp'),
                    ogrn=request.POST.get('issuer_ogrn'),
                    full_name=request.POST.get('issuer_full_name'),
                    short_name=request.POST.get('issuer_short_name'))
                issuer_inn = request.POST.get('issuer_inn')
                if issuer_inn:
                    old_issue = Issue.objects.filter(
                        issuer_inn=issuer_inn).order_by('-id').first()
                else:
                    old_issue = None
                if old_issue:
                    new_issue = deepcopy(old_issue)
                    new_issue.pk = None
                    new_issue.manager = None
                    new_issue.manager_id = None
                    new_issue.user = request.user
                    new_issue.status = consts.ISSUE_STATUS_REGISTERING
                    new_issue.application_doc = None
                    new_issue.bg_doc = None
                    new_issue.contract_of_guarantee = None
                    new_issue.transfer_acceptance_act = None
                    new_issue.additional_doc = None
                    new_issue.bg_contract_doc = None
                    new_issue.save(create_docs=False)

                    related_names = [
                        'org_bank_accounts', 'org_beneficiary_owners',
                        'issuer_founders_legal', 'issuer_founders_physical',
                        'issuer_licences', 'org_management_collegial',
                        'org_management_directors', 'org_management_others'
                    ]
                    for name in related_names:
                        for obj in getattr(old_issue, name).all():
                            obj.issue_id = new_issue.id
                            obj.pk = None
                            obj.save()
                else:
                    new_issue = Issue(
                        issuer=issuer,
                        product=base_form.cleaned_data['product'],
                        status=consts.ISSUE_STATUS_REGISTERING,
                        user=request.user,
                    )  # todo set values
                    # new_issue.fill_from_issuer()
                need_to_notify_for_issue_create = True
                self._issue = new_issue
            issue = self.get_issue()
            issue.comment = base_form.cleaned_data['comment']
            issue.product = base_form.cleaned_data['product']
            issue.save()

            # todo issue process registering form
            product = issue.get_product()
            product.set_issue(issue)
            processed_valid = product.process_registering_form(request)

            if need_to_notify_for_issue_create:
                notify_manager_about_user_created_issue(issue)
            else:
                notify_manager_about_user_updated_issue(issue)

            if issue.issuer_already_has_an_agent:
                url = reverse('issue_registering', args=[issue.id])
                return HttpResponseRedirect(url)

            action = request.POST.get('action', 'save')
            if action == 'save':
                url = reverse('cabinet_requests')
                return HttpResponseRedirect(url)
            elif action == 'next':
                if processed_valid and not issue.check_stop_factors_validity:
                    issue.status = consts.ISSUE_STATUS_CANCELLED
                    issue.save()
                    url = reverse('issue_finished', args=[issue.id])
                    return HttpResponseRedirect(url)

                if processed_valid:
                    url = reverse('issue_survey', args=[issue.id])
                    return HttpResponseRedirect(url)

        return self.return_errors(base_form, *args, **kwargs)
Example #5
0
    def test_underwriting_criteria(self):
        user = User()
        user.save()
        user.refresh_from_db()
        issue = Issue()
        issue.user = user

        # SECTION 1

        issue.bg_sum = 80000
        issue.balance_code_1600_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_1'], 100)

        issue.bg_sum = 80000.01
        issue.balance_code_1600_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_1'], 75)

        issue.bg_sum = 100000
        issue.balance_code_1600_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_1'], 75)

        issue.bg_sum = 100000.01
        issue.balance_code_1600_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_1'], 50)

        issue.bg_sum = 150000
        issue.balance_code_1600_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_1'], 50)

        issue.bg_sum = 150000.01
        issue.balance_code_1600_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_1'], 25)

        issue.bg_sum = 200000
        issue.balance_code_1600_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_1'], 25)

        issue.bg_sum = 200000.01
        issue.balance_code_1600_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_1'], 0)

        # SECTION 2

        issue.tender_final_cost = 100000
        issue.balance_code_2110_offset_1 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_2'], 200)

        issue.tender_final_cost = 100000.01
        issue.balance_code_2110_offset_1 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_2'], 100)

        issue.tender_final_cost = 150000
        issue.balance_code_2110_offset_1 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_2'], 100)

        issue.tender_final_cost = 150000.01
        issue.balance_code_2110_offset_1 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_2'], 50)

        issue.tender_final_cost = 200000
        issue.balance_code_2110_offset_1 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_2'], 50)

        issue.tender_final_cost = 200000.01
        issue.balance_code_2110_offset_1 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_2'], 0)

        # SECTION 3

        issue.balance_code_2110_offset_1 = 70
        issue.balance_code_2110_offset_2 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_3'], 50)

        issue.balance_code_2110_offset_1 = 69
        issue.balance_code_2110_offset_2 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_3'], 37.5)

        issue.balance_code_2110_offset_1 = 50
        issue.balance_code_2110_offset_2 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_3'], 37.5)

        issue.balance_code_2110_offset_1 = 49
        issue.balance_code_2110_offset_2 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_3'], 25)

        issue.balance_code_2110_offset_1 = 25
        issue.balance_code_2110_offset_2 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_3'], 25)

        issue.balance_code_2110_offset_1 = 24
        issue.balance_code_2110_offset_2 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_3'], 0)

        # SECTION 4

        issue.balance_code_2110_offset_0 = 70
        issue.balance_code_2110_analog_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_4'], 50)

        issue.balance_code_2110_offset_0 = 69
        issue.balance_code_2110_analog_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_4'], 37.5)

        issue.balance_code_2110_offset_0 = 50
        issue.balance_code_2110_analog_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_4'], 37.5)

        issue.balance_code_2110_offset_0 = 49
        issue.balance_code_2110_analog_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_4'], 25)

        issue.balance_code_2110_offset_0 = 25
        issue.balance_code_2110_analog_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_4'], 25)

        issue.balance_code_2110_offset_0 = 24
        issue.balance_code_2110_analog_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_4'], 0)

        # SECTION 5.1

        issue.bg_sum = 5000000
        issue.tender_final_cost = 200
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 200)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 200.01
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 150)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 300
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 150)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 300.01
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 50)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 500
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 50)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 500.01
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 0)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 0
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 0)

        # SECTION 5.2

        issue.bg_sum = 10000000
        issue.tender_final_cost = 150
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 200)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 150.01
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 150)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 200
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 150)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 200.01
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 50)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 400
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 50)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 400.01
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 0)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 0
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 0)

        # SECTION 5.3

        issue.bg_sum = 18000000
        issue.tender_final_cost = 130
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 200)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 130.01
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 130)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 200
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 130)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 200.01
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 20)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 300
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 20)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 300.01
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 0)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 0
        issue.similar_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_51'] + data['score_52'] + data['score_53'], 0)

        # SECTION 6

        issue.similar_contract_date = (
            timezone.now() - timezone.timedelta(days=(365 * 2))).date()
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_6'], 125)

        issue.similar_contract_date = (
            timezone.now() - timezone.timedelta(days=(365 * 2 + 1))).date()
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_6'], 62.5)

        issue.similar_contract_date = (
            timezone.now() - timezone.timedelta(days=(365 * 3))).date()
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_6'], 62.5)

        issue.similar_contract_date = (
            timezone.now() - timezone.timedelta(days=(365 * 3 + 1))).date()
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_6'], 0)

        # SECTION 7.1

        issue.bg_sum = 5000000
        issue.tender_final_cost = 200
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 125)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 200.01
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 93.75)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 300
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 93.75)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 300.01
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 31.25)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 500
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 31.25)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 500.01
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 0)

        issue.bg_sum = 5000000
        issue.tender_final_cost = 0
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 0)

        # SECTION 7.2

        issue.bg_sum = 10000000
        issue.tender_final_cost = 150
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 125)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 150.01
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 93.75)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 200
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 93.75)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 200.01
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 31.25)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 400
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 31.25)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 400.01
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 0)

        issue.bg_sum = 10000000
        issue.tender_final_cost = 0
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 0)

        # SECTION 7.3

        issue.bg_sum = 18000000
        issue.tender_final_cost = 130
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 125)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 130.01
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 81.25)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 200
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 81.25)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 200.01
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 12.5)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 300
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 12.5)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 300.01
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 0)

        issue.bg_sum = 18000000
        issue.tender_final_cost = 0
        issue.biggest_contract_sum = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(
            data['score_71'] + data['score_72'] + data['score_73'], 0)

        # SECTION 8

        issue.bg_sum = 100
        issue.tender_final_cost = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_8'], 50)

        issue.bg_sum = 100.01
        issue.tender_final_cost = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_8'], 0)

        # SECTION 9

        issue.has_fines_on_zakupki_gov_ru = False
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_9'], 25)

        issue.has_fines_on_zakupki_gov_ru = True
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_9'], 0)

        # SECTION 10

        issue.has_arbitration = False
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_10'], 25)

        issue.has_arbitration = True
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_10'], 0)

        # SECTION 11

        issue.balance_code_1230_offset_0 = 70
        issue.balance_code_1600_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_11'], 50)

        issue.balance_code_1230_offset_0 = 71
        issue.balance_code_1600_offset_0 = 100
        issue.save()
        issue.refresh_from_db()
        data = CalculateUnderwritingCriteria().calc(issue)
        self.assertEqual(data['score_11'], 0)
Example #6
0
    def post(self, request, *args, **kwargs):
        username = ''
        if request.user.id:
            quick_request_form = QuickRequestForm(request.POST,
                                                  user=request.user)
        else:
            quick_request_form = QuickRequestForm(request.POST)
            quick_request_form.full_clean()
            username = quick_request_form.cleaned_data.get(
                'contact_email', None)
            if username is not None:
                username = User.normalize_username(username)
                if User.objects.filter(username=username).exists():
                    quick_request_form.add_error(
                        'contact_email',
                        'Пользователь с таким email уже существует')
        if quick_request_form.is_valid():
            if not request.user.id:
                # todo create new user an log in
                new_user = User()
                new_user.username = username
                new_user.email = quick_request_form.cleaned_data[
                    'contact_email']
                new_user.phone = quick_request_form.cleaned_data[
                    'contact_phone']
                full_name_arr = quick_request_form.cleaned_data[
                    'contact_person_name'].split(' ')

                new_user.first_name = ''
                new_user.last_name = ''
                if len(full_name_arr) == 1:
                    new_user.first_name = full_name_arr[0]
                elif len(full_name_arr) >= 2:
                    new_user.last_name = full_name_arr[0]
                    new_user.first_name = full_name_arr[1]

                # todo generate and send password
                new_password = new_user.generate_new_password()
                new_user.save()
                new_user.email_user(
                    subject='Новый пользователь',
                    html_template_filename='mail/new_user_by_quick_form.html',
                    context=dict(
                        username=new_user.username,
                        password=new_password,
                    ),
                )
                login(request, new_user)

            issuer_full_name = quick_request_form.cleaned_data[
                'party_full_name']
            issuer_short_name = quick_request_form.cleaned_data[
                'party_short_name']
            issuer_ogrn = quick_request_form.cleaned_data['party_ogrn']
            issuer_inn = quick_request_form.cleaned_data['party_inn']
            issuer_kpp = quick_request_form.cleaned_data['party_kpp']

            issuer = None
            try:
                issuer = Issuer.objects.get(
                    # Q(Q(full_name__iexact=issuer_name) | Q(short_name__iexact=issuer_name))
                    ogrn=issuer_ogrn,
                    inn=issuer_inn,
                    kpp=issuer_kpp,
                )
            except ObjectDoesNotExist:
                issuer = Issuer()
                issuer.user = request.user
                issuer.full_name = issuer_full_name
                issuer.short_name = issuer_short_name
                issuer.ogrn = issuer_ogrn
                issuer.inn = issuer_inn
                issuer.kpp = issuer_kpp
                issuer.save()

            new_issue = Issue()
            new_issue.issuer = issuer
            new_issue.fill_from_issuer()
            new_issue.status = consts.ISSUE_STATUS_REGISTERING
            new_issue.user = request.user  # fixme it's naive when new user, check it
            new_issue.product = quick_request_form.cleaned_data['product']

            new_issue.issuer_okved = quick_request_form.cleaned_data[
                'party_okved']
            new_issue.issuer_okopf = quick_request_form.cleaned_data[
                'party_okopf']

            new_issue.issuer_foreign_name = quick_request_form.cleaned_data[
                'party_foreign_name']
            new_issue.issuer_legal_address = quick_request_form.cleaned_data[
                'party_legal_address']

            head_fio = quick_request_form.cleaned_data['party_head_fio']
            fio_arr = head_fio.split(' ')
            if len(fio_arr) == 1:
                # only name
                new_issue.issuer_head_first_name = fio_arr[0]
            elif len(fio_arr) == 2:
                # last and first names
                new_issue.issuer_head_last_name = fio_arr[0]
                new_issue.issuer_head_first_name = fio_arr[1]
            elif len(fio_arr) == 3:
                # last, first, middle names
                new_issue.issuer_head_last_name = fio_arr[0]
                new_issue.issuer_head_first_name = fio_arr[1]
                new_issue.issuer_head_middle_name = fio_arr[2]

            new_issue.issuer_head_org_position_and_permissions = quick_request_form.cleaned_data[
                'party_head_position']

            new_issue.save()
            notify_manager_about_user_created_issue(new_issue)
            url = reverse('cabinet_request', args=[new_issue.id])
            return HttpResponseRedirect(url)
        else:
            kwargs.update(dict(quick_request_form=quick_request_form))
            return self.get(request, *args, **kwargs)
Example #7
0
def generate_acts_for_issue(issue: Issue) -> Issue:
    transfer_acceptance_path = {
        12:
        os.path.join(
            settings.BASE_DIR,
            'marer/templates/documents/acts/transfer_acceptance_ip.docx'),
        10:
        os.path.join(
            settings.BASE_DIR,
            'marer/templates/documents/acts/transfer_acceptance_ul.docx')
    }.get(len(issue.issuer_inn))
    if transfer_acceptance_path:
        issue.transfer_acceptance_act = generate_doc(transfer_acceptance_path,
                                                     'Акт.docx', issue)

    bg_contract_path = {
        (consts.TENDER_EXEC_LAW_44_FZ, consts.BG_TYPE_APPLICATION_ENSURE):
        'marer/templates/documents/acts/fz44_participation.docx',
        (consts.TENDER_EXEC_LAW_44_FZ, consts.BG_TYPE_CONTRACT_EXECUTION):
        'marer/templates/documents/acts/fz44_execution.docx',
        (consts.TENDER_EXEC_LAW_44_FZ, consts.BG_TYPE_REFUND_OF_ADVANCE):
        'marer/templates/documents/acts/fz44_execution.docx',
        (consts.TENDER_EXEC_LAW_44_FZ, consts.BG_TYPE_WARRANTY_ENSURE):
        'marer/templates/documents/acts/fz44_execution.docx',
        (consts.TENDER_EXEC_LAW_223_FZ, consts.BG_TYPE_APPLICATION_ENSURE):
        'marer/templates/documents/acts/fz233_participation.docx',
        (consts.TENDER_EXEC_LAW_223_FZ, consts.BG_TYPE_CONTRACT_EXECUTION):
        'marer/templates/documents/acts/fz223_execution.docx',
        (consts.TENDER_EXEC_LAW_223_FZ, consts.BG_TYPE_REFUND_OF_ADVANCE):
        'marer/templates/documents/acts/fz223_execution.docx',
        (consts.TENDER_EXEC_LAW_223_FZ, consts.BG_TYPE_WARRANTY_ENSURE):
        'marer/templates/documents/acts/fz223_execution.docx',
        (consts.TENDER_EXEC_LAW_185_FZ, consts.BG_TYPE_APPLICATION_ENSURE):
        'marer/templates/documents/acts/fz185_participation.docx',
        (consts.TENDER_EXEC_LAW_185_FZ, consts.BG_TYPE_CONTRACT_EXECUTION):
        'marer/templates/documents/acts/fz185_execution.docx',
        (consts.TENDER_EXEC_LAW_185_FZ, consts.BG_TYPE_REFUND_OF_ADVANCE):
        'marer/templates/documents/acts/fz185_execution.docx',
        (consts.TENDER_EXEC_LAW_185_FZ, consts.BG_TYPE_WARRANTY_ENSURE):
        'marer/templates/documents/acts/fz185_execution.docx',
    }.get((issue.tender_exec_law, issue.bg_type))
    if bg_contract_path:
        issue.bg_doc = generate_doc(
            os.path.join(settings.BASE_DIR, bg_contract_path), 'Проект.docx',
            issue)

    issue.bg_contract_doc = generate_doc(
        os.path.join(settings.BASE_DIR,
                     'marer/templates/documents/acts/one_commission.docx'),
        'Договор.docx', issue)
    if any([
            issue.issuer_inn.startswith(x)
            for x in ['77', '97', '99', '177', '199', '197']
    ]) and issue.tender_exec_law == consts.TENDER_EXEC_LAW_185_FZ:
        path = 'marer/templates/documents/acts/fz185_additional_for_msk.docx'
        issue.additional_doc = generate_doc(
            os.path.join(settings.BASE_DIR, path),
            'Дополнительный_документ.docx', issue)
    if issue.bg_sum > 5000000 and not len(issue.issuer_inn) == 12:
        issue.contract_of_guarantee = generate_doc(
            os.path.join(
                settings.BASE_DIR,
                'marer/templates/documents/acts/contract_of_guarantee.docx'),
            'Договор_поручительства.docx', issue)

    issue.payment_of_fee = generate_doc(
        os.path.join(settings.BASE_DIR,
                     'marer/templates/documents/payment_of_fee.docx'),
        'Счет.docx', issue)
    return issue