Skip to content

Commit

Permalink
Add CI, reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Dec 14, 2024
1 parent 13982fc commit 2961073
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 45 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Code Style

on:
push:
branches: [ main, master ]
paths-ignore:
- 'pretix_zugferd/locale/**'
- 'pretix_zugferd/static/**'
pull_request:
branches: [ main, master ]
paths-ignore:
- 'pretix_zugferd/locale/**'
- 'pretix_zugferd/static/**'

jobs:
isort:
name: isort
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v1
with:
python-version: 3.11
- uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install pretix
run: pip3 install pretix
- name: Install Dependencies
run: pip3 install isort -Ue .
- name: Run isort
run: isort -c .
flake:
name: flake8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v1
with:
python-version: 3.11
- uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install pretix
run: pip3 install pretix
- name: Install Dependencies
run: pip3 install flake8 -Ue .
- name: Run flake8
run: flake8 .
working-directory: .
black:
name: black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v1
with:
python-version: 3.11
- uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install pretix
run: pip3 install pretix
- name: Install Dependencies
run: pip3 install black -Ue .
- name: Run black
run: black --check .
working-directory: .
packaging:
name: packaging
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v1
with:
python-version: 3.11
- uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install pretix
run: pip3 install pretix
- name: Install Dependencies
run: pip3 install twine check-manifest -Ue .
- name: Run check-manifest
run: check-manifest .
working-directory: .
- name: Build package
run: python setup.py sdist
working-directory: .
- name: Check package
run: twine check dist/*
working-directory: .
36 changes: 36 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Tests

on:
push:
branches: [ main, master ]
paths-ignore:
- 'pretix_zugferd/locale/**'
pull_request:
branches: [ main, master ]
paths-ignore:
- 'pretix_zugferd/locale/**'

jobs:
test:
runs-on: ubuntu-latest
name: Tests
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v1
with:
python-version: 3.11
- uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install system dependencies
run: sudo apt update && sudo apt install gettext
- name: Install pretix
run: pip3 install pretix
- name: Install Dependencies
run: pip3 install pytest pytest-django -Ue .
- name: Run checks
run: py.test tests
55 changes: 28 additions & 27 deletions pretix_zugferd/invoice.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import re

import bleach
import logging
import os
import re
import subprocess
import tempfile
import unicodedata
Expand Down Expand Up @@ -48,7 +47,9 @@ def _zugferd_generate_document(self, invoice):
cc = invoice.event.currency
doc = Document()
if self.profile == "EXTENDED":
doc.context.test_indicator = invoice.invoice_no == "PREVIEW" or invoice.order.testmode
doc.context.test_indicator = (
invoice.invoice_no == "PREVIEW" or invoice.order.testmode
)
doc.header.name = "RECHNUNG"
doc.header.languages.add(invoice.locale[:2])
if self.business_process_id:
Expand Down Expand Up @@ -100,13 +101,9 @@ def _zugferd_generate_document(self, invoice):
li.product.name = desc.split("\n")[0]
li.product.description = desc
# For negative amounts, only the billed quantity may be negative, not the base price per quantity
li.agreement.gross.amount = abs(line.net_value).quantize(
Decimal("0.0001")
)
li.agreement.gross.amount = abs(line.net_value).quantize(Decimal("0.0001"))
li.agreement.gross.basis_quantity = (Decimal("1.0000"), "C62")
li.agreement.net.amount = abs(line.net_value).quantize(
Decimal("0.0001")
)
li.agreement.net.amount = abs(line.net_value).quantize(Decimal("0.0001"))
li.agreement.net.basis_quantity = (Decimal("1.0000"), "C62")
li.delivery.billed_quantity = (Decimal("1.0000") * factor, "C62")
li.settlement.trade_tax.type_code = "VAT"
Expand Down Expand Up @@ -204,17 +201,17 @@ def _zugferd_generate_document(self, invoice):
)

# Autodetect German "Leitweg-ID"
if str(invoice.invoice_to_country) == "DE" and invoice.custom_field and self.re_leitweg_id.match(invoice.custom_field):
if (
str(invoice.invoice_to_country) == "DE"
and invoice.custom_field
and self.re_leitweg_id.match(invoice.custom_field)
):
doc.trade.agreement.seller.electronic_address.add(
URIUniversalCommunication(
uri_ID=("0204", invoice.custom_field)
)
URIUniversalCommunication(uri_ID=("0204", invoice.custom_field))
)
elif invoice.order.email:
doc.trade.agreement.seller.electronic_address.add(
URIUniversalCommunication(
uri_ID=("EM", invoice.order.email)
)
URIUniversalCommunication(uri_ID=("EM", invoice.order.email))
)

if invoice.invoice_to_vat_id:
Expand Down Expand Up @@ -282,8 +279,8 @@ def _zugferd_generate_document(self, invoice):
note.content.add(
remove_control_characters(
" / ".join(
line for line in
invoice.additional_text.split("<br />")
line
for line in invoice.additional_text.split("<br />")
if line.split()
)
)
Expand Down Expand Up @@ -345,7 +342,9 @@ def _zugferd_generate_document(self, invoice):
doc.trade.settlement.terms.add(pt)

if invoice.is_cancellation:
doc.trade.settlement.invoice_referenced_document.issuer_assigned_id = invoice.refers.number
doc.trade.settlement.invoice_referenced_document.issuer_assigned_id = (
invoice.refers.number
)
# todo: doc.trade.settlement.invoice_referenced_document.date_time_string = invoice.refers.date

taxtotal = Decimal(0)
Expand Down Expand Up @@ -380,18 +379,16 @@ def _on_first_page(self, canvas: Canvas, doc):
canvas.rotate(90)
canvas.setFont("OpenSansBd", 8)
canvas.setFillColorRGB(80 / 255, 161 / 255, 103 / 255)
canvas.drawString(
0, 0, _("eInvoice included")
)
canvas.drawString(0, 0, _("eInvoice included"))
canvas.restoreState()

def generate(self, invoice):
self.__zugferd = True
self.invoice = invoice
if (
not invoice.invoice_from_name
or not invoice.invoice_to_country
or not invoice.invoice_from_country
not invoice.invoice_from_name
or not invoice.invoice_to_country
or not invoice.invoice_from_country
):
self.__zugferd = False
elif str(invoice.invoice_to_country) in settings.COUNTRIES_OVERRIDE:
Expand All @@ -406,7 +403,9 @@ def generate(self, invoice):
except Exception:
self.__zugferd = False
logger.exception(
"Could not generate ZUGFeRD data for invoice {}".format(invoice.number)
"Could not generate ZUGFeRD data for invoice {}".format(
invoice.number
)
)

fname, ftype, content = super().generate(invoice)
Expand Down Expand Up @@ -467,7 +466,9 @@ class Modern1ZugferdXRechnungInvoiceRenderer(ZugferdMixin, Modern1Renderer):
identifier = "modern1_zugferd_xrechnung"
profile = "XRECHNUNG"
schema = "EN16931"
guideline_id = "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0"
guideline_id = (
"urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0"
)
business_process_id = "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"
verbose_name = lazy(
lambda a: "{} + ZUGFeRD 2.2 Profil XRECHNUNG".format(
Expand Down
4 changes: 1 addition & 3 deletions pretix_zugferd/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from phonenumber_field.formfields import PhoneNumberField
from pretix.base.forms import SettingsForm
from pretix.base.models import Event
from pretix.control.views.event import (
EventSettingsFormView, EventSettingsViewMixin,
)
from pretix.control.views.event import EventSettingsFormView, EventSettingsViewMixin


class ZugferdSettingsForm(SettingsForm):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ max-line-length = 160
exclude = migrations,.ropeproject,static,_static,build

[isort]
profile = black
combine_as_imports = true
default_section = THIRDPARTY
include_trailing_comma = true
known_third_party = pretix
known_standard_library = typing
multi_line_output = 5
not_skip = __init__.py
skip = setup.py

Expand Down
10 changes: 8 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
from decimal import Decimal
from django_scopes import scopes_disabled
from i18nfield.strings import LazyI18nString

from pretix.base.models import Event, Organizer, Order, OrderPosition, InvoiceAddress, OrderPayment
from pretix.base.models import (
Event,
InvoiceAddress,
Order,
OrderPayment,
OrderPosition,
Organizer,
)
from pytz import UTC


Expand Down
23 changes: 13 additions & 10 deletions tests/test_invoice.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import json
import os
from decimal import Decimal

import pytest
from decimal import Decimal
from django_scopes import scopes_disabled
from pretix.base.services.invoices import (
generate_cancellation,
generate_invoice,
invoice_pdf_task,
)
from pypdf import PdfReader

from pretix.base.services.invoices import generate_invoice, invoice_pdf_task, generate_cancellation
from .utils import compare


def r(fname):
with open(os.path.join(os.path.dirname(__file__) + '/results/', fname), 'rb') as f:
with open(os.path.join(os.path.dirname(__file__) + "/results/", fname), "rb") as f:
return f.read()


Expand Down Expand Up @@ -106,9 +109,9 @@ def test_tax_code_exempt(event, order, tax_rule):
@pytest.mark.django_db
@scopes_disabled()
def test_reverse_charge(event, order, tax_rule):
tax_rule.custom_rules = json.dumps([
{'country': 'DE', 'address_type': '', 'action': 'reverse'}
])
tax_rule.custom_rules = json.dumps(
[{"country": "DE", "address_type": "", "action": "reverse"}]
)
tax_rule.save()
op = order.positions.first()
op._calculate_tax()
Expand All @@ -126,9 +129,9 @@ def test_reverse_charge(event, order, tax_rule):
@pytest.mark.django_db
@scopes_disabled()
def test_guess_tax_code(event, order, tax_rule):
tax_rule.custom_rules = json.dumps([
{'country': 'AU', 'address_type': '', 'action': 'no'}
])
tax_rule.custom_rules = json.dumps(
[{"country": "AU", "address_type": "", "action": "no"}]
)
tax_rule.code = None
tax_rule.save()
ia = order.invoice_address
Expand Down
3 changes: 1 addition & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
from difflib import unified_diff
from xml.dom import minidom

from drafthorse.utils import validate_xml
from xml.dom import minidom


def diff_xml(a, b):
Expand Down

0 comments on commit 2961073

Please sign in to comment.