[IMP]CRM Action : change date from date to datetime (handling data migration)

This commit is contained in:
Fabien BOURGEOIS 2017-10-29 10:12:22 +01:00
parent 7904c0f996
commit 98a83a2f6c
5 changed files with 58 additions and 5 deletions

View File

@ -18,7 +18,7 @@
{
'name': 'CRM Actions',
'summary': 'Action management, instead of new activity, in CRM',
'version': '10.0.1.0.0',
'version': '10.0.1.1.0',
'category': 'Sales',
'author': 'Fabien BOURGEOIS - Yaltik',
'license': 'AGPL-3',

View File

@ -0,0 +1,27 @@
# -*- 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/>.
""" Migration script """
from openupgradelib import openupgrade
@openupgrade.migrate(use_env=True)
def migrate(env, version):
""" Migration function : migrate Date date to datetime """
openupgrade.date_to_datetime_tz(env.cr, 'crm_action', 'user_id',
'date_bak', 'date')
openupgrade.drop_columns(env.cr, [('crm_action', 'date_bak')])

View File

@ -0,0 +1,25 @@
# -*- 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/>.
""" Migration script """
from openupgradelib import openupgrade
@openupgrade.migrate()
def migrate(env, version):
""" Migration function : copy old Date date to legacy column """
openupgrade.copy_columns(env.cr, {'crm_action': [('date', 'date_bak', None)]})

View File

@ -39,12 +39,13 @@ class CrmAction(models.Model):
details = fields.Text()
partner_id = fields.Many2one('res.partner', string='Customer', index=True)
date = fields.Date('Date', required=True, default=fields.Date.context_today)
date = fields.Datetime('Date', required=True, default=fields.Date.context_today)
user_id = fields.Many2one('res.users', string='User', required=True,
default=lambda self: self.env.user)
lead_id = fields.Many2one('crm.lead', string='Lead', ondelete='cascade')
event_id = fields.Many2one('calendar.event', 'Calendar event', ondelete='cascade')
action_type_id = fields.Many2one('crm.action.type', string='Type', required=True,
action_type_id = fields.Many2one(
'crm.action.type', string='Type', required=True,
default=lambda self: self.env['crm.action.type'].search([], limit=1))
action_type_name = fields.Char(related='action_type_id.name')

View File

@ -29,7 +29,7 @@ class CrmLead(models.Model):
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_date = fields.Datetime(related='next_action_id.date', store=True)
next_action_title = fields.Char(related='next_action_id.display_name', store=True)
@api.multi