Skip to content

Vendor

hypha.apply.projects.views.vendor

CreateVendorAccessMixin

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/vendor.py
def dispatch(self, request, *args, **kwargs):
    project_settings = ProjectSettings.for_request(request)
    if not project_settings.vendor_setup_required:
        raise PermissionDenied
    is_admin = request.user.is_apply_staff
    project = self.get_project()
    is_owner = request.user == project.user
    if not (is_owner or is_admin):
        raise PermissionDenied
    if not project.editable_by(request.user):
        raise PermissionDenied
    if not project.vendor:
        raise Http404
    return super().dispatch(request, *args, **kwargs)

DetailVendorAccessMixin

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/vendor.py
def dispatch(self, request, *args, **kwargs):
    project_settings = ProjectSettings.for_request(request)
    if not project_settings.vendor_setup_required:
        raise PermissionDenied
    is_admin = request.user.is_apply_staff
    project = self.get_project()
    is_owner = request.user == project.user
    if not (is_owner or is_admin):
        raise PermissionDenied
    if not project.vendor:
        raise Http404
    return super().dispatch(request, *args, **kwargs)

CreateVendorView

Bases: CreateVendorAccessMixin, SessionWizardView

file_storage class-attribute instance-attribute

file_storage = PrivateStorage()

form_list class-attribute instance-attribute

form_list = [('basic', CreateVendorFormStep1), ('taxes', CreateVendorFormStep2), ('documents', CreateVendorFormStep3), ('bank', CreateVendorFormStep4), ('extra', CreateVendorFormStep5), ('other', CreateVendorFormStep6)]

condition_dict class-attribute instance-attribute

condition_dict = {'other': show_extra_info_form}

template_name class-attribute instance-attribute

template_name = 'application_projects/vendor_form.html'

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/vendor.py
def dispatch(self, request, *args, **kwargs):
    project_settings = ProjectSettings.for_request(request)
    if not project_settings.vendor_setup_required:
        raise PermissionDenied
    is_admin = request.user.is_apply_staff
    project = self.get_project()
    is_owner = request.user == project.user
    if not (is_owner or is_admin):
        raise PermissionDenied
    if not project.editable_by(request.user):
        raise PermissionDenied
    if not project.vendor:
        raise Http404
    return super().dispatch(request, *args, **kwargs)

get_project

get_project()
Source code in hypha/apply/projects/views/vendor.py
def get_project(self):
    return get_object_or_404(Project, pk=self.kwargs["pk"])

done

done(form_list, **kwargs)
Source code in hypha/apply/projects/views/vendor.py
def done(self, form_list, **kwargs):
    vendor_project = self.get_project()
    cleaned_data = self.get_all_cleaned_data()
    vendor = vendor_project.vendor
    need_extra_info = cleaned_data["need_extra_info"]
    bank_info = vendor.bank_info
    account_holder_name = cleaned_data["account_holder_name"]
    account_routing_number = cleaned_data["account_routing_number"]
    account_number = cleaned_data["account_number"]
    account_currency = cleaned_data["account_currency"]
    if not bank_info:
        bank_info = BankInformation.objects.create(
            account_holder_name=account_holder_name,
            account_number=account_number,
            account_routing_number=account_routing_number,
            account_currency=account_currency,
            need_extra_info=need_extra_info,
        )
    else:
        bank_info.account_holder_name = account_holder_name
        bank_info.account_number = account_number
        bank_info.account_currency = account_currency
        bank_info.need_extra_info = need_extra_info
    if need_extra_info:
        ib_account_routing_number = cleaned_data["ib_account_routing_number"]
        ib_account_number = cleaned_data["ib_account_number"]
        ib_account_currency = cleaned_data["ib_account_currency"]
        ib_branch_address = cleaned_data["ib_branch_address"]
        iba_info = bank_info.iba_info
        if not iba_info:
            iba_info = BankInformation.objects.create(
                account_routing_number=ib_account_routing_number,
                account_number=ib_account_number,
                account_currency=ib_account_currency,
                branch_address=ib_branch_address,
            )
        else:
            iba_info.branch_address = ib_branch_address
            iba_info.account_routing_number = ib_account_routing_number
            iba_info.account_number = ib_account_number
            iba_info.account_currency = ib_account_currency
        iba_info.save()
        bank_info.branch_address = cleaned_data["branch_address"]
        bank_info.nid_type = cleaned_data["nid_type"]
        bank_info.nid_number = cleaned_data["nid_number"]
        bank_info.iba_info = iba_info
        vendor.other_info = cleaned_data["other_info"]

    bank_info.save()

    vendor.bank_info = bank_info
    vendor.name = cleaned_data["name"]
    vendor.contractor_name = cleaned_data["contractor_name"]
    vendor.type = cleaned_data["type"]
    vendor.required_to_pay_taxes = cleaned_data["required_to_pay_taxes"]
    vendor.updated_at = timezone.now()
    vendor.user_has_updated_details = True
    vendor.save()

    not_deleted_original_filenames = [
        file["name"]
        for file in json.loads(cleaned_data["due_diligence_documents-uploads"])
    ]
    for f in vendor.due_diligence_documents.all():
        if f.document.name not in not_deleted_original_filenames:
            f.document.delete()
            f.delete()

    for f in cleaned_data["due_diligence_documents"]:
        if not isinstance(f, FieldFile):
            try:
                DueDiligenceDocument.objects.create(vendor=vendor, document=f)
            finally:
                f.close()
    form = self.get_form("documents")
    form.delete_temporary_files()

    messenger(
        MESSAGES.UPDATED_VENDOR,
        request=self.request,
        user=vendor_project.lead,
        source=vendor_project,
    )

    return render(
        self.request,
        "application_projects/vendor_success.html",
        {"project": vendor_project},
    )

