InvenTree icon indicating copy to clipboard operation
InvenTree copied to clipboard

[FR] Loop a quantity in the reports

Open jpeg2600 opened this issue 10 months ago • 0 comments

Please verify that this feature request has NOT been suggested before.

  • [x] I checked and didn't find a similar feature request

Problem statement

I use Inventree to track devices and sometimes, I have to take notes for individual items as they are getting packaged.

I wish to create a new shipment report template with two sections: an upper section with the quantities per items and each individual item + blank lines.

For example:

Blue chair | Qty: 4

Blue chair | ___________ | ___________ Blue chair | ___________ | ___________ Blue chair | ___________ | ___________ Blue chair | ___________ | ___________

Any idea appreciated.

Suggested solution

Implement a helper report function/filter to easily loop a quantity or any number.

Describe alternatives you've considered

I tried looping allocation.quantity with a range function but it seems like I can't use direct python like that. I also can't find an array with individual items to loop.

Here's some non-working code in case that could be useful:

{% extends "report/inventree_order_report_base.html" %}

{% load i18n %}
{% load report %}
{% load barcode %}
{% load inventree_extras %}
{% load markdownify %}

{% block header_content %}

    <img class='logo' src='' alt="{{ order.customer }}" width='150'>

    <div class='header-right'>
        <h3>Livraison {{ prefix }}{{ reference }}</h3>
        Client: {{ order.customer.name }}<br/>
        <i>Bon de vente #{{ order.reference }}</i>
    </div>

{% endblock header_content %}

{% block page_content %}

<h3>Livraison</h3>

<table class='table table-striped table-condensed'>
    <thead>
        <tr>
            <th>Items</th>
            <th>Description</th>
            <th>Quantité</th>
        </tr>
    </thead>
    <tbody>
        {% for allocation in allocations.all %}
        <tr>
            <td>
                <div class='thumb-container'>
                    <img src='{% part_image allocation.line.part height=240 %}' alt='{% trans "Part image" %}' class='part-thumb'>
                </div>
                <div class='part-text'>
                    {{ allocation.line.part.name }}
                </div>
            </td>
            <td>
                  {{ allocation.line.part.description }}
            </td>

            {% if allocation.item and allocation.item.serial and allocation.quantity == 1 %}
                <td>{% trans "Serial Number" %}: {{ allocation.item.serial }}</td>
            {% elif allocation.item and allocation.item.batch %}
                <td>{% trans "Quantity" %}: {% decimal allocation.quantity %} - <i>{% trans "Batch" %}: {{ allocation.item.batch }}</i></td>
            {% else %}
                <td>{% decimal allocation.quantity %}</td>
            {% endif %}
        </tr>
        {% endfor %}
    </tbody>
</table>

<h3>Détails et localisation</h3>
<table class='table table-striped table-condensed'>
    <thead>
        <tr>
            <th>Items</th>
            <th>Identifiant</th>
            <th>Libellé</th>
        </tr>
    </thead>
    <tbody>

      {% for allocation in allocations.all %}
        {% for ## LOOP allocation.quantity times! ## %}
          <tr>
            <td>
              <div class='thumb-container'>
                <img src='{% part_image allocation.line.part height=240 %}' alt='{% trans "Part image" %}' class='part-thumb'>
              </div>
              <div class='part-text'>
                {{ allocation.line.part.name }}
              </div>
            </td>
            <td style="width: 2in">
              <div>&nbsp;</div>
            </td>
      
            <td></td>

          </tr>
          {% endfor %}

      {% endfor %}
    </tbody>
</table>

{% endblock page_content %}

Examples of other systems

No response

Do you want to develop this?

  • [ ] I want to develop this.

jpeg2600 avatar Mar 28 '25 16:03 jpeg2600