Skip to content

Commit

Permalink
feat: add 'receipts' app
Browse files Browse the repository at this point in the history
lots of little changes and fightijng with django
to get basic things to work
  • Loading branch information
WoosterInitiative committed Feb 12, 2024
1 parent de676f3 commit 696f1b1
Show file tree
Hide file tree
Showing 30 changed files with 386 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,5 @@ mailpit
wooster_django/media/

.pytest_cache/

db.sqlite3
16 changes: 14 additions & 2 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
"""
from pathlib import Path

import environ
import environ # type:ignore

BASE_DIR = Path(__file__).resolve(strict=True).parent.parent.parent
# wooster_django/
APPS_DIR = BASE_DIR / "wooster_django"
env = environ.Env()
print(f"'APPS_DIR': {APPS_DIR}")

READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=False)
if READ_DOT_ENV_FILE:
# OS environment variables take precedence over variables from .env
env.read_env(str(BASE_DIR / ".env"))
print(f"'BASE_DIR': {BASE_DIR}")

# GENERAL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = env.bool("DJANGO_DEBUG", False)
print(f"DEBUG: {DEBUG}")
# Local time zone. Choices are
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# though not all of them may be available with every OS.
Expand Down Expand Up @@ -52,6 +55,14 @@
default="postgres://localhost/wooster_django",
),
}

# DATABASES = {
# "default": {
# "ENGINE": "django.db.backends.sqlite3",
# "NAME": BASE_DIR / "db.sqlite3",
# }
# }

DATABASES["default"]["ATOMIC_REQUESTS"] = True
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
Expand Down Expand Up @@ -83,17 +94,18 @@
"allauth",
"allauth.account",
"allauth.socialaccount",
"wooster_django.basemodels",
]

LOCAL_APPS = [
"wooster_django.users",
# Your stuff: custom apps go here
# "wooster_django.containers",
"wooster_django.basemodels",
"wooster_django.customers",
"wooster_django.inventory",
"wooster_django.orders",
"wooster_django.projects",
"wooster_django.receipts",
]
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
Expand Down
2 changes: 2 additions & 0 deletions config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@

# Your stuff...
# ------------------------------------------------------------------------------
# print(f"'DATABASES': {DATABASES}")
# print(f"'INSTALLED_APPS': {INSTALLED_APPS}")
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
path("users/", include("wooster_django.users.urls", namespace="users")),
path("accounts/", include("allauth.urls")),
# Your stuff: custom urls includes go here
# path("receipts/", include("wooster_django.receipts.urls", namespace="receipts")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


Expand Down
5 changes: 3 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
# exceptions on Python 2.
try:
import django # noqa
except ImportError:
except ImportError as e:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
) from e

raise

# This allows easy placement of apps within the interior
# wooster_django directory.
current_path = Path(__file__).parent.resolve()
print(f"'current_path': {current_path}")
sys.path.append(str(current_path / "wooster_django"))

execute_from_command_line(sys.argv)
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ plugins = ["django_coverage_plugin"]

# ==== Ruff ====
[tool.ruff]
fix = true
line-length = 119
select = ["E", "F", "B"]
unfixable = ["B"]
target-version = "py311"

[tool.ruff.format]
quote-style = "double"

[tool.ruff.lint]
fixable = ["ALL"]


# ==== black ====
[tool.black]
Expand All @@ -43,6 +50,9 @@ warn_redundant_casts = true
warn_unused_configs = true
plugins = ["mypy_django_plugin.main"]

[tool.mypy_django_plugin]
ignore_missing_model_attributes = true

[[tool.mypy.overrides]]
# Django migrations should not produce any errors:
module = "*.migrations.*"
Expand Down
3 changes: 2 additions & 1 deletion requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ psycopg[binary]==3.1.14 # https://github.com/psycopg/psycopg
django-stubs[compatible-mypy]==4.2.6 # https://github.com/typeddjango/django-stubs
pytest==7.4.3 # https://github.com/pytest-dev/pytest
pytest-sugar==0.9.7 # https://github.com/Frozenball/pytest-sugar
types-python-slugify==8.0.2.20240127

# Documentation
# ------------------------------------------------------------------------------
Expand All @@ -22,7 +23,7 @@ sphinx-autobuild==2021.3.14 # https://github.com/GaretJax/sphinx-autobuild
# flake8-isort==6.1.1 # https://github.com/gforcada/flake8-isort
ruff==0.1.6
coverage==7.3.2 # https://github.com/nedbat/coveragepy
black==23.11.0 # https://github.com/psf/black
# black==23.11.0 # https://github.com/psf/black
djlint==1.34.0 # https://github.com/Riverside-Healthcare/djLint
pylint-django==2.5.5 # https://github.com/PyCQA/pylint-django
pre-commit==3.5.0 # https://github.com/pre-commit/pre-commit
Expand Down
15 changes: 15 additions & 0 deletions wooster_django/basemodels/migrations/0002_delete_documentnumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by Django 4.2.7 on 2024-02-12 08:51

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("basemodels", "0001_initial"),
]

operations = [
migrations.DeleteModel(
name="DocumentNumber",
),
]
5 changes: 5 additions & 0 deletions wooster_django/basemodels/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .abstract import BaseModel

# from .shared import WhyDoesThisError

__all__ = ["BaseModel"]
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,3 @@ def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name)
super().save(*args, **kwargs)


class DocumentNumber(models.Model):
document = models.CharField(max_length=50, primary_key=True, unique=True)
prefix = models.CharField(max_length=10, blank=True, null=True)
padding_digits = models.IntegerField(blank=True, null=True)
next_counter = models.IntegerField(default=1)
last_number = models.CharField(max_length=50, editable=False, null=True)
last_generated_date = models.DateTimeField(auto_now=True)

def get_next_number(self):
prefix = self.prefix
next_counter = self.next_counter
padded_counter = str(next_counter).zfill(self.padding_digits)
number = f"{prefix}{padded_counter}"

self.next_counter += 1
self.last_number = number

self.save()

return number
24 changes: 24 additions & 0 deletions wooster_django/basemodels/models/shared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.db import models


# Create your models here.
class WhyDoesThisError(models.Model):
document = models.CharField(max_length=50, primary_key=True, unique=True)
prefix = models.CharField(max_length=10, blank=True, null=True)
padding_digits = models.IntegerField(blank=True, null=True)
next_counter = models.IntegerField(default=1)
last_number = models.CharField(max_length=50, editable=False, null=True)
last_generated_date = models.DateTimeField(auto_now=True)

def get_next_number(self):
prefix = self.prefix
next_counter = self.next_counter
padded_counter = str(next_counter).zfill(self.padding_digits)
number = f"{prefix}{padded_counter}"

self.next_counter += 1
self.last_number = number

self.save()

return number
2 changes: 1 addition & 1 deletion wooster_django/customers/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _
from phonenumber_field.modelfields import PhoneNumberField
from phonenumber_field.modelfields import PhoneNumberField # type: ignore

# from slugify import slugify
# from wooster_django.basemodels.models import BaseModel
Expand Down
4 changes: 3 additions & 1 deletion wooster_django/inventory/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import shortuuid
from basemodels.models import BaseModel
from colorfield.fields import ColorField
from colorfield.fields import ColorField # type:ignore

# from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _
from slugify import slugify

# from wooster_django.projects.models import BasalModel

# Chosen from https://htmlcolorcodes.com/color-names
COMMON_COLOR_PALETTE = [
("#FFFFFF", "white"),
Expand Down
23 changes: 23 additions & 0 deletions wooster_django/orders/migrations/0007_documentnumbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.7 on 2024-02-12 08:51

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("orders", "0006_order_notes_orderitem_notes_alter_orderitem_rank"),
]

operations = [
migrations.CreateModel(
name="DocumentNumbers",
fields=[
("document", models.CharField(max_length=50, primary_key=True, serialize=False, unique=True)),
("prefix", models.CharField(blank=True, max_length=10, null=True)),
("padding_digits", models.IntegerField(blank=True, null=True)),
("next_counter", models.IntegerField(default=1)),
("last_number", models.CharField(editable=False, max_length=50, null=True)),
("last_generated_date", models.DateTimeField(auto_now=True)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.7 on 2024-02-12 09:41

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("orders", "0007_documentnumbers"),
]

operations = [
migrations.RenameModel(
old_name="DocumentNumbers",
new_name="DocumentNumber",
),
]
28 changes: 26 additions & 2 deletions wooster_django/orders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime as dt
from datetime import timedelta

from basemodels.models import BaseModel, DocumentNumber
from basemodels.models import BaseModel # , WhyDoesThisError
from django.db import models
from django.db.models import F, Max, Sum
from django.utils.translation import gettext_lazy as _
Expand All @@ -12,10 +12,34 @@
# from wooster_django.projects.models import Project
from slugify import slugify

# from wooster_django.projects.models import DocumentNumber
# from wooster_django.projects.models import DocumentNumbers # , BasalModel


# Create your models here.


class DocumentNumber(models.Model):
document = models.CharField(max_length=50, primary_key=True, unique=True)
prefix = models.CharField(max_length=10, blank=True, null=True)
padding_digits = models.IntegerField(blank=True, null=True)
next_counter = models.IntegerField(default=1)
last_number = models.CharField(max_length=50, editable=False, null=True)
last_generated_date = models.DateTimeField(auto_now=True)

def get_next_number(self):
prefix = self.prefix
next_counter = self.next_counter
padded_counter = str(next_counter).zfill(self.padding_digits)
number = f"{prefix}{padded_counter}"

self.next_counter += 1
self.last_number = number

self.save()

return number


class Order(BaseModel):
name = None
number = models.CharField(_("Order Number"), max_length=50, unique=True, editable=False)
Expand Down
9 changes: 4 additions & 5 deletions wooster_django/projects/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from django.contrib import admin

from .models import DocumentNumber, Project

from .models import Project

# Register your models here.
@admin.register(DocumentNumber)
class DocumentNumberAdmin(admin.ModelAdmin):
list_display = ["document", "last_number", "next_counter"]
# @admin.register(DocumentNumbers)
# class DocumentNumberAdmin(admin.ModelAdmin):
# list_display = ["document", "last_number", "next_counter"]


@admin.register(Project)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.7 on 2024-02-12 08:51

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("projects", "0003_project_order"),
]

operations = [
migrations.RenameModel(
old_name="DocumentNumber",
new_name="DocumentNumbers",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.7 on 2024-02-12 09:41

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("projects", "0004_rename_documentnumber_documentnumbers"),
]

operations = [
migrations.RenameModel(
old_name="DocumentNumbers",
new_name="DocumentNumber",
),
]
Loading

0 comments on commit 696f1b1

Please sign in to comment.