示例#1
0
    def test_str02(self):
        FieldsConfig.create(
            Address,
            descriptions=[
                ('zipcode', {
                    FieldsConfig.HIDDEN: True
                }),
                ('department', {
                    FieldsConfig.HIDDEN: True
                }),
                ('state', {
                    FieldsConfig.HIDDEN: True
                }),
            ],
        )

        address_value = '21 jump street'
        po_box = 'Popop'
        city = 'Atlantis'
        state = '??'
        address = Address(
            name='Address#1',
            address=address_value,
            po_box=po_box,
            zipcode='424242',
            city=city,
            department='rucrazy',
            state=state,
            country='wtf',
        )
        self.assertEqual('{} {}'.format(address_value, city), str(address))

        self.assertEqual(po_box, str(Address(po_box=po_box, state=state)))
示例#2
0
    def test_current_year05(self):
        "closing_date is hidden"
        user = self.login()

        FieldsConfig.create(Opportunity,
                            descriptions=[('closing_date', {
                                FieldsConfig.HIDDEN: True
                            })])

        create_orga = partial(Organisation.objects.create, user=user)
        emitter = create_orga(name='Emitter', is_managed=True)
        target = create_orga(name='Target')

        won_sp = SalesPhase.objects.filter(won=True).first()

        Opportunity.objects.create(
            user=user,
            name='Opp',
            closing_date=now(),
            sales_phase=won_sp,
            emitter=emitter,
            target=target,
        )

        self.assertEqual([
            _('The field «Actual closing date» is hidden ; these statistics are not available.'
              )
        ],
                         CurrentYearStatistics(Opportunity, Organisation)())
示例#3
0
    def test_edit06(self):
        "With FieldsConfig"
        model = FakeContact
        hidden_fname1 = 'description'
        hidden_fname2 = 'position'
        FieldsConfig.create(model,
                            descriptions=[
                                (hidden_fname1, {
                                    FieldsConfig.HIDDEN: True
                                }),
                                (hidden_fname2, {
                                    FieldsConfig.HIDDEN: True
                                }),
                            ])
        sci = SearchConfigItem.create_if_needed(model, fields=['first_name'])

        response = self.assertGET200(self._build_edit_url(sci))

        with self.assertNoException():
            fields_f = response.context['form'].fields['fields']

        self.assertEqual(['first_name'], fields_f.initial)

        self._find_field_index(fields_f, 'first_name')
        self._find_field_index(fields_f, 'civility__title')

        self._assertNotInChoices(fields_f, hidden_fname1)
        self._assertNotInChoices(fields_f, 'position__title')
示例#4
0
    def test_related_opportunity03(self):
        """Opportunity.description is hidden"""
        user = self.login()

        FieldsConfig.create(Opportunity,
                            descriptions=[('description', {FieldsConfig.HIDDEN: True})],
                           )

        casca = Contact.objects.create(user=user, first_name='Casca', last_name='Miura')
        event = Event.objects.create(user=user, name='Eclipse',
                                     type=EventType.objects.first(),
                                     start_date=now(),
                                    )

        emitter = Organisation.objects.create(user=user, name='My society', is_managed=True)

        name = 'Opp01'
        response = self.client.post(self._build_related_opp_url(event, casca), follow=True,
                                    data={'user':        user.id,
                                          'name':        name,
                                          'sales_phase': SalesPhase.objects.first().id,
                                          'target':      self.formfield_value_generic_entity(casca),
                                          'emitter':     emitter.id,
                                          'currency':    DEFAULT_CURRENCY_PK,
                                         }
                                   )
        self.assertNoFormError(response)

        opp = self.get_object_or_fail(Opportunity, name=name)
        self.assertFalse(opp.description)
