Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions django_afip/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ msgstr "La cotización de la moneda en el día que fue emitido este comprobante.
msgid "related receipts"
msgstr "comprobantes relacionados"

msgid "client VAT condition"
msgstr "condición IVA del cliente"

msgid "The client VAT condition of the recipient of this receipt."
msgstr "La condición frente al IVA del cliente para el cual este comprobante es emitido."

#, python-format
msgid "Unnumbered %s"
msgstr "%s sin número"
Expand Down
21 changes: 20 additions & 1 deletion django_afip/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,20 @@ class Meta:
verbose_name_plural = _("receipt validations")


class ClientVatConditionManager(models.Manager):
"""Manager for ClientVatCondition.

This class is only used to provide natural key support for the
:class:`~.ClientVatCondition` class.
"""

def get_by_natural_key(self, code: str) -> ClientVatCondition:
return self.get(code=code)

def exists_by_natural_key(self, code: str) -> bool:
return self.filter(code=code).exists()


class ClientVatCondition(models.Model):
"""Client VAT condition for certain types of Receipts.

Expand All @@ -1898,6 +1912,8 @@ class ClientVatCondition(models.Model):
set of fields. This one has different fields, so is modelled separately.
"""

objects = ClientVatConditionManager()

code = models.CharField(
_("code"),
max_length=3,
Expand Down Expand Up @@ -1952,5 +1968,8 @@ def populate(
},
)

def natural_key(self) -> tuple[str]:
return (self.code,)

def __str__(self) -> str:
return f"{self.description} ({self.code})"
return self.description
31 changes: 31 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,34 @@ def test_client_vat_condition_populate(live_ticket: models.AuthTicket) -> None:
initial_count = models.ClientVatCondition.objects.count()
models.ClientVatCondition.populate(ticket=live_ticket)
assert models.ClientVatCondition.objects.count() == initial_count


@pytest.mark.django_db
def test_load_metadata() -> None:
"""Test populating AFIP models from fixtures."""
fetched_models = [
models.ClientVatCondition,
models.ConceptType,
models.CurrencyType,
models.DocumentType,
models.OptionalType,
models.ReceiptType,
models.TaxType,
models.VatType,
]

# At first we have no data
for m in fetched_models:
assert m.objects.count() == 0

# Load data and expect data
models.load_metadata()
counts = []
for m in fetched_models:
assert m.objects.count() > 0
counts.append(m.objects.count())

# Load data again and expect no change
models.load_metadata()
for i, m in enumerate(fetched_models):
assert m.objects.count() == counts[i]