wbaccounting 2.2.1__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wbaccounting/__init__.py +1 -0
- wbaccounting/admin/__init__.py +5 -0
- wbaccounting/admin/booking_entry.py +53 -0
- wbaccounting/admin/entry_accounting_information.py +10 -0
- wbaccounting/admin/invoice.py +26 -0
- wbaccounting/admin/invoice_type.py +8 -0
- wbaccounting/admin/transactions.py +16 -0
- wbaccounting/apps.py +5 -0
- wbaccounting/dynamic_preferences_registry.py +107 -0
- wbaccounting/factories/__init__.py +10 -0
- wbaccounting/factories/booking_entry.py +21 -0
- wbaccounting/factories/entry_accounting_information.py +46 -0
- wbaccounting/factories/invoice.py +43 -0
- wbaccounting/factories/transactions.py +32 -0
- wbaccounting/files/__init__.py +0 -0
- wbaccounting/files/invoice_document_file.py +134 -0
- wbaccounting/files/utils.py +331 -0
- wbaccounting/generators/__init__.py +6 -0
- wbaccounting/generators/base.py +120 -0
- wbaccounting/io/handlers/__init__.py +0 -0
- wbaccounting/io/handlers/transactions.py +32 -0
- wbaccounting/io/parsers/__init__.py +0 -0
- wbaccounting/io/parsers/societe_generale_lux.py +49 -0
- wbaccounting/io/parsers/societe_generale_lux_prenotification.py +60 -0
- wbaccounting/migrations/0001_initial_squashed_squashed_0005_alter_bookingentry_counterparty_and_more.py +284 -0
- wbaccounting/migrations/0006_alter_invoice_status.py +30 -0
- wbaccounting/migrations/0007_alter_invoice_options.py +23 -0
- wbaccounting/migrations/0008_alter_invoice_options.py +20 -0
- wbaccounting/migrations/0009_invoicetype_alter_bookingentry_options_and_more.py +366 -0
- wbaccounting/migrations/0010_alter_bookingentry_options.py +20 -0
- wbaccounting/migrations/0011_transaction.py +103 -0
- wbaccounting/migrations/0012_entryaccountinginformation_external_invoice_users.py +25 -0
- wbaccounting/migrations/__init__.py +0 -0
- wbaccounting/models/__init__.py +6 -0
- wbaccounting/models/booking_entry.py +167 -0
- wbaccounting/models/entry_accounting_information.py +157 -0
- wbaccounting/models/invoice.py +467 -0
- wbaccounting/models/invoice_type.py +30 -0
- wbaccounting/models/model_tasks.py +71 -0
- wbaccounting/models/transactions.py +112 -0
- wbaccounting/permissions.py +6 -0
- wbaccounting/processors/__init__.py +0 -0
- wbaccounting/processors/dummy_processor.py +5 -0
- wbaccounting/serializers/__init__.py +12 -0
- wbaccounting/serializers/booking_entry.py +78 -0
- wbaccounting/serializers/consolidated_invoice.py +109 -0
- wbaccounting/serializers/entry_accounting_information.py +149 -0
- wbaccounting/serializers/invoice.py +95 -0
- wbaccounting/serializers/invoice_type.py +16 -0
- wbaccounting/serializers/transactions.py +50 -0
- wbaccounting/tests/__init__.py +0 -0
- wbaccounting/tests/conftest.py +65 -0
- wbaccounting/tests/test_displays/__init__.py +0 -0
- wbaccounting/tests/test_displays/test_booking_entries.py +1 -0
- wbaccounting/tests/test_models/__init__.py +0 -0
- wbaccounting/tests/test_models/test_booking_entries.py +119 -0
- wbaccounting/tests/test_models/test_entry_accounting_information.py +81 -0
- wbaccounting/tests/test_models/test_invoice_types.py +21 -0
- wbaccounting/tests/test_models/test_invoices.py +73 -0
- wbaccounting/tests/test_models/test_transactions.py +40 -0
- wbaccounting/tests/test_processors.py +28 -0
- wbaccounting/tests/test_serializers/__init__.py +0 -0
- wbaccounting/tests/test_serializers/test_booking_entries.py +69 -0
- wbaccounting/tests/test_serializers/test_entry_accounting_information.py +64 -0
- wbaccounting/tests/test_serializers/test_invoice_types.py +35 -0
- wbaccounting/tests/test_serializers/test_transactions.py +72 -0
- wbaccounting/urls.py +68 -0
- wbaccounting/viewsets/__init__.py +12 -0
- wbaccounting/viewsets/booking_entry.py +61 -0
- wbaccounting/viewsets/buttons/__init__.py +3 -0
- wbaccounting/viewsets/buttons/booking_entry.py +15 -0
- wbaccounting/viewsets/buttons/entry_accounting_information.py +100 -0
- wbaccounting/viewsets/buttons/invoice.py +65 -0
- wbaccounting/viewsets/cashflows.py +124 -0
- wbaccounting/viewsets/display/__init__.py +8 -0
- wbaccounting/viewsets/display/booking_entry.py +58 -0
- wbaccounting/viewsets/display/cashflows.py +58 -0
- wbaccounting/viewsets/display/entry_accounting_information.py +91 -0
- wbaccounting/viewsets/display/invoice.py +218 -0
- wbaccounting/viewsets/display/invoice_type.py +19 -0
- wbaccounting/viewsets/display/transactions.py +35 -0
- wbaccounting/viewsets/endpoints/__init__.py +1 -0
- wbaccounting/viewsets/endpoints/invoice.py +6 -0
- wbaccounting/viewsets/entry_accounting_information.py +143 -0
- wbaccounting/viewsets/invoice.py +277 -0
- wbaccounting/viewsets/invoice_type.py +25 -0
- wbaccounting/viewsets/menu/__init__.py +6 -0
- wbaccounting/viewsets/menu/booking_entry.py +15 -0
- wbaccounting/viewsets/menu/cashflows.py +10 -0
- wbaccounting/viewsets/menu/entry_accounting_information.py +11 -0
- wbaccounting/viewsets/menu/invoice.py +15 -0
- wbaccounting/viewsets/menu/invoice_type.py +15 -0
- wbaccounting/viewsets/menu/transactions.py +15 -0
- wbaccounting/viewsets/titles/__init__.py +4 -0
- wbaccounting/viewsets/titles/booking_entry.py +12 -0
- wbaccounting/viewsets/titles/entry_accounting_information.py +12 -0
- wbaccounting/viewsets/titles/invoice.py +23 -0
- wbaccounting/viewsets/titles/invoice_type.py +12 -0
- wbaccounting/viewsets/transactions.py +34 -0
- wbaccounting-2.2.1.dist-info/METADATA +8 -0
- wbaccounting-2.2.1.dist-info/RECORD +102 -0
- wbaccounting-2.2.1.dist-info/WHEEL +5 -0
wbaccounting/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
from .booking_entry import BookingEntryInline, BookingEntryModelAdmin
|
|
2
|
+
from .entry_accounting_information import EntryAccountingInformationModelAdmin
|
|
3
|
+
from .invoice_type import InvoiceTypeModelAdmin
|
|
4
|
+
from .invoice import InvoiceModelAdmin
|
|
5
|
+
from .transactions import TransactionModelAdmin
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from datetime import date
|
|
2
|
+
|
|
3
|
+
from django.contrib import admin
|
|
4
|
+
from wbaccounting.models import BookingEntry, Invoice
|
|
5
|
+
from wbcore.contrib.directory.models import Entry
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BookingEntryInline(admin.TabularInline):
|
|
9
|
+
model = BookingEntry
|
|
10
|
+
fields = ("booking_date", "net_value", "vat")
|
|
11
|
+
ordering = ("vat", "title")
|
|
12
|
+
|
|
13
|
+
def has_add_permission(self, request, obj=None):
|
|
14
|
+
return False
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@admin.register(BookingEntry)
|
|
18
|
+
class BookingEntryModelAdmin(admin.ModelAdmin):
|
|
19
|
+
list_display = (
|
|
20
|
+
"title",
|
|
21
|
+
"booking_date",
|
|
22
|
+
"net_value",
|
|
23
|
+
"vat",
|
|
24
|
+
"currency",
|
|
25
|
+
"payment_date",
|
|
26
|
+
"counterparty",
|
|
27
|
+
"reference_date",
|
|
28
|
+
)
|
|
29
|
+
search_fields = ["counterparty__computed_str"]
|
|
30
|
+
autocomplete_fields = ("counterparty", "currency")
|
|
31
|
+
|
|
32
|
+
# TODO: Remove or adjust.
|
|
33
|
+
def create_invoice(self, request, queryset):
|
|
34
|
+
counterparty = list(set(queryset.values_list("counterparty__id", flat=True)))
|
|
35
|
+
if len(counterparty) == 1:
|
|
36
|
+
counterparty = Entry.objects.get(id=counterparty[0])
|
|
37
|
+
invoice = Invoice.objects.create(
|
|
38
|
+
title=f"Rebate Invoice {counterparty.computed_str} ({queryset.earliest('from_date').from_date:%d.%m.%Y} - {queryset.latest('to_date').to_date:%d.%m.%Y})",
|
|
39
|
+
invoice_date=date.today(),
|
|
40
|
+
reference_date=date.today(),
|
|
41
|
+
counterparty=counterparty,
|
|
42
|
+
invoice_currency=counterparty.entry_accounting_information.default_currency,
|
|
43
|
+
is_counterparty_invoice=True,
|
|
44
|
+
)
|
|
45
|
+
queryset.update(invoice=invoice)
|
|
46
|
+
invoice.save()
|
|
47
|
+
|
|
48
|
+
else:
|
|
49
|
+
print("-------------------------------") # noqa: T201
|
|
50
|
+
print(f"Too many counterparties selected ({len(counterparty)})") # noqa: T201
|
|
51
|
+
print("-------------------------------") # noqa: T201
|
|
52
|
+
|
|
53
|
+
actions = [create_invoice]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from django.contrib import admin
|
|
2
|
+
from wbaccounting.models import EntryAccountingInformation
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@admin.register(EntryAccountingInformation)
|
|
6
|
+
class EntryAccountingInformationModelAdmin(admin.ModelAdmin):
|
|
7
|
+
list_display = ("entry", "send_mail", "counterparty_is_private")
|
|
8
|
+
autocomplete_fields = ["default_currency", "entry", "email_to", "email_cc", "email_bcc", "exempt_users"]
|
|
9
|
+
|
|
10
|
+
search_fields = ["entry__computed_str"]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from django.contrib import admin
|
|
2
|
+
from wbaccounting.admin import BookingEntryInline
|
|
3
|
+
from wbaccounting.models import Invoice
|
|
4
|
+
from wbcore.contrib.documents.admin import DocumentInLine
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@admin.register(Invoice)
|
|
8
|
+
class InvoiceModelAdmin(admin.ModelAdmin):
|
|
9
|
+
fsm_field = ["status"]
|
|
10
|
+
search_fields = ("counterparty__computed_str", "title", "invoice_type__name")
|
|
11
|
+
list_display = (
|
|
12
|
+
"status",
|
|
13
|
+
"title",
|
|
14
|
+
"gross_value",
|
|
15
|
+
"net_value",
|
|
16
|
+
"invoice_date",
|
|
17
|
+
"invoice_currency",
|
|
18
|
+
"counterparty",
|
|
19
|
+
"invoice_type",
|
|
20
|
+
"reference_date",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
autocomplete_fields = ("counterparty",)
|
|
24
|
+
inlines = [BookingEntryInline, DocumentInLine]
|
|
25
|
+
|
|
26
|
+
raw_id_fields = ["counterparty", "invoice_currency", "invoice_type"]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from django.contrib import admin
|
|
2
|
+
from wbaccounting.models import Transaction
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@admin.register(Transaction)
|
|
6
|
+
class TransactionModelAdmin(admin.ModelAdmin):
|
|
7
|
+
list_display = ["booking_date", "value_date", "value", "bank_account", "prenotification"]
|
|
8
|
+
|
|
9
|
+
raw_id_fields = ["import_source"]
|
|
10
|
+
|
|
11
|
+
autocomplete_fields = [
|
|
12
|
+
"bank_account",
|
|
13
|
+
"from_bank_account",
|
|
14
|
+
"to_bank_account",
|
|
15
|
+
"currency",
|
|
16
|
+
]
|
wbaccounting/apps.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
from django.conf import settings
|
|
2
|
+
from dynamic_preferences.preferences import Section
|
|
3
|
+
from dynamic_preferences.registries import global_preferences_registry
|
|
4
|
+
from dynamic_preferences.types import (
|
|
5
|
+
IntegerPreference,
|
|
6
|
+
LongStringPreference,
|
|
7
|
+
ModelMultipleChoicePreference,
|
|
8
|
+
StringPreference,
|
|
9
|
+
)
|
|
10
|
+
from wbcore.contrib.currency.models import Currency
|
|
11
|
+
from wbcore.contrib.directory.models import Person
|
|
12
|
+
|
|
13
|
+
accounting_section = Section("wbaccounting")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def format_invoice_number(number):
|
|
17
|
+
global_preferences = global_preferences_registry.manager()
|
|
18
|
+
ts = global_preferences["wbaccounting__invoice_thousand_seperator"]
|
|
19
|
+
ds = global_preferences["wbaccounting__invoice_decimal_seperator"]
|
|
20
|
+
if not number:
|
|
21
|
+
number = 0
|
|
22
|
+
s = "{:,.2f}".format(number)
|
|
23
|
+
s = s.replace(",", "//")
|
|
24
|
+
s = s.replace(".", "\\")
|
|
25
|
+
|
|
26
|
+
return s.replace("//", ts).replace("\\", ds)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@global_preferences_registry.register
|
|
30
|
+
class DefaultEntryAccountingInformationCurrency(StringPreference):
|
|
31
|
+
section = accounting_section
|
|
32
|
+
name = "default_entry_account_information_currency_key"
|
|
33
|
+
default = "CHF"
|
|
34
|
+
|
|
35
|
+
verbose_name = "The currency key used for the default currency of newly created entry accounting informations."
|
|
36
|
+
|
|
37
|
+
def validate(self, value):
|
|
38
|
+
if not Currency.objects.filter(key=value).exists():
|
|
39
|
+
return ValueError("The specified currency key is not valid")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@global_preferences_registry.register
|
|
43
|
+
class ExternalEmailAddress(StringPreference):
|
|
44
|
+
section = accounting_section
|
|
45
|
+
name = "external_email_address"
|
|
46
|
+
default = ""
|
|
47
|
+
|
|
48
|
+
verbose_name = "External Email Address"
|
|
49
|
+
help_text = "The Email Address used to send Invoices to the external party."
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@global_preferences_registry.register
|
|
53
|
+
class InvoiceEmailBody(LongStringPreference):
|
|
54
|
+
section = accounting_section
|
|
55
|
+
name = "invoice_email_body"
|
|
56
|
+
default = ""
|
|
57
|
+
|
|
58
|
+
verbose_name = "The default E-Mail Body used for emailing Invoices"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@global_preferences_registry.register
|
|
62
|
+
class InvoiceThousandSeperatorPreference(StringPreference):
|
|
63
|
+
section = accounting_section
|
|
64
|
+
name = "invoice_thousand_seperator"
|
|
65
|
+
default = ","
|
|
66
|
+
|
|
67
|
+
verbose_name = "Invoice Thousand Seperator"
|
|
68
|
+
help_text = "Thousand Seperator for Invoices"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@global_preferences_registry.register
|
|
72
|
+
class InvoiceDecimalSeperatorPreference(StringPreference):
|
|
73
|
+
section = accounting_section
|
|
74
|
+
name = "invoice_decimal_seperator"
|
|
75
|
+
default = "."
|
|
76
|
+
|
|
77
|
+
verbose_name = "Invoice Decimal Seperator"
|
|
78
|
+
help_text = "Decimal Seperator for Invoices"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@global_preferences_registry.register
|
|
82
|
+
class InvoiceSignerPreference(ModelMultipleChoicePreference):
|
|
83
|
+
section = accounting_section
|
|
84
|
+
name = "invoice_signers"
|
|
85
|
+
queryset = Person.objects.all()
|
|
86
|
+
default = None
|
|
87
|
+
verbose_name = "Invoice Signers"
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@global_preferences_registry.register
|
|
91
|
+
class InvoiceCompanyPreference(IntegerPreference):
|
|
92
|
+
section = accounting_section
|
|
93
|
+
name = "invoice_company"
|
|
94
|
+
default = 0
|
|
95
|
+
|
|
96
|
+
verbose_name = "Invoice Company"
|
|
97
|
+
help_text = "The PK of the company who issues the invoices"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@global_preferences_registry.register
|
|
101
|
+
class DefaultFromEmailAddressPreference(StringPreference):
|
|
102
|
+
section = accounting_section
|
|
103
|
+
name = "default_from_email_address"
|
|
104
|
+
default = settings.DEFAULT_FROM_EMAIL
|
|
105
|
+
|
|
106
|
+
verbose_name = "The default from email address"
|
|
107
|
+
help_text = "The default from email address used to send invoice"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from .booking_entry import BookingEntryFactory
|
|
2
|
+
from .entry_accounting_information import (
|
|
3
|
+
CompanyAccountingFactory,
|
|
4
|
+
EntryAccountingInformationFactory,
|
|
5
|
+
)
|
|
6
|
+
from .invoice import (
|
|
7
|
+
InvoiceFactory,
|
|
8
|
+
InvoiceTypeFactory,
|
|
9
|
+
)
|
|
10
|
+
from .transactions import TransactionFactory, LocalCurrencyTransactionFactory
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import factory
|
|
2
|
+
from factory.fuzzy import FuzzyDecimal
|
|
3
|
+
from wbaccounting.models import BookingEntry
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BookingEntryFactory(factory.django.DjangoModelFactory):
|
|
7
|
+
class Meta: # type: ignore
|
|
8
|
+
model = BookingEntry
|
|
9
|
+
|
|
10
|
+
# resolved
|
|
11
|
+
title = factory.Faker("text", max_nb_chars=64)
|
|
12
|
+
booking_date = factory.Faker("date_between", start_date="+2d", end_date="+3d")
|
|
13
|
+
payment_date = factory.Faker("date_object")
|
|
14
|
+
reference_date = factory.Faker("date_object")
|
|
15
|
+
gross_value = factory.Faker("pydecimal", right_digits=4, min_value=0, max_value=99999999999)
|
|
16
|
+
net_value = factory.Faker("pydecimal", right_digits=4, min_value=0, max_value=99999999999)
|
|
17
|
+
vat = FuzzyDecimal(0, 0.9, 4)
|
|
18
|
+
currency = factory.SelfAttribute("invoice.invoice_currency")
|
|
19
|
+
|
|
20
|
+
invoice = factory.SubFactory("wbaccounting.factories.InvoiceFactory")
|
|
21
|
+
counterparty = factory.SubFactory("wbcore.contrib.directory.factories.EntryFactory")
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import factory
|
|
2
|
+
from factory.fuzzy import FuzzyDecimal
|
|
3
|
+
from wbaccounting.models import EntryAccountingInformation
|
|
4
|
+
from wbcore.contrib.directory.factories import CompanyFactory, EmailContactFactory
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class EntryAccountingInformationFactory(factory.django.DjangoModelFactory):
|
|
8
|
+
class Meta: # type: ignore
|
|
9
|
+
model = EntryAccountingInformation
|
|
10
|
+
|
|
11
|
+
entry = factory.SubFactory("wbcore.contrib.directory.factories.EntryFactory")
|
|
12
|
+
tax_id = factory.Faker("text", max_nb_chars=64)
|
|
13
|
+
vat = FuzzyDecimal(0, 0.9, 4)
|
|
14
|
+
send_mail = factory.Faker("pybool")
|
|
15
|
+
counterparty_is_private = False
|
|
16
|
+
|
|
17
|
+
email_body = factory.Faker("paragraph")
|
|
18
|
+
|
|
19
|
+
@factory.post_generation
|
|
20
|
+
def post(self, create, extracted, **kwargs):
|
|
21
|
+
if isinstance(self, EntryAccountingInformationFactory) and not create:
|
|
22
|
+
self.email_to.add(EmailContactFactory.create())
|
|
23
|
+
self.email_cc_add(EmailContactFactory.create())
|
|
24
|
+
self.email_bcc.add(EmailContactFactory.create())
|
|
25
|
+
|
|
26
|
+
if isinstance(self, dict):
|
|
27
|
+
self["email_to"] = [EmailContactFactory.create().id]
|
|
28
|
+
self["email_cc"] = [EmailContactFactory.create().id]
|
|
29
|
+
self["email_bcc"] = [EmailContactFactory.create().id]
|
|
30
|
+
|
|
31
|
+
@factory.post_generation
|
|
32
|
+
def exempt_users(self, create, extracted, **kwargs):
|
|
33
|
+
if not create:
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
if extracted:
|
|
37
|
+
for user in extracted:
|
|
38
|
+
self.exempt_users.add(user)
|
|
39
|
+
|
|
40
|
+
default_currency = factory.SubFactory("wbcore.contrib.currency.factories.CurrencyFactory")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class CompanyAccountingFactory(CompanyFactory):
|
|
44
|
+
entry_accounting_information = factory.RelatedFactory(
|
|
45
|
+
"wbaccounting.factories.EntryAccountingInformationFactory", "entry"
|
|
46
|
+
)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import factory
|
|
2
|
+
from wbaccounting.models import Invoice, InvoiceType
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class InvoiceFactory(factory.django.DjangoModelFactory):
|
|
6
|
+
class Meta: # type: ignore
|
|
7
|
+
model = Invoice
|
|
8
|
+
|
|
9
|
+
title = factory.Faker("text", max_nb_chars=64)
|
|
10
|
+
invoice_date = factory.Faker("date_object")
|
|
11
|
+
reference_date = factory.Faker("date_object")
|
|
12
|
+
invoice_currency = factory.SubFactory("wbcore.contrib.currency.factories.CurrencyUSDFactory")
|
|
13
|
+
|
|
14
|
+
counterparty = factory.SubFactory("wbcore.contrib.directory.factories.EntryFactory")
|
|
15
|
+
invoice_type = factory.SubFactory("wbaccounting.factories.InvoiceTypeFactory")
|
|
16
|
+
|
|
17
|
+
text_above = factory.Faker("text")
|
|
18
|
+
text_below = factory.Faker("text")
|
|
19
|
+
|
|
20
|
+
# @factory.post_generation
|
|
21
|
+
# def invoice_document(self, create, extracted, **kwargs):
|
|
22
|
+
# self.refresh_invoice_document(override_status=True)
|
|
23
|
+
|
|
24
|
+
# is_counterparty_invoice
|
|
25
|
+
|
|
26
|
+
# @classmethod
|
|
27
|
+
# def _create(cls, model_class, *args, **kwargs):
|
|
28
|
+
# company = CompanyFactory()
|
|
29
|
+
# signee = PersonSignatureFactory()
|
|
30
|
+
# global_preferences_registry.manager()["wbaccounting__invoice_company"] = company.id
|
|
31
|
+
# global_preferences_registry.manager()["wbaccounting__invoice_signers"] = Person.objects.filter(id=signee.id)
|
|
32
|
+
# """Override the default ``_create`` with our custom call."""
|
|
33
|
+
# manager = cls._get_manager(model_class)
|
|
34
|
+
# # The default would use ``manager.create(*args, **kwargs)``
|
|
35
|
+
# return manager.create(*args, **kwargs)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class InvoiceTypeFactory(factory.django.DjangoModelFactory):
|
|
39
|
+
name = factory.Sequence(lambda n: f"Invoice Type {n}")
|
|
40
|
+
processor = factory.Faker("text", max_nb_chars=64)
|
|
41
|
+
|
|
42
|
+
class Meta: # type: ignore
|
|
43
|
+
model = InvoiceType
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from decimal import Decimal
|
|
2
|
+
|
|
3
|
+
import factory
|
|
4
|
+
from wbaccounting.models import Transaction
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AbstractTransactionFactory(factory.django.DjangoModelFactory):
|
|
8
|
+
class Meta:
|
|
9
|
+
model = Transaction
|
|
10
|
+
abstract = True
|
|
11
|
+
|
|
12
|
+
booking_date = factory.Faker("date_between", start_date="+2d", end_date="+3d")
|
|
13
|
+
value_date = factory.Faker("date_object")
|
|
14
|
+
|
|
15
|
+
bank_account = factory.SubFactory("wbcore.contrib.directory.factories.BankingContactFactory")
|
|
16
|
+
from_bank_account = factory.SubFactory("wbcore.contrib.directory.factories.BankingContactFactory")
|
|
17
|
+
to_bank_account = factory.SubFactory("wbcore.contrib.directory.factories.BankingContactFactory")
|
|
18
|
+
|
|
19
|
+
@factory.post_generation
|
|
20
|
+
def set_currency(self, create, extracted, **kwargs):
|
|
21
|
+
if isinstance(self, dict):
|
|
22
|
+
self["currency"] = self["bank_account"].currency
|
|
23
|
+
else:
|
|
24
|
+
self.currency = self.bank_account.currency
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TransactionFactory(AbstractTransactionFactory):
|
|
28
|
+
value = factory.Faker("pydecimal", min_value=Decimal(0.1), max_value=Decimal(10000000))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class LocalCurrencyTransactionFactory(AbstractTransactionFactory):
|
|
32
|
+
value_local_ccy = factory.Faker("pydecimal", min_value=Decimal(0.1), max_value=Decimal(10000000))
|
|
File without changes
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from contextlib import suppress
|
|
3
|
+
from io import BytesIO
|
|
4
|
+
|
|
5
|
+
from dynamic_preferences.registries import global_preferences_registry
|
|
6
|
+
from reportlab import platypus
|
|
7
|
+
from reportlab.lib.pagesizes import A4
|
|
8
|
+
from reportlab.lib.units import cm
|
|
9
|
+
from reportlab.platypus import BaseDocTemplate, NextPageTemplate, PageTemplate
|
|
10
|
+
from reportlab.platypus.frames import Frame
|
|
11
|
+
from wbaccounting.files import utils as invoice_utils
|
|
12
|
+
from wbcore.contrib.directory.models import Entry
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger("wbaccounting.files.invoice_document_file")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def generate_file(invoice):
|
|
18
|
+
debug = 0
|
|
19
|
+
|
|
20
|
+
total_gross_value, total_net_value = invoice_utils.get_gross_and_net_value(invoice)
|
|
21
|
+
show_tax_id = total_gross_value != total_net_value
|
|
22
|
+
|
|
23
|
+
styles = invoice_utils.get_styles()
|
|
24
|
+
|
|
25
|
+
output = BytesIO()
|
|
26
|
+
doc = BaseDocTemplate(output, pagesize=A4, rightMargin=10, leftMargin=10, topMargin=10, bottomMargin=10)
|
|
27
|
+
|
|
28
|
+
global_preferences = global_preferences_registry.manager()
|
|
29
|
+
invoice_company = Entry.objects.get(id=global_preferences["wbaccounting__invoice_company"])
|
|
30
|
+
signees = global_preferences["wbaccounting__invoice_signers"]
|
|
31
|
+
|
|
32
|
+
logo_ratio = 0
|
|
33
|
+
logo = None
|
|
34
|
+
try:
|
|
35
|
+
logo, logo_ratio = invoice_utils.logo_block(invoice_company.profile_image)
|
|
36
|
+
except ValueError:
|
|
37
|
+
pass
|
|
38
|
+
logo_frame = Frame(
|
|
39
|
+
x1=0,
|
|
40
|
+
y1=A4[1] - (30 + 1 * cm),
|
|
41
|
+
width=30 * logo_ratio + 1.5 * cm,
|
|
42
|
+
height=30 + 1 * cm,
|
|
43
|
+
leftPadding=1.5 * cm,
|
|
44
|
+
bottomPadding=0,
|
|
45
|
+
rightPadding=0,
|
|
46
|
+
topPadding=1 * cm,
|
|
47
|
+
id="logo_frame",
|
|
48
|
+
showBoundary=debug,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
address_frame = Frame(
|
|
52
|
+
x1=A4[0] - (12 * cm),
|
|
53
|
+
y1=A4[1] - (6 * cm),
|
|
54
|
+
width=12 * cm,
|
|
55
|
+
height=6 * cm,
|
|
56
|
+
leftPadding=0,
|
|
57
|
+
bottomPadding=0,
|
|
58
|
+
rightPadding=1.5 * cm,
|
|
59
|
+
topPadding=2.5 * cm,
|
|
60
|
+
id="address_frame",
|
|
61
|
+
showBoundary=debug,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
content_frame = Frame(
|
|
65
|
+
x1=0,
|
|
66
|
+
y1=0,
|
|
67
|
+
width=A4[0],
|
|
68
|
+
height=A4[1] - (6 * cm),
|
|
69
|
+
leftPadding=1.5 * cm,
|
|
70
|
+
bottomPadding=1 * cm,
|
|
71
|
+
rightPadding=1.5 * cm,
|
|
72
|
+
topPadding=0,
|
|
73
|
+
id="content_frame",
|
|
74
|
+
showBoundary=debug,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
content_frame2 = Frame(
|
|
78
|
+
x1=0,
|
|
79
|
+
y1=0,
|
|
80
|
+
width=A4[0],
|
|
81
|
+
height=A4[1],
|
|
82
|
+
leftPadding=1.5 * cm,
|
|
83
|
+
bottomPadding=1 * cm,
|
|
84
|
+
rightPadding=1.5 * cm,
|
|
85
|
+
topPadding=1 * cm,
|
|
86
|
+
id="content_frame2",
|
|
87
|
+
showBoundary=debug,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
doc.addPageTemplates(
|
|
91
|
+
[
|
|
92
|
+
PageTemplate(id="TitlePage", frames=[logo_frame, address_frame, content_frame]),
|
|
93
|
+
PageTemplate(id="OtherPage", frames=[content_frame2]),
|
|
94
|
+
]
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
elements = list()
|
|
98
|
+
elements.append(NextPageTemplate(["OtherPage"]))
|
|
99
|
+
if logo:
|
|
100
|
+
elements.append(logo)
|
|
101
|
+
elements.append(platypus.FrameBreak("address_frame"))
|
|
102
|
+
|
|
103
|
+
if invoice.is_counterparty_invoice:
|
|
104
|
+
elements.extend(invoice_utils.address_block(invoice_company, invoice, styles, right=True))
|
|
105
|
+
else:
|
|
106
|
+
elements.extend(invoice_utils.address_block(invoice.counterparty, invoice, styles, right=True))
|
|
107
|
+
|
|
108
|
+
elements.append(platypus.FrameBreak("content_frame"))
|
|
109
|
+
elements.extend(invoice_utils.city_and_date_block(invoice, styles, entry=invoice_company))
|
|
110
|
+
|
|
111
|
+
if invoice.is_counterparty_invoice:
|
|
112
|
+
elements.extend(invoice_utils.address_block(invoice.counterparty, invoice, styles, tax_id=show_tax_id))
|
|
113
|
+
else:
|
|
114
|
+
elements.extend(invoice_utils.address_block(invoice_company, invoice, styles, tax_id=show_tax_id))
|
|
115
|
+
|
|
116
|
+
elements.extend(invoice_utils.add_text_block_with_context(invoice.text_above, invoice, styles))
|
|
117
|
+
elements.extend(invoice_utils.add_booking_entries(invoice, styles, False))
|
|
118
|
+
elements.extend(invoice_utils.add_text_block_with_context(invoice.text_below, invoice, styles))
|
|
119
|
+
elements.extend(
|
|
120
|
+
invoice_utils.add_transfer_block(
|
|
121
|
+
invoice,
|
|
122
|
+
invoice_company if not invoice.is_counterparty_invoice else invoice.counterparty,
|
|
123
|
+
styles,
|
|
124
|
+
total_gross_value,
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
with suppress(ValueError):
|
|
128
|
+
elements.extend(invoice_utils.signature_block(signees, styles))
|
|
129
|
+
doc.build(elements)
|
|
130
|
+
|
|
131
|
+
pdf = output.getvalue()
|
|
132
|
+
output.close()
|
|
133
|
+
|
|
134
|
+
return pdf
|