Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
DATABASE_URL=sqlite:///db.sqlite3
EMAIL_URL=smtp+tls://user:hunter2%40%3Axyz%3F%21@localhost:587
EMAIL_FROM_ADDRESS=sample_bar@example.com
LANGUAGE_CODE=en-us
TIME_ZONE=Europe/Berlin
SECRET_KEY=GENERATE THIS! See e.g. https://humberto.io/blog/tldr-generate-django-secret-key/
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ jobs:

- name: Install dependencies
run: |
pip3 install -r requirements.txt
pip3 install -r requirements.txt -r requirements-dev.txt
cp .env.example .env
touch db.sqlite3
chmod 666 db.sqlite3

- name: Lint and format check
run: |
ruff format --check . || (echo "Run 'ruff format .' to fix formatting" && exit 1)
ruff check . || (echo "Run 'ruff check --fix .' to fix lint violations" && exit 1)

- name: Run unit tests
run: python3 manage.py test

Expand Down
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ In case you do not want to use the Docker installation method, e.g. because you
# possibly: sudo apt install virtualenv
virtualenv -p python3 .
source bin/activate # activate virtualenv
pip3 install -r requirements.txt
pip3 install -r requirements.txt -r requirements-dev.txt
# Create .env configuration file and generate SECRET_KEY
cat .env.example | grep -v "SECRET_KEY" > .env
echo SECRET_KEY=$(tr -dc 'a-z0-9!@#%^&*(-_=+)' < /dev/urandom | head -c50) >> .env
Expand Down Expand Up @@ -216,7 +216,7 @@ You can also look into the git log:
```bash
git fetch # get information about changes but do not touch local files
git log origin/master # show latest changes on master
````
```

