API¶
Core models¶
These are the code models which will normally be used for Receipt
validation.
-
class
django_afip.models.
PointOfSales
(id, number, issuance_type, blocked, drop_date, owner)¶ Parameters: - number (PositiveSmallIntegerField) – Number
- issuance_type (CharField) – Indicates if thie POS emits using CAE and CAEA.
- blocked (BooleanField) – Blocked
- drop_date (DateField) – Drop date
- owner_id (ForeignKey to
TaxPayer
) – Owner
-
class
django_afip.models.
Receipt
(*args, **kwargs)¶ A receipt, as sent to AFIP.
Note that AFIP allows sending ranges of receipts, but this isn’t generally what you want, so we model invoices individually.
You’ll probably want to relate some Sale or Order object from your model with each Receipt.
Parameters: - batch_id (ForeignKey to
ReceiptBatch
) – Receipts are validated in batches, so it must be assigned one before validation is possible. - concept_id (ForeignKey to
ConceptType
) – Concept - document_type_id (ForeignKey to
DocumentType
) – The document type of the customer to whom this receipt is addressed - document_number (BigIntegerField) – The document number of the customer to whom this receipt is addressed
- receipt_number (PositiveIntegerField) – Receipt number
- issued_date (DateField) – Can diverge up to 5 days for good, or 10 days otherwise
- total_amount (DecimalField) – Must be equal to untaxed amount + exempt amount + taxes + vat.
- net_untaxed (DecimalField) – The total amount to which taxes do not apply. For C-type receipts, this must be zero.
- net_taxed (DecimalField) – The total amount to which taxes apply. For C-type receipts, this is equal to the subtotal.
- exempt_amount (DecimalField) – Only for categories which are tax-exempt. For C-type receipts, this must be zero.
- service_start (DateField) – Date on which a service started. No applicable for goods.
- service_end (DateField) – Date on which a service ended. No applicable for goods.
- expiration_date (DateField) – Date on which this receipt expires. No applicable for goods.
- currency_id (ForeignKey to
CurrencyType
) – Currency in which this receipt is issued. - currency_quote (DecimalField) – Quote of the day for the currency used in the receipt
- receipt_type_id (ForeignKey to
ReceiptType
) – Receipt type - point_of_sales_id (ForeignKey to
PointOfSales
) – Point of sales - related_receipts (ManyToManyField) – Related receipts
- batch_id (ForeignKey to
-
class
django_afip.models.
ReceiptBatch
(*args, **kwargs)¶ Receipts are validated sent in batches.
Parameters: - receipt_type_id (ForeignKey to
ReceiptType
) – Receipt type - point_of_sales_id (ForeignKey to
PointOfSales
) – Point of sales
- receipt_type_id (ForeignKey to
-
class
django_afip.models.
ReceiptValidation
(*args, **kwargs)¶ The validation for a single receipt.
This contains all validation-related data for a receipt, including its CAE and the CAE expiration, unless validation ahs failed.
The
observation
field may contain any data returned by AFIP regarding validation failure.Parameters: - validation_id (ForeignKey to
Validation
) – Validation - result (CharField) – Result
- cae (CharField) – Cae
- cae_expiration (DateField) – Cae expiration
- receipt_id (OneToOneField to
Receipt
) – Receipt - observations (ManyToManyField) – Observations
- validation_id (ForeignKey to
-
class
django_afip.models.
Tax
(*args, **kwargs)¶ A tax (type+amount) for a specific Receipt.
Parameters: -
compute_amount
()¶ Auto-assign and return the total amount for this tax.
-
-
class
django_afip.models.
TaxPayer
(*args, **kwargs)¶ Represents an AFIP TaxPayer.
This class has the bare minimum required for most AFIP services.
Note that multiple instances of this object can actually represent the same taxpayer, each using a different key.
Parameters: - name (CharField) – A friendly name to recognize this taxpayer.
- key (FileField) – Key
- certificate (FileField) – Certificate
- cuit (BigIntegerField) – Cuit
- is_sandboxed (BooleanField) – Indicates if this taxpayer interacts with the sandbox servers rather than the production servers
-
create_ticket
(service)¶ Create an AuthTicket for a given service.
-
fetch_points_of_sales
(ticket=None)¶ Fetch all point of sales objects.
Fetch all point of sales from the WS and store (or update) them locally.
Returns a list of tuples with the format (pos, created,).
-
get_or_create_ticket
(service)¶ Return or create a new AuthTicket for a given serivce.
Return an existing ticket for a service if one is available, otherwise, create a new one and return that.
This is generally the preferred method of obtaining tickets for any service.
-
get_ticket
(service)¶ Return an existing AuthTicket for a given service.
-
class
django_afip.models.
Validation
(*args, **kwargs)¶ The validation result for a batch.
The validation result for an attempt to validate a batch. Note that each Receipt inside the batch will have its own
ReceiptValidation
.Parameters: - processed_date (DateTimeField) – Processed date
- result (CharField) – Result
- batch_id (ForeignKey to
ReceiptBatch
) – Receipt batch
Metadata models¶
These models represent metadata like currency types or document types. Their
tables should be populated from AFIP’s webservices, using the afipmetadata
command.
-
class
django_afip.models.
ConceptType
(*args, **kwargs)¶ An AFIP concept type.
See the AFIP’s documentation for details on each concept type.
Parameters: - code (CharField) – Code
- description (CharField) – Description
- valid_from (DateField) – Valid from
- valid_to (DateField) – Valid until
-
class
django_afip.models.
CurrencyType
(*args, **kwargs)¶ An AFIP curreny type.
See the AFIP’s documentation for details on each currency type.
Parameters: - code (CharField) – Code
- description (CharField) – Description
- valid_from (DateField) – Valid from
- valid_to (DateField) – Valid until
-
class
django_afip.models.
DocumentType
(*args, **kwargs)¶ An AFIP document type.
See the AFIP’s documentation for details on each document type.
Parameters: - code (CharField) – Code
- description (CharField) – Description
- valid_from (DateField) – Valid from
- valid_to (DateField) – Valid until
-
class
django_afip.models.
Observation
(*args, **kwargs)¶ An observation returned by AFIP.
AFIP seems to assign re-used codes to Observation, so we actually store them as separate objects, and link to them from failed validations.
Parameters: - code (PositiveSmallIntegerField) – Code
- message (CharField) – Message
-
class
django_afip.models.
ReceiptType
(*args, **kwargs)¶ An AFIP receipt type.
See the AFIP’s documentation for details on each receipt type.
Parameters: - code (CharField) – Code
- description (CharField) – Description
- valid_from (DateField) – Valid from
- valid_to (DateField) – Valid until
-
class
django_afip.models.
TaxType
(*args, **kwargs)¶ An AFIP tax type.
See the AFIP’s documentation for details on each tax type.
Parameters: - code (CharField) – Code
- description (CharField) – Description
- valid_from (DateField) – Valid from
- valid_to (DateField) – Valid until
-
class
django_afip.models.
VatType
(*args, **kwargs)¶ An AFIP VAT type.
See the AFIP’s documentation for details on each VAT type.
Parameters: - code (CharField) – Code
- description (CharField) – Description
- valid_from (DateField) – Valid from
- valid_to (DateField) – Valid until