Skip to content

Add CondicionIVAReceptorId field #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

manusturla
Copy link

Changes:

  • Added ClientVatCondition model.
  • Added Receipt.client_vat_condition FK to ClientVatCondition.
  • Added CondicionIVAReceptorId=receipt.client_vat_condition.code to serialize_receipt.
  • Added clientvatcondition fixture.
  • Added load_client_vat_conditions command to retrieve ClientVatConditions from FEParamGetCondicionIvaReceptor and sync them.

Potential improvements
I think that there are some improvements that could be made to this implementation:

  • Relate the cmp_clase field of ClientVatCondition to ReceiptTypes.
  • Maybe handle ClientVatCondition as a subclass of GenericAfipType.
  • Add some tests.

This implementation has an Issue
When serializing a Receipt in the serialize_receipt function the FECAEDetRequest method will return this error:

TypeError: {http://ar.gov.afip.dif.FEV1/}FECAEDetRequest() got an unexpected keyword argument 'CondicionIVAReceptorId'...

This is because the Client created as f = _LazyFactory() and used by the serializer is being created with the default parameter sandbox=False. This causes the error because the parameter CondicionIVAReceptorId is currently only available on Sandbox mode only.

Related to:

Copy link
Owner

@WhyNotHugo WhyNotHugo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add values for client_vat_condition to receipts created via factories. Once that is done, we can run tests on the testing environemnt with tox -e live.

Comment on lines +1 to +42
from __future__ import annotations

from django.core.management.base import BaseCommand
from django.utils.translation import gettext as _

from django_afip import clients, models, serializers


class Command(BaseCommand):
help = _(
"Retrieves all the ClientVatConditions from the AFIP server and updates it in the DB."
)
requires_migrations_checks = True

def add_arguments(self, parser):
parser.add_argument(
"cuit",
type=int,
help=_("CUIT of the tax payer to be used to authenticate."),
)

def handle(self, *args, **options) -> None:
from django_afip.models import TaxPayer

tax_payer = TaxPayer.objects.get(cuit=options["cuit"])
ticket = tax_payer.get_or_create_ticket("wsfe")

client = clients.get_client("wsfe", sandbox=tax_payer.is_sandboxed)
response = client.service.FEParamGetCondicionIvaReceptor(
serializers.serialize_ticket(ticket),
)

for condition in response.ResultGet.CondicionIvaReceptor:
models.ClientVatCondition.objects.get_or_create(
code=condition.Id,
defaults={
"description": condition.Desc,
"cmp_clase": condition.Cmp_Clase,
},
)
self.stdout.write(self.style.SUCCESS(f"Loaded {condition.Desc}"))
self.stdout.write(self.style.SUCCESS("All done!"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto debería ir en scripts/dump_metadata.py.

@@ -94,6 +94,7 @@ def serialize_receipt(receipt: Receipt): # noqa: ANN201
ImpTrib=sum(tax.amount for tax in taxes),
MonId=receipt.currency.code,
MonCotiz=receipt.currency_quote,
CondicionIVAReceptorId=receipt.client_vat_condition.code,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crashes if receipt.client_vat_condition is None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants