Skip to content

Commit

Permalink
[IMP] crm, website_crm: replace support of activities
Browse files Browse the repository at this point in the history
crm.lead model now supports activities. Filters have been added to ease
their management. Mail activities replace the old crm.activity model. All code
related to crm.activity is then removed, including views and custom widget.
Standard activities feature is now used widely in Odoo addons and replace
those custom activities.

A small update is required in website_crm_partner_assign. Now the portal user
can only update or create its own activities aka assigned to him. If he has
an activity assigned to him it is displayed in the opportunity website view.
If not editing the opportunity will create a new activity assigned to him.
  • Loading branch information
Ravi Gadhia authored and tde-banana-odoo committed Dec 21, 2016
1 parent 4aa3f3f commit 87e4571
Show file tree
Hide file tree
Showing 26 changed files with 304 additions and 666 deletions.
5 changes: 1 addition & 4 deletions addons/crm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
'web_tour',
],
'data': [
'data/crm_activity_data.xml',
'data/crm_data.xml',
'data/crm_stage_data.xml',
'data/sales_config_settings_data.xml',
Expand All @@ -53,7 +52,6 @@
'security/ir.model.access.csv',

'wizard/base_partner_merge_views.xml',
'wizard/crm_activity_log_views.xml',
'wizard/crm_lead_lost_views.xml',
'wizard/crm_lead_to_opportunity_views.xml',
'wizard/crm_merge_opportunities_views.xml',
Expand All @@ -64,7 +62,6 @@

'views/crm_templates.xml',
'views/crm_views.xml',
'views/crm_activity_views.xml',
'views/crm_stage_views.xml',
'views/crm_lead_views.xml',
'views/calendar_views.xml',
Expand All @@ -74,8 +71,8 @@
],
'demo': [
'data/crm_demo.xml',
'data/mail_activity_demo.xml',
'data/crm_lead_demo.xml',
'data/crm_activity_demo.xml',
'data/base_action_rule_demo.xml',
],
'css': ['static/src/css/crm.css'],
Expand Down
16 changes: 0 additions & 16 deletions addons/crm/data/crm_activity_data.xml

This file was deleted.

37 changes: 0 additions & 37 deletions addons/crm/data/crm_activity_demo.xml

This file was deleted.

132 changes: 95 additions & 37 deletions addons/crm/data/crm_lead_demo.xml

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions addons/crm/data/mail_activity_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<odoo>
<record id="mail_activity_demo_followup_quote" model="mail.activity.type">
<field name="name">Follow-up Quote</field>
<field name="icon">fa-file-text-o</field>
<field name="res_model_id" ref="crm.model_crm_lead"/>
<field name="summary">Follow-up quote</field>
<field name="days">30</field>
</record>
<record id="mail_activity_demo_make_quote" model="mail.activity.type">
<field name="name">Make Quote</field>
<field name="icon">fa-file-text-o</field>
<field name="res_model_id" ref="crm.model_crm_lead"/>
<field name="summary">Send a quotation</field>
<field name="days">15</field>
</record>
<record id="mail_activity_demo_call_demo" model="mail.activity.type">
<field name="name">Call for Demo</field>
<field name="icon">fa-phone</field>
<field name="res_model_id" ref="crm.model_crm_lead"/>
<field name="days">10</field>
<field name="summary">Call for a demo</field>
</record>
</odoo>
1 change: 0 additions & 1 deletion addons/crm/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import res_users
import calendar
import crm_activity
import crm_lead
import crm_stage
import crm_team
Expand Down
50 changes: 0 additions & 50 deletions addons/crm/models/crm_activity.py

This file was deleted.

57 changes: 19 additions & 38 deletions addons/crm/models/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@


class Lead(FormatAddress, models.Model):

_name = "crm.lead"
_description = "Lead/Opportunity"
_order = "priority desc,date_action,id desc"
_inherit = ['mail.thread', 'utm.mixin']
_order = "priority desc,activity_date_deadline,id desc"
_inherit = ['mail.thread', 'mail.activity.mixin', 'utm.mixin']
_mail_mass_mailing = _('Leads / Opportunities')

def _default_probability(self):
Expand Down Expand Up @@ -116,12 +115,6 @@ def _default_stage_id(self):
probability = fields.Float('Probability', group_operator="avg", default=lambda self: self._default_probability())
planned_revenue = fields.Float('Expected Revenue', track_visibility='always')
date_deadline = fields.Date('Expected Closing', help="Estimate of the date on which the opportunity will be won.")

# CRM Actions
next_activity_id = fields.Many2one("crm.activity", string="Next Activity", index=True)
date_action = fields.Date('Next Activity Date', index=True)
title_action = fields.Char('Next Activity Summary')

