{% extends "base.html" %} {% from "components/ui.html" import page_header %} {% block content %} {% set breadcrumbs = [ {'text': 'Inventory', 'url': url_for('inventory.list_stock_items')}, {'text': 'Stock Movements'} ] %} {{ page_header( icon_class='fas fa-exchange-alt', title_text='Stock Movements', subtitle_text='View inventory movement history', breadcrumbs=breadcrumbs, actions_html='Record Movement' if (current_user.is_admin or has_permission('manage_stock_movements')) else None ) }}
{% for movement in movements %} {% else %} {% endfor %}
{{ _('Date') }} {{ _('Item') }} {{ _('Warehouse') }} {{ _('Type') }} {{ _('Quantity') }} {{ _('Unit Cost') }} {{ _('Reference') }} {{ _('Reason') }} {{ _('User') }}
{{ movement.moved_at|user_datetime if movement.moved_at else '—' }} {{ movement.stock_item.name }} ({{ movement.stock_item.sku }}) {{ movement.warehouse.code }} {% set ns = namespace(is_devalued=false) %} {% if movement.movement_type == 'devaluation' %} {% set ns.is_devalued = true %} {% elif movement.lot_allocations %} {% for alloc in movement.lot_allocations %} {% if alloc.stock_lot and alloc.stock_lot.lot_type == 'devalued' %} {% set ns.is_devalued = true %} {% endif %} {% endfor %} {% endif %}
{{ movement.movement_type }} {% if ns.is_devalued %} {{ _('Devalued') }} {% endif %}
{{ '+' if movement.quantity > 0 else '' }}{{ movement.quantity }} {% if movement.unit_cost is not none %} {{ movement.unit_cost }} {% elif movement.lot_allocations %} {% set ns_cost = namespace(total_qty=0, total_val=0) %} {% for alloc in movement.lot_allocations %} {% set q = alloc.quantity %} {% if q < 0 %} {% set q = -q %} {% endif %} {% set ns_cost.total_qty = ns_cost.total_qty + q %} {% set ns_cost.total_val = ns_cost.total_val + (q * alloc.unit_cost) %} {% endfor %} {% if ns_cost.total_qty > 0 %} {{ (ns_cost.total_val / ns_cost.total_qty) | round(2) }} {% else %} — {% endif %} {% else %} — {% endif %} {% if movement.reference_type and movement.reference_id %} {% if movement.reference_type == 'invoice' %} Invoice #{{ movement.reference_id }} {% elif movement.reference_type == 'quote' %} Quote #{{ movement.reference_id }} {% else %} {{ movement.reference_type }} #{{ movement.reference_id }} {% endif %} {% else %} — {% endif %} {{ movement.reason or '—' }} {{ movement.moved_by_user.username if movement.moved_by_user else '—' }}
{{ _('No stock movements found.') }}
{% endblock %}