I have the following code by the kind courtesy of @Jeel
{% set grouped_items = {} %}
{% for item in doc.items %}
{% set key = item.color + ‘-’ + item.size + ‘-’ + item.item_code %}
{% if key not in grouped_items %}
{% set grouped_items = grouped_items | merge({ key: {‘qty’: 0, ‘amount’: 0} }) %}
{% endif %}
{% set grouped_items = grouped_items | merge({ key: { ‘qty’: grouped_items[key].qty + item.qty, ‘amount’: grouped_items[key].amount + item.amount } }) %}
{% endfor %}
{% for key, values in grouped_items.items() %} {% set parts = key.split(‘-’) %} {% endfor %}
Item Code Color Size Quantity Amount
{{ parts[2] }} {{ parts[0] }} {{ parts[1] }} {{ values.qty }} {{ values.amount }}
This has the error while saving the code in a custom Print Format:
Syntax error in template as line 8: No filter named ‘merge’.
What correction should be made?
I want to achieve the following of my above screenshot in the original question when grouped by the code:
Item A, GREEN color, M size, 200 qty, Amount 2000
Item A, RED color, M size, 150 qty, Amount 4500
Item A GREEN color, L size, 50 qty, Amount 1000
Item B, GREEN color, M size, 500 qty, Amount 5000
If there were no colors but only size in the above example:
Item A, M size, 350 qty, Amount 3500 (Example=@BDT 10, ignoring color wise rates)
Item A, L size, 50 qty, Amount 1000
Item B, M size, 500 qty, Amount 5000
If there were no size but only colors:
Item A, GREEN color, 250 qty, Amount 2500 (Example: @BDT 10, ignoring size wise rate))
Item A, RED color, 150 qty, Amount 4500
Item B, GREEN color, 500 qty, Amount 5000
Sometimes there might only be color or size and other times both like this example.
Thanks.