Odoo 将现有字段添加到报告中
Odoo add and existing field to a report
在 Odoo 中,addons/crm/report/crm_opportunity_report.py
中有一份报告 OpportunityReport
。我知道它需要来自 crm.lead
的字段。除了我需要的一个字段:name
也在 crm.lead
.
中
我将修改现有的 OpportunityReport
如下:
Index: odoo/addons/crm/report/crm_opportunity_report.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- odoo/addons/crm/report/crm_opportunity_report.py (date 1523367742000)
+++ odoo/addons/crm/report/crm_opportunity_report.py (date 1523367742000)
@@ -13,6 +13,7 @@
_description = "CRM Opportunity Analysis"
_rec_name = 'date_deadline'
+ name = fields.Char('Name', readonly=True)
date_deadline = fields.Date('Expected Closing', readonly=True)
create_date = fields.Datetime('Creation Date', readonly=True)
opening_date = fields.Datetime('Assignation Date', readonly=True)
@@ -54,6 +55,7 @@
CREATE VIEW crm_opportunity_report AS (
SELECT
c.id,
+ c.name,
c.date_deadline,
c.date_open as opening_date,
但是据我所知,我不应该破坏数据库中关于此报告的现有自定义设置。我如何更新该报告?我需要创建一个模块吗?
如何向此报告添加字段 name
?我会:首先创建一个继承此报告的自定义报告(带有一个新模块),然后使用该新报告,但在 Python 和 Odoo 中是新手不知道该怎么做。
我从哪里开始? :-)
您将需要继承视图 table 'crm.opportunity.report'
请创建一个新模块并在 depends 中添加 crm。
然后将此代码添加到您的 .py 文件中
from odoo import fields, models, tools
from ..models import crm_stage
class OpportunityReport(models.Model):
""" CRM Opportunity Analysis """
_inherit = "crm.opportunity.report"
name = fields.Char('Name', readonly=True)
def init(self):
tools.drop_view_if_exists(self._cr, 'crm_opportunity_report')
self._cr.execute("""
CREATE VIEW crm_opportunity_report AS (
SELECT
c.id,
c.date_deadline,
c.name as name,
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
FROM
"crm_lead" c
LEFT JOIN "crm_stage" stage
ON stage.id = c.stage_id
GROUP BY c.id, stage.name
)""")
如有疑问请告知
在 Odoo 中,addons/crm/report/crm_opportunity_report.py
中有一份报告 OpportunityReport
。我知道它需要来自 crm.lead
的字段。除了我需要的一个字段:name
也在 crm.lead
.
我将修改现有的 OpportunityReport
如下:
Index: odoo/addons/crm/report/crm_opportunity_report.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- odoo/addons/crm/report/crm_opportunity_report.py (date 1523367742000)
+++ odoo/addons/crm/report/crm_opportunity_report.py (date 1523367742000)
@@ -13,6 +13,7 @@
_description = "CRM Opportunity Analysis"
_rec_name = 'date_deadline'
+ name = fields.Char('Name', readonly=True)
date_deadline = fields.Date('Expected Closing', readonly=True)
create_date = fields.Datetime('Creation Date', readonly=True)
opening_date = fields.Datetime('Assignation Date', readonly=True)
@@ -54,6 +55,7 @@
CREATE VIEW crm_opportunity_report AS (
SELECT
c.id,
+ c.name,
c.date_deadline,
c.date_open as opening_date,
但是据我所知,我不应该破坏数据库中关于此报告的现有自定义设置。我如何更新该报告?我需要创建一个模块吗?
如何向此报告添加字段 name
?我会:首先创建一个继承此报告的自定义报告(带有一个新模块),然后使用该新报告,但在 Python 和 Odoo 中是新手不知道该怎么做。
我从哪里开始? :-)
您将需要继承视图 table 'crm.opportunity.report'
请创建一个新模块并在 depends 中添加 crm。
然后将此代码添加到您的 .py 文件中
from odoo import fields, models, tools
from ..models import crm_stage
class OpportunityReport(models.Model):
""" CRM Opportunity Analysis """
_inherit = "crm.opportunity.report"
name = fields.Char('Name', readonly=True)
def init(self):
tools.drop_view_if_exists(self._cr, 'crm_opportunity_report')
self._cr.execute("""
CREATE VIEW crm_opportunity_report AS (
SELECT
c.id,
c.date_deadline,
c.name as name,
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
FROM
"crm_lead" c
LEFT JOIN "crm_stage" stage
ON stage.id = c.stage_id
GROUP BY c.id, stage.name
)""")
如有疑问请告知