Search code examples
printingreportodooinvoiceqweb

Strip string from a field with defined separator in invoice report


first of all - I'm still newbie in Odoo so this is maybe explained wrong but I will try.

In inherited invoice_report xml document i have conditional field that needs to be shown - if column (field) in db is equal to another column. To be more precise - if invoice_origin from account_move is equal to name in sale_order.

This is it's code:

<t t-foreach="request.env['sale.order'].search([('name', '=', o.invoice_origin)])" t-as="obj">

For example in database this invoice_origin is [{'invoice_origin': 'S00151-2022'}]

On invoices that are created from more than one sales orders it is this [{'invoice_origin': 'S00123-2022, S00066-2022'}]

How can I strip this data to use in foreach separately the part [{'invoice_origin': 'S00123-2022'}] and separately [{'invoice_origin': 'S00066-2022'}]

Thank you.


Solution

  • You can try to split up the invoice origin and use the result for your existing code:

    <t t-set="origin_list" t-value="o.invoice_origin and o.invoice_origin.split(', ') or []" />
    <t t-foreach="request.env['sale.order'].search([('name', 'in', origin_list)])" t-as="obj">
        <!-- do something -->
    </t>