Skip to content
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

CAEA support #164

Draft
wants to merge 61 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4e366c8
set enviroment and ignore files
erebodino Sep 6, 2022
fdf20c0
Caea model created
erebodino Sep 6, 2022
aff4096
added get_caea and consult_caea methods to TaxPayer
erebodino Sep 6, 2022
ce686b5
Added field generetad to Receipt to ensure compability with CAEA
erebodino Sep 7, 2022
2af368f
Modified _validate method to add CAEA support, added serializers and …
erebodino Sep 8, 2022
039b1ff
add field to ReceiptValidation, create CaeaCounter to store correlati…
erebodino Sep 8, 2022
3284b40
reorder logic in Receipt.save()
erebodino Sep 13, 2022
d0cf1c0
Modified Receipt and validation model to register CAEA validation, mo…
erebodino Sep 14, 2022
82fe800
Modified Receipt and validation model to register CAEA validation, mo…
erebodino Sep 14, 2022
ca587ea
Black formatting
erebodino Sep 14, 2022
fc02db2
added 2 new tests to ensure the type of insuance
erebodino Sep 16, 2022
ce40139
Modified logic in _validate to check if CAE or CAEA
erebodino Sep 19, 2022
7f5e4d6
add pre_save to receipt, add __str__ to CaeaCounter, modify some test…
erebodino Sep 21, 2022
f25df0a
add method to consult and inform CAEA without movement
erebodino Sep 21, 2022
4c9d26a
added test to check InformedCaea and rewrite some test with CaeaFactory
erebodino Sep 22, 2022
521d3c7
Formatting of variables in docs
erebodino Sep 22, 2022
fd055bf
Added support for PDF generation with CAEA
erebodino Sep 22, 2022
08a96c7
added tests to PDF creations
erebodino Sep 22, 2022
c29e0fc
Merge branch 'to-merge-1' into final-1
erebodino Sep 22, 2022
4ac986a
change .gitignore and __init__
erebodino Sep 22, 2022
0572768
merge all the migrations from remote-origin and local
erebodino Sep 22, 2022
d11f58f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2022
d0e8e5f
Change number of POS in CAEA factory
erebodino Oct 4, 2022
8b5edd9
Merge branch 'main' into main
erebodino Oct 4, 2022
4e3e664
Solved errors marked by pre-commit.ci
erebodino Oct 11, 2022
f9db7c3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2022
27078ae
Added ready_to_print property on Receipt, refactor func generate_rece…
erebodino Oct 15, 2022
b284605
Refactor caea assignation on save for receipts, now can handle multip…
erebodino Oct 15, 2022
44c3fca
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 15, 2022
f5d2eaf
Uncomment settings.DATABASES
erebodino Oct 15, 2022
b0653f9
test_caea_creation_live change get(pk=1) for first()
erebodino Oct 15, 2022
9c3a66c
Update django_afip/models.py
erebodino Oct 15, 2022
5947663
Update django_afip/models.py
erebodino Oct 15, 2022
ff4ee10
Update django_afip/serializers.py
erebodino Oct 15, 2022
198257a
Update django_afip/models.py
erebodino Oct 15, 2022
b1ecfaa
Added Unique Constraint to CAEA and refactor test
erebodino Oct 15, 2022
50f6b89
Update aclarations on pdf.py, CAEA is now supported
erebodino Oct 15, 2022
ad53fa5
Ordering in Receipts fixed, test added to ensure that
erebodino Oct 15, 2022
5c3d1a3
Fixed CaeaFactory, not CAEA in _validate
erebodino Oct 16, 2022
cab7ba1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 16, 2022
dc9fa86
Uncomment validation and receipt_validation on views
erebodino Oct 17, 2022
1735e01
Rename get_cae for request_new_cae, rename consult_caea for fetch_cae…
erebodino Oct 17, 2022
71f3243
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2022
fed9a7c
Refactor consult_caea and _inform_caea,methods moved from TaxPayer to…
erebodino Oct 17, 2022
bfcd5ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2022
41667dd
Refactor _validate from ReceiptQuerySet
erebodino Oct 17, 2022
8c40a08
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2022
1524dce
Added null=True to -generated- attribute from Receipt model
erebodino Oct 17, 2022
e542898
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2022
91cc5af
Rename final_date_inform attibute to report_deadline from Caea model
erebodino Oct 17, 2022
2bcd233
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2022
4f2e04e
Moved active field of Caea to a property, create custom queryset tofi…
erebodino Oct 17, 2022
1e0ccc4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2022
c1138e6
Update django_afip/factories.py
erebodino Oct 17, 2022
58ba38b
Change over ready_to_print if clause, and add some explanation
erebodino Oct 17, 2022
13e4eb1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2022
32bc979
Deleted CaeaCounter, now the receipt_number is assigned filtering rec…
erebodino Oct 18, 2022
3851a1a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2022
087248e
Modify caea is_active property, CaeaQueryset and tests
erebodino Oct 18, 2022
7f1eff1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2022
578929f
Correct command for pytest on tox.ini
erebodino Oct 19, 2022
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ django_afip/version.py
testapp/test_ticket.yaml
test.csr
test2.csr

