56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright 2017 Fabien Bourgeois <fabien@yaltik.com>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
""" CRM Lead adaptations """
|
|
|
|
from odoo import models, fields, api
|
|
|
|
|
|
class CrmLead(models.Model):
|
|
""" CRM Lead adaptations """
|
|
_inherit = 'crm.lead'
|
|
|
|
action_count = fields.Integer(compute='_compute_action_count')
|
|
action_ids = fields.One2many('crm.action', 'lead_id', string='Actions')
|
|
next_action_id = fields.Many2one('crm.action', string='Next Action',
|
|
compute='compute_next_action', store=True)
|
|
next_action_date = fields.Date(related='next_action_id.date', store=True)
|
|
next_action_title = fields.Char(related='next_action_id.display_name', store=True)
|
|
|
|
@api.multi
|
|
def _compute_action_count(self):
|
|
""" Count actions """
|
|
for lead in self:
|
|
lead.action_count = len(lead.action_ids)
|
|
|
|
@api.depends('action_ids.date', 'action_ids.display_name', 'action_ids.state')
|
|
def compute_next_action(self):
|
|
""" Computes next action """
|
|
for lead in self:
|
|
domain = ['&', ('lead_id', '=', lead.id), ('state', '=', 'draft')]
|
|
action = self.env['crm.action'].search(domain, order='date', limit=1)
|
|
lead.next_action_id = action or False
|
|
|
|
@api.multi
|
|
def next_action_done(self):
|
|
""" Mark next action as done """
|
|
self.ensure_one()
|
|
lead = self[0]
|
|
if lead.next_action_id:
|
|
lead.next_action_id.confirm()
|