示例#5
0
    def test_editcomment01(self):
        self.login()
        FieldsConfig.create(
            CreditNote,
            descriptions=[('issuing_date', {
                FieldsConfig.HIDDEN: True
            })],
        )

        credit_note = self.create_credit_note_n_orgas('Credit Note 001')[0]

        url = self._build_editcomment_url(credit_note)
        response = self.assertGET200(url)
        self.assertTemplateUsed(
            response, 'creme_core/generics/blockform/edit-popup.html')
        # self.assertEqual(_('Edit «%s»') % credit_note, response.context.get('title'))
        self.assertEqual(
            _('Edit «{object}»').format(object=credit_note),
            response.context.get('title'))

        # ---
        comment = 'Special gift'
        self.assertNoFormError(self.client.post(url, data={'comment':
                                                           comment}))
        self.assertEqual(comment, self.refresh(credit_note).comment)
示例#6
0
    def test_edit07(self):
        "With FieldsConfig + selected hidden fields"
        model = FakeContact
        hidden_fname1 = 'description'
        hidden_fname2 = 'position'
        hidden_sub_fname2 = hidden_fname2 + '__title'
        sci = SearchConfigItem.create_if_needed(model,
                                                fields=[
                                                    'first_name',
                                                    hidden_fname1,
                                                    hidden_sub_fname2,
                                                ])

        FieldsConfig.create(model,
                            descriptions=[
                                (hidden_fname1, {
                                    FieldsConfig.HIDDEN: True
                                }),
                                (hidden_fname2, {
                                    FieldsConfig.HIDDEN: True
                                }),
                            ])

        response = self.assertGET200(self._build_edit_url(sci))

        with self.assertNoException():
            fields_f = response.context['form'].fields['fields']

        self.assertEqual(['first_name', hidden_fname1, hidden_sub_fname2],
                         fields_f.initial)

        self._find_field_index(fields_f, 'first_name')
        self._find_field_index(fields_f, hidden_fname1)
        self._find_field_index(fields_f, hidden_sub_fname2)
示例#7
0
    def test_mass_import03(self):
        "FieldsConfig on Address sub-field."
        user = self.login()
        FieldsConfig.create(Address,
                            descriptions=[('po_box', {FieldsConfig.HIDDEN: True})],
                           )

        name = 'Nerv'
        city = 'Tokyo'
        po_box = 'ABC123'
        doc = self._build_csv_doc([(name, city, po_box)])
        response = self.client.post(
            self._build_import_url(Organisation), follow=True,
            data={**self.IMPORT_DATA,
                  'document': doc.id,
                  'user': user.id,

                  'billaddr_city_colselect':   2,
                  'billaddr_po_box_colselect': 3,  # Should not be used
                 },
        )
        self.assertNoFormError(response)

        self._execute_job(response)
        billing_address = self.get_object_or_fail(Organisation, name=name).billing_address

        self.assertIsNotNone(billing_address)
        self.assertEqual(city, billing_address.city)
        self.assertFalse(billing_address.po_box)
    def test_get_total_won_quote_this_year04(self):
        "'acceptation_date' is hidden + populate_entities()"
        user = self.login()
        quote1, source1, target1 = self.create_quote_n_orgas('Quote1')
        quote2, source2, target2 = self.create_quote_n_orgas('Quote2')

        FieldsConfig.create(Quote,
                            descriptions=[('acceptation_date', {
                                FieldsConfig.HIDDEN: True
                            })])

        # funf = target1.function_fields.get('total_won_quote_this_year')
        funf = function_field_registry.get(Organisation,
                                           'total_won_quote_this_year')

        FieldsConfig.get_4_model(Quote)  # Fill cache

        with self.assertNumQueries(0):
            funf.populate_entities([target1, target2], user)

        with self.assertNumQueries(0):
            total1 = get_total_won_quote_this_year(target1, user)
            total2 = get_total_won_quote_this_year(target2, user)

        msg = _('Error: «Acceptation date» is hidden')
        self.assertEqual(msg, total1)
        self.assertEqual(msg, total2)