#Branch files
Pipfile
Pipfile.lock
1 change: 1 addition & 0 deletions django_afip/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,4 @@ def successful(self, obj):
admin.site.register(models.VatType)
admin.site.register(models.TaxType)
admin.site.register(models.Observation)
admin.site.register(models.Caea)
4 changes: 4 additions & 0 deletions django_afip/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ class CannotValidateTogether(DjangoAfipException):

class ValidationError(DjangoAfipException):
"""Raised when a single Receipt failed to validate with AFIP's WS."""


class CaeaCountError(DjangoAfipException):
"""Raised when query the caea to obtain the number but 0 or 2 or more."""
39 changes: 39 additions & 0 deletions django_afip/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from pathlib import Path

import pytest
erebodino marked this conversation as resolved.
Show resolved Hide resolved
from django.contrib.auth.models import User
from django.utils.timezone import make_aware
from factory import LazyFunction
Expand All @@ -22,6 +23,14 @@ def get_test_file(filename: str, mode="r") -> Path:
return path


def get_order_of_date() -> int:
erebodino marked this conversation as resolved.
Show resolved Hide resolved
today = datetime.now()
order = 1
if today.day > 15:
order = 2
return order
erebodino marked this conversation as resolved.
Show resolved Hide resolved


class UserFactory(DjangoModelFactory):
class Meta:
model = User
Expand Down Expand Up @@ -120,6 +129,12 @@ class Meta:
sales_terms = "Credit Card"


class PointOfSalesFactoryCaea(PointOfSalesFactory):

number = 4
issuance_type = "CAEA"


class ReceiptFactory(DjangoModelFactory):
class Meta:
model = models.Receipt
Expand Down Expand Up @@ -149,6 +164,15 @@ def post(obj: models.Receipt, create, extracted, **kwargs):
TaxFactory(tax_type__code=3, receipt=obj)


class ReceiptWithVatAndTaxFactoryCaea(ReceiptFactory):
"""Receipt with a valid Vat and Tax, ready to validate."""

@post_generation
def post(obj: models.Receipt, create, extracted, **kwargs):
VatFactory(vat_type__code=5, receipt=obj)
TaxFactory(tax_type__code=3, receipt=obj)


class ReceiptWithInconsistentVatAndTaxFactory(ReceiptWithVatAndTaxFactory):
"""Receipt with a valid Vat and Tax, ready to validate."""

Expand Down Expand Up @@ -243,6 +267,21 @@ class Meta:
tax_type = SubFactory(TaxTypeFactory)


class CaeaFactory(DjangoModelFactory):
class Meta:
model = models.Caea

caea_code = "12345678974125"
period = datetime.today().strftime("%Y%m")
order = LazyFunction(get_order_of_date)
valid_since = make_aware(datetime(2022, 6, 1))
expires = make_aware(datetime(2022, 6, 15))
generated = make_aware(datetime(2022, 5, 30, 21, 6, 4))
report_deadline = make_aware(datetime(2022, 6, 20))
taxpayer = SubFactory(TaxPayerFactory)
active = True


class ReceiptEntryFactory(DjangoModelFactory):
class Meta:
model = models.ReceiptEntry
Expand Down
78 changes: 78 additions & 0 deletions django_afip/migrations/0011_caea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Generated by Django 4.1.1 on 2022-09-06 15:02

import django.core.validators
import django.db.models.deletion
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("afip", "0010_alter_authticket_service"),
]

