Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.5.6.2 #184

Merged
merged 2 commits into from
Feb 1, 2024
Merged
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
630 changes: 334 additions & 296 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion django_ledger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
default_app_config = 'django_ledger.apps.DjangoLedgerConfig'

"""Django Ledger"""
__version__ = '0.5.6.1'
__version__ = '0.5.6.2'
__license__ = 'GPLv3 License'

__author__ = 'Miguel Sanda'
Expand Down
36 changes: 30 additions & 6 deletions django_ledger/io/io_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ def dispatch(self,
if isinstance(ledger_model, LedgerModel):
self.ENTITY_MODEL.validate_ledger_model_for_entity(ledger_model)

blueprint_gen = self.IO_LIBRARY.get_blueprint(name)
blueprint = blueprint_gen(**kwargs)
self.blueprints[ledger_model].append(blueprint)
blueprint_func = self.IO_LIBRARY.get_blueprint(name)
blueprint_txs = blueprint_func(**kwargs)
self.blueprints[ledger_model].append(blueprint_txs)

def compile_instructions(self):

Expand All @@ -143,7 +143,8 @@ def compile_instructions(self):

if total_credits != total_debits:
raise IOCursorValidationError(
message=_('Total transactions Credits and Debits must equal: ')
message=_('Total transactions Credits and Debits must be equal. '
'Got CREDITs: {} and DEBITs: {}.'.format(total_credits, total_debits))
)

self.instructions = instructions
Expand Down Expand Up @@ -213,7 +214,9 @@ def commit(self,

instructions = self.compile_instructions()
account_codes = set(tx.account_code for tx in chain.from_iterable(tr for _, tr in instructions.items()))
account_models = {acc.code: acc for acc in self.resolve_account_model_qs(codes=account_codes)}
account_models = {
acc.code: acc for acc in self.resolve_account_model_qs(codes=account_codes)
}

for tx in chain.from_iterable(tr for _, tr in instructions.items()):
tx.account_model = account_models[tx.account_code]
Expand Down Expand Up @@ -258,7 +261,7 @@ def __init__(self, precision_decimals: int = 2):
def _round_amount(self, amount: Decimal) -> Decimal:
return round(amount, self.precision_decimals)

def _amount(self, amount: Union[float, Decimal]) -> Decimal:
def _amount(self, amount: Union[float, Decimal, int]) -> Decimal:
if amount <= 0:
raise IOBluePrintValidationError(
message='Amounts must be greater than 0'
Expand All @@ -270,6 +273,9 @@ def _amount(self, amount: Union[float, Decimal]) -> Decimal:
elif isinstance(amount, Decimal):
return self._round_amount(amount)

elif isinstance(amount, int):
return Decimal(str(amount))

raise IOBluePrintValidationError(
message='Amounts must be float or Decimal'
)
Expand All @@ -294,6 +300,24 @@ def debit(self, account_code: str, amount: Union[float, Decimal], description: s
description=description
))

def commit(self,
entity_model: EntityModel,
user_model,
ledger_model: Optional[Union[str, LedgerModel, UUID]] = None,
je_timestamp: Optional[Union[datetime, date, str]] = None,
post_new_ledgers: bool = False,
post_journal_entries: bool = False):

blueprint_lib = IOLibrary(name='blueprint')
cursor = blueprint_lib.get_cursor(entity_model=entity_model, user_model=user_model)
cursor.blueprints[ledger_model].append(self)

return cursor.commit(
je_timestamp=je_timestamp,
post_new_ledgers=post_new_ledgers,
post_journal_entries=post_journal_entries
)


class IOLibrary:

Expand Down
7 changes: 3 additions & 4 deletions django_ledger/models/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,13 @@ def configure(self,
ledger_model.clean_fields()
self.ledger = ledger_model

if commit_ledger:
self.ledger.save()

if self.can_generate_bill_number():
self.generate_bill_number(commit=commit)

self.clean()
self.clean_fields()

if commit_ledger or commit:
self.ledger.save()

if commit:
self.save()
Expand Down
8 changes: 4 additions & 4 deletions django_ledger/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,17 +441,17 @@ def configure(self,
ledger_model.clean_fields()
self.ledger = ledger_model

if commit_ledger:
self.ledger.save()

if self.can_generate_invoice_number():
self.generate_invoice_number(commit=commit)

self.clean()
self.clean_fields()

if commit_ledger or commit:
self.ledger.save()

if commit:
self.save()

return self.ledger, self

# ### ItemizeMixIn implementation START...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@
{% block view_content %}
<div class="columns is-centered">
<div class="column is-6-desktop">
<div class="box">
<form action="{% url 'django_ledger:bank-account-create' entity_slug=view.kwargs.entity_slug %}"
method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit"
class="button is-primary is-outlined is-fullwidth djetler_my_1">{% trans 'Create' %}
</button>
<a href="{% url 'django_ledger:bank-account-list' entity_slug=view.kwargs.entity_slug %}"
class="button is-small is-dark is-fullwidth">{% trans 'Back' %}</a>
</form>
<div class="card">

<div class="card-header">
<div class="card-header-title has-text-weight-light is-size-4 is-centered">{% trans 'Create Bank Account' %}</div>
</div>


<div class="card-content">
<form action="{% url 'django_ledger:bank-account-create' entity_slug=view.kwargs.entity_slug %}"
method="post">
{% csrf_token %}
{{ form }}
<button type="submit"
class="button is-primary is-outlined is-fullwidth djetler_my_1">{% trans 'Create' %}
</button>
<a href="{% url 'django_ledger:bank-account-list' entity_slug=view.kwargs.entity_slug %}"
class="button is-small is-dark is-fullwidth">{% trans 'Back' %}</a>
</form>
</div>

</div>
</div>
</div>
Expand Down
54 changes: 29 additions & 25 deletions django_ledger/templates/django_ledger/bills/bill_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,41 @@
<div class="column is-6-desktop">
<div class="card">
<div class="card-header">
<h2 class="card-header-title has-text-weight-light is-size-3">{% trans 'Create Bill' %}</h2>
<h2 class="card-header-title has-text-weight-light is-size-4 is-centered">{% trans 'Create Bill' %}</h2>
</div>
<div class="card-content">
<form action="{{ form_action_url }}" method="post" id="djl-bill-model-create-form-id">
<div class="columns is-multiline is-centered">
{% csrf_token %}
{% if po_model %}
<div class="column is-12 has-text-centered">
<h2 class="title">{% trans 'Bill for' %} {{ po_model.po_number }}</h2>
<h3 class="subtitle has-text-weight-light">{% trans 'Bill for' %} {{ po_model.po_title }}</h3>
{% for itemtxs in po_itemtxs_qs %}
<p>{{ itemtxs }}</p>
{% endfor %}
</div>
{% endif %}
{{ form }}
<div class="column is-4">
<button type="submit"
id="djl-bill-create-button"
class="button is-primary is-outlined is-fullwidth my-2">Create
</button>
<a href="{% url 'django_ledger:bill-list' entity_slug=view.kwargs.entity_slug %}"
id="djl-bill-create-back-button"
class="button is-small is-dark is-fullwidth">{% trans 'Cancel' %}</a>
<form action="{{ form_action_url }}" method="post" id="djl-bill-model-create-form-id">
<div class="card-content">

{% csrf_token %}
{% if po_model %}
<div class="column is-12 has-text-centered">
<h2 class="title">{% trans 'Bill for' %} {{ po_model.po_number }}</h2>
<h3 class="subtitle has-text-weight-light">{% trans 'Bill for' %} {{ po_model.po_title }}</h3>
{% for itemtxs in po_itemtxs_qs %}
<p>{{ itemtxs }}</p>
{% endfor %}
</div>
{% endif %}
{{ form }}
</div>

<div class="card-content">
<div class="buttons">
<button type="submit"
id="djl-bill-create-button"
class="button is-primary is-outlined is-fullwidth my-2">{% trans 'Create' %}
</button>
<a href="{% url 'django_ledger:bill-list' entity_slug=view.kwargs.entity_slug %}"
id="djl-bill-create-back-button"
class="button is-small is-dark is-fullwidth">{% trans 'Cancel' %}</a>
</div>
</form>
</div>
</div>

</form>
</div>
</div>
</div>
</div>
{% endblock %}


Expand Down
45 changes: 26 additions & 19 deletions django_ledger/templates/django_ledger/invoice/invoice_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

{% block view_content %}
<div class="columns is-multiline is-centered">

{% if estimate_model %}
<div class="column is-12 has-text-centered">
<h2 class="is-size-2">{% trans 'Invoice for Estimate' %}: {{ estimate_model.title }}</h2>
Expand All @@ -15,29 +16,35 @@ <h4 class="is-size-4 mt-2">{{ estimate_model.customer }}</h4>
{% trans 'Back to Estimate' %}</a>
</div>
{% endif %}
<div class="column is-6-desktop">

<div class="column is-10-tablet is-6-desktop">
<div class="card">

<div class="card-header">
<h2 class="card-header-title has-text-weight-light is-size-3">{% trans 'Create Invoice' %}</h2>
<h2 class="card-header-title has-text-weight-light is-size-4 is-centered">{% trans 'Create Invoice' %}</h2>
</div>
<div class="card-content">
<form action="{{ form_action_url }}"
method="post" id="djl-bill-create-form-id">
<div class="columns is-multiline is-centered">
{% csrf_token %}
{{ form }}
<div class="column is-4">
<button type="submit"
id="djl-invoice-create-button"
class="button is-primary is-outlined is-fullwidth my-2">{% trans 'Create' %}
</button>
<a href="{% url 'django_ledger:invoice-list' entity_slug=view.kwargs.entity_slug %}"
id="djl-invoice-create-back-button"
class="button is-small is-dark is-fullwidth">{% trans 'Cancel' %}</a>
</div>

<form action="{{ form_action_url }}" method="post" id="djl-bill-create-form-id">

<div class="card-content">
{% csrf_token %}
{{ form }}
</div>

<div class="card-content">
<div class="buttons">
<button type="submit"
id="djl-invoice-create-button"
class="button is-primary is-fullwidth mb-4">{% trans 'Create' %}
</button>
<a href="{% url 'django_ledger:invoice-list' entity_slug=view.kwargs.entity_slug %}"
id="djl-invoice-create-back-button"
class="button is-fullwidth mt-4">{% trans 'Cancel' %}</a>
</div>
</form>
</div>

</div>
</form>

</div>
</div>
</div>
Expand Down
7 changes: 3 additions & 4 deletions django_ledger/views/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ def get_form(self, form_class=None):
def form_valid(self, form):
bill_model: BillModel = form.save(commit=False)
ledger_model, bill_model = bill_model.configure(
entity_slug=self.kwargs['entity_slug'],
commit_ledger=True,
ledger_posted=False,
user_model=self.request.user)
entity_slug=self.AUTHORIZED_ENTITY_MODEL,
commit_ledger=True
)

if self.for_estimate:
ce_pk = self.kwargs['ce_pk']
Expand Down
4 changes: 2 additions & 2 deletions django_ledger/views/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def get_form(self, form_class=None):
def form_valid(self, form):
invoice_model: InvoiceModel = form.save(commit=False)
ledger_model, invoice_model = invoice_model.configure(
entity_slug=self.kwargs['entity_slug'],
user_model=self.request.user,
entity_slug=self.AUTHORIZED_ENTITY_MODEL,
commit_ledger=True
)

if self.for_estimate:
Expand Down
5 changes: 5 additions & 0 deletions docs/source/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ IO Library
IO Digest
---------
.. automodule:: django_ledger.io.io_digest
:members:

Account Roles
-------------
.. automodule:: django_ledger.io.roles
:members:
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "django-ledger"
version = "0.5.6.1"
version = "0.5.6.2"
readme = "README.md"
requires-python = ">=3.7"
description = "Bookkeeping & Financial analysis backend for Django. Balance Sheet, Income Statements, Chart of Accounts, Entities"
Expand Down