示例#9
0
    def test_mass_import04(self):
        "FieldsConfig on 'billing_address' FK field."
        user = self.login()
        FieldsConfig.create(Organisation,
                            descriptions=[('billing_address', {FieldsConfig.HIDDEN: True})],
                           )

        name = 'Nerv'
        doc = self._build_csv_doc([(name, 'Tokyo', 'ABC123')])
        response = self.client.post(
            self._build_import_url(Organisation), follow=True,
            data={**self.IMPORT_DATA,
                  'document': doc.id,
                  'user': user.id,

                  'billaddr_city_colselect': 2,  # Should not be used
                  'billaddr_po_box_colselect': 3,  # Should not be used
                 },
        )
        self.assertNoFormError(response)

        job = self._execute_job(response)

        orga = self.get_object_or_fail(Organisation, name=name)
        self.assertIsNone(orga.billing_address)

        self._assertNoResultError(self._get_job_results(job))
    def test_get_4_model01(self):
        model = FakeContact
        h_field1 = 'phone'
        h_field2 = 'mobile'
        FieldsConfig.create(
            model,
            descriptions=[
                (h_field1, {
                    FieldsConfig.HIDDEN: True
                }),
                (h_field2, {
                    FieldsConfig.HIDDEN: True
                }),
            ],
        )

        with self.assertNumQueries(1):
            fc = FieldsConfig.get_4_model(model)

        is_hidden = fc.is_fieldname_hidden
        self.assertTrue(is_hidden(h_field1))
        self.assertTrue(is_hidden(h_field2))
        self.assertFalse(is_hidden('description'))

        with self.assertNumQueries(0):  # cache
            FieldsConfig.get_4_model(model)
 def test_create_errors_03(self):
     "Invalid attribute name"
     with self.assertRaises(FieldsConfig.InvalidAttribute):
         FieldsConfig.create(FakeContact,
                             descriptions=[('phone', {
                                 'invalid': True
                             })])
 def test_create_errors_04(self):
     "Invalid attribute value"
     with self.assertRaises(FieldsConfig.InvalidAttribute):
         FieldsConfig.create(
             FakeContact,
             descriptions=[('phone', {
                 FieldsConfig.HIDDEN: 5
             })],
         )
示例#13
0
    def test_createview03(self):
        "FieldsConfig on Address sub-fields"
        user = self.login()
        FieldsConfig.create(
            Address,
            descriptions=[('po_box', {
                FieldsConfig.HIDDEN: True
            })],
        )

        response = self.assertGET200(reverse('persons__create_organisation'))

        with self.assertNoException():
            fields = response.context['form'].fields

        self.assertIn('name', fields)
        self.assertIn('billing_address-address', fields)
        self.assertNotIn('billing_address-po_box', fields)

        name = 'Bebop'

        b_address = 'Mars gate'
        b_po_box = 'Mars1233546'
        b_zipcode = '9874541'
        b_city = 'Redsand'
        b_department = 'Great crater'
        b_state = 'State#3'
        b_country = 'Terran federation'

        response = self.client.post(
            reverse('persons__create_organisation'),
            follow=True,
            data={
                'user': user.pk,
                'name': name,
                'billing_address-address': b_address,
                'billing_address-po_box': b_po_box,  # <== should not be used
                'billing_address-zipcode': b_zipcode,
                'billing_address-city': b_city,
                'billing_address-department': b_department,
                'billing_address-state': b_state,
                'billing_address-country': b_country,
            })
        self.assertNoFormError(response)

        orga = self.get_object_or_fail(Organisation, name=name)
        billing_address = orga.billing_address
        self.assertIsNotNone(billing_address)
        self.assertEqual(b_address, billing_address.address)
        self.assertEqual(b_zipcode, billing_address.zipcode)
        self.assertEqual(b_city, billing_address.city)
        self.assertEqual(b_department, billing_address.department)
        self.assertEqual(b_state, billing_address.state)
        self.assertEqual(b_country, billing_address.country)

        self.assertFalse(billing_address.po_box)
