Skip to content

Commit bec5461

Browse files
committed
BugFix BillUpdate/Migrate.
Added Inventory link on Menu. Inventory URL module and preliminary List View. Additional POModel fulfillment validation.
1 parent 3daabd4 commit bec5461

File tree

19 files changed

+171
-31
lines changed

19 files changed

+171
-31
lines changed

django_ledger/forms/purchase_order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ class Meta:
143143
'class': DJANGO_LEDGER_FORM_INPUT_CLASSES + ' is-small',
144144
}),
145145
'unit_cost': TextInput(attrs={
146-
'class': DJANGO_LEDGER_FORM_INPUT_CLASSES,
146+
'class': DJANGO_LEDGER_FORM_INPUT_CLASSES + ' is-small',
147147
}),
148148
'quantity': TextInput(attrs={
149-
'class': DJANGO_LEDGER_FORM_INPUT_CLASSES,
149+
'class': DJANGO_LEDGER_FORM_INPUT_CLASSES + ' is-small',
150150
})
151151
}
152152

@@ -190,7 +190,7 @@ def __init__(self, *args, entity_slug, user_model, po_model: PurchaseOrderModel,
190190
form.fields['quantity'].disabled = True
191191
form.fields['entity_unit'].disabled = True
192192
form.fields['item_model'].disabled = True
193-
if self.PO_MODEL.po_status != PurchaseOrderModel.PO_STATUS_APPROVED:
193+
if self.PO_MODEL.po_status != PurchaseOrderModel.PO_STATUS_APPROVED or self.PO_MODEL.fulfilled:
194194
form.fields['po_item_status'].disabled = True
195195
form.fields['po_item_status'].widget.attrs['class'] += form.instance.get_status_css_class()
196196
# PO is Draft

django_ledger/models/bill.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ def get_item_data(self, entity_slug, queryset=None):
148148
'entity_unit__uuid',
149149
'item_model__expense_account__balance_type').values(
150150
'item_model__expense_account__uuid',
151+
'item_model__inventory_account__uuid',
151152
'item_model__expense_account__balance_type',
153+
'item_model__inventory_account__balance_type',
152154
'entity_unit__slug',
153155
'entity_unit__uuid',
154156
'total_amount').annotate(

django_ledger/models/inventory.py

Whitespace-only changes.

django_ledger/models/items.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def expenses(self, entity_slug: str, user_model):
106106
)
107107

108108
def inventory(self, entity_slug: str, user_model):
109-
qs = self.for_entity_active(entity_slug=entity_slug, user_model=user_model)
109+
qs = self.for_entity(entity_slug=entity_slug, user_model=user_model)
110110
return qs.filter(for_inventory=True)
111111

112112
def for_bill(self, entity_slug: str, user_model):
@@ -278,6 +278,14 @@ def for_po(self, entity_slug, user_model, po_pk):
278278
qs = self.for_entity(entity_slug=entity_slug, user_model=user_model)
279279
return qs.filter(po_model__uuid__exact=po_pk)
280280

281+
def inventory_all(self, entity_slug, user_model):
282+
qs = self.for_entity(entity_slug=entity_slug, user_model=user_model)
283+
return qs.filter(item_model__for_inventory=True)
284+
285+
def inventory_received(self, entity_slug, user_model):
286+
qs = self.inventory_all(entity_slug=entity_slug, user_model=user_model)
287+
return qs.filter(po_item_status=ItemThroughModel.STATUS_RECEIVED)
288+
281289

282290
class ItemThroughModelAbstract(NodeTreeMixIn, CreateUpdateMixIn):
283291
STATUS_NOT_ORDERED = 'not_ordered'

django_ledger/models/mixins.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,18 +334,30 @@ def migrate_state(self,
334334
(a['account_uuid'], a['unit_uuid'], a['balance_type']): a['balance'] for a in digest_data
335335
}
336336

337-
item_data = self.get_item_data(entity_slug=entity_slug, queryset=itemthrough_queryset)
337+
# todo: temporary fix... Inventory accounts must be properly mapped...
338+
item_data = list(self.get_item_data(entity_slug=entity_slug, queryset=itemthrough_queryset))
339+
340+
for item in item_data:
341+
account_uuid_expense = item.get('item_model__expense_account__uuid')
342+
account_uuid_inventory = item.get('item_model__inventory_account__uuid')
343+
if account_uuid_expense:
344+
item['account_uuid'] = account_uuid_expense
345+
item['account_balance_type'] = item.get('item_model__expense_account__balance_type')
346+
elif account_uuid_inventory:
347+
item['account_uuid'] = account_uuid_inventory
348+
item['account_balance_type'] = item.get('item_model__inventory_account__balance_type')
349+
338350

339351
if isinstance(self, lazy_loader.get_bill_model()):
340352
item_data_gb = groupby(item_data,
341-
key=lambda a: (a['item_model__expense_account__uuid'],
353+
key=lambda a: (a['account_uuid'],
342354
a['entity_unit__uuid'],
343-
a['item_model__expense_account__balance_type']))
355+
a['account_balance_type']))
344356
elif isinstance(self, lazy_loader.get_invoice_model()):
345357
item_data_gb = groupby(item_data,
346-
key=lambda a: (a['item_model__earnings_account__uuid'],
358+
key=lambda a: (a['account_uuid'],
347359
a['entity_unit__uuid'],
348-
a['item_model__earnings_account__balance_type']))
360+
a['account_balance_type']))
349361

