Exemple #1
0
def headquar_add(request):
    """
    Agrega sede
    """
    d = Headquar()
    d.phone = ""
    d.address = ""
    if request.method == "POST":
        try:
            sid = transaction.savepoint()
            d.name = request.POST.get("name")
            d.phone = request.POST.get("phone")
            d.address = request.POST.get("address")
            d.is_main = False
            d.locality_name = request.POST.get("locality_name")
            if request.POST.get("locality_name"):
                d.locality, is_locality_created = Locality.objects.get_or_create(
                    name=request.POST.get("locality_name"),  # name__iexact
                    )
            d.association_id = DataAccessToken.get_association_id(request.session)
            d.enterprise_id = DataAccessToken.get_enterprise_id(request.session)

            if normalize("NFKD", u"%s" % d.name).encode("ascii", "ignore").lower() in list(
                normalize("NFKD", u"%s" % col["name"]).encode("ascii", "ignore").lower() for col in Headquar.objects.values("name").exclude(id=d.id).filter(enterprise_id=d.enterprise_id)
                ):
                raise Exception("La sede <b>%s</b> ya existe " % (d.name))
            d.save()
            if d.id:
                Message.info(request, ("Sede <b>%(name)s</b> ha sido registrado correctamente.") % {"name":d.name})
                return Redirect.to_action(request, "index")
        except Exception, e:
            transaction.savepoint_rollback(sid)
            Message.error(request, e)
Exemple #2
0
def enterprise_add(request):
    """
    Agrega empresa dentro de una asociación, para ello deberá agregarse con una sede Principal
    """
    d = Enterprise()
    d.sede = "Principal"
    if request.method == "POST":
        try:
            sid = transaction.savepoint()
            d.name = request.POST.get("name")
            d.tax_id = request.POST.get("tax_id")
            d.type_e = request.POST.get("type_e")
            d.solution_id = request.POST.get("solution_id")
            # solution=Solution.objects.get(id=d.solution_id) #no es necesario
            if normalize("NFKD", u"%s" % d.name).encode(
                    "ascii", "ignore").lower() in list(
                        normalize("NFKD", u"%s" % col["name"]).encode(
                            "ascii", "ignore").lower()
                        for col in Enterprise.objects.values("name").exclude(
                            id=d.id)):
                raise Exception(
                    ("Empresa <b>%(name)s</b> ya existe.") % {"name": d.name})

            if Enterprise.objects.exclude(id=d.id).filter(
                    tax_id=d.tax_id).count() > 0:
                raise Exception("La empresa con RUC <b>%s</b> ya existe " %
                                (d.tax_id))

            d.save()

            headquar = Headquar()
            headquar.name = request.POST.get("sede")
            headquar.association_id = DataAccessToken.get_association_id(
                request.session)
            headquar.enterprise = d

            if normalize("NFKD", u"%s" % headquar.name).encode(
                    "ascii", "ignore").lower() in list(
                        normalize("NFKD", u"%s" % col["name"]).encode(
                            "ascii", "ignore").lower()
                        for col in Headquar.objects.values("name").exclude(
                            id=headquar.id).filter(
                                enterprise_id=headquar.enterprise_id)):
                raise Exception("La sede <b>%s</b> ya existe " %
                                (headquar.name))

            headquar.save()

            if d.id:
                Message.info(request, (
                    "Empresa <b>%(name)s</b> ha sido registrado correctamente."
                ) % {"name": d.name})
                return Redirect.to_action(request, "index")
        except Exception, e:
            transaction.savepoint_rollback(sid)
            Message.error(request, e)
Exemple #3
0
def enterprise_add(request):
    """
    Agrega empresa dentro de una asociación, para ello deberá agregarse con una sede Principal
    """
    d = Enterprise()
    d.sede = "Principal"
    if request.method == "POST":
        try:
            sid = transaction.savepoint()
            d.name = request.POST.get("name")
            d.tax_id = request.POST.get("tax_id")
            d.type_e = request.POST.get("type_e")
            d.solution_id = request.POST.get("solution_id")
            # solution=Solution.objects.get(id=d.solution_id) #no es necesario
            if normalize("NFKD", u"%s" % d.name).encode("ascii", "ignore").lower() in list(
                normalize("NFKD", u"%s" % col["name"]).encode("ascii", "ignore").lower() for col in Enterprise.objects.values("name").exclude(id=d.id)
                ):
                raise Exception(("Empresa <b>%(name)s</b> ya existe.") % {"name":d.name})

            if Enterprise.objects.exclude(id=d.id).filter(tax_id=d.tax_id).count() > 0:
                raise Exception("La empresa con RUC <b>%s</b> ya existe " % (d.tax_id))

            d.save()

            headquar = Headquar()
            headquar.name = request.POST.get("sede")
            headquar.association_id = DataAccessToken.get_association_id(request.session)
            headquar.enterprise = d

            if normalize("NFKD", u"%s" % headquar.name).encode("ascii", "ignore").lower() in list(
                normalize("NFKD", u"%s" % col["name"]).encode("ascii", "ignore").lower() for col in Headquar.objects.values("name").exclude(id=headquar.id).filter(enterprise_id=headquar.enterprise_id)
                ):
                raise Exception("La sede <b>%s</b> ya existe " % (headquar.name))

            headquar.save()

            if d.id:
                Message.info(request, ("Empresa <b>%(name)s</b> ha sido registrado correctamente.") % {"name":d.name})
                return Redirect.to_action(request, "index")
        except Exception, e:
            transaction.savepoint_rollback(sid)
            Message.error(request, e)
Exemple #4
0
def headquar_add(request):
    """
    Agrega sede
    """
    d = Headquar()
    d.phone = ""
    d.address = ""
    if request.method == "POST":
        try:
            sid = transaction.savepoint()
            d.name = request.POST.get("name")
            d.phone = request.POST.get("phone")
            d.address = request.POST.get("address")
            d.is_main = False
            d.locality_name = request.POST.get("locality_name")
            if request.POST.get("locality_name"):
                d.locality, is_locality_created = Locality.objects.get_or_create(
                    name=request.POST.get("locality_name"),  # name__iexact
                )
            d.association_id = DataAccessToken.get_association_id(
                request.session)
            d.enterprise_id = DataAccessToken.get_enterprise_id(
                request.session)

            if normalize("NFKD", u"%s" % d.name).encode(
                    "ascii", "ignore").lower() in list(
                        normalize("NFKD", u"%s" % col["name"]).encode(
                            "ascii", "ignore").lower()
                        for col in Headquar.objects.values("name").exclude(
                            id=d.id).filter(enterprise_id=d.enterprise_id)):
                raise Exception("La sede <b>%s</b> ya existe " % (d.name))
            d.save()
            if d.id:
                Message.info(
                    request,
                    ("Sede <b>%(name)s</b> ha sido registrado correctamente.")
                    % {"name": d.name})
                return Redirect.to_action(request, "index")
        except Exception, e:
            transaction.savepoint_rollback(sid)
            Message.error(request, e)