operations = [
migrations.CreateModel(
name="Caea",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"caea_code",
models.BigIntegerField(
help_text="CAEA code to operate offline AFIP",
unique=True,
validators=[
django.core.validators.RegexValidator(regex="[0-9]{14}")
],
),
),
(
"period",
models.IntegerField(
help_text="Period to send in the CAEA request (yyyymm)"
),
),
(
"order",
models.IntegerField(
choices=[(1, "1"), (2, "2")],
help_text="Month is divided in 1st quarter or 2nd quarter",
),
),
("valid_since", models.DateTimeField(verbose_name="valid_to")),
("expires", models.DateTimeField(verbose_name="expires")),
("generated", models.DateTimeField(verbose_name="generated")),
(
"final_date_inform",
models.DateTimeField(verbose_name="final_date_inform"),
),
(
"service",
models.CharField(
help_text="Service for which this ticket has been authorized.",
max_length=34,
verbose_name="service",
),
),
("active", models.BooleanField(default=False)),
(
"taxpayer",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="caea_tickets",
to="afip.taxpayer",
verbose_name="taxpayer",
),
),
],
),
]
28 changes: 28 additions & 0 deletions django_afip/migrations/0012_alter_caea_caea_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.1.1 on 2022-09-06 15:15

import django.core.validators
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("afip", "0011_caea"),
]

operations = [
migrations.AlterField(
model_name="caea",
name="caea_code",
field=models.BigIntegerField(
help_text="CAEA code to operate offline AFIP",
unique=True,
validators=[
django.core.validators.RegexValidator(regex="[0-9]{14}"),
django.core.validators.MinLengthValidator(14),
django.core.validators.MaxLengthValidator(14),
],
),
),
]
27 changes: 27 additions & 0 deletions django_afip/migrations/0013_alter_caea_caea_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.1.1 on 2022-09-06 15:24

import django.core.validators
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("afip", "0012_alter_caea_caea_code"),
]

operations = [
migrations.AlterField(
model_name="caea",
name="caea_code",
field=models.PositiveBigIntegerField(
help_text="CAEA code to operate offline AFIP",
unique=True,
validators=[
django.core.validators.RegexValidator(regex="[0-9]{14}"),
django.core.validators.MaxValueValidator(99999999999999),
],
),
),
]
17 changes: 17 additions & 0 deletions django_afip/migrations/0014_remove_caea_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.1.1 on 2022-09-06 21:34

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("afip", "0013_alter_caea_caea_code"),
]

operations = [
migrations.RemoveField(
model_name="caea",
name="service",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.1.1 on 2022-09-06 21:43

from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("afip", "0014_remove_caea_service"),
]

operations = [
migrations.AlterField(
model_name="caea",
name="expires",
field=models.DateField(verbose_name="expires"),
),
migrations.AlterField(
model_name="caea",
name="final_date_inform",
field=models.DateField(verbose_name="final_date_inform"),
),
migrations.AlterField(
model_name="caea",
name="valid_since",
field=models.DateField(verbose_name="valid_to"),
),
]
25 changes: 25 additions & 0 deletions django_afip/migrations/0016_receipt_generated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.1.1 on 2022-09-07 13:01

import django.utils.timezone
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("afip", "0015_alter_caea_expires_alter_caea_final_date_inform_and_more"),
]

operations = [
migrations.AddField(
model_name="receipt",
name="generated",
field=models.DateTimeField(
auto_now_add=True,
default=django.utils.timezone.now,
verbose_name="Time when the receipt was created",
),
preserve_default=False,
),
]
35 changes: 35 additions & 0 deletions django_afip/migrations/0017_receipt_caea_receiptvalidation_caea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.1.1 on 2022-09-08 19:18

import django.db.models.deletion
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("afip", "0016_receipt_generated"),
]

operations = [
migrations.AddField(
model_name="receipt",
name="caea",
field=models.ForeignKey(
blank=True,
help_text="CAEA in case that the receipt must contain it",
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="afip.caea",
),
),
migrations.AddField(
model_name="receiptvalidation",
name="caea",
field=models.BooleanField(
default=False,
help_text="Indicate if the validation was from a CAEA receipt, in that case the field cae contains the CAEA number",
verbose_name="is_caea",
),
),
]
53 changes: 53 additions & 0 deletions django_afip/migrations/0018_caeacounter_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 4.1.1 on 2022-09-08 20:18

import django.db.models.deletion
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("afip", "0017_receipt_caea_receiptvalidation_caea"),
]

operations = [
migrations.CreateModel(
name="CaeaCounter",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("value", models.BigIntegerField(default=1)),
(
"pos",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="counter",
to="afip.pointofsales",
),
),
(
"receipt_type",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="counter",
to="afip.receipttype",
),
),
],
),
migrations.AddConstraint(
model_name="caeacounter",
constraint=models.UniqueConstraint(
fields=("pos", "receipt_type"),
name="unique_migration_pos_receipt_combination",
),
),
]
Loading