350362
progress = self.get_progress()
351363

django_ledger/models/purchase_order.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,26 @@ def clean(self):
9494
self.po_number = generate_po_number()
9595
if self.fulfillment_date:
9696
self.fulfilled = True
97+
if self.fulfilled:
98+
self.po_amount_received = self.po_amount
9799
if self.fulfilled and not self.fulfillment_date:
98100
self.fulfillment_date = localdate()
99101

100-
101102
def get_po_item_data(self, queryset=None) -> tuple:
102103
if not queryset:
103104
queryset = self.itemthroughmodel_set.all()
104105
return queryset, queryset.aggregate(
105106
amount_due=Sum('total_amount'),
107+
total_paid=Sum('bill_model__amount_paid'),
106108
total_items=Count('uuid')
107109
)
108110

109111
def update_po_state(self, queryset=None, item_list: list = None) -> None or tuple:
110112
if item_list:
111113
self.amount_due = Decimal.from_float(round(sum(a.total_amount for a in item_list), 2))
112114
return
115+
116+
# todo: explore if queryset can be passed from PO Update View...
113117
queryset, item_data = self.get_po_item_data(queryset=queryset)
114118
qs_values = queryset.values(
115119
'total_amount', 'po_item_status'

django_ledger/templates/django_ledger/includes/card_bill.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ <h2 class="card-header-title has-text-weight-light is-size-3">
9696
max="100">
9797
{{ bill.get_progress | percentage }}
9898
</progress>
99+
{# todo: fix card footer #}
99100
<footer class="card-footer">
100101
<a href="{% url 'django_ledger:bill-update' entity_slug=entity_slug bill_pk=bill.uuid %}"
101102
class="card-footer-item has-text-primary has-text-centered">{% trans 'Update' %}</a>
102103
<a onclick="djLedger.toggleModal('{{ bill.get_html_id }}')"
103104
class="card-footer-item has-text-info has-text-centered">{% trans 'Mark as Paid' %}</a>
104105
<a href="{% url 'django_ledger:bill-delete' entity_slug=entity_slug bill_pk=bill.uuid %}"
105-
class="card-footer-item has-text-danger has-text-centered">{% trans 'Delete' %}</a>
106+
class="card-footer-item has-text-danger has-text-centered">{% trans 'Delet' %}</a>
106107
<a href="{% url 'django_ledger:bill-void' entity_slug=entity_slug bill_pk=bill.uuid %}"
107108
class="card-footer-item has-text-warning has-text-centered">{% trans 'Void' %}</a>
108109
</footer>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{% extends 'django_ledger/layouts/content_layout_1.html' %}
2+
{% load i18n %}
3+
{% load static %}
4+
{% load django_ledger %}
5+
6+
{% block view_content %}
7+
<div class="container">
8+
<div class="columns">
9+
<div class="column">
10+
<h1 class="is-size-1 has-text-weight-light has-text-centered">Inventory On Hand</h1>
11+
</div>
12+
</div>
13+
<div class="columns">
14+
<div class="column">
15+
<div class="box">
16+
<div class="table-container">
17+
<table class="table is-fullwidth is-narrow is-striped is-bordered">
18+
<thead>
19+
<tr class="has-text-centered">
20+
<th>Item</th>
21+
<th>UOM</th>
22+
<th>Quantity</th>
23+
<th>Value</th>
24+
</tr>
25+
</thead>
26+
<tbody>
27+
{% for inventory in inventory_list %}
28+
<tr>
29+
<td>{{ inventory.item_model__name }}</td>
30+
<td>{{ inventory.item_model__uom__name }}</td>
31+
<td>{{ inventory.total_quantity }}</td>
32+
<td>{% currency_symbol %}{{ inventory.total_value | currency_format }}</td>
33+
</tr>
34+
{% endfor %}
35+
</tbody>
36+
</table>
37+
</div>
38+
39+
</div>
40+
</div>
41+
</div>
42+
</div>
43+
44+
{% endblock %}

django_ledger/templates/django_ledger/po_detail.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{% load django_ledger %}
55

66
{% block view_content %}
7-
87
<div class="columns">
98
<div class="column is-4">
109
<div class="columns is-multiline">
@@ -100,8 +99,4 @@ <h3 class="is-size-3 has-text-weight-light">{{ po_model.po_title }}</h3>
10099
</div>
101100
</div>
102101
</div>
103-
104-
105-
106-
107102
{% endblock %}

django_ledger/templates/django_ledger/po_update.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ <h2 class="title">{{ po_model.po_number }}</h2>
3535
{{ form.po_date }}
3636
</div>
3737
</div>
38-
3938
<div class="field">
4039
<label for="{{ form.po_status.id_for_label }}" class="label">{{ form.po_status.label }}</label>
4140
<div class="control">
@@ -72,6 +71,8 @@ <h3 class="is-size-3 has-text-weight-light">{% trans 'Purchase Order Amount' %}:
7271
{% currency_symbol %}{{ po_model.po_amount | currency_format }}</h3>
7372
<h3 class="is-size-3 has-text-weight-light">{% trans 'Received Amount' %}:
7473
{% currency_symbol %}{{ po_model.po_amount_received | currency_format }}</h3>
74+
<h3 class="is-size-3 has-text-weight-light">{% trans 'Paid Amount' %}:
75+
{% currency_symbol %}{{ total_paid | currency_format }}</h3>
7576
</div>
7677
</div>
7778
</form>

0 commit comments

Comments
 (0)