When you want to apply the update, simply pull in the changes (you should not have modified any pybarsys files):
```bash
Expand Down
2 changes: 1 addition & 1 deletion barsys/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class BarsysConfig(AppConfig):
name = 'barsys'
name = "barsys"
103 changes: 68 additions & 35 deletions barsys/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,82 @@


class UserFilter(django_filters.FilterSet):
display_name = django_filters.CharFilter(lookup_expr='icontains')
email = django_filters.CharFilter(lookup_expr='icontains')
purchases_paid_by_other = django_filters.BooleanFilter(method="filter_has_purchases_paid_by_other")
display_name = django_filters.CharFilter(lookup_expr="icontains")
email = django_filters.CharFilter(lookup_expr="icontains")
purchases_paid_by_other = django_filters.BooleanFilter(
method="filter_has_purchases_paid_by_other"
)
created_date = django_filters.DateTimeFromToRangeFilter(
help_text="Format YYYY-MM-DD HH:MM. Time is 00:00 by default.")
help_text="Format YYYY-MM-DD HH:MM. Time is 00:00 by default."
)

class Meta:
model = User
fields = ['display_name', 'email', 'is_active', 'is_buyer', 'is_favorite', 'is_admin', 'is_autolocked']
fields = [
"display_name",
"email",
"is_active",
"is_buyer",
"is_favorite",
"is_admin",
"is_autolocked",
]

def filter_has_purchases_paid_by_other(self, queryset, name, value):
return queryset.filter(purchases_paid_by_other__isnull=not value)


class PurchaseFilter(django_filters.FilterSet):
username = django_filters.CharFilter(field_name="user__display_name", lookup_expr='icontains')

product_name = django_filters.CharFilter(lookup_expr='icontains')
product_amount = django_filters.CharFilter(lookup_expr='icontains')
product_category = django_filters.CharFilter(lookup_expr='icontains')
invoice = django_filters.BooleanFilter(method='filter_has_invoice', label="Invoiced")
username = django_filters.CharFilter(
field_name="user__display_name", lookup_expr="icontains"
)

product_name = django_filters.CharFilter(lookup_expr="icontains")
product_amount = django_filters.CharFilter(lookup_expr="icontains")
product_category = django_filters.CharFilter(lookup_expr="icontains")
invoice = django_filters.BooleanFilter(
method="filter_has_invoice", label="Invoiced"
)
created_date = django_filters.DateTimeFromToRangeFilter(
help_text="Format YYYY-MM-DD HH:MM. Time is 00:00 by default.")
is_free_item_purchase = django_filters.BooleanFilter(help_text="Whether the purchase was done with a free item "
"(i.e. it was already purchased with a cost before). "
"If you only want to count 'real' purchases you should set "
"this to 'No'.")
help_text="Format YYYY-MM-DD HH:MM. Time is 00:00 by default."
)
is_free_item_purchase = django_filters.BooleanFilter(
help_text="Whether the purchase was done with a free item "
"(i.e. it was already purchased with a cost before). "
"If you only want to count 'real' purchases you should set "
"this to 'No'."
)

def filter_has_invoice(self, queryset, name, value):
return queryset.filter(invoice__isnull=not value)

class Meta:
model = Purchase
fields = ["user", "is_free_item_purchase", ]
fields = [
"user",
"is_free_item_purchase",
]


class ProductAutochangeSetFilter(django_filters.FilterSet):
title = django_filters.CharFilter(lookup_expr='icontains')
description = django_filters.CharFilter(lookup_expr='icontains')
title = django_filters.CharFilter(lookup_expr="icontains")
description = django_filters.CharFilter(lookup_expr="icontains")

class Meta:
model = ProductAutochangeSet
fields = ['title', 'description']
fields = ["title", "description"]


class PaymentFilter(django_filters.FilterSet):
payment_method = django_filters.ChoiceFilter(choices=Payment.PAYMENT_METHOD_CHOICES)

comment = django_filters.CharFilter(lookup_expr='icontains')
amount__gte = django_filters.NumberFilter(field_name='amount', lookup_expr='gte')
amount__lte = django_filters.NumberFilter(field_name='amount', lookup_expr='lte')
comment = django_filters.CharFilter(lookup_expr="icontains")
amount__gte = django_filters.NumberFilter(field_name="amount", lookup_expr="gte")
amount__lte = django_filters.NumberFilter(field_name="amount", lookup_expr="lte")

created_date = django_filters.DateTimeFromToRangeFilter(
help_text="Format YYYY-MM-DD HH:MM. Time is 00:00 by default.")
help_text="Format YYYY-MM-DD HH:MM. Time is 00:00 by default."
)

value_date = django_filters.DateFromToRangeFilter(help_text="Format YYYY-MM-DD.")

Expand All @@ -67,8 +89,10 @@ class Meta:


class FreeItemFilter(django_filters.FilterSet):
comment = django_filters.CharFilter(lookup_expr='icontains')
leftover_quantity__gte = django_filters.NumberFilter(field_name='leftover_quantity', lookup_expr='gte')
comment = django_filters.CharFilter(lookup_expr="icontains")
leftover_quantity__gte = django_filters.NumberFilter(
field_name="leftover_quantity", lookup_expr="gte"
)

class Meta:
model = FreeItem
Expand All @@ -77,36 +101,45 @@ class Meta:

class InvoiceFilter(django_filters.FilterSet):
created_date = django_filters.DateTimeFromToRangeFilter(
help_text="Format YYYY-MM-DD HH:MM. Time is 00:00 by default.")
purchases__gte = django_filters.NumberFilter(field_name='amount_purchases', lookup_expr='gte', label="Purchases >=")
purchases__lte = django_filters.NumberFilter(field_name='amount_purchases', lookup_expr='lte', label="Purchases <=")

payments__gte = django_filters.NumberFilter(field_name='amount_payments', lookup_expr='gte', label="Payments >=")
payments__lte = django_filters.NumberFilter(field_name='amount_payments', lookup_expr='lte', label="Payments <=")
help_text="Format YYYY-MM-DD HH:MM. Time is 00:00 by default."
)
purchases__gte = django_filters.NumberFilter(
field_name="amount_purchases", lookup_expr="gte", label="Purchases >="
)
purchases__lte = django_filters.NumberFilter(
field_name="amount_purchases", lookup_expr="lte", label="Purchases <="
)

payments__gte = django_filters.NumberFilter(
field_name="amount_payments", lookup_expr="gte", label="Payments >="
)
payments__lte = django_filters.NumberFilter(
field_name="amount_payments", lookup_expr="lte", label="Payments <="
)

class Meta:
model = Invoice
fields = ["recipient"]


class CategoryFilter(django_filters.FilterSet):
name = django_filters.CharFilter(lookup_expr='icontains')
name = django_filters.CharFilter(lookup_expr="icontains")

class Meta:
model = Category
fields = []


class ProductFilter(django_filters.FilterSet):
name = django_filters.CharFilter(lookup_expr='icontains')
name = django_filters.CharFilter(lookup_expr="icontains")

class Meta:
model = Product
fields = ["name", "category", "is_active"]


class StatsDisplayFilter(django_filters.FilterSet):
title = django_filters.CharFilter(lookup_expr='icontains')
title = django_filters.CharFilter(lookup_expr="icontains")

class Meta:
model = StatsDisplay
Expand Down
Loading
Loading