diff options
| author | Ravi Gadhia <rga@odoo.com> | 2016-11-21 11:33:02 +0100 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2016-12-21 10:58:49 +0100 |
| commit | 87e457158e83295a17761a1ea0d251ba87472596 (patch) | |
| tree | 6d0e9c8bb03dad25c571d0c0178902fafa1ab943 /addons/website_crm_partner_assign/models | |
| parent | 4aa3f3f94eb094e18d7b381e0d0cdff0cc10ffb9 (diff) | |
[IMP] crm, website_crm: replace support of activities
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.
Diffstat (limited to 'addons/website_crm_partner_assign/models')
| -rw-r--r-- | addons/website_crm_partner_assign/models/crm_lead.py | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/addons/website_crm_partner_assign/models/crm_lead.py b/addons/website_crm_partner_assign/models/crm_lead.py index 0689d809053..95cf731c869 100644 --- a/addons/website_crm_partner_assign/models/crm_lead.py +++ b/addons/website_crm_partner_assign/models/crm_lead.py @@ -226,30 +226,33 @@ class CrmLead(models.Model): @api.multi def update_lead_portal(self, values): self.check_access_rights('write') + for lead in self: - if values['date_action'] == '': - values['date_action'] = False - if lead.next_activity_id.id != values['activity_id'] or lead.title_action != values['title_action']\ - or lead.date_action != values['date_action']: - activity = lead.sudo().next_activity_id - body_html = "<div><b>%(title)s</b>: %(next_activity)s</div>%(description)s" % { - 'title': _('Activity Done'), - 'next_activity': activity.name, - 'description': lead.title_action and '<p><em>%s</em></p>' % 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 + } |