示例#14
0
 def test_ml_contacts_filter03(self):
     "'email' is hidden"
     mlist = MailingList.objects.create(user=self.user, name='ml01')
     FieldsConfig.create(
         Contact,
         descriptions=[('email', {
             FieldsConfig.HIDDEN: True
         })],
     )
     self.assertGET409(self._build_addcontactfilter_url(mlist))
示例#15
0
    def test_ml_orgas02(self):
        "'email' is hidden"
        mlist = MailingList.objects.create(user=self.user, name='ml01')

        FieldsConfig.create(
            Organisation,
            descriptions=[('email', {
                FieldsConfig.HIDDEN: True
            })],
        )
        self.assertGET409(self._build_addorga_url(mlist))
示例#16
0
    def test_editcomment02(self):
        "'comment' is hidden"
        self.login()
        FieldsConfig.create(
            CreditNote,
            descriptions=[('comment', {
                FieldsConfig.HIDDEN: True
            })],
        )

        credit_note = self.create_credit_note_n_orgas('Credit Note 001')[0]
        self.assertGET409(self._build_editcomment_url(credit_note))
 def _create_contact_conf(self):
     FieldsConfig.create(
         FakeContact,
         descriptions=[
             ('phone', {
                 FieldsConfig.HIDDEN: True
             }),
             ('mobile', {
                 FieldsConfig.HIDDEN: True
             }),
         ],
     )
示例#18
0
    def test_respond_to_a_call05(self):
        """FieldsConfig: some fields are hidden"""
        user = self.login()

        FieldsConfig.create(Contact,
                            descriptions=[('phone', {FieldsConfig.HIDDEN: True})]
                           )

        phone = '558899'
        contact = Contact.objects.create(user=user, first_name='Bean', last_name='Bandit', phone=phone)
        response = self.assertGET200(self.RESPOND_URL, data={'number': phone})
        self.assertNotContains(response, str(contact))
示例#19
0
    def test_create_billing02(self):
        "FK is hidden"
        orga = self.login()

        FieldsConfig.create(
            Organisation,
            descriptions=[('billing_address', {
                FieldsConfig.HIDDEN: True
            })],
        )
        self.assertGET409(
            reverse('persons__create_billing_address', args=(orga.id, )))
示例#20
0
    def test_set_default_in_invoice04(self):
        "'payment_info' is hidden."
        user = self.login()

        invoice, sony_source = self.create_invoice_n_orgas('Playstations')[:2]
        pi_sony = PaymentInformation.objects.create(organisation=sony_source, name='RIB sony')

        FieldsConfig.create(Invoice,
                            descriptions=[('payment_info', {FieldsConfig.HIDDEN: True})],
                           )

        self.assertPOST409(self._build_setdefault_url(pi_sony, invoice))
示例#21
0
    def test_display_custombrick03(self):
        "With FieldsConfig on sub-fields"
        user = self.login()

        hidden_fname = 'zipcode'
        FieldsConfig.create(
            FakeAddress,
            descriptions=[(hidden_fname, {
                FieldsConfig.HIDDEN: True
            })],
        )
        build_cell = EntityCellRegularField.build
        cbc_item = CustomBrickConfigItem.objects.create(
            id='tests-contacts1',
            name='Contact info',
            content_type=ContentType.objects.get_for_model(FakeContact),
            cells=[
                build_cell(FakeContact, 'last_name'),
                build_cell(FakeContact, 'address__' + hidden_fname),
                build_cell(FakeContact, 'address__city'),
            ],
        )
        bdl = BrickDetailviewLocation.create_if_needed(
            brick_id=cbc_item.generate_id(),
            order=1000,  # Should be the last block
            model=FakeContact,
            zone=BrickDetailviewLocation.BOTTOM,
        )
        naru = FakeContact.objects.create(
            user=user,
            last_name='Narusegawa',
            first_name='Naru',
            phone='1122334455',
        )
        naru.address = FakeAddress.objects.create(
            value='Hinata Inn',
            city='Tokyo',
            zipcode='112233',
            entity=naru,
        )
        naru.save()

        content_node = self._get_contact_brick_content(naru,
                                                       brick_id=bdl.brick_id)
        self.assertEqual(
            naru.last_name,
            self.get_brick_tile(content_node, 'regular_field-last_name').text)
        self.assertEqual(
            naru.address.city,
            self.get_brick_tile(content_node,
                                'regular_field-address__city').text)
        self._assertNoBrickTile(content_node, 'regular_field-address__zipcode')
示例#22
0
    def test_search10(self):
        "With FieldsConfig"
        user = self.login()

        hidden_fname1 = 'description'
        hidden_fname2 = 'sector'
        SearchConfigItem.create_if_needed(
            FakeContact,
            [
                'first_name',
                'last_name',
                hidden_fname1,
                hidden_fname2 + '__title',
            ],
        )

        sector = FakeSector.objects.create(title='Linux dev')

        create_contact = partial(FakeContact.objects.create, user=user)
        linus = create_contact(first_name='Linus',
                               last_name='Torvalds',
                               description="Alan's friend")
        alan = create_contact(first_name='Alan',
                              last_name='Cox',
                              description="Linus' friend")
        andrew = create_contact(first_name='Andrew',
                                last_name='Morton',
                                sector=sector)

        FieldsConfig.create(FakeContact,
                            descriptions=[
                                (hidden_fname1, {
                                    FieldsConfig.HIDDEN: True
                                }),
                                (hidden_fname2, {
                                    FieldsConfig.HIDDEN: True
                                }),
                            ])

        response = self._search('Linu', self.contact_ct_id)
        self.assertEqual(200, response.status_code)

        self.assertContains(response, linus.get_absolute_url())
        self.assertNotContains(response, alan.get_absolute_url())
        self.assertNotContains(response, andrew.get_absolute_url())

        self.assertContains(response, _('First name'))
        self.assertContains(response, _('Last name'))
        self.assertNotContains(response, _('Description'))
        self.assertNotContains(response, _('Sector'))
示例#23
0
    def test_event_createview04(self):
        "FieldsConfig: end is hidden"
        self.login()

        FieldsConfig.create(Event,
                            descriptions=[('end_date', {FieldsConfig.HIDDEN: True})],
                           )

        event = self._create_event('Comiket',
                                   start_date='2016-7-25 8:00',
                                   end_date='2016-7-29 18:30',
                                  )
        self.assertEqual(self.create_datetime(year=2016, month=7, day=25, hour=8), event.start_date)
        self.assertIsNone(event.end_date)
示例#24
0
    def test_addresses_brick07(self):
        "With field config on 'shipping_address' FK field"
        FieldsConfig.create(
            Contact,
            descriptions=[('shipping_address', {
                FieldsConfig.HIDDEN: True
            })],
        )

        c = self._create_contact_n_addresses()

        brick_node = self._get_address_brick_node(c)
        self._assertAddressIn(brick_node, c.billing_address,
                              _('Billing address'))
        self._assertAddressNotIn(brick_node, c.shipping_address)
示例#25
0
    def test_search_field02(self):
        "Ignore hidden fields"
        self.login(create_orga=False)

        FieldsConfig.create(
            Address,
            descriptions=[('city', {
                FieldsConfig.HIDDEN: True
            })],
        )

        field = AddressFKField(
            cell=EntityCellRegularField.build(model=Organisation,
                                              name='billing_address'),
            user=self.user,
        )

        create_orga = partial(Organisation.objects.create, user=self.user)
        orga1 = create_orga(name='Orga without address')
        orga2 = create_orga(name='Orga with empty address')
        orga3 = create_orga(name='Orga with address #1')
        orga4 = create_orga(name='Orga with address #2 (hidden field)')
        orga5 = create_orga(name='Orga with address #3 (not OK)')
        orga6 = create_orga(name='Orga with named address')
        orga_ids = [orga1.id, orga2.id, orga3.id, orga4.id, orga5.id, orga6.id]

        create_address = Address.objects.create
        addr2 = create_address(address='', owner=orga2)
        addr3 = create_address(address='42 Towel street', owner=orga3)
        addr4 = create_address(city='TowelCity', owner=orga4)
        addr5 = create_address(address='42 Fish street', owner=orga5)
        addr6 = create_address(name='Towel', owner=orga6)

        orga2.billing_address = addr2
        orga2.save()
        orga3.billing_address = addr3
        orga3.save()
        orga4.billing_address = addr4
        orga4.save()
        orga5.billing_address = addr5
        orga5.save()
        orga6.billing_address = addr6
        orga6.save()

        self.assertListEqual([orga3], [
            *Organisation.objects.filter(id__in=orga_ids).filter(
                field.to_python(value='towel'))
        ])
