3
votes

I have modified crm_opportunity_report :

  • added a boolean field is_customer = fields.Boolean('Is customer', readonly=True)

  • added a field to the view

    CREATE VIEW crm_opportunity_report AS (
        SELECT
            <...>omitted<...>
            rp.customer as is_customer
        FROM
            "crm_lead" c                        
            LEFT JOIN "res_partner" rp ON rp.id = c.partner_id
            <...>omitted<...>                
        GROUP BY c.id, stage.name, is_customer
    

After this in the report when I click "+" and choose "Is customer" sometimes value Undefined appears as a value for it.

Tried this: COALESCE(rp.customer, FALSE) as is_customer (and the same in Group by) but "Undefined" is still present.

How in Odoo report I can make Undefined mean False so that when it's "Undefined" appears "False"?

Note: when debugging with Firefox I can observe that from the server comes (jsonrpc) data with either "is_customer: false" or "is_customer: true" on items of report. But somehow those items that have "is_customer: false" on the report view are displayed as if "is_customer: Undefined".

Update

Somewhat accidentally I stumbled upon this line

if (value === false) return _t("Undefined");

What might be the reason behind this logic: 'if value is false return "Undefined"'?

Funny part, I can add if (value === true) return _t("Whatever"); :)

1
Is it possible that some leads in your report do not have a partner_id and are this undefined instead of False?travisw
@travisw That is right, some leads have no partner_id and so they cannot have is customer (set to true) because "customer(boolean)" field comes from res_partner. Anyway those should have False either because of COALESCE(rp.customer, FALSE) . And they have... But in report false values appear as "Undefined" .Developer Marius Žilėnas
Can you instead use COALESCE(rp.customer, 'f')? As you found, Odoo will translate False to "Undefined", but it ought to translate 'f' to "False" since that's how it stores in the database.travisw
@travisw Thank You:). I tried and the result was the same. 'f' and FALSE in Postgresql are both valid literal values for the "false" state same postgresql.org/docs/9.1/static/datatype-boolean.html :/ . I also tried to change field's is_customer datatype to fields.Char and it didn't give (with 'f') "False" in Odoo either. This is Odoo 10. Are you referring to Odoo 10 :)?Developer Marius Žilėnas
@travisw Thank you :).Developer Marius Žilėnas

1 Answers

2
votes

It’s not ideal, but you could create a kind of computed copy/dummy field on res.partner that stores a Char version of the Boolean field.

Take this for example where the compute method just checks if the field is True and stores as 't' or 'f' depending on that.

is_customer_string = fields.Char('Is a Customer? (text)', compute='_compute_is_customer_string', store=True)

@api.multi
@api.depends('is_customer')
def _compute_is_customer_string(self):
    for partner in self:
        partner.is_customer_string = 't' if partner.is_customer else 'f'

Documentation on computed fields

Note: store=True is probably optional, but if you store the field, then you must use some depends field as a trigger to recompute. If you don't store the computed field, then the depends should be left off.