color = fields.Integer('Color Index', default=0)
partner_address_name = fields.Char('Partner Contact Name', related='partner_id.name', readonly=True)
partner_address_email = fields.Char('Partner Contact Email', related='partner_id.email', readonly=True)
Expand Down Expand Up @@ -170,8 +163,8 @@ def _compute_kanban_state(self):
today = date.today()
for lead in self:
kanban_state = 'grey'
if lead.date_action:
lead_date = fields.Date.from_string(lead.date_action)
if lead.activity_date_deadline:
lead_date = fields.Date.from_string(lead.activity_date_deadline)
if lead_date >= today:
kanban_state = 'green'
else:
Expand Down Expand Up @@ -270,18 +263,6 @@ def _onchange_state(self):
if self.state_id:
self.country_id = self.state_id.country_id.id

@api.onchange('next_activity_id')
def _onchange_next_activity_id(self):
values = {
'title_action': False,
'date_action': False,
}
if self.next_activity_id:
values['title_action'] = self.next_activity_id.description
if self.next_activity_id.days:
values['date_action'] = fields.Datetime.to_string(datetime.now() + timedelta(days=self.next_activity_id.days))
self.update(values)

# ----------------------------------------
# ORM override (CRUD, fields_view_get, ...)
# ----------------------------------------
Expand Down Expand Up @@ -934,13 +915,13 @@ def retrieve_sales_dashboard(self):
if date_deadline < date.today():
result['closing']['overdue'] += 1
# Next activities
if opp.next_activity_id and opp.date_action:
date_action = fields.Date.from_string(opp.date_action)
if date_action == date.today():
for activity in opp.activity_ids:
date_deadline = fields.Date.from_string(activity.date_deadline)
if date_deadline == date.today():
result['activity']['today'] += 1
if date.today() <= date_action <= date.today() + timedelta(days=7):
if date.today() <= date_deadline <= date.today() + timedelta(days=7):
result['activity']['next_7_days'] += 1
if date_action < date.today():
if date_deadline < date.today():
result['activity']['overdue'] += 1
# Won in Opportunities
if opp.date_closed:
Expand All @@ -957,19 +938,19 @@ def retrieve_sales_dashboard(self):
# crm.activity is a very messy model so we need to do that in order to retrieve the actions done.
self._cr.execute("""
SELECT
m.id,
m.subtype_id,
m.date,
l.user_id,
l.type
FROM mail_message M
LEFT JOIN crm_lead L ON (M.res_id = L.id)
INNER JOIN crm_activity A ON (M.subtype_id = A.subtype_id)
mail_message.id,
mail_message.subtype_id,
mail_message.mail_activity_type_id,
mail_message.date,
crm_lead.user_id,
crm_lead.type
FROM mail_message
LEFT JOIN crm_lead ON (mail_message.res_id = crm_lead.id)
INNER JOIN mail_activity_type activity_type ON (mail_message.mail_activity_type_id = activity_type.id)
WHERE
(M.model = 'crm.lead') AND (L.user_id = %s) AND (L.type = 'opportunity')
(mail_message.model = 'crm.lead') AND (crm_lead.user_id = %s) AND (crm_lead.type = 'opportunity')
""", (self._uid,))
activites_done = self._cr.dictfetchall()

