def test_BRCNPJField(self): instance = models.BRCNPJField() name, path, args, kwargs = instance.deconstruct() new_instance = models.BRCNPJField(*args, **kwargs) self.assertEqual(instance.max_length, new_instance.max_length) self.assertEqual(instance.description, new_instance.description) self.assertEqual(instance.validators, new_instance.validators)
class PessoaJuridica(Pessoa): class Meta: verbose_name = _("Pessoa Jurídica") verbose_name_plural = _("Pessoas Jurídicas") cnpj = lf_models.BRCNPJField(unique=True) matriz = models.ForeignKey("self", blank=True, null=True, on_delete=models.PROTECT, related_name="filiais") @property def razao_social(self): return self.nome_razao_social @razao_social.setter def razao_social(self, value): self.nome_razao_social = value def get_absolute_url(self): from django.urls import reverse return reverse("sgi_base:pessoajuridica-detail", kwargs={"pk": self.pk}) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # pylint: disable=no-member self._meta.get_field("nome_razao_social").verbose_name = _( "Razão Social") def __str__(self): return "{nome_razao_social} ({cnpj})".format(**vars(self))
class PessoaJuridica(Pessoa): class Meta: verbose_name = _('Pessoa Jurídica') verbose_name_plural = _('Pessoas Jurídicas') cnpj = lf_models.BRCNPJField(unique=True) content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=True) object_id = models.PositiveIntegerField(null=True) matriz = GenericForeignKey('content_type', 'object_id') filiais = GenericRelation('PessoaJuridica') @property def razao_social(self): return self.nome_razao_social @razao_social.setter def razao_social(self, value): self.nome_razao_social = value def get_absolute_url(self): from django.urls import reverse return reverse('sagii_base:pessoajuridica-detail', kwargs={'pk': self.pk}) def __init__(self, *args, **kwargs): instance = super().__init__(*args, **kwargs) self._meta.get_field('nome_razao_social').verbose_name = _( 'Razão Social') return instance