示例#26
0
    def test_editview04(self):
        "Contact is a user + emails is hidden (crashed)"
        user = self.login()
        contact = self.get_object_or_fail(Contact, is_user=user)

        FieldsConfig.create(
            Contact,
            descriptions=[('email', {
                FieldsConfig.HIDDEN: True
            })],
        )

        url = contact.get_edit_absolute_url()
        response = self.assertGET200(url)

        with self.assertNoException():
            fields = response.context['form'].fields

        self.assertNotIn('email', fields)

        last_name = user.last_name
        first_name = user.first_name
        email = user.email
        description = 'First contact user'
        response = self.client.post(
            url,
            follow=True,
            data={
                'user': user.id,
                'last_name': last_name,
                'first_name': first_name,
                'email': '*****@*****.**',
                'description': description,
            },
        )
        self.assertNoFormError(response)

        contact = self.refresh(contact)
        self.assertEqual(first_name, contact.first_name)
        self.assertEqual(last_name, contact.last_name)
        self.assertEqual(email, contact.email)  # <= no change
        self.assertEqual(description, contact.description)

        user = self.refresh(user)
        self.assertEqual(first_name, user.first_name)
        self.assertEqual(last_name, user.last_name)
        self.assertEqual(email, user.email)  # <= no change
    def test_get_total_won_quote_this_year02(self):
        "'acceptation_date' is hidden"
        user = self.login()

        quote, source, target = self.create_quote_n_orgas('Quote #1')
        FieldsConfig.create(Quote,
                            descriptions=[('acceptation_date', {FieldsConfig.HIDDEN: True})]
                           )

        funf = function_field_registry.get(Organisation, 'total_won_quote_this_year')

        FieldsConfig.get_4_model(Quote)  # Fill cache

        with self.assertNumQueries(0):
            total = funf(target, user).for_csv()

        self.assertEqual(_('Error: «Acceptation date» is hidden'), total)
    def test_get_4_model03(self):
        "Cache not created"
        model = FakeContact
        FieldsConfig.create(
            model,
            descriptions=[('phone', {
                FieldsConfig.HIDDEN: True
            })],
        )

        set_global_info(per_request_cache=None)

        with self.assertNumQueries(1):
            FieldsConfig.get_4_model(model)

        with self.assertNumQueries(0):
            FieldsConfig.get_4_model(model)
    def test_get_total_won_quote_last_year02(self):
        "'acceptation_date' is hidden"
        user = self.login()
        quote, source, target = self.create_quote_n_orgas("YOLO")

        FieldsConfig.create(Quote,
                            descriptions=[('acceptation_date', {FieldsConfig.HIDDEN: True})]
                           )

        quote.acceptation_date = self.today_date
        self._set_managed(source)

        FieldsConfig.get_4_model(Quote)  # Fill cache

        with self.assertNumQueries(0):
            total = get_total_won_quote_last_year(target, user)

        self.assertEqual(_('Error: «Acceptation date» is hidden'), total)
示例#30
0
    def test_info_names02(self):
        FieldsConfig.create(
            Address,
            descriptions=[('po_box', {
                FieldsConfig.HIDDEN: True
            })],
        )

        self.assertSetEqual(
            {
                'name',
                'address',
                'zipcode',
                'city',
                'department',
                'state',
                'country',
            }, {*Address.info_field_names()})