Odoo中crm_opportunity_report字段显示Undefined而非False的问题
is_customer in CRM Opportunity Report Let's break down why you're seeing "Undefined" instead of False for your new is_customer field, and how to fix it quickly.
Root Cause
Your report uses a LEFT JOIN between crm_lead and res_partner. When a lead doesn't have an associated partner (i.e., c.partner_id is NULL), all fields from the res_partner table (including rp.customer) will return NULL in the SQL view.
Odoo's Boolean fields expect explicit True/False values—NULL isn't recognized as a valid boolean state, so it renders as "Undefined" in the report.
Solution: Use COALESCE to Handle NULL Values
Modify your SQL view definition to replace NULL values from rp.customer with FALSE using the COALESCE function. This ensures every row gets a valid boolean value:
CREATE VIEW crm_opportunity_report AS ( SELECT -- [your existing selected fields] COALESCE(rp.customer, FALSE) as is_customer -- Replace rp.customer with this line FROM "crm_lead" c LEFT JOIN "res_partner" rp ON rp.id = c.partner_id -- [your existing JOINs, WHERE, GROUP BY clauses] GROUP BY c.id, stage.name, is_customer -- Ensure is_customer is still in GROUP BY );
What COALESCE Does
COALESCE(a, b) returns the first non-null value from the arguments. So if rp.customer is NULL (no partner linked), it will return FALSE instead—exactly what you expect for leads without a customer partner.
Additional Checks
- Verify Field Definition: Your
is_customer = fields.Boolean('Is customer', readonly=True)is correct—readonly makes sense here since it's a computed report field. - Clear Odoo Cache: After updating the SQL view, restart your Odoo server and clear the model cache (you can do this by updating the module or using the "Clear Cache" option in the developer tools) to ensure Odoo picks up the updated view structure.
This should resolve the "Undefined" issue and show False for leads without an associated customer partner, and the correct True/False for leads that do have one.
内容的提问来源于stack exchange,提问作者Developer Marius Žilėnas

