-
Notifications
You must be signed in to change notification settings - Fork 6
Invoice calls validation checkbox #1104
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Generated by Django 5.2.3 on 2025-10-15 21:54 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
import counter.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("club", "0014_alter_club_options_rename_unix_name_club_slug_name_and_more"), | ||
("counter", "0032_scheduledproductaction"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="InvoiceCall", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"is_validated", | ||
models.BooleanField(default=False, verbose_name="is validated"), | ||
), | ||
("month", counter.models.MonthField(verbose_name="invoice date")), | ||
( | ||
"club", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="club.club" | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Invoice call", | ||
"verbose_name_plural": "Invoice calls", | ||
"constraints": [ | ||
models.UniqueConstraint( | ||
fields=("club", "month"), | ||
name="counter_invoicecall_unique_club_month", | ||
) | ||
], | ||
}, | ||
), | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from datetime import date, datetime | ||
|
||
import pytest | ||
from dateutil.relativedelta import relativedelta | ||
from django.contrib.auth.models import Permission | ||
from django.core.exceptions import ValidationError | ||
from django.test import Client | ||
from django.urls import reverse | ||
from django.utils.timezone import localdate | ||
from model_bakery import baker | ||
from pytest_django.asserts import assertRedirects | ||
|
||
from club.models import Club | ||
from core.models import User | ||
from counter.baker_recipes import sale_recipe | ||
from counter.forms import InvoiceCallForm | ||
from counter.models import Customer, InvoiceCall, Selling | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize( | ||
"month", [date(2025, 10, 20), "2025-10", datetime(2025, 10, 15, 12, 30)] | ||
) | ||
def test_invoice_date_with_date(month: date | datetime | str): | ||
club = baker.make(Club) | ||
invoice = InvoiceCall.objects.create(club=club, month=month) | ||
invoice.refresh_from_db() | ||
assert not invoice.is_validated | ||
assert invoice.month == date(2025, 10, 1) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_invoice_call_invalid_month_string(): | ||
club = baker.make(Club) | ||
|
||
with pytest.raises(ValidationError): | ||
InvoiceCall.objects.create(club=club, month="2025-13") | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize("query", [None, {"month": "2025-08"}]) | ||
def test_invoice_call_view(client: Client, query: dict | None): | ||
user = baker.make( | ||
User, | ||
user_permissions=[ | ||
*Permission.objects.filter( | ||
codename__in=["view_invoicecall", "change_invoicecall"] | ||
) | ||
], | ||
) | ||
client.force_login(user) | ||
url = reverse("counter:invoices_call", query=query) | ||
assert client.get(url).status_code == 200 | ||
assertRedirects(client.post(url), url) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_invoice_call_form(): | ||
Selling.objects.all().delete() | ||
month = localdate() - relativedelta(months=1) | ||
clubs = baker.make(Club, _quantity=2) | ||
recipe = sale_recipe.extend(date=month, customer=baker.make(Customer, amount=10000)) | ||
recipe.make(club=clubs[0], quantity=2, unit_price=200) | ||
recipe.make(club=clubs[0], quantity=3, unit_price=5) | ||
recipe.make(club=clubs[1], quantity=20, unit_price=10) | ||
form = InvoiceCallForm( | ||
month=month, data={str(clubs[0].id): True, str(clubs[1].id): False} | ||
) | ||
assert form.is_valid() | ||
form.save() | ||
assert InvoiceCall.objects.filter( | ||
club=clubs[0], month=month, is_validated=True | ||
).exists() | ||
assert InvoiceCall.objects.filter( | ||
club=clubs[1], month=month, is_validated=False | ||
).exists() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.