From 87e457158e83295a17761a1ea0d251ba87472596 Mon Sep 17 00:00:00 2001
From: Ravi Gadhia
You will be able to customize your followup activities. Examples:
Select a standard activity for now on.
"), - 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", diff --git a/addons/crm/tests/test_crm_activity.py b/addons/crm/tests/test_crm_activity.py index 01747143ace..b18840e75f7 100644 --- a/addons/crm/tests/test_crm_activity.py +++ b/addons/crm/tests/test_crm_activity.py @@ -3,52 +3,47 @@ from .common import TestCrmCases from odoo import fields -from datetime import date +from datetime import datetime, timedelta -class TestCrmActivity(TestCrmCases): +class TestCrmMailActivity(TestCrmCases): def setUp(self): - super(TestCrmActivity, self).setUp() + super(TestCrmMailActivity, self).setUp() # Set up activities - Activity = self.env['crm.activity'] - self.activity3 = Activity.create({ + lead_model_id = self.env['ir.model'].search([('model', '=', 'crm.lead')]).id + ActivityType = self.env['mail.activity.type'] + self.activity3 = ActivityType.create({ 'name': 'Celebrate the sale', 'days': 3, - 'description': 'ACT 3 : Beers for everyone because I am a good salesman !', - 'internal': True, - 'res_model': 'crm.lead', + 'summary': 'ACT 3 : Beers for everyone because I am a good salesman !', + 'res_model_id': lead_model_id, }) - self.activity2 = Activity.create({ + self.activity2 = ActivityType.create({ 'name': 'Call for Demo', 'days': 6, - 'description': 'ACT 2 : I want to show you my ERP !', - 'internal': True, - 'res_model': 'crm.lead', - 'recommended_activity_ids': [(6, 0, [self.activity3.id])], + 'summary': 'ACT 2 : I want to show you my ERP !', + 'res_model_id': lead_model_id, }) - self.activity1 = Activity.create({ + self.activity1 = ActivityType.create({ 'name': 'Initial Contact', 'days': 5, - 'description': 'ACT 1 : Presentation, barbecue, ... ', - 'internal': True, - 'res_model': 'crm.lead', - 'recommended_activity_ids': [(6, 0, [self.activity2.id])], + 'summary': 'ACT 1 : Presentation, barbecue, ... ', + 'res_model_id': lead_model_id, }) # I create an opportunity, as salesman self.partner_client = self.env.ref("base.res_partner_1") - Lead = self.env['crm.lead'].sudo(self.crm_salesman.id) - self.lead = Lead.create({ + self.lead = self.env['crm.lead'].sudo(self.crm_salesman.id).create({ + 'name': 'Test Opp', 'type': 'opportunity', - 'name': 'Test Opportunity Activity Log', 'partner_id': self.partner_client.id, 'team_id': self.env.ref("sales_team.team_sales_department").id, 'user_id': self.crm_salesman.id, }) def test_crm_activity_recipients(self): - """ This test case check : + """ This test case checks - no internal subtype followed by client - activity subtype are not default ones - only activity followers are recipients when this kind of activity is logged @@ -60,73 +55,60 @@ class TestCrmActivity(TestCrmCases): self.lead.message_subscribe([self.partner_client.id]) # Check the client is not follower of any internal subtype - is_internal_subtype_for_client = self.lead.message_follower_ids.filtered(lambda fol: fol.partner_id.id == self.partner_client.id).mapped('subtype_ids.internal') - self.assertFalse(any(is_internal_subtype_for_client), 'Partner client is following an internal subtype') + internal_subtypes = self.lead.message_follower_ids.filtered(lambda fol: fol.partner_id == self.partner_client).mapped('subtype_ids').filtered(lambda subtype: subtype.internal) + self.assertFalse(internal_subtypes) # Add sale manager as follower of default subtypes self.lead.message_subscribe([self.crm_salemanager.partner_id.id]) - # Make the sale manager follower of the activity subtype - manager_follower = self.env['mail.followers'].sudo().search([('res_model', '=', 'crm.lead'), ('res_id', '=', self.lead.id), ('partner_id', '=', self.crm_salemanager.partner_id.id)]) - manager_follower.write({ - 'subtype_ids': [(4, activity.subtype_id.id)] - }) - # Instanciate wizard, trigger onchange lead and set the next activity - ActivityLogWizard = self.env['crm.activity.log'].sudo(self.crm_salesman.id) - wizard = ActivityLogWizard.create({ + activity = self.env['mail.activity'].sudo(self.crm_salesman.id).create({ + 'activity_type_id': self.activity1.id, 'note': 'Content of the activity to log', - 'lead_id': self.lead.id, + 'res_id': self.lead.id, + 'res_model_id': self.env.ref('crm.model_crm_lead').id, }) - wizard.onchange_lead_id() - wizard.write({ - 'next_activity_id': activity.id, - }) - wizard.action_log() + activity._onchange_activity_type_id() + self.assertEqual(self.lead.activity_type_id, self.activity1) + self.assertEqual(self.lead.activity_summary, self.activity1.summary) + # self.assertEqual(self.lead.activity_date_deadline, self.activity1.summary) - # Check message recipients + # mark as done, check lead and posted message + activity.action_done() + self.assertFalse(self.lead.activity_type_id.id) + self.assertFalse(self.lead.activity_ids) activity_message = self.lead.message_ids[0] - self.assertEqual(activity_message.needaction_partner_ids, self.crm_salemanager.partner_id, 'Only the crm manager should be notified by the activity') - self.assertEqual(self.lead.next_activity_id.id, False, 'When logging activity, the next activity planned is erased') + self.assertEqual(activity_message.needaction_partner_ids, self.crm_salemanager.partner_id) + self.assertEqual(activity_message.subtype_id, self.env.ref('mail.mt_activities')) def test_crm_activity_next_action(self): """ This test case set the next activity on a lead, log another, and schedule a third. """ # Add the next activity (like we set it from a form view) - self.lead.write({ - 'next_activity_id': self.activity1.id + lead_model_id = self.env['ir.model'].search([('model', '=', 'crm.lead')]).id + activity = self.env['mail.activity'].sudo(self.crm_salesman.id).create({ + 'activity_type_id': self.activity1.id, + 'summary': 'My Own Summary', + 'res_id': self.lead.id, + 'res_model_id': lead_model_id, }) - self.lead._onchange_next_activity_id() + activity._onchange_activity_type_id() # Check the next activity is correct - self.assertEqual(self.lead.title_action, self.activity1.description, 'Activity title should be the same on the lead and on the chosen activity') + self.assertEqual(self.lead.activity_summary, activity.summary) + self.assertEqual(self.lead.activity_type_id, activity.activity_type_id) + # self.assertEqual(fields.Datetime.from_string(self.lead.activity_date_deadline), datetime.now() + timedelta(days=activity.activity_type_id.days)) - # Instanciate the wizard to schedule the next activity - wizard = self.env['crm.activity.log'].sudo(self.crm_salesman.id).create({ + activity.write({ + 'activity_type_id': self.activity2.id, + 'summary': '', 'note': 'Content of the activity to log', - 'lead_id': self.lead.id, }) - wizard.onchange_lead_id() - wizard.write({ - 'next_activity_id': self.activity2.id, - }) - wizard.action_log() + activity._onchange_activity_type_id() + + self.assertEqual(self.lead.activity_summary, activity.activity_type_id.summary) + self.assertEqual(self.lead.activity_type_id, activity.activity_type_id) + # self.assertEqual(fields.Datetime.from_string(self.lead.activity_date_deadline), datetime.now() + timedelta(days=activity.activity_type_id.days)) + + activity.action_done() # Check the next activity on the lead has been removed - self.assertFalse(self.lead.next_activity_id.id, 'No next activity should be set on lead, since we jsut log another activity') - - # Instanciate the wizard to schedule the next activity - self.env['crm.activity.log'].sudo(self.crm_salesman.id).create({ - 'next_activity_id': self.activity3.id, - 'note': 'Content of the activity to log', - 'lead_id': self.lead.id, - }) - wizard.onchange_lead_id() - wizard.write({ - 'next_activity_id': self.activity3.id, - }) - wizard.onchange_next_activity_id() - wizard.action_schedule() - - # Check the activity is well scheldule on lead - delta_days = (fields.Date.from_string(self.lead.date_action) - date.today()).days - self.assertEqual(self.activity3.days, delta_days, 'The action date should be in the number of days set up on the activity 3') - self.assertEqual(self.lead.title_action, self.activity3.description, 'Activity title should be the same on the lead and on the activity 3') + self.assertFalse(self.lead.activity_type_id) diff --git a/addons/crm/views/crm_activity_views.xml b/addons/crm/views/crm_activity_views.xml deleted file mode 100644 index 0950ccec890..00000000000 --- a/addons/crm/views/crm_activity_views.xml +++ /dev/null @@ -1,67 +0,0 @@ - -Click to create a new activity.
-%s
' % log.title_action or '', - 'note': log.note or '', - } - log.lead_id.message_post(body_html, subject=log.title_action, subtype_id=log.next_activity_id.subtype_id.id) - log.lead_id.write({ - 'date_deadline': log.date_deadline, - 'planned_revenue': log.planned_revenue, - 'title_action': False, - 'date_action': False, - 'next_activity_id': False, - }) - return True - - @api.multi - def action_schedule(self): - for log in self: - log.lead_id.write({ - 'title_action': log.title_action, - 'date_action': log.date_action, - 'next_activity_id': log.next_activity_id.id, - }) - return True diff --git a/addons/crm/wizard/crm_activity_log_views.xml b/addons/crm/wizard/crm_activity_log_views.xml deleted file mode 100644 index 5de65762396..00000000000 --- a/addons/crm/wizard/crm_activity_log_views.xml +++ /dev/null @@ -1,85 +0,0 @@ - -%s
' % lead.title_action or '', - } - lead.message_post( - body=body_html, - subject=lead.title_action, - subtype="mail.mt_note") - lead.write({ + lead_values = { 'planned_revenue': values['planned_revenue'], 'probability': values['probability'], - 'next_activity_id': values['activity_id'], - 'title_action': values['title_action'], - 'date_action': values['date_action'] if values['date_action'] else False, 'priority': values['priority'], - 'date_deadline': values['date_deadline'] if values['date_deadline'] else False, - }) + } + # As activities may belong to several users, only the current portal user activity + # will be modified by the portal form. If no activity exist we create a new one instead + # that we assign to the portal user. + user_activity = lead.activity_ids.filtered(lambda activity: activity.user_id == self.env.user)[:1] + if user_activity: + user_activity.sudo().write({ + 'activity_type_id': values['activity_type_id'], + 'summary': values['activity_summary'], + 'date_deadline': values['activity_date_deadline'], + }) + else: + self.env['mail.activity'].sudo().create({ + 'res_model_id': self.env.ref('crm.model_crm_lead').id, + 'res_id': lead.id, + 'user_id': self.env.user.id, + 'activity_type_id': values['activity_type_id'], + 'summary': values['activity_summary'], + 'date_deadline': values['activity_date_deadline'], + }) + lead.write(lead_values) @api.model def create_opp_portal(self, values): @@ -276,4 +279,4 @@ class CrmLead(models.Model): lead.convert_opportunity(lead.partner_id.id) return { 'id': lead.id - } \ No newline at end of file + } diff --git a/addons/website_crm_partner_assign/security/ir.model.access.csv b/addons/website_crm_partner_assign/security/ir.model.access.csv index 476522c536e..fd1b860ebc5 100644 --- a/addons/website_crm_partner_assign/security/ir.model.access.csv +++ b/addons/website_crm_partner_assign/security/ir.model.access.csv @@ -13,5 +13,4 @@ partner_access_crm_lead,crm.lead,crm.model_crm_lead,base.group_portal,1,1,0,0 access_res_partner_grade_invoicing_payment,res.partner.grade,model_res_partner_grade,account.group_account_invoice,1,0,0,0 access_res_partner_grade_portal,res.partner.grade,model_res_partner_grade,base.group_portal,1,0,0,0 crm_lead_portal_access,crm.lead.portal,crm.model_crm_lead,base.group_portal,1,1,0,0 -crm_activity_portal_access,crm.activity.portal,crm.model_crm_activity,base.group_portal,1,1,1,0 mail_message_subtype_portal_access,mail.message.subtype.portal,mail.model_mail_message_subtype,base.group_portal,1,1,1,0 \ No newline at end of file diff --git a/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js b/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js index ab42dac9690..3357c9d9384 100644 --- a/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js +++ b/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js @@ -124,12 +124,11 @@ $('.edit_opp_confirm').on('click',function(){ $btn.prop('disabled', true); new Model('crm.lead') .call("update_lead_portal", [[parseInt($('.edit_opp_form .opportunity_id').val())],{ - activity_id: parseInt($('.edit_opp_form .next_activity').find(":selected").attr('data')), planned_revenue: parseFloat($('.edit_opp_form .planned_revenue').val()), probability: parseFloat($('.edit_opp_form .probability').val()), - date_deadline: $('.edit_opp_form .date_deadline').val(), - title_action: $('.edit_opp_form .title_action').val(), - date_action: $('.edit_opp_form .date_action').val(), + activity_type_id: parseInt($('.edit_opp_form .next_activity').find(":selected").attr('data')), + activity_summary: $('.edit_opp_form .activity_summary').val(), + activity_date_deadline: $('.edit_opp_form .activity_date_deadline').val(), priority: $('input[name="PriorityRadioOptions"]:checked').val(), }]) .fail(function() { @@ -143,14 +142,14 @@ $('.edit_opp_confirm').on('click',function(){ $('.edit_opp_form .next_activity').on('change', function(){ var selected = $('.edit_opp_form .next_activity').find(":selected"); - if(selected.attr('description')){ - $('.edit_opp_form .title_action').val(selected.attr('description')); + if(selected.attr('activity_summary')){ + $('.edit_opp_form .activity_summary').val(selected.attr('activity_summary')); } if(selected.attr('days')){ var date_now = moment(); var days = parseInt(selected.attr('days')); var date = date_now.add(days, 'days'); - $('.edit_opp_form .date_action').val(date.format('YYYY-MM-DD')); + $('.edit_opp_form .activity_date_deadline').val(date.format('YYYY-MM-DD')); } }); diff --git a/addons/website_crm_partner_assign/views/website_crm_partner_assign_templates.xml b/addons/website_crm_partner_assign/views/website_crm_partner_assign_templates.xml index 2fb4aea29b0..5195f4fae57 100644 --- a/addons/website_crm_partner_assign/views/website_crm_partner_assign_templates.xml +++ b/addons/website_crm_partner_assign/views/website_crm_partner_assign_templates.xml @@ -757,19 +757,19 @@