Skip to Content
Menu
This question has been flagged

The Default Batch payment report appears to sort itself based on the Payment Journal ID Number, How do I change this so it sorts by Customer / Vendor A-Z?

I assume the 3rd line    <t t-foreach="docs" t-as="o"> needs a 'sorted' command but I have no idea on the python / Odoo code.

Any help & guidance is most appreciated!


t-name="account_batch_payment.print_batch_payment">

    <t t-call="web.basic_layout">

        <t t-foreach="docs" t-as="o">

            <div class="page page_batch_payment">

                <div class="oe_structure"/>

                <div class="row batch_details">

                    <div class="col-6"><span t-out="o.journal_id.company_id.name">Odoo Payments LLC</span></div>

                    <div class="col-6 text-end"><span t-out="o.journal_id.name">Bank Transfer</span> : <span t-out="o.name">Monthly Payment</span></div>

                </div>

                <div class="oe_structure"/>

                <div class="row batch_details">

                    <div class="col-6"><span t-out="o.date">2023-08-14</span></div>

                </div>

                <div class="oe_structure"/>

                <div class="row batch_details">

                    <div t-if="o.journal_id.bank_acc_number" class="col-6" style="font-size:18px;">Issuing bank account : <span t-out="o.journal_id.bank_acc_number">3956012345678</span></div>

                </div>

                <div class="oe_structure"/>

                <table class="table table-bordered table-sm">

                    <thead>

                        <tr>

                            <th class="text-start">Customer</th>

                            <th class="text-start">Date</th>

                            <th class="text-start">Memo</th>

                            <th class="text-start">Recipient Bank Account</th>

                            <th class="text-end">Amount</th>

                        </tr>

                    </thead>

                    <tr t-foreach="o.payment_ids" t-as="payment">

                        <td class="text-start"><span t-out="payment.partner_id.name">ABC Suppliers</span></td>

                        <td class="text-start"><span t-out="payment.date" t-options="{&quot;widget&quot;: &quot;date&quot;}">2023-08-15</span></td>

                        <td class="text-start"><span t-out="payment.ref">Demo Ref</span></td>

                        <td class="text-start"><span t-out="payment.partner_bank_id.acc_number">3956012345678</span></td>

                        <td class="text-end"><span t-out="payment.amount" t-options="{'widget': 'monetary', 'display_currency': payment.currency_id}">$1000.0</span></td>

                    </tr>

                    <tr>

                        <td style="font-weight: bold;">TOTAL</td>

                        <td/>

                        <td/>

                        <td/>

                        <td class="text-end" style="font-weight: bold;"><span t-out="o.amount" t-options="{'widget': 'monetary', 'display_currency': o.currency_id}">$1000.0</span></td>

                    </tr>

                </table>

                <div class="oe_structure"/>

            </div>

        </t>

    </t>

Avatar
Discard
Best Answer

Hi,


You're absolutely right — the default account_batch_payment report in Odoo does not sort payments by partner name; it simply displays them in the order they're linked to the batch (usually by payment ID, hence indirectly sorted by journal ID).


To sort the payments alphabetically by Customer/Vendor name, you can apply a sorted() call in the template.


Try with the following code.


<tr t-foreach="sorted(o.payment_ids, key=lambda p: p.partner_id.name)" t-as="payment">

    <td class="text-start"><span t-out="payment.partner_id.name"/></td>

    <td class="text-start"><span t-out="payment.date" t-options="{ 'widget': 'date' }"/></td>

    <td class="text-start"><span t-out="payment.ref"/></td>

    <td class="text-start"><span t-out="payment.partner_bank_id.acc_number"/></td>

    <td class="text-end">

        <span t-out="payment.amount" t-options="{ 'widget': 'monetary', 'display_currency': payment.currency_id }"/>

    </td>

</tr>



This will alphabetically sort the payments shown in each batch by partner name (Customer/Vendor).


- If any payment.partner_id.name is empty or null, it will appear first in the sorted list.


-Ensure the report uses t-call="web.basic_layout" or similar to get full Python environment access, which supports sorted() in QWeb.



Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
2
Jun 25
892
2
Mar 25
895
0
Mar 25
961
0
Mar 25
805
1
Mar 25
875