get_form_initial

get_form_initial(step)
Source code in hypha/apply/projects/views/vendor.py
def get_form_initial(self, step):
    vendor_project = self.get_project()
    vendor = vendor_project.vendor
    initial_dict = self.initial_dict.get(step, {})
    if vendor:
        initial_dict["basic"] = {
            "name": vendor.name,
            "contractor_name": vendor.contractor_name,
            "type": vendor.type,
        }
        initial_dict["taxes"] = {
            "required_to_pay_taxes": vendor.required_to_pay_taxes
        }
        initial_dict["documents"] = {
            "due_diligence_documents": [
                f.document for f in vendor.due_diligence_documents.all()
            ]
        }
        bank_info = vendor.bank_info
        if bank_info:
            initial_dict["bank"] = {
                "account_holder_name": bank_info.account_holder_name,
                "account_routing_number": bank_info.account_routing_number,
                "account_number": bank_info.account_number,
                "account_currency": bank_info.account_currency,
            }
            initial_dict["extra"] = {"need_extra_info": bank_info.need_extra_info}
            initial_dict["other"] = {
                "branch_address": bank_info.branch_address,
                "nid_type": bank_info.nid_type,
                "nid_number": bank_info.nid_number,
                "other_info": vendor.other_info,
            }
            iba_info = bank_info.iba_info
            if iba_info:
                initial_dict["other"][
                    "ib_account_routing_number"
                ] = iba_info.account_routing_number
                initial_dict["other"]["ib_account_number"] = iba_info.account_number
                initial_dict["other"][
                    "ib_account_currency"
                ] = iba_info.account_currency
                initial_dict["other"]["ib_branch_address"] = iba_info.branch_address
    return initial_dict.get(step, {})

get_form_kwargs

get_form_kwargs(step)
Source code in hypha/apply/projects/views/vendor.py
def get_form_kwargs(self, step):
    kwargs = super(CreateVendorView, self).get_form_kwargs(step)
    kwargs["site"] = Site.find_for_request(self.request)
    return kwargs

VendorDetailView

Bases: DetailVendorAccessMixin, DetailView

model class-attribute instance-attribute

model = Vendor

template_name class-attribute instance-attribute

template_name = 'application_projects/vendor_detail.html'

dispatch

dispatch(request, *args, **kwargs)
Source code in hypha/apply/projects/views/vendor.py
def dispatch(self, request, *args, **kwargs):
    project_settings = ProjectSettings.for_request(request)
    if not project_settings.vendor_setup_required:
        raise PermissionDenied
    is_admin = request.user.is_apply_staff
    project = self.get_project()
    is_owner = request.user == project.user
    if not (is_owner or is_admin):
        raise PermissionDenied
    if not project.vendor:
        raise Http404
    return super().dispatch(request, *args, **kwargs)

get_object

get_object(queryset=None)
Source code in hypha/apply/projects/views/vendor.py
def get_object(self, queryset=None):
    return get_object_or_404(self.model, id=self.kwargs["vendor_pk"])

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/projects/views/vendor.py
def get_context_data(self, **kwargs):
    context = super().get_context_data(**kwargs)
    context["vendor_detailed_response"] = self.get_detailed_response()
    context["project"] = self.get_project()
    vendor = self.get_object()
    context["due_diligence_documents"] = vendor.due_diligence_documents.all()
    return context

get_project

get_project()
Source code in hypha/apply/projects/views/vendor.py
def get_project(self):
    return get_object_or_404(Project, pk=self.kwargs["pk"])

get_detailed_response

get_detailed_response()
Source code in hypha/apply/projects/views/vendor.py
def get_detailed_response(self):
    vendor = self.get_object()
    vendor_form_settings = VendorFormSettings.for_request(self.request)
    data = {}
    group = 0
    data.setdefault(
        group, {"title": str(_("Contracting Information")), "questions": []}
    )
    data[group]["questions"] = [
        (vendor_form_settings.name_label, vendor.name),
        (vendor_form_settings.contractor_name_label, vendor.contractor_name),
        (vendor_form_settings.type_label, vendor.type),
        (
            vendor_form_settings.required_to_pay_taxes_label,
            vendor.required_to_pay_taxes,
        ),
        ("Due Diligence Documents", ""),
    ]
    group = group + 1
    data.setdefault(
        group, {"title": str(_("Bank Account Information")), "questions": []}
    )
    bank_info = vendor.bank_info
    data[group]["questions"] = [
        (
            vendor_form_settings.account_holder_name_label,
            bank_info.account_holder_name if bank_info else "",
        ),
        (
            vendor_form_settings.account_routing_number_label,
            bank_info.account_routing_number if bank_info else "",
        ),
        (
            vendor_form_settings.account_number_label,
            bank_info.account_number if bank_info else "",
        ),
        (
            vendor_form_settings.account_currency_label,
            bank_info.account_currency if bank_info else "",
        ),
    ]
    group = group + 1
    data.setdefault(
        group,
        {
            "title": str(_("(Optional) Extra Information for Accepting Payments")),
            "questions": [],
        },
    )
    data[group]["questions"] = [
        (
            vendor_form_settings.branch_address_label,
            self.get_address_display(bank_info.branch_address) if bank_info else "",
        ),
    ]
    group = group + 1
    data.setdefault(
        group,
        {"title": str(_("Intermediary Bank Account Information")), "questions": []},
    )
    iba_info = bank_info.iba_info if bank_info else None
    data[group]["questions"] = [
        (
            vendor_form_settings.ib_account_routing_number_label,
            iba_info.account_routing_number if iba_info else "",
        ),
        (
            vendor_form_settings.ib_account_number_label,
            iba_info.account_number if iba_info else "",
        ),
        (
            vendor_form_settings.ib_account_currency_label,
            iba_info.account_currency if iba_info else "",
        ),
        (
            vendor_form_settings.ib_branch_address_label,
            self.get_address_display(iba_info.branch_address) if iba_info else "",
        ),
    ]
    group = group + 1
    data.setdefault(
        group,
        {
            "title": str(
                _("Account Holder National Identity Document Information")
            ),
            "questions": [],
        },
    )
    data[group]["questions"] = [
        (
            vendor_form_settings.nid_type_label,
            bank_info.nid_type if bank_info else "",
        ),
        (
            vendor_form_settings.nid_number_label,
            bank_info.nid_number if bank_info else "",
        ),
    ]
    group = group + 1
    data.setdefault(group, {"title": None, "questions": []})
    data[group]["questions"] = [
        (vendor_form_settings.other_info_label, vendor.other_info),
    ]
    return data

get_address_display

get_address_display(address)
Source code in hypha/apply/projects/views/vendor.py
def get_address_display(self, address):
    try:
        address = json.loads(address)
    except (json.JSONDecodeError, AttributeError):
        return ""
    else:
        return ", ".join(
            address.get(field)
            for field in ADDRESS_FIELDS_ORDER
            if address.get(field)
        )

VendorPrivateMediaView

Bases: UserPassesTestMixin, PrivateMediaView

storage class-attribute instance-attribute

storage = PrivateStorage()

raise_exception class-attribute instance-attribute

raise_exception = True

get

get(*args, **kwargs)
Source code in hypha/apply/utils/storage.py
def get(self, *args, **kwargs):
    file_to_serve = self.get_media(*args, **kwargs)
    return FileResponse(file_to_serve)

dispatch

dispatch(*args, **kwargs)
Source code in hypha/apply/projects/views/vendor.py
def dispatch(self, *args, **kwargs):
    pk = self.kwargs["pk"]
    vendor_pk = self.kwargs["vendor_pk"]
    self.vendor = get_object_or_404(Vendor, pk=vendor_pk)
    self.project = get_object_or_404(Project, pk=pk)

    return super().dispatch(*args, **kwargs)

get_media

get_media(*args, **kwargs)
Source code in hypha/apply/projects/views/vendor.py
def get_media(self, *args, **kwargs):
    file_pk = kwargs.get("file_pk")
    document = get_object_or_404(self.vendor.due_diligence_documents, pk=file_pk)
    return document.document

test_func

test_func()
Source code in hypha/apply/projects/views/vendor.py
def test_func(self):
    if self.request.user.is_apply_staff:
        return True

    if self.request.user == self.project.user:
        return True

    return False

show_extra_info_form

show_extra_info_form(wizard)
Source code in hypha/apply/projects/views/vendor.py
def show_extra_info_form(wizard):
    # try to get the cleaned data of step where we ask if extra info is needed
    cleaned_data = wizard.get_cleaned_data_for_step("extra") or {}
    # check if the field ``extra_info`` box was checked.
    return cleaned_data.get("need_extra_info", True)