在Sales -> Reports -> Pipeline
中,我想允许按res.partner.category过滤。
在Odoo中res.partner
有一个字段category_id
category_id = fields.Many2many('res.partner.category', column1='partner_id',
column2='category_id', string='Tags', default=_default_category)
我试过复制
category_id = fields.Many2many('res.partner.category', column1='partner_id',
column2='category_id', string='Tags', default=_default_category)` to my crm_opportunity_report (that has inherited crm.opportunity.report) but I get errors.
尝试添加字段
category_ids = fields.Many2many(comodel_name='res.partner.category', relation="res_partner_res_partner_category_rel",
column1='category_id', column2='partner_id')
这也失败了。
如何将类别名称添加为crm_opportunity_report的过滤器?可以采取哪些措施来按类别进行过滤?
答案 0 :(得分:1)
这里有点解决方案(基于讨论:见问题评论)。它会从标记名称中生成一个字符串("'标记名1';'标记名2&#39 ;;'标记名3&#39 ;; ...")以进行过滤
SELECT
c.id,
c.name as name,
c.date_deadline,
c.date_open as opening_date,
c.date_closed as date_closed,
c.date_last_stage_update as date_last_stage_update,
c.user_id,
c.probability,
c.stage_id,
stage.name as stage_name,
c.type,
c.company_id,
c.priority,
c.team_id,
(SELECT COUNT(*)
FROM mail_message m
WHERE m.model = 'crm.lead' and m.res_id = c.id) as nbr_activities,
c.active,
c.campaign_id,
c.source_id,
c.medium_id,
c.partner_id,
c.city,
c.country_id,
c.planned_revenue as total_revenue,
c.planned_revenue*(c.probability/100) as expected_revenue,
c.create_date as create_date,
extract('epoch' from (c.date_closed-c.create_date))/(3600*24) as delay_close,
abs(extract('epoch' from (c.date_deadline - c.date_closed))/(3600*24)) as delay_expected,
extract('epoch' from (c.date_open-c.create_date))/(3600*24) as delay_open,
c.lost_reason,
c.date_conversion as date_conversion,
COALESCE(rp.customer, FALSE) as is_customer,
COALESCE(x.Categories, '') AS Categories
FROM
"crm_lead" c
LEFT JOIN "res_partner" rp ON rp.id = c.partner_id
LEFT JOIN "crm_stage" stage ON stage.id = c.stage_id
LEFT JOIN
(
SELECT rp.id AS partner_id, array_to_string(array_agg(''''||rpc.name||'''' ORDER BY rp.id, rpc.name),';') AS Categories
FROM res_partner_res_partner_category_rel rpcl
JOIN res_partner_category rpc ON rpc.id = rpcl.category_id
JOIN res_partner rp ON rp.id = rpcl.partner_id
GROUP BY rp.id
ORDER BY rp.id
) AS x ON x.partner_id = c.partner_id
GROUP BY c.id, stage.name, COALESCE(rp.customer, FALSE), COALESCE(x.Categories, '')
ORDER BY c.partner_id