Skip to content

Instantly share code, notes, and snippets.

@almet
Last active April 20, 2022 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almet/ae6b7d63d890177ab952331b10f8c007 to your computer and use it in GitHub Desktop.
Save almet/ae6b7d63d890177ab952331b10f8c007 to your computer and use it in GitHub Desktop.
Sums for delivery in Odoo (Action)
<?xml version="1.0"?>
<t t-name="stock.report_deliverylist">
<t t-call="web.basic_layout">
<div class="page o_report_layout_boxed">
<t t-set="totals" t-value="{}"></t>
<t t-foreach="docs" t-as="o" t-if="o.state!='done'">
<t t-set="lines" t-value="o.move_lines.filtered(lambda x: x.product_uom_qty)"/>
<t t-foreach="lines" t-as="move">
<t t-if="not(move.product_id.packaging_ids)">
<t t-set="dummy" t-value="totals.setdefault(move.product_id.id, {})"></t>
<t t-set="qty" t-value="totals[move.product_id.id].get('qty', 0)"></t>
<t t-set="qty" t-value="qty + move.product_qty"></t>
<t t-set="dummy" t-value="totals[move.product_id.id].update(qty=qty)"></t>
<t t-set="dummy" t-value="totals[move.product_id.id].update(product=move.product_id)"></t>
<t t-set="dummy" t-value="totals[move.product_id.id].update(uom=move.product_uom)"></t>
<t t-set="dummy" t-value="totals[move.product_id.id].update(pack=qty)"></t>
</t>
<t t-foreach="move.product_id.packaging_ids" t-as="packaging">
<t t-set="dummy" t-value="totals.setdefault(move.product_id.id, {})"></t>
<t t-set="qty" t-value="totals[move.product_id.id].get('qty', 0)"></t>
<t t-set="qty" t-value="qty + move.product_qty"></t>
<t t-set="dummy" t-value="totals[move.product_id.id].update(qty=qty)"></t>
<t t-set="dummy" t-value="totals[move.product_id.id].update(product=move.product_id)"></t>
<t t-set="dummy" t-value="totals[move.product_id.id].update(uom=move.product_uom)"></t>
<t t-set="pack" t-value="qty // packaging.qty"></t>
<t t-set="dummy" t-value="totals[move.product_id.id].update(pack=pack)"></t>
</t>
</t>
</t>
<h4>Totaux</h4>
<h5>75cl</h5>
<ul>
<li t-foreach="totals" t-as="i" t-if="totals[i]['product'].default_code and totals[i]['product'].default_code.endswith('75')">
<span t-raw="int(totals[i]['pack'])"/> × <span t-raw="totals[i]['product'].default_code"/>
</li>
</ul>
<h5>33cl</h5>
<ul>
<li t-foreach="totals" t-as="i" t-if="totals[i]['product'].default_code and totals[i]['product'].default_code.endswith(('33', '44'))">
<span t-raw="int(totals[i]['pack'])"/> × <span t-raw="totals[i]['product'].default_code"/>
</li>
</ul>
<h5>Fûts</h5>
<ul>
<li t-foreach="totals" t-as="i" t-if="totals[i]['product'].default_code and totals[i]['product'].default_code.endswith(('20', '30'))">
<span t-raw="int(totals[i]['pack'])"/> × <span t-raw="totals[i]['product'].default_code"/>
</li>
</ul>
<h5>Autres</h5>
<ul>
<li t-foreach="totals" t-as="i" t-if="not totals[i]['product'].default_code">
<span t-raw="int(totals[i]['pack'])"/> × <span t-raw="totals[i]['product'].name"/>
</li>
</ul>
Total : ~<span t-raw="int(sum([totals[i]['pack'] for i in totals]))" /> cartons.
</div>
</t>
</t>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment