28 lines
975 B
Python
28 lines
975 B
Python
from django.test import TestCase
|
|
from datetime import date
|
|
from decimal import Decimal
|
|
|
|
from django.contrib.auth import get_user_model
|
|
from modules.invoicing.models import Invoice
|
|
from modules.invoicing.utils import generate_invoice_number
|
|
from modules.crm.models import Client
|
|
|
|
|
|
class UtilsTests(TestCase):
|
|
def setUp(self):
|
|
User = get_user_model()
|
|
self.user = User.objects.create_user(username="creator", email="c@example.com", password="pass")
|
|
self.client = Client.objects.create(name="Client Utils")
|
|
|
|
def test_generate_invoice_number_increments(self):
|
|
year = date.today().year
|
|
Invoice.objects.create(
|
|
invoice_number=f"INV-{year}-0001",
|
|
creator=self.user,
|
|
client=self.client,
|
|
amount=Decimal("1.00"),
|
|
due_date=date.today()
|
|
)
|
|
next_num = generate_invoice_number()
|
|
# očekujemo INV-<year>-0002
|
|
self.assertTrue(next_num.endswith("-0002")) |