Esempio n. 1
0
    def save(self, request, client, *args, **kwargs):
        company_client = super(CompanyClientForm, self).save(commit=False,
                                                             *args,
                                                             **kwargs)
        company_client.company = client.person.company

        if not request.POST.get(
                'client_id'
        ):  # client and person is new, lets create it before
            person = Person(name=request.POST.get('name'))
            person.save()
            person.organization.add(request.user.get_profile().org_active.id)
            client_related = Client(
                person=person,
                idRecord=request.user.get_profile().org_active.last_id_record +
                1)
            client_related.save()
            company_client.active = True
        else:  # client already exist, let's create or edit some existing relation
            if not request.POST.get('client_id') in [
                    i.client.id
                    for i in client.person.company.companyclient_set.all()
            ] and not request.POST.get(
                    'active'):  # relation already exists, let's edit it
                company_client.active = True
            client_related = Client.objects.get(
                pk=request.POST.get('client_id'),
                person__organization=request.user.get_profile().org_active)

        company_client.client = client_related
        company_client.responsible = False if not request.POST.get(
            'responsible') else True
        company_client.save()

        return company_client
Esempio n. 2
0
    def save(self, request, client, *args, **kwargs):
        company_client = super(CompanyClientForm, self).\
            save(commit=False, *args, **kwargs)
        company_client.company = client.person.company

        # client and person is new, lets create it before
        if not request.POST.get('client_id'):
            person = Person(name=request.POST.get('name'))
            person.save()
            person.organization.add(request.user.get_profile().org_active.id)
            client_related = Client(person=person,
                                    idRecord=request.user.get_profile().
                                    org_active.last_id_record + 1)
            client_related.save()
            company_client.active = True
        # client already exist, let's create or edit some existing relation
        else:
            # relation already exists, let's edit it
            if not request.POST.get('client_id') in [
                i.client.id for i in
                client.person.company.
                companyclient_set.all()]\
                    and not request.POST.get('active'):
                company_client.active = True
            client_related = Client.objects.get(pk=request.POST.get(
                'client_id'), person__organization=request.
                user.get_profile().org_active)

        company_client.client = client_related
        company_client.responsible = False if not request.POST.get(
            'responsible') else True
        company_client.save()

        return company_client
Esempio n. 3
0
    def test_raise_exception_when_missing_fields(self):
        user = mommy.make('auth.User')
        person = mommy.make('person.Person', user=user)

        client = Client()
        with self.assertRaisesMessage(DatabaseError, "person_id"):
            client.save()

        client.person = person
        with self.assertRaisesMessage(DatabaseError, "idRecord"):
            client.save()
Esempio n. 4
0
    def test_can_save_client_with_min_attributes(self):
        user = mommy.make('auth.User')
        person = mommy.make('person.Person', user=user)

        old_count = Client.objects.count()

        client = Client()
        client.person = person
        client.idRecord = 42
        client.save()
        self.assertGreater(Client.objects.count(), old_count)
Esempio n. 5
0
    def test_raise_exception_when_missing_fields(self):
        user = mommy.make('auth.User')
        person = mommy.make('person.Person', user=user)

        client = Client()
        with self.assertRaisesMessage(DatabaseError, "person_id"):
            client.save()

        client.person = person
        with self.assertRaisesMessage(DatabaseError, "idRecord"):
            client.save()
Esempio n. 6
0
    def test_can_save_client_with_min_attributes(self):
        user = mommy.make('auth.User')
        person = mommy.make('person.Person', user=user)

        old_count = Client.objects.count() 

        client = Client()
        client.person = person
        client.idRecord = 42
        client.save()
        self.assertGreater(Client.objects.count(), old_count)
Esempio n. 7
0
    def setUp(self):
        self.factory = RequestFactory()
        p = Person()

        User.objects.create(username="******", password="******")      
        p.user = User.objects.get(username="******")

        p.save()

        client = Client(person=p, idRecord=1)
        client.save()

        self.person = Person.objects.get(user_id=p.user.id)
Esempio n. 8
0
    def save(self, request, client, *args, **kwargs):
        family = super(FamilyForm, self).save(*args, **kwargs)
        family.client = client
        if request.POST.get('client_id'): # existing client
            client_related = Client.objects.filter(pk=request.POST.get('client_id'), person__organization = request.user.get_profile().org_active)[0]
        else: # client and person is new, lets create it before
            person = Person(name=request.POST.get('name'))
            person.save()
            person.organization.add(request.user.get_profile().org_active.id)
            client_related = Client(person=person, idRecord = request.user.get_profile().org_active.last_id_record + 1)
            client_related.save()

        family.client_related = client_related
        family.save()
        return family
Esempio n. 9
0
def setup_required_client():
    organization1 = Organization.objects.get(name=user_stub()["organization"])

    user = User.objects.create(username="******", password="******")
    user.save()

    person = Person.objects.create(user=user)
    person.name = "Pessoa"
    person.nickname = "nickname"
    person.organization.add(organization1)
    person.save()

    client = Client()
    client.person = person
    client.idRecord = 2
    client.is_active = False
    client.save()
Esempio n. 10
0
def setup_required_client():
    organization1 = Organization.objects.get(name=user_stub()["organization"])

    user = User.objects.create(username="******", password="******")
    user.save()

    person = Person.objects.create(user=user)
    person.name = "Pessoa"
    person.nickname = "nickname"
    person.organization.add(organization1)
    person.save()

    client = Client()
    client.person = person
    client.idRecord = 2
    client.is_active = False
    client.save()
Esempio n. 11
0
    def save(self, request, client, *args, **kwargs):
        family = super(FamilyForm, self).save(*args, **kwargs)
        family.client = client
        if request.POST.get('client_id'):  # existing client
            client_related = Client.objects.filter(
                pk=request.POST.get('client_id'),
                person__organization=request.user.get_profile().org_active)[0]
        else:  # client and person is new, lets create it before
            person = Person(name=request.POST.get('name'))
            person.save()
            person.organization.add(request.user.get_profile().org_active.id)
            client_related = Client(
                person=person,
                idRecord=request.user.get_profile().org_active.last_id_record +
                1)
            client_related.save()

        family.client_related = client_related
        family.save()
        return family