for activity in activites_done:
if activity['date']:
date_act = fields.Date.from_string(activity['date'])
Expand Down
6 changes: 4 additions & 2 deletions addons/crm/report/crm_activity_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class ActivityReport(models.Model):
team_id = fields.Many2one('crm.team', 'Sales Team', readonly=True)
lead_id = fields.Many2one('crm.lead', "Lead", readonly=True)
subject = fields.Char('Summary', readonly=True)
subtype_id = fields.Many2one('mail.message.subtype', 'Activity', readonly=True)
subtype_id = fields.Many2one('mail.message.subtype', 'Subtype', readonly=True)
mail_activity_type_id = fields.Many2one('mail.activity.type', 'Activity Type', readonly=True)
country_id = fields.Many2one('res.country', 'Country', readonly=True)
company_id = fields.Many2one('res.company', 'Company', readonly=True)
stage_id = fields.Many2one('crm.stage', 'Stage', readonly=True)
Expand All @@ -37,6 +38,7 @@ def init(self):
select
m.id,
m.subtype_id,
m.mail_activity_type_id,
m.author_id,
m.date,
m.subject,
Expand All @@ -57,5 +59,5 @@ def init(self):
on
(m.res_id = l.id)
WHERE
(m.model = 'crm.lead')
(m.model = 'crm.lead' AND m.mail_activity_type_id IS NOT NULL)
)""")
8 changes: 4 additions & 4 deletions addons/crm/report/crm_activity_report_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<field name="model">crm.activity.report</field>
<field name="arch" type="xml">
<graph string="Activities Analysis" stacked="True">
<field name="subtype_id" type="col"/>
<field name="mail_activity_type_id" type="col"/>
<field name="date" interval="month" type="row"/>
</graph>
</field>
Expand All @@ -17,7 +17,7 @@
<field name="model">crm.activity.report</field>
<field name="arch" type="xml">
<pivot string="Activities Analysis" disable_linking="True">
<field name="subtype_id" type="col"/>
<field name="mail_activity_type_id" type="col"/>
<field name="date" interval="month" type="row"/>
</pivot>
</field>
Expand All @@ -28,7 +28,7 @@
<field name="model">crm.activity.report</field>
<field name="arch" type="xml">
<search string="Activities Analysis">
<filter string="My Activities" name="my_activity" domain="[('user_id', '=', uid)]"/>
<filter string="My Activities" name="activities_my" domain="[('user_id', '=', uid)]"/>
<separator/>
<filter name="lead" string="Leads" domain="[('lead_type','=', 'lead')]" help="Show only lead"/>
<filter name="opportunity" string="Opportunities" domain="[('lead_type','=','opportunity')]" help="Show only opportunity"/>
Expand Down Expand Up @@ -58,7 +58,7 @@
<field name="res_model">crm.activity.report</field>
<field name="view_type">form</field>
<field name="view_mode">pivot,graph</field>
<field name="context">{'search_default_my_activity': True}</field>
<field name="context">{'search_default_activities_my': True}</field>
<field name="domain">[]</field>
</record>

Expand Down
3 changes: 0 additions & 3 deletions addons/crm/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ access_crm_lead_tag_manager,crm_lead_tag manager,model_crm_lead_tag,sales_team.g
access_crm_lost_reason_manager,crm.lost.reason.manager,model_crm_lost_reason,sales_team.group_sale_manager,1,1,1,1
access_crm_lost_reason_salesman,crm.lost.reason.salesman,model_crm_lost_reason,sales_team.group_sale_salesman,1,0,0,0
access_crm_lost_reason_user,crm.lost.reason.user,model_crm_lost_reason,base.group_user,1,0,0,0
access_crm_activity_user,crm.activity.user,model_crm_activity,base.group_user,1,1,1,0
access_crm_activity_manager,crm.activity.manager,model_crm_activity,sales_team.group_sale_manager,1,1,1,1
access_crm_activity_salesman,crm.activity.salesman,model_crm_activity,sales_team.group_sale_salesman,1,1,1,0
access_crm_activity_report_user,crm.activity.report.user,model_crm_activity_report,base.group_user,1,0,0,0
access_calendar_event_manager,calendar.event.manager,calendar.model_calendar_event,sales_team.group_sale_manager,1,1,1,1
access_calendar_event,calendar.event,calendar.model_calendar_event,sales_team.group_sale_salesman,1,1,1,0
Expand Down
16 changes: 10 additions & 6 deletions addons/crm/static/src/js/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@ tour.register('crm_tour', {
position: "right",
run: "drag_and_drop .o_opportunity_kanban .o_kanban_group:eq(2) ",
}, {
trigger: ".o_kanban_record:not(.o_updating) .oe_kanban_status_grey",
trigger: ".o_kanban_record:not(.o_updating) .o_activity_color_default",
extra_trigger: ".o_opportunity_kanban",
content: _t("This opportunity has <b>no next activity scheduled</b>. <i>Click to set one.</i>"),
content: _t("This opportunity has <b>no activity planned</b>. <i>Click to check them.</i>"),
position: "bottom"
}, {
trigger: ".o_recommended_activity .o_radio_item",
trigger: ".o_schedule_activity",
extra_trigger: ".o_opportunity_kanban",
content: _t("Schedule an activity by clicking here"),
position: "bottom"
}, {
trigger: ".modal-body .o_form_field_many2one",
extra_trigger: ".o_opportunity_kanban",
content: _t("<p>You will be able to customize your followup activities. Examples:</p><ol><li>introductory email</li><li>call 10 days after</li><li>second call 3 days after, ...</li></ol><p class='mb0'><i>Select a standard activity for now on.</i></p>"),
position: "left",
position: "bottom",
run: function (actions) {
actions.auto(this.$anchor.children("input").first());
actions.auto(".modal-footer .btn-primary");
actions.auto(".modal-footer .btn-default");
},
}, {
trigger: ".o_kanban_record",
Expand Down
Loading

0 comments on commit 87e4571

Please sign in to comment.