0

I'm trying to generate an invoice on pdf, part of the scope is to add some additional fields on the report, which I can edit the qweb xml and add things.

The problem I'm facing now, I'm trying to do some conditional testing, and based on the test, the report(pdf) should decide to insert the field or not.

<div t-if="o.move_type == 'out_invoice' and o.state == 'draft'">
Company ID:<b> <span t-field="o.company_id"/> </b>
Salespersone ID:<b> <span t-field="o.invoice_user_id"/> </b>
<br></br>
</div> 
                  

The above code generates correctly. but the below code does not generate anything.

<div t-if="o.move_type == 'out_invoice' and o.invoice_user_id == 'Steven'">
Company ID:<b> <span t-field="o.company_id"/> </b>
Sales ID:<b> <span t-field="o.invoice_user_id"/> </b>
<br></br>
</div> 

Somehow, it seems the o.invoice_user_id == 'Steven' is never evaluated. The code above does not produce any error, but there is no output given the conditional logic.

I have tried:

Double Quote, spacing, without single quote - no result

Please Help...

1

invoice_user_id is a Many2one field and the o.invoice_user_id == 'Steven' expression will never be evaluated to True because o.invoice_user_id is a recordset (res.users(id,)).

You should see a warning similar to the following in the log:

WARNING demo14 odoo.models: Comparing apples and oranges: res.users(2,) == 'Steven' (None:2)

To check the user name, try the following:

o.invoice_user_id.name == 'Steven'

Not the answer you're looking for? Browse other questions tagged or ask your own question.